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