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 | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 11 | |
| 12 | |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 13 | TEI="$CORPUS/TEI" # output zipped tei files of the selection |
| 14 | #TEI="$TEST/TEI" # output zipped tei files of the selection |
| 15 | |
| 16 | #TEIFORMAT="tei"; |
| 17 | TEIFORMAT="i5"; |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 18 | |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 19 | MASK=""; |
| 20 | #MASK="-m"; |
| 21 | |
| 22 | PERL_BAD=0; # to supress warnings about locale |
| 23 | |
Harald Lüngen | 197aa20 | 2024-09-04 17:42:31 +0300 | [diff] [blame] | 24 | mkdir -p $TEST |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 25 | mkdir -p $XML |
| 26 | mkdir -p $TEI |
| 27 | |
| 28 | |
| 29 | |
| 30 | # Multiple threads for a loop in bash: |
| 31 | |
| 32 | ## for stuff in things |
| 33 | ## do |
| 34 | ## ( something |
| 35 | ## with |
| 36 | ## stuff ) & |
| 37 | ## done |
| 38 | ## wait # for all the something with stuff |
| 39 | |
| 40 | |
| 41 | |
| 42 | # Generate corpus files by year and source in vrt |
| 43 | |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 44 | # for VRT in $DAT/*.vrt # loop to be applied to yearly files |
| 45 | for VRT in $DAT/klk_fi_v2_201[0-3].vrt |
| 46 | # for VRT in "$DAT/klk_fi_v2_2015.vrt" |
| 47 | # for VRT in "$DAT/klk_fi_v2_2019.vrt" "$DAT/klk_fi_v2_2020.vrt" "$DAT/klk_fi_v2_2021.vrt" |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 48 | do # ( |
| 49 | |
| 50 | BASENAME=`basename $VRT .vrt` |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 51 | YEAR=`echo $BASENAME | gawk 'BEGIN {FS="_"} {print $4}'` |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 52 | |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 53 | echo "Generating proper XML files from $VRT in $XML/$YEAR by source..." |
| 54 | gawk -v OUTDIR="$XML" -v YEAR="$YEAR" -f vrt2xml.awk $VRT |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 55 | |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 56 | #-------------------------------------------------------- |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 57 | # Checking Wellformedness of the XML and generating TEI |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 58 | #-------------------------------------------------------- |
| 59 | |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 60 | for s in $XML/*/ |
| 61 | # for s in $XML/Suomen_Kuvalehti/ |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 62 | do ( # threading |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 63 | SOURCE=`basename $s` |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 64 | x=$s/$SOURCE$YEAR.xml |
| 65 | |
| 66 | # Some checks of the XML beforehand: |
| 67 | |
| 68 | if [[ ! -f $x ]] ; then |
| 69 | echo "Warning: klk2eureco.sh: File $x does not exist; skipping" |
| 70 | break; |
| 71 | fi |
| 72 | |
| 73 | if [[ -z `grep "<text " $x` ]] ; then |
| 74 | echo "Warning: klk2eureco.sh: File $x does not contain any <text>s ; skipping" |
| 75 | break; |
| 76 | fi |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 77 | |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 78 | echo " checking wellformedness of $x" |
| 79 | xmllint --stream --noout $x |
| 80 | if [[ $R != "" ]] ; then |
| 81 | echo "Error: xmllint error with error return code $R" >&2; |
| 82 | break; |
| 83 | fi |
| 84 | |
| 85 | |
| 86 | #-------------------- |
| 87 | # calling vrt2tei.pl |
| 88 | #-------------------- |
| 89 | |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 90 | BASENAME=`basename $x .xml` |
| 91 | mkdir -p $TEI/$SOURCE |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 92 | t="$TEI/$SOURCE/$BASENAME.$TEIFORMAT.xml" |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 93 | |
Harald Lüngen | 197aa20 | 2024-09-04 17:42:31 +0300 | [diff] [blame] | 94 | echo " generating $t using vrt2tei.pl, and prettifying..." |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 95 | perl vrt2tei.pl -t $TEIFORMAT $MASK $x | |
Harald Lüngen | 7aac973 | 2024-09-17 09:07:25 +0300 | [diff] [blame] | 96 | xml_pp | # xml_pp works but takes ages; |
| 97 | gawk -f rearrange-idsDoc.awk > $t # rearranging the start and end tag of idsDoc |
| 98 | # xmllint- format geht out of memory und --stream machen funktioniert nicht |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 99 | ls -l $t |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 100 | |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 101 | if [ "$TEIFORMAT" == "i5" ] ; then |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 102 | echo " validating $t..." |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 103 | xmllint --stream --noout --valid $t |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 104 | else |
| 105 | echo " validating $t..." |
| 106 | xmllint --stream --noout --dtdvalid $TEIDTD $t # scheint so zu funktioneren - nicht kombinieren mit --format! |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 107 | fi |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 108 | |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 109 | # echo " zipping $x..." |
| 110 | # gzip -f $x |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 111 | |
Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 112 | # echo " zipping $t..." |
| 113 | # gzip -f $t |
| 114 | |
Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 115 | echo ) & |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 116 | done |
Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame^] | 117 | wait # ) & # wait seems to have to be there for it to terminate |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 118 | |
| 119 | done |
| 120 | # wait |
| 121 | |
| 122 | |
| 123 | |