blob: 027f06b50d5dc8c306de6e2a69341a9bc7e6cd87 [file] [log] [blame]
Harald Lüngen5bebb0c2024-08-27 16:44:34 +03001#/bin/bash
2
3EURECO="/scratch/project_2010889/eureco"
Harald Lüngen197aa202024-09-04 17:42:31 +03004TEST="/scratch/project_2010889/TEST"
Harald Lüngen5bebb0c2024-08-27 16:44:34 +03005
6CORPUS="$EURECO/klk-fi-v2-vrt"
7TEIDTD="$EURECO/tei/tei_all.dtd"
8
9DAT="$CORPUS/data" # input vrt files of klk-fi by year
Harald Lüngen197aa202024-09-04 17:42:31 +030010XML="$CORPUS/XML" # output zipped vrtxml files of selection of newspapers
Harald Lüngencb223bd2024-09-19 10:52:09 +030011TEI="$CORPUS/TEI" # output zipped tei files of the selection
12#TEI="$TEST/TEI" # output zipped tei files of the selection
13
14#TEIFORMAT="tei";
15TEIFORMAT="i5";
Harald Lüngen5bebb0c2024-08-27 16:44:34 +030016
Harald Lüngen197aa202024-09-04 17:42:31 +030017mkdir -p $TEST
Harald Lüngen5bebb0c2024-08-27 16:44:34 +030018mkdir -p $XML
19mkdir -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üngencb223bd2024-09-19 10:52:09 +030038#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"
40for VRT in "$DAT/klk_fi_v2_2018.vrt" "$DAT/klk_fi_v2_2019.vrt"
Harald Lüngen5bebb0c2024-08-27 16:44:34 +030041do # (
42
43 BASENAME=`basename $VRT .vrt`
44 YY=`echo $BASENAME | gawk 'BEGIN {FS="_"} {print $4}'`
45
Harald Lüngencb223bd2024-09-19 10:52:09 +030046 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üngen5bebb0c2024-08-27 16:44:34 +030048
Harald Lüngencb223bd2024-09-19 10:52:09 +030049done
50exit
51
52
Harald Lüngen6feedd22024-08-29 13:33:59 +030053 # Checking Wellformedness of the XML and generating TEI
Harald Lüngencb223bd2024-09-19 10:52:09 +030054 for s in $XML/*/
55 # for s in $XML/Suomen_Kuvalehti/
Harald Lüngen7aac9732024-09-17 09:07:25 +030056 # for s in $XML/Lansi-Savo/
Harald Lüngen197aa202024-09-04 17:42:31 +030057 # 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üngencb223bd2024-09-19 10:52:09 +030059 do ( # threading
Harald Lüngen5bebb0c2024-08-27 16:44:34 +030060 SOURCE=`basename $s`
61 x=$s/$SOURCE$YY.xml
62
Harald Lüngen6feedd22024-08-29 13:33:59 +030063 ## echo " checking wellformedness of $x"
Harald Lüngen86cbd932024-09-10 15:52:18 +030064 ## xmllint --noout $x # ToDo: make if condition for continuing only if well-formed
Harald Lüngen6feedd22024-08-29 13:33:59 +030065 # if($R != 0){
Harald Lüngen86cbd932024-09-10 15:52:18 +030066 # echo "Error: xmllint error with error return code $R" >&2;
Harald Lüngen6feedd22024-08-29 13:33:59 +030067 # break;
68 # }
69
Harald Lüngen5bebb0c2024-08-27 16:44:34 +030070 BASENAME=`basename $x .xml`
71 mkdir -p $TEI/$SOURCE
Harald Lüngencb223bd2024-09-19 10:52:09 +030072 t="$TEI/$SOURCE/$BASENAME.$TEIFORMAT.xml"
Harald Lüngen5bebb0c2024-08-27 16:44:34 +030073
Harald Lüngen197aa202024-09-04 17:42:31 +030074 echo " generating $t using vrt2tei.pl, and prettifying..."
Harald Lüngen7aac9732024-09-17 09:07:25 +030075 ./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üngen5bebb0c2024-08-27 16:44:34 +030079 ls -l $t
Harald Lüngen6feedd22024-08-29 13:33:59 +030080
81 echo " validating..."
Harald Lüngencb223bd2024-09-19 10:52:09 +030082 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üngen5bebb0c2024-08-27 16:44:34 +030087
Harald Lüngen6feedd22024-08-29 13:33:59 +030088 # echo " zipping $x..."
89 # gzip -f $x
Harald Lüngen5bebb0c2024-08-27 16:44:34 +030090
Harald Lüngen6feedd22024-08-29 13:33:59 +030091 # echo " zipping $t..."
92 # gzip -f $t
93
Harald Lüngencb223bd2024-09-19 10:52:09 +030094 echo ) &
Harald Lüngen5bebb0c2024-08-27 16:44:34 +030095 done
Harald Lüngen6feedd22024-08-29 13:33:59 +030096 # wait # ) & # wait does not seem to make sense if nothing follows
Harald Lüngen5bebb0c2024-08-27 16:44:34 +030097
98done
99# wait
100
101
102