2017-02-21 09:31:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$url = 'http://@concordia_host@:@concordia_port@';
|
2017-02-21 12:55:08 +01:00
|
|
|
$inputSentence = $_GET["pattern"];
|
2017-02-22 10:29:15 +01:00
|
|
|
$tmId = intval($_GET["tmId"]);
|
|
|
|
$data = array("operation" => "concordiaSearch","tmId" => $tmId,"pattern" => $inputSentence);
|
2017-02-21 09:31:48 +01:00
|
|
|
|
|
|
|
// use key 'http' even if you send the request to https://...
|
|
|
|
$options = array(
|
|
|
|
'http' => array(
|
|
|
|
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
|
|
|
|
'method' => 'POST',
|
|
|
|
'content' => json_encode($data),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$context = stream_context_create($options);
|
2017-02-21 11:57:52 +01:00
|
|
|
$response = file_get_contents($url, false, $context);
|
2017-02-21 09:31:48 +01:00
|
|
|
|
2017-02-21 11:57:52 +01:00
|
|
|
$data = json_decode($response);
|
2017-02-22 10:29:15 +01:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
2017-02-21 09:31:48 +01:00
|
|
|
?>
|
2017-02-21 11:51:47 +01:00
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<script src="js/jquery-1.11.3.min.js"></script>
|
|
|
|
<script src="js/cat.js"></script>
|
2017-02-22 10:29:15 +01:00
|
|
|
<link rel="stylesheet" href="css/concordia_cat.css" />
|
2017-02-21 11:51:47 +01:00
|
|
|
<meta charset="UTF-8">
|
|
|
|
</head>
|
2017-02-21 11:57:52 +01:00
|
|
|
<body>
|
2017-02-22 10:29:15 +01:00
|
|
|
<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>
|
|
|
|
|
2017-02-21 12:00:15 +01:00
|
|
|
<div id="header">
|
|
|
|
</div>
|
|
|
|
<div id="content">
|
2017-02-22 10:29:15 +01:00
|
|
|
<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"/>
|
|
|
|
|
2017-02-21 12:00:15 +01:00
|
|
|
<div id="result">
|
2017-02-21 12:07:01 +01:00
|
|
|
<div id="result-score">Concordia score: <b><?= round($data->result->bestOverlayScore*100) ?>%</b></div>
|
2017-02-22 10:29:15 +01:00
|
|
|
<div id="result-sentence"><?php
|
2017-02-21 11:57:52 +01:00
|
|
|
|
2017-02-22 10:29:15 +01:00
|
|
|
$lastInsertedEnd = 0;
|
2017-02-21 12:43:05 +01:00
|
|
|
|
2017-02-22 10:29:15 +01:00
|
|
|
for($i=0; $i<count($data->result->bestOverlay);$i++) {
|
|
|
|
$fragment = $data->result->bestOverlay[$i];
|
|
|
|
//previous unmarked fragment
|
|
|
|
echo sub($inputSentence,$lastInsertedEnd, $fragment->matchedPatternStart);
|
|
|
|
//the marked fragment
|
|
|
|
?><span onclick="displayDetails(this, <?= $i ?>)" class="matchedFragment"><?= sub($inputSentence,$fragment->matchedPatternStart, $fragment->matchedPatternEnd) ?></span><?php
|
|
|
|
$lastInsertedEnd = $fragment->matchedPatternEnd;
|
|
|
|
//fragments += renderFragment(fragment, i);
|
|
|
|
}
|
|
|
|
//remaining unmarked fragment
|
|
|
|
echo sub($inputSentence, $lastInsertedEnd);
|
|
|
|
?></div>
|
2017-02-21 12:39:22 +01:00
|
|
|
<br/><br/><br/>
|
2017-02-22 10:29:15 +01:00
|
|
|
<?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
|
|
|
|
}
|
|
|
|
?>
|
2017-02-21 12:00:15 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-21 11:51:47 +01:00
|
|
|
</body>
|
|
|
|
</html>
|