Χρήστης:Flubot/παραγωγή λίστας iw
Εμφάνιση
Προβλήματα: Τα αρχεία τίτλων παράγονται κάθε μέρα, λίγο μετά τις 8:00 UTC. Πρέπει να βρεθεί λυση, ώστε αν θελήσουμε να κάνουμε αυτή τη δουλειά νωρίτερα, να κατεβάσουμε τα αρχεία της προηγούμενης ημέρας.
#!/bin/bash
# This script generates an iw action list from scratch.
# the contents of said file look like
#
# șarpe||addition:ru fr en ro io
# abut||removal:cs
# téléphone||removal:mg||addition:eu
#
# and so on.
# It takes 2 mandatory arguments:
#
# 1) the name of the full xml file from el wikt,
# presumably updated with getrcs.sh
#
# 2) the name of the output file for the action list.
#
# All intermediate files are written to the subdir
# iw_tmp
#
usage() {
echo "Usage: $0 fullxmlfile outputfile"
echo
echo " fullxmlfile name of the xml file with current page contents"
echo " outputfile name of file to which we will write iw action list"
echo " -n για να δημιουργήσουμε ξανά τον κατάλογο των Βικιλεξικών"
echo
echo "For example:"
echo " $0 ../getrcs/last_full.xml iw-action-list.txt"
echo " $0 -n ../getrcs/last_full.xml.bz2 iw-action-list.txt"
echo
exit 1
}
makeListOfWikts() {
echo "getting list of all wiktionaries"
if [ ! -e "iw_tmp" ]; then
mkdir iw_tmp
fi
cd iw_tmp/
wget -N -q 'http://noc.wikimedia.org/conf/all.dblist'
wget -N -q 'http://noc.wikimedia.org/conf/closed.dblist'
if [ ! -e "all.dblist" ]; then
echo "Failed to retrieve http://noc.wikimedia.org/conf/all.dblist, exiting"
exit 1
fi
if [ ! -e "closed.dblist" ]; then
echo "Failed to retrieve http://noc.wikimedia.org/conf/closed.dblist, exiting"
exit 1
fi
if [ ! -e "titles" ]; then
mkdir titles
fi
sort all.dblist > all-sorted
sort closed.dblist > closed-sorted
comm -3 all-sorted closed-sorted | grep wiktionary > wikts
cd ..
}
if [ "$#" -lt "2" -o "$#" -gt "3" ]; then
usage
fi
infile=""
outfile=""
for i in $@; do
if [ $i == "-n" ]; then
makeListOfWikts
elif [ -z "$infile" ]; then
infile="$i"
else
outfile="$i"
fi
done
if [ ! -e "$infile" ]; then
echo "Error: Failed to find file $infile"
echo
usage
fi
echo "removing all pages not in ns0 from dump file"
cat $infile | perl xml-σελίδες-ns0.pl > iw_tmp/full-ns0.xml
echo "generating list of iws per lemma from our xml dump file"
#cat iws_tmp/full-ns0.xml | python dump-our-iws.py | grep -v 'unicode test: triggers problem' > iws_tmp/our-iws.txt
cat iw_tmp/full-ns0.xml | python dump-our-iws.py --dir=iw_tmp > iw_tmp/our-iws.txt
DATE=`date +%Y%m%d` #date format yyyymmdd eg 20131227
cd iw_tmp/
langs=`cat wikts | sed -e 's/wiktionary//g;'`
# δεν συμφέρει να βάλουμε τη λέξη wiktionary μέσα στη μεταβλητή
echo "generating current list of lemmas for each project"
# γράψε ένα αρχείο με όλα τα gz αρχεία τίτλων που πρέπει να κατεβάσουμε
# κάθε gz βρίσκεται σε μια διεύθυνση όπως αυτή:
# http://dumps.wikimedia.org/other/pagetitles/20131228/afwiktionary-20131228-all-titles-in-ns-0.gz
# τι γίνεται αν έχει αλλάξει η μέρα και δεν έχει εκδοθεί ακόμη το αρχείο τίτλων;
if [ -e "listOfGZfiles" ]; then
rm listOfGZfiles
fi
touch listOfGZfiles
for i in $langs; do
echo 'http://dumps.wikimedia.org/other/pagetitles/'$DATE'/'$i'wiktionary-'$DATE'-all-titles-in-ns-0.gz' >> listOfGZfiles
done
# wget -N -q -i http://dumps.wikimedia.org/other/pagetitles/20140106/zhwiktionary-20140106-all-titles-in-ns-0.gz
cd titles/
# κατέβασε όλα τα αρχεία και αποσυμπίεσέ τα
wget -N -q -i ../listOfGZfiles
gzip -d *.gz
for i in $langs; do
fileoftitles=$i'wiktionary-'$DATE'-all-titles-in-ns-0'
i=`echo $i | sed 's/_/-/g'`
sed -i 's/$/||'$i'/g' $fileoftitles
done
cat * > ../all-lemmas.txt
cd ..
sed -i 's/_/ /g' all-lemmas.txt
cd ..
echo "sorting list of lemmas"
bash sortlemmas.sh iw_tmp/all-lemmas.txt iw_tmp/all-lemmas-sorted.txt
echo "collecting languages per lemma"
cat iw_tmp/all-lemmas-sorted.txt | perl langs-per-lemma.pl | grep -vaP "\xc2\x85" > iw_tmp/langs-per-lemma.txt
echo "getting rid of all entries not contained in our wiktionary"
cat iw_tmp/langs-per-lemma.txt | python toss-extra-titles.py --file=iw_tmp/our-iws.txt > iw_tmp/their-iws.txt
if [ -z "$outfile" ]; then
outfile=$DATE
fi
echo "writing iw action list"
python check-our-iws.py --ouriwfile=iw_tmp/our-iws.txt --theiriwfile=iw_tmp/their-iws.txt > $outfile
exit 0