#!/usr/bin/bash # Le script doit être lancé depuis le répertoire PROJET-MOT-SUR-LE-WEB/PROGRAMMES. Un répertoire INDEX a été créé, ainsi qu'un répertoire FICHIERS-GLOBAUX. Le programme minigrepmultilingue.pl se trouve dans le répertoire PROGRAMMES/minigrep. Le fichier motif.txt utilisé avec minigrep se trouve dans PROGRAMMES ; il contient : # MOTIF=healthy? food|alimentation saine|alimentación sana|alimentación saludable|dieta sana|dieta saludable|健康食品 # La variable motif renvoie, dans les paramètres, à : (healthy? food|alimentation saine|(alimentación|dieta) (sana|saludable)|健康食品) read repertoirefichiers read pagehtml read motif echo "Tableau des URLS" > $pagehtml let "y = 0" for fichier in `ls $repertoirefichiers` do let "y += 1" let "x = 0" let "nbdump = 0" echo "" >> $pagehtml mkdir -p ../PAGES-ASPIREES/$y mkdir -p ../DUMP-TEXT/$y mkdir -p ../CONTEXTES/$y mkdir -p ../INDEX/$y mkdir -p ../FICHIERS-GLOBAUX/$y for ligne in `cat $repertoirefichiers/$fichier` do let "x += 1" wget -O ../PAGES-ASPIREES/$y/$x.html -t5 $ligne retourwget=$? taillefichier=$(stat -c "%s" ../PAGES-ASPIREES/$y/$x.html) if (( $taillefichier < 2000 )) then retourwget="page d'erreur" fi if [[ $retourwget != 0 ]] # Si wget n'a pas fonctionné then echo "" >> $pagehtml else # Si wget a fonctionné encodage=$(file -i ../PAGES-ASPIREES/$y/$x.html | cut -d= -f2) # On utilise file pour trouver l'encodage if [[ $encodage == "utf-8" ]] # Si la page est en utf-8 uniquement, on dump then lynx -dump -nolist -display_charset=$encodage ../PAGES-ASPIREES/$y/$x.html > ../DUMP-TEXT/$y/$x-utf8.txt #1# On dump egrep -i "$motif" ../DUMP-TEXT/$y/$x-utf8.txt > ../CONTEXTES/$y/$x.txt #2# On extrait le contexte du fichier texte perl minigrep/minigrepmultilingue.pl "utf-8" ../DUMP-TEXT/$y/$x-utf8.txt ./motif.txt #3# On extrait le contexte avec minigrep mv resultat-extraction.html ../CONTEXTES/$y/$x.html freqmotif=$(egrep -coi "$motif" ../DUMP-TEXT/$y/$x-utf8.txt) #4# On compte combien de fois apparaît le motif egrep -o "\w+" ../DUMP-TEXT/$y/$x-utf8.txt | sort | uniq -c | sort -gr > ../INDEX/$y/index$x.txt #5# On crée l'index du dump dans un nouveau dossier let "nbdump += 1" echo "" >> ../FICHIERS-GLOBAUX/$y/dumpglobal.txt #6# On crée le fichier de dump global cat ../DUMP-TEXT/$y/$x-utf8.txt >> ../FICHIERS-GLOBAUX/$y/dumpglobal.txt egrep -o "\w+" ../FICHIERS-GLOBAUX/$y/dumpglobal.txt | sort | uniq -c | sort -gr > ../FICHIERS-GLOBAUX/$y/indexdumpglobal.txt #7# On crée l'index du dump global (les fichiers globaux vont être enrichis à chaque tour) echo "" >> ../FICHIERS-GLOBAUX/$y/contexteglobal.txt #8# Fichier de contexte global cat ../CONTEXTES/$y/$x.txt >> ../FICHIERS-GLOBAUX/$y/contexteglobal.txt egrep -o "\w+" ../FICHIERS-GLOBAUX/$y/contexteglobal.txt | sort | uniq -c | sort -gr > ../FICHIERS-GLOBAUX/$y/indexcontexteglobal.txt #9# Index du contexte global echo "" >> $pagehtml else # Si l'encodage n'est pas en utf-8 d'après file, on extrait le charset s'il y en a un if egrep -i "" >> $pagehtml else # Si l'encodage est connu de iconv if [[ $encodage == "utf-8" ]] # Si la page est en utf-8, on dump then lynx -dump -nolist -display_charset=$encodage ../PAGES-ASPIREES/$y/$x.html > ../DUMP-TEXT/$y/$x-utf8.txt egrep -i "$motif" ../DUMP-TEXT/$y/$x-utf8.txt > ../CONTEXTES/$y/$x.txt perl minigrep/minigrepmultilingue.pl "utf-8" ../DUMP-TEXT/$y/$x-utf8.txt ./motif.txt mv resultat-extraction.html ../CONTEXTES/$y/$x.html freqmotif=$(egrep -coi "$motif" ../DUMP-TEXT/$y/$x-utf8.txt) egrep -o "\w+" ../DUMP-TEXT/$y/$x-utf8.txt | sort | uniq -c | sort -gr > ../INDEX/$y/index$x.txt let "nbdump += 1" echo "" >> ../FICHIERS-GLOBAUX/$y/dumpglobal.txt cat ../DUMP-TEXT/$y/$x-utf8.txt >> ../FICHIERS-GLOBAUX/$y/dumpglobal.txt egrep -o "\w+" ../FICHIERS-GLOBAUX/$y/dumpglobal.txt | sort | uniq -c | sort -gr > ../FICHIERS-GLOBAUX/$y/indexdumpglobal.txt echo "" >> ../FICHIERS-GLOBAUX/$y/contexteglobal.txt cat ../CONTEXTES/$y/$x.txt >> ../FICHIERS-GLOBAUX/$y/contexteglobal.txt egrep -o "\w+" ../FICHIERS-GLOBAUX/$y/contexteglobal.txt | sort | uniq -c | sort -gr > ../FICHIERS-GLOBAUX/$y/indexcontexteglobal.txt echo "" >> $pagehtml else # Si la page n'est pas en utf-8, on dump puis on transcode lynx -dump -nolist -display_charset=$encodage ../PAGES-ASPIREES/$y/$x.html > ../DUMP-TEXT/$y/$x.txt iconv -f $encodage -t utf-8 ../DUMP-TEXT/$y/$x.txt > ../DUMP-TEXT/$y/$x-utf8.txt # Transcodage egrep -i "$motif" ../DUMP-TEXT/$y/$x-utf8.txt > ../CONTEXTES/$y/$x.txt perl minigrep/minigrepmultilingue.pl "utf-8" ../DUMP-TEXT/$y/$x-utf8.txt ./motif.txt mv resultat-extraction.html ../CONTEXTES/$y/$x.html freqmotif=$(egrep -coi "$motif" ../DUMP-TEXT/$y/$x-utf8.txt) egrep -o "\w+" ../DUMP-TEXT/$y/$x-utf8.txt | sort | uniq -c | sort -gr > ../INDEX/$y/index$x.txt let "nbdump += 1" echo "" >> ../FICHIERS-GLOBAUX/$y/dumpglobal.txt cat ../DUMP-TEXT/$y/$x-utf8.txt >> ../FICHIERS-GLOBAUX/$y/dumpglobal.txt egrep -o "\w+" ../FICHIERS-GLOBAUX/$y/dumpglobal.txt | sort | uniq -c | sort -gr > ../FICHIERS-GLOBAUX/$y/indexdumpglobal.txt echo "" >> ../FICHIERS-GLOBAUX/$y/contexteglobal.txt cat ../CONTEXTES/$y/$x.txt >> ../FICHIERS-GLOBAUX/$y/contexteglobal.txt egrep -o "\w+" ../FICHIERS-GLOBAUX/$y/contexteglobal.txt | sort | uniq -c | sort -gr > ../FICHIERS-GLOBAUX/$y/indexcontexteglobal.txt echo "" >> $pagehtml fi fi else # S'il n'y a pas de charset : rien echo "" >> $pagehtml fi # Fin de boucle : s'il y a un charset fi # Fin de boucle : si l'encodage est en utf-8 fi # Fin de boucle : si wget a fonctionné done echo "
Tableau n°$y
n°URL URL Page aspirée Retour Wget Encodage Dump initial (encodage) Dump utf-8 Contexte Contexte html Fréq motif Index dump
$x $ligne page non aspirée $retourwget - - - - - - -
$x $ligne $x.html 0K $encodage - $x-utf8.txt $x.txt $x.html $freqmotif index$x
$x $ligne $x.html 0K encodage non détecté - - - - - -
$x $ligne $x.html 0K $encodage - $x-utf8.txt $x.txt $x.html $freqmotif index$x
$x $ligne $x.html 0K $encodage $x.txt $x-utf8.txt $x.txt $x.html $freqmotif index$x
$x $ligne $x.html 0K encodade non détecté - - - - - -
Dump global ($nbdump fichiers) Index dump global ($nbdump fichiers) Contexte global ($nbdump fichiers) Index contexte global ($nbdump fichiers)
" >> $pagehtml done echo "" >> $pagehtml