Commit db694ac3 authored by Pierric0790's avatar Pierric0790
Browse files

Add Page

parent 14a06394
This diff is collapsed.
This diff is collapsed.
<?php
include('../init.php');
putenv('LC_ALL='.$locale);
$online = true;
$title = array (
'eng' => 'French-Latin active reading',
'fra' => 'Lecture active latin-français',
);
$h1Message = array (
'eng' => 'Active Reading: adding translations to texts',
'fra' => 'Lecture active : ajout de traductions aux textes',
);
$legendMessage = array (
'eng' => 'Enter Latin text',
'fra' => 'Saisissez un texte en latin',
);
$submitMessage = array (
'eng' => 'Add translations',
'fra' => 'Ajouter traductions',
);
$displayTranslationsMessage = array (
'eng' => 'Note: hover over a word to display its translation.',
'fra' => 'Note : passez la souris sur un mot pour afficher ses traductions.',
);
$langNames = array (
'eng' => array( 'eng' => 'English', 'fra' => 'French'),
'fra' => array( 'eng' => 'anglais', 'fra' => 'français'),
);
$treeTagger = '/home/getalp/mangeot/Logiciels/uplug/uplug-treetagger/blib/lib/auto/share/dist/Uplug/ext/tree-tagger/cmd/tree-tagger-latin';
//$treeTagger = "$treeTagger/cmd/utf8-tokenize.perl -e -a $treeTagger/lib/french-abbreviations-utf8 | $treeTagger/bin/tree-tagger $treeTagger/lib/french-utf8.par -token -lemma -sgml -no-unknown";
$tagger = $treeTagger;
$api = 'http://papillon.imag.fr/papillon/api/';
$dict = 'Gaffiot';
$langtext = 'lat';
$cdm_query_key = 'cdm-headword';
$cdm_query_array = array('cdm-translation','cdm-contribution-id'); // add queries here
$strategy = '?strategy=EQUAL';
$cdm_query_result = implode('|', $cdm_query_array);
$startApiURL = $api . $dict . '/' . $langtext . '/' . $cdm_query_key . '/';
$endApiURL = '/' . $cdm_query_result . '/' . $strategy;
function pipe_exec($command, $input) {
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w")
);
$process = proc_open($command, $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $input);
fclose($pipes[0]);
$result = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
}
return $result;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$resultArray = array();
$lemmasArray = array();
$traductions = array();
if (!empty($_REQUEST['text'])) {
$text = $_REQUEST['text'];
$text = preg_replace('/\R?$/','',$text);
$text = preg_replace('/\R/','<br/>',$text);
$text = preg_replace('/"/','\\"',$text);
echo "commande : <br/>echo '$text' | $tagger\n<br/><br/>";
// bouchon
if ($online) {
$taggerResult = pipe_exec($tagger, $text);
$taggerResult = `echo '$text' | $tagger`;
} else {
$taggerResult = "\treading parameters ...\n\ttagging ...\nSed\tCC\tsed\nueteris\tADJ\tveter|vetus\npopuli\tN:gen\tpopulus\nRomani\tADJ\tromanus\nprospera\tADJ\tprosper|prosperus\nuel\tCC\tvel\naduersa\tADJ\tadversus\nclaris\tADJ:abl\tclarus\nscriptoribus\tN:abl\tscriptor\nmemorata\tV:PTC:nom\tmemoro\nsunt\tESSE:IND\tsum\n.\tSENT\t.\n\tfinished.\n";
}
$taggerResult = preg_replace('/\s+$/', '',$taggerResult);
echo "tagger result:<br/> [$taggerResult]<br/><br/>";
$taggerResultArray = preg_split ('/$\R?^/m', $taggerResult); // $taggerResultArray : ['\treading parameters ...' | '\ttagging ...' | 'Sed\tCC\tsed' | 'ueteris\tADJ\tveter|vetus' | 'populi\tN:gen\tpopulus' | 'Romani\tADJ\tromanus' | 'prospera\tADJ\tprosper|prosperus' | 'uel\tCC\tvel' | 'aduersa\tADJ\tadversus' | 'claris\tADJ:abl\tclarus' | 'scriptoribus\tN:abl\tscriptor' | 'memorata\tV:PTC:nom\tmemoro' | 'sunt\tESSE:IND\tsum' | '.\tSENT\t.' | '\tfinished.' | '']
foreach ($taggerResultArray as $taggerLine) {
$taggerLineArray = preg_split ('/\t/m', $taggerLine); // 'Sed\tCC\tsed' => ['Sed' | 'CC' | 'sed']
$result = $taggerLineArray[0];
$pos = '';
$lemma = '';
if (preg_match('/^\tfinished.$/',$result)) $result = '<br/>'; // $taggerResultArray[-1]
else if (empty($result)) continue; // $taggerResultArray[0] et [1]
else {
$pos = $taggerLineArray[1];
$lemma = $taggerLineArray[2];
$lemmaList = preg_split ('/\|/m', $lemma); // ex. for ['belli' ; 'N:gen' ; 'bellis|bellum'] : 'bellis|bellum' => [bellis ; bellum]
//echo "($result)($lemma)($pos)<br/>";
foreach ($lemmaList as $l)
if (!in_array($l, $lemmasArray) && $pos != 'SENT' && $pos != 'PUN' && $pos != 'ADJ:NUM')
$lemmasArray[] = $l;
}
$resultLineArray = array($result, $pos, $lemmaList);
array_push($resultArray,$resultLineArray);
}
echo "<br/>resultArray: <br/>";
foreach ($resultArray as $index => $resArr) {
echo "$index => [ ", $resArr[0], " | ", $resArr[1], " | ", implode(';',$resArr[2]), " ]<br/>";
}
echo "<br/>";
$lemmasString = implode('|',$lemmasArray);
// TO EDIT
$url = $startApiURL . $lemmasString . $endApiURL;
echo 'URL lem: ',$url,'<br/>';
curl_setopt($ch, CURLOPT_URL, $url); // get the url contents
$data = curl_exec($ch); // execute curl request
$xml = simplexml_load_string($data);
//print_r ($xml);
$xml->registerXPathNamespace('d', 'http://www-clips.imag.fr/geta/services/dml');
foreach ($xml->xpath('/d:entry-list/d:entry') as $entry) {
$lemma = (string) $entry->xpath('./d:criteria/text()')[0];
$tradList = array();
foreach ($entry->xpath('.//text()') as $text){
$tradList[] = $text;
//echo "$text<br/>";
}
if (count($tradList)>0)
$traductions[$lemma] = $tradList;
echo implode(' ; ', $tradList), "<br/>";
}
curl_close($ch);
// END EDIT
}
?><!DOCTYPE html>
<html xmlns:og="http://ogp.me/ns#" lang="<?php echo $locale;?>" xml:lang="<?php echo $locale;?>">
<head>
<?php include(SITE_PATH.'includes/head_'.$LANG.'.php');?>
<title><?php echo $title[$LANG];?></title>
<script type="text/javascript">
<!--
function showhidetranscription(lang) {
if (lang == 'jpn') {
document.getElementById('transcriptionSelect').setAttribute('style','display:inline;');
}
else {
document.getElementById('transcriptionSelect').setAttribute('style','display:none;');
}
}
// -->
</script>
<style type="text/css">
<!--
#BannerContent {
text-align:center;
display: block;
}
#textform form {
text-align:center;
padding:10px;
margin:10px;
}
#textform fieldset {
margin: auto; 
padding: 1em;
}
#textform legend {
padding: 1em;
}
.explication {
padding: 20px;
margin: 20px;
}
section#furigana {
border: 1px solid grey;
padding: 20px;
margin: 20px;
font-size: 150%;
}
.prefooter {
padding-bottom: 45px;
}
.translation {
border: 1px solid grey;
border-radius: 4px;
margin-top: 40px;
margin-left: -10px;
background-color:rgb(242, 242, 242);
position:absolute;
display:none;
font-size:.8em;
padding: 4px;
}
rt {
color: #245F1C;
font-size:70%;
}
// -->
</style>
</head>
<body>
<header>
<!-- <?php include(SITE_PATH.'includes/headerMenu.php');?> -->
<div id="BannerContent">
<h1><?php echo $h1Message[$LANG];?></h1>
</div>
</header>
<section id="textform">
<form action="?" method="post">
<fieldset>
<legend><?php echo $legendMessage[$LANG];?></legend>
<div style="padding: 1em;">
<textarea name="text" cols="60" rows="15" style="font-size: 120%"><?php if (!empty($_REQUEST['text'])) {echo $_REQUEST['text'];}?></textarea>
<br/>
<input type="submit" name="submit" value="<?php echo $submitMessage[$LANG];?>"/>
</div>
</fieldset>
</form>
</section>
<p class="explication"><?php echo $displayTranslationsMessage[$LANG];?></p>
<section id="furigana"><?php
foreach ($resultArray as $resultLine) {
$word = $resultLine[0];
$lemmaList = $resultLine[2];
$color = 'blue';
$result = $word;
$messageList = array();
foreach ($lemmaList as $lemma){
if (isset($traductions[$lemma])){
$tradString = implode('; ',$traductions[$lemma]);
$messageList[] = $tradString;
}
}
if (count($messageList)>0){
$message = implode('<br/>',$messageList);
$result = '<span onmouseover="this.getElementsByTagName(\'span\')[0].style.display=\'inline\'" onmouseout="this.getElementsByTagName(\'span\')[0].style.display=\'none\'" ><span class="translation" style="color: '.$color.'; ">'.$message.'</span>'.$result.'</span>';
}
if ($result != '.' && $result != ',' && $result != ';') {
echo ' ';
}
echo $result;
}
?></section>
<p class="prefooter"><!-- // --></p>
<!-- <?php include(SITE_PATH.'includes/footer_'.$LANG.'.php');?> -->
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment