-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·167 lines (150 loc) · 5.26 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/*
tableau
select avec tous les fichiers du corpus
*/
set_time_limit('120');
ini_set('memory_limit', '512M');
include("functions.php");
include("db.php");
$db = connect();
if(isset($_GET["h"])){
echo '<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>'.$_GET["h"].'</title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<div class="occ-list"><p>Cliquer sur une occurrence pour voir le contexte</p>';
$occurrences = get_occurrences($_GET["h"], $db);
echo '<h1>'.$_GET["h"].'</h1>';
echo '<h2>'.count($occurrences).' occurrences</h2>';
echo '<ul>';
foreach($occurrences as $occurrence){
echo '<li><a target="_blank" href="http://www.theatre-classique.fr/pages/programmes/edition.php?t=../documents/'.strtoupper($occurrence["play"]).'.xml#A'.$occurrence["act_n"].'.S'.$occurrence["act_n"].$occurrence["scene_n"].'">'.$occurrence["author"].', <i>'.$occurrence["title"].'</i> ('.$occurrence["genre"].', '.$occurrence["created"].'), '.roman($occurrence["act_n"]).', '.$occurrence["scene_n"];
if($occurrence["line"]!=""){echo ', v. '.$occurrence["line_n"].' : '.$occurrence["line"];}
echo '</a></li>';
}
echo '</ul>';
echo '</div></body></html>';
return;
}
// var_dump($_POST["post"]);
if(!isset($_POST["text"])){
include("form.php");
return;
}
echo '<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Détection des hémistiches formulaires</title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<div class="result"><p>Cliquer sur un hémistiche pour afficher toutes les occurrences</p><br/><br/>';
$diereses = file_get_contents("dierese.csv");
$diereses = explode("\n", $diereses);
foreach ($diereses as $dierese) {
$dierese = explode("\t", $dierese);
$search[] = $dierese[1];
$replace[] = $dierese[0];
}
// $file = "../tcp5t/corneillep_cinna.txt";
// $text = file_get_contents($file);
if($_POST["corpus"] == "") {
$text = $_POST["text"];
}else{
$text = select("SELECT text FROM plays WHERE play = '".$_POST["corpus"]."'", $db);
$text = $text["text"];
}
$text = str_replace("\r", "\n", $text);
$verses = explode("\n", $text);
foreach ($verses as $verse) {
echo "<p>";
$verse = preg_replace($search, $replace, $verse);
$verse = preg_replace("#qu(?=[aeiouyæàâäéèêëîïœôöùûü])#ui", "$", $verse);
$verse = preg_replace("#gu(?=[aeiouyæàâäéèêëîïœôöùûü])#ui", "@", $verse);
preg_match_all("#eau|oeu|œu|oui|oei|œi|aie|aou|uie|eui|iai|oue|oie|oè|eh|ai|aî|au|oi|oî|ou|où|oû|ei|eu|ieau|ioeu|ia|iaî|iau|ioi|iou|ioù|iei|ieu|ïeu|ia|ie|ée|ié|iè|iê|io|iu|ui|uei|ue|ïe|ïu|(?<![qg])u|(?<=[g])u(?![aeioyæàâäéèêëîïœôöùûü])|[aioæàâäéèêëîïœôöùûü]|(?<![aeioæàâäéèêëîïœôöùûü])y(?![aeioæàâäéèêëîïœôöùûü])|e(?!([ ,.…«»\)\(\-\":;!|)\?\n]*([\nhaeiouyæàâäéèêëîïœôöùûü]|$)|(s[ ,.…:;!«»\)\(\"\?\n]*$)|(nt[ ,.…:;«»!\"\)\(\?\n]*$)))#ui", $verse, $matches, PREG_OFFSET_CAPTURE);
$count = count($matches[0]);
if ($count == 12) {
$cesura = strrpos(substr($verse, $matches[0][5][1], $matches[0][6][1] - $matches[0][5][1]) , " ");
if ($cesura) {
$hemistich = substr($verse, 0, $matches[0][5][1] + $cesura);
// echo "<br/>".$hemistich."<br/>";
echo display($hemistich, $db, 1);
echo " ";
$hemistich = substr($verse, $matches[0][5][1] + $cesura + 1);
// echo "<br/>".$hemistich."<br/>";
echo display($hemistich, $db, 2);
}else{
echo remove_dieresis($verse, 1);
// echo "<pre>";print_r($matches);echo "</pre>";
}
} elseif ($count == 6) {
echo display($verse, $db, 1);
} else{
echo remove_dieresis($verse, 1);
// echo "<pre>";print_r($matches);echo "</pre>";
}
echo "</p>";
}
echo '</div></body></html>';
function display($hemistich, $db, $position){
$hemistich = remove_dieresis($hemistich, $position);
$count = occurrences($hemistich, $db);
// $hemistich = str_replace("'", , $subject [, &$replace_count])
//fffff = 1
//ff0000 > 20
//ff888 < 20
// $count = 255-((255*$count)/119);
if($count <= 1){
return "<a>".$hemistich."</a>";
}
else {
$color = 210-((255*$count)/119);
return '<a target="_blank" href="index.php?h='.$hemistich.'" title="'.$count.' occurrences" style="background-color:rgb(255,'.$color.','.$color.');">'.$hemistich.'</a>';
}
// else{
// //2 = 9999
// //3 = 8888
// //0000 > 20
// $count = 10000-min(($count*1000), 10000);
// $count = "ff".sprintf('%04d', $count);;
// }
}
function occurrences($string, $db){
$string = clean($string);
$string = str_replace("’", "'", $string);
$string = str_replace("'", "''", $string);
$sql = "SELECT c as count FROM hc WHERE graph = '".$string."'";
$count = select($sql, $db);
return $count["count"];
}
function remove_dieresis($string, $position) {
//nettoie l'hémistiche pour affichage
$string = str_replace(array(
"#",
"@",
"$"
) , array(
"",
"gu",
"qu"
) , $string);
if($position == 1){
$string = ucfirst($string);
}
return $string;
}
function get_occurrences($h, $db){
$h = clean($h);
$h = str_replace("’", "'", $h);
$h = str_replace("'", "''", $h);
$sql = "SELECT play, author, title, genre, created, act_n, scene_n, line_n, line FROM patterns where graph = '".$h."'";
$results = mselect($sql, $db);
return $results;
}
?>