concordia-server/cat/concordia_search.php_pattern

129 lines
5.7 KiB
Plaintext
Raw Permalink Normal View History

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"]);
2017-02-21 09:31:48 +01:00
2017-02-22 11:22:20 +01:00
if (!empty($inputSentence)) {
$request = array("operation" => "concordiaSearch","tmId" => $tmId,"pattern" => $inputSentence);
2017-02-21 09:31:48 +01:00
2017-02-22 11:22:20 +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($request),
),
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$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"/>
<img style="cursor:pointer" src="images/help.png" alt="help" onclick="toggleHelp()" title="show/hide help"/>
<div id="help" class="hidden">
Welcome to the search window of Concordia Desktop. When Concordia Desktop is running in the tray, select a portion of text no longer than 500 characters (e.g. a sentence) from any application and press ctrl+q. This will search the selected text in Concordia and open your browser on Concordia search results (that is - this page). You can also press ctrl+w to select all the text in your application and search for it. After searching in Concordia, the text you selected remains in the clipboard, ready to be pasted into any other searcher.
</div>
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>