new concordia cat

This commit is contained in:
Rafał Jaworski 2017-02-22 10:29:15 +01:00
parent 41f96c5ad9
commit dff6e2f15c
4 changed files with 114 additions and 46 deletions

View File

@ -2,7 +2,8 @@
$url = 'http://@concordia_host@:@concordia_port@'; $url = 'http://@concordia_host@:@concordia_port@';
$inputSentence = $_GET["pattern"]; $inputSentence = $_GET["pattern"];
$data = array("operation" => "concordiaSearch","tmId" => intval($_GET["tmId"]),"pattern" => $inputSentence); $tmId = intval($_GET["tmId"]);
$data = array("operation" => "concordiaSearch","tmId" => $tmId,"pattern" => $inputSentence);
// use key 'http' even if you send the request to https://... // use key 'http' even if you send the request to https://...
$options = array( $options = array(
@ -16,46 +17,104 @@ $context = stream_context_create($options);
$response = file_get_contents($url, false, $context); $response = file_get_contents($url, false, $context);
$data = json_decode($response); $data = json_decode($response);
function sub($string, $start, $end = null) {
if (is_null($end)) {
return mb_substr($string, $start, null, 'UTF-8');
} else {
return mb_substr($string, $start, $end-$start, 'UTF-8');
}
}
?> ?>
<html> <html>
<head> <head>
<script src="js/jquery-1.11.3.min.js"></script> <script src="js/jquery-1.11.3.min.js"></script>
<script src="js/cat.js"></script> <script src="js/cat.js"></script>
<link rel="stylesheet" href="css/iatagger.css" /> <link rel="stylesheet" href="css/concordia_cat.css" />
<meta charset="UTF-8"> <meta charset="UTF-8">
</head> </head>
<body> <body>
<script>
var concordiaUrl = 'http://@concordia_host@:@concordia_port@';
var currentTmId = <?= $tmId ?>;
var disablePhraseSearch = true;
$(document).ready(function() {
$('#search-input').bind("enterKey",function(e){
searchHandle(currentTmId);
});
$('#search-input').keyup(function(e){
if(e.keyCode == 13) {
$(this).trigger("enterKey");
}
});
});
</script>
<div id="header"> <div id="header">
</div> </div>
<div id="content"> <div id="content">
<input id="search-input" type="text" value="<?= $inputSentence ?>" />
<img id="search-icon" src="images/search.png" alt="search" onclick="searchHandle(currentTmId)" title="search"/>
<img id="clear-icon" src="images/reset.png" alt="clear" onclick="$('#search-input').val('')" title="clear search field"/>
<div id="result"> <div id="result">
<div id="result-score">Concordia score: <b><?= round($data->result->bestOverlayScore*100) ?>%</b></div> <div id="result-score">Concordia score: <b><?= round($data->result->bestOverlayScore*100) ?>%</b></div>
<?php <div id="result-sentence"><?php
$markedSentence = ""; $lastInsertedEnd = 0;
$fragments = array();
$lastInsertedEnd = 0;
for($i=0; $i<count($data->result->bestOverlay);$i++) { for($i=0; $i<count($data->result->bestOverlay);$i++) {
$fragment = $data->result->bestOverlay[i]; $fragment = $data->result->bestOverlay[$i];
//previous unmarked fragment //previous unmarked fragment
$markedSentence += substr($inputSentence,$lastInsertedEnd, $fragment->matchedPatternStart - $lastInsertedEnd); echo sub($inputSentence,$lastInsertedEnd, $fragment->matchedPatternStart);
//the marked fragment
//the marked fragment ?><span onclick="displayDetails(this, <?= $i ?>)" class="matchedFragment"><?= sub($inputSentence,$fragment->matchedPatternStart, $fragment->matchedPatternEnd) ?></span><?php
$markedSentence += '<span onclick="displayDetails(this, '+i+')" class="matchedFragment">'+substr($inputSentence,$fragment->matchedPatternStart, $fragment->matchedPatternEnd - $fragment->matchedPatternStart)+'</span>'; $lastInsertedEnd = $fragment->matchedPatternEnd;
//fragments += renderFragment(fragment, i);
$lastInsertedEnd = $fragment->matchedPatternEnd; }
//remaining unmarked fragment
//fragments += renderFragment(fragment, i); echo sub($inputSentence, $lastInsertedEnd);
?></div>
}
//remaining unmarked fragment
$markedSentence += substr($inputSentence, $lastInsertedEnd);
?>
<div id="result-sentence"><?=$inputSentence ?><?=$markedSentence ?></div>
<br/><br/><br/> <br/><br/><br/>
<?php
$i=0;
foreach ($data->result->bestOverlay as $fragment) {
?>
<div style="display:none" id="fragment<?= $i ?>" class="fragmentDetails">
<table>
<tr>
<td><!-- source segment --->
<?= sub($fragment->sourceSegment, 0, $fragment->matchedExampleStart) ?>
<span class="matchedFragment"><?= sub($fragment->sourceSegment, $fragment->matchedExampleStart, $fragment->matchedExampleEnd) ?></span>
<?= sub($fragment->sourceSegment, $fragment->matchedExampleEnd)?>
</td>
</tr>
<tr>
<td>
<?php
$currStart = 0;
foreach ($fragment->targetFragments as $targetFragment) {
?>
<?= sub($fragment->targetSegment, $currStart, $targetFragment[0]); ?>
<span class="matchedFragment"><?= sub($fragment->targetSegment, $targetFragment[0], $targetFragment[1]); ?></span>
<?php
$currStart = $targetFragment[1];
}
echo sub($fragment->targetSegment, $currStart);
?>
</td>
</tr>
</table>
<?php
$i++;
?>
</div>
<?php
}
?>
</div> </div>
</div> </div>
</body> </body>

View File

@ -56,6 +56,10 @@
cursor:pointer; cursor:pointer;
} }
#clear-icon {
cursor:pointer;
}
#help-icon { #help-icon {
margin-left:20px; margin-left:20px;
@ -173,9 +177,9 @@
#result-sentence { #result-sentence {
text-align:center; text-align:left;
font-size:24px; font-size:16px;
white-space:pre; line-height: 40px;
} }
/** General Style Info **/ /** General Style Info **/

