Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 1 | #/bin/bash |
| 2 | |
| 3 | EURECO="/scratch/project_2010889/eureco" |
Harald Lüngen | 197aa20 | 2024-09-04 17:42:31 +0300 | [diff] [blame] | 4 | TEST="/scratch/project_2010889/TEST" |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 5 | |
| 6 | CORPUS="$EURECO/klk-fi-v2-vrt" |
| 7 | TEIDTD="$EURECO/tei/tei_all.dtd" |
| 8 | |
| 9 | DAT="$CORPUS/data" # input vrt files of klk-fi by year |
Harald Lüngen | 197aa20 | 2024-09-04 17:42:31 +0300 | [diff] [blame] | 10 | XML="$CORPUS/XML" # output zipped vrtxml files of selection of newspapers |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame^] | 11 | TEI="$CORPUS/TEI" # output zipped tei files of the selection |
| 12 | #TEI="$TEST/TEI" # output zipped tei files of the selection |
| 13 | |
| 14 | #TEIFORMAT="tei"; |
| 15 | TEIFORMAT="i5"; |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 16 | |
Harald Lüngen | 197aa20 | 2024-09-04 17:42:31 +0300 | [diff] [blame] | 17 | mkdir -p $TEST |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 18 | mkdir -p $XML |
| 19 | mkdir -p $TEI |
| 20 | |
| 21 | |
| 22 | |
| 23 | # Multiple threads for a loop in bash: |
| 24 | |
| 25 | ## for stuff in things |
| 26 | ## do |
| 27 | ## ( something |
| 28 | ## with |
| 29 | ## stuff ) & |
| 30 | ## done |
| 31 | ## wait # for all the something with stuff |
| 32 | |
| 33 | |
| 34 | |
| 35 | # Generate corpus files by year and source in vrt |
| 36 | |
| 37 | # for VRT in "$DAT/*.vrt" |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame^] | 38 | #for VRT in "$DAT/klk_fi_v2_2021.vrt" # to be applied to yearly files |
| 39 | # for VRT in "$DAT/klk_fi_v2_2020.vrt" |
| 40 | for VRT in "$DAT/klk_fi_v2_2018.vrt" "$DAT/klk_fi_v2_2019.vrt" |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 41 | do # ( |
| 42 | |
| 43 | BASENAME=`basename $VRT .vrt` |
| 44 | YY=`echo $BASENAME | gawk 'BEGIN {FS="_"} {print $4}'` |
| 45 | |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame^] | 46 | echo "Generating proper XML files from $VRT in $XML/$YY by source..." |
| 47 | gawk -v OUTDIR="$XML" -v YEAR="$YY" -f vrt2xml.awk $VRT # will generate corpus files for different sources in the YEAR dir |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 48 | |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame^] | 49 | done |
| 50 | exit |
| 51 | |
| 52 | |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 53 | # Checking Wellformedness of the XML and generating TEI |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame^] | 54 | for s in $XML/*/ |
| 55 | # for s in $XML/Suomen_Kuvalehti/ |
Harald Lüngen | 7aac973 | 2024-09-17 09:07:25 +0300 | [diff] [blame] | 56 | # for s in $XML/Lansi-Savo/ |
Harald Lüngen | 197aa20 | 2024-09-04 17:42:31 +0300 | [diff] [blame] | 57 | # for s in $XML/Helsingin_Sanomat/ |
| 58 | # for s in $XML/Aamulehti/ $XML/Etela-Suomen_Sanomat/ $XML/Hameen_Sanomat/ $XML/Helsingin_Sanomat/ $XML/Ilkka-Pohjalainen/ $XML/Ilta-Sanomat/ $XML/Kaleva/ $XML/Keskipohjanmaa/ $XML/Satakunnan_Kansa/ $XML/Savon_Sanomat/ $XML/Turun_Sanomat/ |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame^] | 59 | do ( # threading |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 60 | SOURCE=`basename $s` |
| 61 | x=$s/$SOURCE$YY.xml |
| 62 | |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 63 | ## echo " checking wellformedness of $x" |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 64 | ## xmllint --noout $x # ToDo: make if condition for continuing only if well-formed |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 65 | # if($R != 0){ |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 66 | # echo "Error: xmllint error with error return code $R" >&2; |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 67 | # break; |
| 68 | # } |
| 69 | |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 70 | BASENAME=`basename $x .xml` |
| 71 | mkdir -p $TEI/$SOURCE |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame^] | 72 | t="$TEI/$SOURCE/$BASENAME.$TEIFORMAT.xml" |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 73 | |
Harald Lüngen | 197aa20 | 2024-09-04 17:42:31 +0300 | [diff] [blame] | 74 | echo " generating $t using vrt2tei.pl, and prettifying..." |
Harald Lüngen | 7aac973 | 2024-09-17 09:07:25 +0300 | [diff] [blame] | 75 | ./vrt2tei.pl $x | |
| 76 | xml_pp | # xml_pp works but takes ages; |
| 77 | gawk -f rearrange-idsDoc.awk > $t # rearranging the start and end tag of idsDoc |
| 78 | # xmllint- format geht out of memory und --stream machen funktioniert nicht |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 79 | ls -l $t |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 80 | |
| 81 | echo " validating..." |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame^] | 82 | if [ "$TEIFORMAT" == "i5" ] ; then |
| 83 | xmllint --stream --noout --valid $t |
| 84 | else |
| 85 | xmllint --stream --noout --dtdvalid $TEIDTD $t # TEI; scheint so zu funktioneren - nicht kombinieren mit --format! |
| 86 | fi |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 87 | |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 88 | # echo " zipping $x..." |
| 89 | # gzip -f $x |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 90 | |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 91 | # echo " zipping $t..." |
| 92 | # gzip -f $t |
| 93 | |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame^] | 94 | echo ) & |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 95 | done |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 96 | # wait # ) & # wait does not seem to make sense if nothing follows |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 97 | |
| 98 | done |
| 99 | # wait |
| 100 | |
| 101 | |
| 102 | |