| 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 | |
| Martin Matthiesen | 0579bf1 | 2026-09-10 08:48:56 +0300 | [diff] [blame] | 9 | SCRIPTDIR="$(cd "$(dirname "$0")" && pwd)" |
| 10 | ZIPFILE=`ls "$SCRIPTDIR"/workdir/*.zip 2>/dev/null | head -1` # whichever archive of yearly vrt files sits in workdir/; members are streamed, never extracted to disk |
| 11 | if [[ -z "$ZIPFILE" ]] ; then |
| 12 | echo "Error: klk2eureco.sh: no .zip file found in $SCRIPTDIR/workdir" >&2 |
| 13 | exit 1 |
| 14 | fi |
| Harald Lüngen | 197aa20 | 2024-09-04 17:42:31 +0300 | [diff] [blame] | 15 | XML="$CORPUS/XML" # output zipped vrtxml files of selection of newspapers |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 16 | |
| 17 | |
| Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 18 | TEI="$CORPUS/TEI" # output zipped tei files of the selection |
| 19 | #TEI="$TEST/TEI" # output zipped tei files of the selection |
| 20 | |
| Harald Lüngen | 34c0561 | 2025-02-04 15:08:08 +0200 | [diff] [blame] | 21 | TEIFORMAT="tei"; |
| 22 | #TEIFORMAT="i5"; |
| Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 23 | |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 24 | MASK=""; |
| 25 | #MASK="-m"; |
| 26 | |
| 27 | PERL_BAD=0; # to supress warnings about locale |
| 28 | |
| Harald Lüngen | 197aa20 | 2024-09-04 17:42:31 +0300 | [diff] [blame] | 29 | mkdir -p $TEST |
| Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 30 | mkdir -p $XML |
| 31 | mkdir -p $TEI |
| 32 | |
| 33 | |
| 34 | |
| 35 | # Multiple threads for a loop in bash: |
| 36 | |
| 37 | ## for stuff in things |
| 38 | ## do |
| 39 | ## ( something |
| 40 | ## with |
| 41 | ## stuff ) & |
| 42 | ## done |
| 43 | ## wait # for all the something with stuff |
| 44 | |
| 45 | |
| 46 | |
| 47 | # Generate corpus files by year and source in vrt |
| 48 | |
| Martin Matthiesen | 0579bf1 | 2026-09-10 08:48:56 +0300 | [diff] [blame] | 49 | for ZIPMEMBER in `unzip -Z1 "$ZIPFILE" | grep '\.vrt$'` # loop over every yearly vrt file found in the archive |
| Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 50 | do # ( |
| 51 | |
| Martin Matthiesen | 0579bf1 | 2026-09-10 08:48:56 +0300 | [diff] [blame] | 52 | BASENAME=`basename $ZIPMEMBER .vrt` |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 53 | YEAR=`echo $BASENAME | gawk 'BEGIN {FS="_"} {print $4}'` |
| Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 54 | |
| Martin Matthiesen | 0579bf1 | 2026-09-10 08:48:56 +0300 | [diff] [blame] | 55 | echo "Generating proper XML files from $ZIPMEMBER in $ZIPFILE, in $XML by source..." |
| 56 | unzip -p "$ZIPFILE" "$ZIPMEMBER" | gawk -v OUTDIR="$XML" -v YEAR="$YEAR" -f vrt2xml.awk |
| Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 57 | |
| Martin Matthiesen | 0579bf1 | 2026-09-10 08:48:56 +0300 | [diff] [blame] | 58 | |
| 59 | |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 60 | #-------------------------------------------------------- |
| Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 61 | # Checking Wellformedness of the XML and generating TEI |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 62 | #-------------------------------------------------------- |
| 63 | |
| Martin Matthiesen | 0579bf1 | 2026-09-10 08:48:56 +0300 | [diff] [blame] | 64 | for s in $XML/*/ # every source vrt2xml.awk actually produced output for |
| 65 | do # ( # threading |
| Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 66 | SOURCE=`basename $s` |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 67 | x=$s/$SOURCE$YEAR.xml |
| 68 | |
| Harald Lüngen | 34c0561 | 2025-02-04 15:08:08 +0200 | [diff] [blame] | 69 | #--------------------------------------------------------------- |
| 70 | # Some existence checks and removal of empty files beforehand: |
| 71 | #--------------------------------------------------------------- |
| 72 | |
| 73 | if [[ ! -f $x ]] ; then |
| 74 | echo "Warning: klk2eureco.sh: File $x does not exist; skipping"; |
| 75 | break; |
| 76 | fi |
| 77 | |
| 78 | if [[ -z `grep -l "<text " $x` ]] ; then |
| 79 | #echo "Warning: klk2eureco.sh: File $x does not contain any <text>s, skipping" |
| 80 | echo "Warning: klk2eureco.sh: File $x does not contain any <text>s,removing" |
| 81 | rm -fv $x; |
| 82 | break; |
| 83 | fi |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 84 | |
| Harald Lüngen | 34c0561 | 2025-02-04 15:08:08 +0200 | [diff] [blame] | 85 | #--------------------------------- |
| 86 | # checking well-formedness of $x |
| 87 | #--------------------------------- |
| 88 | |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 89 | echo " checking wellformedness of $x" |
| Harald Lüngen | 34c0561 | 2025-02-04 15:08:08 +0200 | [diff] [blame] | 90 | xmllint --stream --noout $x |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 91 | if [[ $R != "" ]] ; then |
| 92 | echo "Error: xmllint error with error return code $R" >&2; |
| 93 | break; |
| 94 | fi |
| 95 | |
| 96 | |
| Harald Lüngen | 34c0561 | 2025-02-04 15:08:08 +0200 | [diff] [blame] | 97 | |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 98 | #-------------------- |
| 99 | # calling vrt2tei.pl |
| 100 | #-------------------- |
| 101 | |
| Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 102 | BASENAME=`basename $x .xml` |
| 103 | mkdir -p $TEI/$SOURCE |
| Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 104 | t="$TEI/$SOURCE/$BASENAME.$TEIFORMAT.xml" |
| Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 105 | |
| Martin Matthiesen | f4fc6c8 | 2026-09-10 08:32:22 +0300 | [diff] [blame] | 106 | echo " generating $t using vrt2tei.pl..." |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 107 | perl vrt2tei.pl -t $TEIFORMAT $MASK $x | |
| Harald Lüngen | 7aac973 | 2024-09-17 09:07:25 +0300 | [diff] [blame] | 108 | gawk -f rearrange-idsDoc.awk > $t # rearranging the start and end tag of idsDoc |
| Martin Matthiesen | f4fc6c8 | 2026-09-10 08:32:22 +0300 | [diff] [blame] | 109 | # pretty-printing now done in-process by XML::Twig (pretty_print => 'record'), |
| 110 | # replacing the old xml_pp re-parse pass (xmllint --format runs out of memory, --stream can't format) |
| Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 111 | ls -l $t |
| Harald Lüngen | 6feedd2 | 2024-08-29 13:33:59 +0300 | [diff] [blame] | 112 | |
| Harald Lüngen | 34c0561 | 2025-02-04 15:08:08 +0200 | [diff] [blame] | 113 | # if $t is empty, remove it: |
| Martin Matthiesen | f4fc6c8 | 2026-09-10 08:32:22 +0300 | [diff] [blame] | 114 | if [ ! -s $t ]; then |
| 115 | rm -f $t |
| Harald Lüngen | 34c0561 | 2025-02-04 15:08:08 +0200 | [diff] [blame] | 116 | fi |
| 117 | |
| 118 | # validating $t: |
| Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 119 | if [ "$TEIFORMAT" == "i5" ] ; then |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 120 | echo " validating $t..." |
| Harald Lüngen | cb223bd | 2024-09-19 10:52:09 +0300 | [diff] [blame] | 121 | xmllint --stream --noout --valid $t |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 122 | else |
| 123 | echo " validating $t..." |
| 124 | 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] | 125 | fi |
| Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 126 | |
| Harald Lüngen | 34c0561 | 2025-02-04 15:08:08 +0200 | [diff] [blame] | 127 | ###TMP # echo " zipping $x..." |
| 128 | ###TMP # gzip -f $x |
| 129 | ###TMP |
| 130 | ###TMP # echo " zipping $t..." |
| 131 | ###TMP # gzip -f $t |
| 132 | |
| 133 | echo # ) & |
| Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame] | 134 | done |
| Harald Lüngen | d488d5c | 2024-09-25 09:01:51 +0300 | [diff] [blame] | 135 | 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] | 136 | |
| 137 | done |
| 138 | # wait |
| 139 | |
| 140 | |
| 141 | |