11
15 deuxieme=$2;
16 troisieme=$3;
17
19
20 ecriture_entete_html () {
21 echo "<html>" > $deuxieme ;
22 echo "<head><title>PREMIERE PAGE</title>
23 <meta charset=\"UTF-8\" /></head>" >> $deuxieme ;
24 echo "<body>" >> $deuxieme ;
25 }
26 ecriture_fin_html () {
27 echo "</body>" >> $deuxieme ;
28 echo "</html>" >> $deuxieme ;
29 }
31 ecriture_tableau_debut () {
32 echo "<table align=\"center\" border=\"1\">" >> $deuxieme ;
33 echo "<caption align=\"center\">TABLEAU N°$compteurtableau</caption>
34 <thead><tr bgcolor=\"pink\">
35 <th>N°</th>
36 <th>Code Http</th>
37 <th>URL</th>
38 <th>Page Aspirée</th>
39 <th>Encodage Entrée</th>
40 <th>Encodage Sortie</th>
41 <th>Dump</th>
42 <th>Contexte</th>
43 <th>Contexte HTML</th>
44 <th>Fq Motif</th>
45 <th>Index</th>
46 <th>Bigramme</th>
47 <th>Trigramme</th>
48 </tr></thead>" >> $deuxieme ;
49 }
51 ecriture_tableau_normal () {
57 echo "<tr>
58 <td>$compteur</td>
59 <td>$code_sortie</td>
60 <td><a target=\"_blank\" href=\"$ligne\">Lien n°$compteur</a></td>
61 <td><a target=\"_blank\" href=\"../PAGES-ASPIREES/$3/$compteurtableau-$compteur.html\">Page aspirée n° $compteur</a></td>
62 <td>$1</td>
63 <td>$2</td>
64 <td><a target=\"_blank\" href=\"../DUMP-TEXT/$3/$compteurtableau-$compteur$4.txt\">DUMP n° $compteur</a></td>
65 <td><a target=\"_blank\" href=\"../CONTEXTES/$3/$compteurtableau-$compteur-contexte.txt\">CT $compteurtableau-$compteur</a></td>
66 <td><a target=\"_blank\" href=\"../CONTEXTES/$3/$compteurtableau-$compteur.html\">CTh $compteurtableau-$compteur</a></td>
67 <td>$nbmotif</td>
68 <td><a target=\"_blank\" href=\"../DUMP-TEXT/$3/index-$compteurtableau-$compteur.txt\">Ind $compteurtableau-$compteur</a></td>
69 <td><a target=\"_blank\" href=\"../DUMP-TEXT/$3/bigramme-$compteurtableau-$compteur.txt\">Bigr $compteurtableau-$compteur</a></td>
70 <td><a target=\"_blank\" href=\"../DUMP-TEXT/$3/trigramme-$compteurtableau-$compteur.txt\">Trigr $compteurtableau-$compteur</a></td>
71 </tr>" >> $deuxieme ;
72 }
73 ecriture_tableau_pb_encodage () {
75 echo "<tr>
76 <td>$compteur</td>
77 <td>$code_sortie</td>
78 <td><a target=\"_blank\" href=\"$ligne\">Lien n°$compteur</a></td>
79 <td>-</td>
80 <td>$ENCODAGE</td>
81 <td>NON CONFORME<br>($ENCODAGEFILE)</td>
82 <td>-</td>
83 <td>-</td>
84 <td>-</td>
85 <td>-</td>
86 <td>-</td>
87 <td>-</td>
88 <td>-</td>
89 </tr>" >> $deuxieme ;
90 }
91 ecriture_tableau_noResult () {
93 echo "<tr>
94 <td>$compteur</td>
95 <td><font color=\"red\"><b>$code_sortie</b></td>
96 <td><a target=\"_blank\" href=\"$ligne\">Lien n°$compteur</a></td>
97 <td>-</td>
98 <td>-</td>
99 <td>-</td>
100 <td>-</td>
101 <td>-</td>
102 <td>-</td>
103 <td>-</td>
104 <td>-</td>
105 <td>-</td>
106 <td>-</td>
107 </tr>" >> $deuxieme ;
108 }
109 ecriture_tableau_fin () {
111 echo "</table>" >> $deuxieme ;
112 echo "<hr color=\"pink\"/>" >> $deuxieme ;
113 }
114
116 msg_initial_OK () {
117 echo -e "ENCODAGE initial <$ENCODAGE> OK : on passe au traitement \n";
118 }
119 msg_traiter_non_UTF8 () {
120 echo -e "==> il faut traiter les URLs OK qui ne sont pas a priori en UTF8\n" ;
121 }
122 msg_apres_extraction () {
123 echo -e "ENCODAGE initial vide. ENCODAGE extrait via file : <$ENCODAGEFILE> \n";
124 echo -e "Il faut désormais s'assurer que cet encodage peut être OK ou pas... \n";
125 }
126 msg_second_OK () {
127 echo -e "ENCODAGE secondaire <$ENCODAGEFILE> OK : on passe au traitement \n";
128 }
129 msg_encodage_vide () {
130 echo -e "PB....ENCODAGE VIDE "; repere
131 }
132 msg_second_connu_de_iconv () {
133 echo -e "ENCODAGE secondaire <$ENCODAGEFILE> OK, connu de iconv : on passe au traitement \n";
134 }
135 msg_abandon () {
136 echo -e "PB....ENCODAGE PAS CONNU DE ICONV -- ABANDON "; repere
137 }
138 msg_initial_connu_de_iconv () {
139 echo -e "ENCODAGE initial <$ENCODAGE> OK, connu de iconv : on passe au traitement \n";
140 }
141 msg_non_pertinent () {
142 echo -e "L'encodage initial n'est pas un encodage pertinent...\n";
143 echo -e "Utilisation de file pour extraire le charset dans la page aspirée...\n";
144 }
145 msg_initial_non_connu_de_iconv () {
146 echo -e "ENCODAGE initial non connu de iconv. ENCODAGE extrait via file : $ENCODAGEFILE \n";
147 echo -e "Il faut désormais s'assurer que cet encodage peut être OK ou pas... \n";
148 }
149 msg_non_trouve () {
150 echo -e "PB....ENCODAGE NON TROUVE PAR FILE (VIDE OU NON UTF-8) "; repere
151 }
152 msg_pb () {
153 echo -e "PB...."; repere
154 }
155
157 recherche_encodage () {
158 ENCODAGE=$(curl -sL "$ligne" | egrep -o "meta.+charset *= *[^>]+" | egrep -o "charset *= *[^>]+" | cut -f2 -d"=" | egrep -o "(\w+|\-)+" | uniq | tr "[a-z]" "[A-Z]" | tr -d "\n" | tr -d "\r") ;
159 }
160 repere () {
162 echo -e "$compteurtableau::$compteur::$code_sortie::$1::$ligne\n";
163 }
164 aspiration () {
166 curl -sL -o ./PAGES-ASPIREES/$1/$compteurtableau-$compteur.html $ligne;
167 }
168 dump_simple () {
171 lynx -dump -nolist $ligne > ./DUMP-TEXT/$1/$compteurtableau-$compteur.txt ;
172 }
173 dump_lv2 () {
176 lynx --assume-charset="$2" --display-charset="$2" -dump -nolist $ligne > ./DUMP-TEXT/$1/$compteurtableau-$compteur.txt ;
177 iconv -f $2 -t utf-8 ./DUMP-TEXT/$1/$compteurtableau-$compteur.txt > ./DUMP-TEXT/$1/$compteurtableau-$compteur-utf8.txt ;
178 ENCODAGESORTIE=$(file -i ./DUMP-TEXT/$1/$compteurtableau-$compteur-utf8.txt | cut -d"=" -f2 | tr '[a-z]' '[A-Z]');
179 }
180 contextmotif () {
184
186 egrep -i "$troisieme" ./DUMP-TEXT/$1/$compteurtableau-$compteur$2.txt > ./CONTEXTES-CONCAT/$1/$compteurtableau-$compteur.txt;
187 case $1 in
188 zh) bash ../../../stanford-segmenter/segment.sh pku ./CONTEXTES-CONCAT/zh/$compteurtableau-$compteur.txt UTF-8 0 > ./CONTEXTES-CONCAT/zh/$compteurtableau-$compteur-sg.txt ;
190 rm ./CONTEXTES-CONCAT/zh/*[^-sg].txt;
191 ;;
192 jp) chasen -j ./CONTEXTES-CONCAT/jp/$compteurtableau-$compteur.txt | cut -f1 > ./CONTEXTES-CONCAT/jp/$compteurtableau-$compteur-sg.txt ;
193 rm ./CONTEXTES-CONCAT/jp/*[^-sg].txt;
194 ;;
195 esac
197 case $1 in
198 fr) cp ./DUMP-TEXT/fr/$compteurtableau-$compteur$2.txt ./DUMP-CONCAT/fr ;
199 ;;
200 esac
201
203 nbmotif=$(egrep -coi "$troisieme" ./DUMP-TEXT/$1/$compteurtableau-$compteur$2.txt);
204
206 perl ./minigrep/minigrepmultilingue.pl "utf-8" ./DUMP-TEXT/$1/$compteurtableau-$compteur$2.txt ./minigrep/parametre-motif-$1.txt ;
207 mv resultat-extraction.html ./CONTEXTES/$1/$compteurtableau-$compteur.html ;
208 }
209 extraction_encodage2 () {
212 ENCODAGEFILE=$(file -i ./PAGES-ASPIREES/$1/$compteurtableau-$compteur.html | cut -d"=" -f2 | tr '[a-z]' '[A-Z]');
213 }
214 indexfr () {
217 egrep -o "\w+" ./DUMP-TEXT/fr/$compteurtableau-$compteur$1.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/fr/index-$compteurtableau-$compteur.txt ;
218 }
219 indexzh () {
222 bash ../../../stanford-segmenter/segment.sh pku ./DUMP-TEXT/zh/$compteurtableau-$compteur$1.txt UTF-8 0 > ./DUMP-TEXT/zh/$compteurtableau-$compteur-sg.txt ;
223 egrep -o "\w+" ./DUMP-TEXT/zh/$compteurtableau-$compteur-sg.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/zh/index-$compteurtableau-$compteur.txt ;
224
226 cp ./DUMP-TEXT/zh/$compteurtableau-$compteur-sg.txt ./DUMP-CONCAT/zh ;
227 }
228 indexjp () {
231 chasen -j ./DUMP-TEXT/jp/$compteurtableau-$compteur$1.txt | cut -f1 > ./DUMP-TEXT/jp/$compteurtableau-$compteur-sg.txt ;
232 egrep -o "\w+" ./DUMP-TEXT/jp/$compteurtableau-$compteur-sg.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/jp/index-$compteurtableau-$compteur.txt ;
233
235 cp ./DUMP-TEXT/jp/$compteurtableau-$compteur-sg.txt ./DUMP-CONCAT/jp ;
236 }
237 ngram () {
240
242 egrep -o "\w+" ./DUMP-TEXT/$1/$compteurtableau-$compteur$2.txt > bi1.txt;
243
245 tail -n +2 bi1.txt > bi2.txt ;
246 paste bi1.txt bi2.txt > bi3.txt ;
247 cat bi3.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/$1/bigramme-$compteurtableau-$compteur.txt ;
248
250 tail -n +3 bi1.txt > bi3.txt ;
251 paste bi1.txt bi2.txt bi3.txt > bi4.txt;
252 cat bi4.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/$1/trigramme-$compteurtableau-$compteur.txt ;
253 }
254 contextextract () {
258 egrep -C 1 "$troisieme" ./DUMP-TEXT/$1/$compteurtableau-$compteur$2.txt > ./CONTEXTES/$1/$compteurtableau-$compteur-contexte.txt;
259 }
260 concatenation () {
263 for fichier in $(ls ./CONTEXTES-CONCAT/$1/ | egrep "\.txt")
264 do
265 echo -e "<fichier=\"$fichier\">\n" >> ./CONCAT/$1/contexte-concat-$1.txt;
266 cat ./CONTEXTES-CONCAT/$1/$fichier >> ./CONCAT/$1/contexte-concat-$1.txt;
267 echo -e "\n</fichier>\n" >> ./CONCAT/$1/contexte-concat-$1.txt;
268 done
269
271 for fichier in $(ls ./DUMP-CONCAT/$1/ | egrep "\.txt")
272 do
273 echo -e "<fichier=\"$fichier\">\n" >> ./CONCAT/$1/dump-concat-$1.txt;
274 cat ./DUMP-CONCAT/$1/$fichier >> ./CONCAT/$1/dump-concat-$1.txt;
275 echo -e "\n</fichier>\n" >> ./CONCAT/$1/dump-concat-$1.txt;
276 done
277 }
278 selection_langue_fichier () {
282 case $fichier in
283 *zh.txt) $1 zh $2;
284 ;;
285 *fr.txt) $1 fr $2;
286 ;;
287 *jp.txt) $1 jp $2;
288 ;;
289 esac
290 }
293 preparation_simplefr () {
296 dump_simple fr
297 contextmotif fr
298 indexfr
299 ngram fr
300 contextextract fr
301 }
302 preparation_simplezh () {
304 dump_simple zh
305 contextmotif zh
306 indexzh
307 ngram zh -sg
308 contextextract zh
309 }
310 preparation_simplejp () {
312 dump_simple jp
313 contextmotif jp
314 indexjp
315 ngram jp -sg
316 contextextract jp
317 }
318 preparation_lv2fr () {
321 dump_lv2 fr $1
322 contextmotif fr -utf8
323 indexfr -utf8
324 ngram fr -utf8
325 contextextract fr -utf8
326 }
327 preparation_lv2zh () {
330 dump_lv2 zh $1
331 contextmotif zh -utf8
332 indexzh -utf8
333 ngram zh -sg
334 contextextract zh -utf8
335 }
336 preparation_lv2jp () {
339 dump_lv2 jp $1
340 contextmotif jp -utf8
341 indexjp -utf8
342 ngram jp -sg
343 contextextract jp -utf8
344 }
346 selection_preparation_simple () {
348 case $fichier in
349 *zh.txt) preparation_simplezh
350 ;;
351 *fr.txt) preparation_simplefr
352 ;;
353 *jp.txt) preparation_simplejp
354 ;;
355 esac
356 }
357 selection_preparation_lv2 () {
360 case $fichier in
361 *zh.txt) preparation_lv2zh $1
362 ;;
363 *fr.txt) preparation_lv2fr $1
364 ;;
365 *jp.txt) preparation_lv2jp $1
366 ;;
367 esac
368 }
370 traitement_simple_A () {
371 selection_langue_fichier aspiration
372 selection_preparation_simple
373
375 selection_langue_fichier "ecriture_tableau_normal $ENCODAGE $ENCODAGE"
376 }
377 recherche_encodage_lv2 () {
378 selection_langue_fichier aspiration
379 selection_langue_fichier extraction_encodage2
380 }
381 traitement_simple_B () {
382 selection_preparation_simple
383
385 selection_langue_fichier "ecriture_tableau_normal $ENCODAGE $ENCODAGEFILE"
386 }
387 traitement_lv2_A () {
388 selection_preparation_lv2 $ENCODAGEFILE
389
391 selection_langue_fichier "ecriture_tableau_normal $ENCODAGEFILE $ENCODAGESORTIE" -utf8
392 }
393 traitement_lv2_B () {
394 selection_langue_fichier aspiration
395 selection_preparation_lv2 $ENCODAGE
396
398 selection_langue_fichier "ecriture_tableau_normal $ENCODAGE $ENCODAGESORTIE" -utf8
399 }
401 condition_non_utf8 () {
402 reponse=$(iconv -l | grep $ENCODAGEFILE) ;
403 if [[ $ENCODAGEFILE == "" ]]
404 then
405 msg_encodage_vide
406 ecriture_tableau_pb_encodage
407 elif [[ $reponse != "" ]]
408 then
409 msg_second_connu_de_iconv
411 traitement_lv2_A
412 else
413 msg_abandon
414 ecriture_tableau_pb_encodage
415 fi
416 }
417 condition_utf8 () {
418 case $ENCODAGE in
419 "UTF-8") msg_initial_OK
420 traitement_simple_A
421 ;;
422 *) condition_non_utf8_lv2
423 ;;
424 esac
425 }
426 condition_utf8_lv2 () {
429 case $ENCODAGEFILE in
430 "UTF-8") msg_second_OK
431 traitement_simple_B
432 ;;
433 *) $1
434 $2
435 ;;
436 esac
437 }
438 condition_non_vide_non_utf8 () {
441 reponse=$(iconv -l | grep $ENCODAGE) ;
442 if [[ $reponse != "" ]]
443 then
444 msg_initial_connu_de_iconv
445 traitement_lv2_B
446 else
447 msg_non_pertinent
449 recherche_encodage_lv2
450 msg_initial_non_connu_de_iconv
451
452 condition_utf8_lv2 msg_non_trouve ecriture_tableau_pb_encodage
453 fi
454 }
455 condition_non_utf8_lv2 () {
456 msg_traiter_non_UTF8
457 case $ENCODAGE in
459 "") ENCODAGE="-";
461 recherche_encodage_lv2
462 msg_apres_extraction
463 condition_utf8_lv2 condition_non_utf8
464 ;;
465 *) condition_non_vide_non_utf8
467 ;;
468 esac
469 }
471 traitement_global () {
473 case $code_sortie in
474 200)
477 recherche_encodage
478
480 repere $ENCODAGE
481
482 condition_utf8
483 ;;
484 *)
486 msg_pb
487 ecriture_tableau_noResult
488 ;;
489 esac
490 compteur=$((compteur + 1));
491 echo -e "_____________________________________________________________________\n";
492 }
494
496 ecriture_entete_html
499 compteurtableau=1;
501 for fichier in $(ls $1)
502 do
504 ecriture_tableau_debut
505
508 compteur=1;
510 for ligne in $(cat $1/$fichier)
511 do
512 traitement_global
513 done
516 selection_langue_fichier concatenation
518 ecriture_tableau_fin
519 compteurtableau=$((compteurtableau + 1))
520 done
523 ecriture_fin_html
525
527 exit;