View File

@ -2,7 +2,7 @@
<head> <head>
<script src="../js/jquery-1.11.3.min.js"></script> <script src="../js/jquery-1.11.3.min.js"></script>
<script src="../js/cat.js"></script> <script src="../js/cat.js"></script>
<link rel="stylesheet" href="../css/iatagger.css" /> <link rel="stylesheet" href="../css/concordia_cat.css" />
<meta charset="UTF-8"> <meta charset="UTF-8">
</head> </head>
<body> <body>

View File

@ -54,7 +54,12 @@ function renderResult(data) {
var score = data['result']['bestOverlayScore']*100; var score = data['result']['bestOverlayScore']*100;
res += '<div id="result-score">Concordia score: <b>'+score.toFixed(0)+'%</b></div>'; res += '<div id="result-score">Concordia score: <b>'+score.toFixed(0)+'%</b></div>';
} }
res += '<div id="phrase-selection">Phrase search mode:&nbsp;<img id="phrase-off-icon" src="../images/switchOff.png" alt="enter phrase search mode" onclick="togglePhraseSearchMode()" title="search for phrases"/><img class="hidden" id="phrase-on-icon" src="../images/switchOn.png" alt="cancel phrase search" onclick="togglePhraseSearchMode()" title="cancel phrase search"/><span id="phrase-prompt" class="hidden">Select continuous phrase: </span></div>';
if (typeof disablePhraseSearch !== 'undefined') {
// ignore
} else {
res += '<div id="phrase-selection">Phrase search mode:&nbsp;<img id="phrase-off-icon" src="../images/switchOff.png" alt="enter phrase search mode" onclick="togglePhraseSearchMode()" title="search for phrases"/><img class="hidden" id="phrase-on-icon" src="../images/switchOn.png" alt="cancel phrase search" onclick="togglePhraseSearchMode()" title="cancel phrase search"/><span id="phrase-prompt" class="hidden">Select continuous phrase: </span></div>';
}
var inputSentence = $('#search-input').val(); var inputSentence = $('#search-input').val();
var markedSentence = ''; var markedSentence = '';