Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 1 | #! /usr/bin/perl -w |
| 2 | |
| 3 | |
| 4 | ########################################################################################################################################################### |
| 5 | # vrt2tei.pl |
| 6 | # eureco |
| 7 | # leibniz-institut fuer deutsche sprache / csc finland esbo |
| 8 | # august 2024 |
| 9 | # |
| 10 | # |
| 11 | # using XML::Twig , see http://www.xmltwig.org/, https://metacpan.org/pod/XML::Twiga |
| 12 | # |
Harald Lüngen | ccd8490 | 2024-08-27 16:03:47 +0300 | [diff] [blame] | 13 | # usage: see below the usage fugnction |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 14 | # Usage: ./vrt2tei.pl <vrtxmlfile.xml> <outfile> |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 15 | # <vrtxmlfile>: xml-ised vrt file |
| 16 | # |
| 17 | # |
| 18 | # TODO: |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 19 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 20 | # 3a remove the vrt positional attribute comment line / all comment lines |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 21 | # 3b add @head and @deprel to I5 sowie auch @msd |
| 22 | # 3c bearbeitung von @head und @deprel in tei2korapxml durch Nils? |
| 23 | # 3d build 30 billion corpus |
| 24 | |
| 25 | # 4a take care of IDs |
| 26 | # 4b see to the values of @xml:lang |
| 27 | # 5 abfangen von unerwarteten elementen dh andere als <sentence> und <paragraph> |
| 28 | # 5a wort reihenfolge nochmal checken |
| 29 | # 6 checks and balances |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 30 | # 7 How to encode Kielipankki and National Library of Finland? in teiCorpus Header |
| 31 | # 8 construct <idsDoc>s for the months (or go for TEI) |
| 32 | # 9 parallelisation in bash and application on sub corpora of KLK |
| 33 | # 10 re-implementation of the gawk code in the perl script |
| 34 | # 12 re-implement creation of text header from xml file in another twig / parametrize TEI vs I5 |
| 35 | |
| 36 | |
| 37 | |
| 38 | #remember |
| 39 | #formatted.xml:105613: element w: validity error : No declaration for attribute deprel of element w |
| 40 | #formatted.xml:105613: element w: validity error : No declaration for attribute head of element w |
| 41 | |
| 42 | |
| 43 | # |
| 44 | # |
| 45 | ############################################################################################################################################################ |
| 46 | |
| 47 | |
| 48 | use strict; |
| 49 | use warnings; |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 50 | #use diagnostics; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 51 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 52 | use Getopt::Std; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 53 | use XML::Twig; |
| 54 | use XML::Generator ':pretty'; # apparently no effect when using flush(); |
| 55 | |
| 56 | |
| 57 | use locale; # diese drei Zeilen, damit \b im regex nicht Umlaute und ß matcht. |
| 58 | use POSIX qw(locale_h); # to be able to use setlocale() |
| 59 | #setlocale(LC_ALL,'de_DE'); |
| 60 | setlocale(LC_ALL, "fi_FI"); |
| 61 | use utf8; |
| 62 | use open qw( :std :encoding(UTF-8) ); |
| 63 | |
| 64 | use Time::Piece; |
| 65 | use Tie::IxHash; |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 66 | use Data::Random::String; |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 67 | |
| 68 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 69 | #---------------------- |
| 70 | # check file arguments: |
| 71 | #---------------------- |
| 72 | |
| 73 | # arg0 infile: vrt-xml |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 74 | |
Harald Lüngen | a20e69d | 2024-08-29 13:33:08 +0300 | [diff] [blame] | 75 | unless($ARGV[0]) {&usage_message()} ; # min arg0, the input file |
| 76 | if ($ARGV[1]) {&usage_message()}; # max arg0, the input file |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 77 | |
| 78 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 79 | #-------------------------- |
| 80 | # get options / auxiliary files |
| 81 | #-------------------------- |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 87 | #################### |
| 88 | # GLOBAL VARIABLES |
| 89 | #################### |
| 90 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 91 | my $encoding = "UTF-8"; # dieses $encoding ist NUR fuer das output s.u. twig funktion |
| 92 | |
| 93 | #my $TEIFORMAT = "TEI"; |
| 94 | my $TEIFORMAT = "I5"; |
| 95 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 96 | my $DTDDECL = 'idsCorpus PUBLIC "-//IDS//DTD IDS-I5 1.0//EN" "http://corpora.ids-mannheim.de/I5/DTD/i5.dtd"'; # for I5 |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 97 | |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 98 | my $textcounter = 0; |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 99 | my $LASTMONTH = 0; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 100 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 101 | our %corpusids = (); |
Harald Lüngen | ba0354b | 2024-09-11 16:24:08 +0300 | [diff] [blame] | 102 | our %srcfullnames = (); |
| 103 | our %srcpubplaces = (); |
| 104 | our %srcpublishers = (); |
| 105 | our %srctexttypes = (); |
| 106 | our %srctextlangs = (); |
| 107 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 108 | our %expandLang = (); |
| 109 | |
| 110 | |
| 111 | my %doccounter = ( # by the month as in dereko |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 112 | "01" => 1, |
| 113 | "02" => 1, |
| 114 | "03" => 1, |
| 115 | "04" => 1, |
| 116 | "05" => 1, |
| 117 | "06" => 1, |
| 118 | "07" => 1, |
| 119 | "08" => 1, |
| 120 | "09" => 1, |
| 121 | "10" => 1, |
| 122 | "11" => 1, |
| 123 | "12" => 1, |
| 124 | ); |
| 125 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 126 | # global variables pertaining to the original corpus of *all* newspapers: |
| 127 | my $kielipankkiCorpus = "klk-fi-v2-vrt"; |
| 128 | my $kielipankkiLicense = "CLARIN-RES"; |
| 129 | my $CountryKey = "FI"; |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 130 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 131 | # Table with metadata about the different sources (newspapers) |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 132 | my $sourcescsvfile = "sources_klk_fi_v2_2021_4eureco.csv"; |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 133 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 134 | # corpusheader and textheader skeletons |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 135 | my $corpheaderfile = "teiCorpusHeaderSkeleton.tei.xml"; |
| 136 | my $textheaderfile = "teiTextHeaderSkeleton.tei.xml"; |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 137 | if($TEIFORMAT eq "I5"){ |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 138 | $corpheaderfile = "i5CorpusHeaderSkeleton.i5.xml"; |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 139 | $textheaderfile = "i5TextHeaderSkeleton.i5.xml"; |
| 140 | } |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 141 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 142 | |
| 143 | my $twig=""; |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 144 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 145 | # variables $fnsource and $fnyear taken from the filename |
| 146 | my @array = split(/\//, $ARGV[0]); |
| 147 | my $l = scalar(@array); |
| 148 | my $fnsource = $array[$l-1]; |
| 149 | $fnsource =~ s/([0-9][0-9][0-9][0-9])\.xml$//; |
| 150 | |
| 151 | my $fnyear = $1; # $1 contains substring in first bracket in regex above |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 152 | my $fnYY = substr($fnyear, 2, 2); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 153 | |
| 154 | |
| 155 | # months |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 156 | my %months = ( |
| 157 | "01" => "JAN", |
| 158 | "02" => "FEB", |
| 159 | "03" => "MAR", |
| 160 | "04" => "APR", |
| 161 | "05" => "MAY", |
| 162 | "06" => "JUN", |
| 163 | "07" => "JUL", |
| 164 | "08" => "AUG", |
| 165 | "09" => "SEP", |
| 166 | "10" => "OCT", |
| 167 | "11" => "NOV", |
| 168 | "12" => "DEC", |
| 169 | ); |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 170 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 171 | my %monthnames = ( |
| 172 | "01" => "January", |
| 173 | "02" => "February", |
| 174 | "03" => "March", |
| 175 | "04" => "April", |
| 176 | "05" => "May", |
| 177 | "06" => "June", |
| 178 | "07" => "July", |
| 179 | "08" => "August", |
| 180 | "09" => "September", |
| 181 | "10" => "October", |
| 182 | "11" => "November", |
| 183 | "12" => "December", |
| 184 | ); |
| 185 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 186 | my %mapping = (); |
| 187 | $mapping{"aikakausi"} = "Zeitschrift"; |
| 188 | $mapping{"sanomalehti"} = "Zeitung"; |
| 189 | |
| 190 | |
| 191 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 192 | #------------------------------------------------------------------------------------------- |
| 193 | # read source metadata file (prepared manually => ultimately read the info from CMDI File?) |
| 194 | # and set variables |
| 195 | #------------------------------------------------------------------------------------------- |
| 196 | |
| 197 | open(my $SOURCES, "< $sourcescsvfile") || die("$0: cannot open file for reading: $sourcescsvfile"); |
| 198 | while(my $fline = <$SOURCES>){ |
| 199 | chomp($fline); |
| 200 | |
| 201 | if ($fline=~/^\#/ || $fline=~/^\s*$/ || $fline =~ "TEICORPUSID"){next;} # skip line if empty line or comment line or first line |
| 202 | my @flarray = split(/\s*\t+\s*/, $fline); # split each line into array |
| 203 | |
| 204 | # set full titles ($flarray[1]) as keys: |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 205 | # (ToDo: these hashes could probably conflated into an array of hashes or so) |
| 206 | $corpusids{$flarray[1]} = $flarray[0]; |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 207 | $srcfullnames{$flarray[1]} = $flarray[1]; |
| 208 | $srcpubplaces{$flarray[1]} = $flarray[6]; |
| 209 | $srcpublishers{$flarray[1]} = $flarray[7]; |
| 210 | $srctexttypes{$flarray[1]} = $flarray[4]; |
| 211 | $srctextlangs{$flarray[1]} = $flarray[5]; |
| 212 | |
| 213 | # also set simple titles ($flarray[2]) as keys: |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 214 | $corpusids{$flarray[2]} = $flarray[0]; |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 215 | $srcfullnames{$flarray[2]} = $flarray[1]; |
| 216 | $srcpubplaces{$flarray[2]} = $flarray[6]; |
| 217 | $srcpublishers{$flarray[2]} = $flarray[7]; |
| 218 | $srctexttypes{$flarray[2]} = $flarray[4]; |
| 219 | $srctextlangs{$flarray[2]} = $flarray[5]; |
| 220 | } |
| 221 | close($SOURCES); |
| 222 | |
| 223 | $expandLang{"fi"} = "Finnish"; |
| 224 | $expandLang{"sv"} = "Swedish"; |
| 225 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 226 | #------------------------------------------------------------------ |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 227 | # read corpusHeaderSkeleton document and start a twig for it |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 228 | #------------------------------------------------------------------ |
| 229 | |
| 230 | my $teiCorpusHeaderDocTwig = new XML::Twig( |
| 231 | keep_spaces => 1, |
| 232 | keep_atts_order => 1, |
| 233 | comments => 'drop', |
| 234 | ); |
| 235 | |
| 236 | |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 237 | $teiCorpusHeaderDocTwig->parsefile($corpheaderfile); |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 238 | my $corpusHeader = $teiCorpusHeaderDocTwig->root; # getting the teiHeader for corpus out of the teiCorpusHeaderSkeleton document |
| 239 | |
| 240 | |
| 241 | #------------------------------------------------------------------ |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 242 | # read textHeaderSkeleton document and start a twig for it |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 243 | #------------------------------------------------------------------ |
| 244 | |
| 245 | my $teiTextHeaderDocTwig = new XML::Twig( |
| 246 | keep_spaces => 1, |
| 247 | keep_atts_order => 1, |
| 248 | comments => 'drop', |
| 249 | ); |
| 250 | |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 251 | $teiTextHeaderDocTwig->parsefile($textheaderfile); |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 252 | my $textHeader = $teiTextHeaderDocTwig->root; # getting the teiHeader for corpus out of the teiTextHeaderSkeleton document |
| 253 | |
| 254 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 255 | #--------------------------------------------------------- |
| 256 | # define a subtree for idsDoc |
| 257 | # for the time being it will only be used for the first |
| 258 | # idsDoc header, to be inserted in the root hander |
| 259 | #--------------------------------------------------------- |
| 260 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 261 | my $idsDoc = XML::Twig::Elt->new('idsDoc'); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 262 | my $idsDocHeader = XML::Twig::Elt->new('idsHeader'); |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 263 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 264 | if($TEIFORMAT eq "I5"){ |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 265 | my $docFileDesc = XML::Twig::Elt->new('fileDesc'); |
| 266 | my $docTitleStmt = XML::Twig::Elt->new('titleStmt'); |
| 267 | my $dtitle = XML::Twig::Elt->new('d.title'); |
| 268 | my $docSigle = XML::Twig::Elt->new('dokumentSigle'); |
| 269 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 270 | my $docPublicationStmt = XML::Twig::Elt->new('publicationStmt'); |
| 271 | my $docDistributor = XML::Twig::Elt->new('distributor'); |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 272 | my $docPubAddress = XML::Twig::Elt->new('pubAddress'); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 273 | my $docAvailability = XML::Twig::Elt->new('availability'); |
| 274 | my $docPubDate = XML::Twig::Elt->new('pubDate'); |
| 275 | |
| 276 | my $docSourceDesc = XML::Twig::Elt->new('sourceDesc'); |
| 277 | my $docBiblStruct = XML::Twig::Elt->new('biblStruct'); |
| 278 | my $docMonogr = XML::Twig::Elt->new('monogr'); |
| 279 | my $docHTitle = XML::Twig::Elt->new('h.title'); |
| 280 | my $docImprint = XML::Twig::Elt->new('imprint'); |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 281 | |
| 282 | $idsDoc -> set_att('version', "1.0"); |
| 283 | $idsDoc -> set_att('TEIform', "TEI.2"); |
| 284 | |
| 285 | $idsDocHeader -> set_att('version', "1.1"); |
| 286 | $idsDocHeader -> set_att('type', "document"); |
| 287 | $idsDocHeader -> set_att('pattern', "text"); |
| 288 | $idsDocHeader -> set_att('TEIform', "teiHeader"); |
| 289 | |
| 290 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 291 | |
| 292 | $docSigle -> paste("first_child", $docTitleStmt); |
| 293 | $dtitle -> paste("last_child", $docTitleStmt); |
| 294 | $docTitleStmt -> paste("last_child", $docFileDesc); |
| 295 | $docFileDesc -> paste("last_child", $idsDocHeader); |
| 296 | $docPublicationStmt -> paste("last_child", $docFileDesc); |
| 297 | $docDistributor -> paste("last_child", $docPublicationStmt); |
| 298 | $docPubAddress -> paste("last_child", $docPublicationStmt); |
| 299 | |
| 300 | $docAvailability -> paste("last_child", $docPublicationStmt); |
| 301 | $docPubDate -> paste("last_child", $docPublicationStmt); |
| 302 | |
| 303 | $docSourceDesc -> paste("last_child", $docFileDesc); |
| 304 | $docBiblStruct -> paste("last_child", $docSourceDesc); |
| 305 | $docMonogr -> paste("last_child", $docBiblStruct); |
| 306 | $docHTitle -> paste("last_child", $docMonogr); |
| 307 | $docImprint -> paste("last_child", $docMonogr); |
| 308 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 309 | $idsDocHeader -> paste("last_child", $idsDoc); |
| 310 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 311 | $docSigle->set_text($corpusids{$fnsource} . $fnYY . "/JAN"); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 312 | $dtitle ->set_text($srcfullnames{$fnsource} . ", January " . $fnyear); |
| 313 | } |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 314 | |
| 315 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 316 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 317 | #---------------------------------- |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 318 | # read the input VRT-XML document |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 319 | #---------------------------------- |
| 320 | |
| 321 | open(my $IN, "< $ARGV[0]") || die("$0: cannot open file for reading: $ARGV[0]"); # open input file and initialise filehandel, actually does not seem to be needed |
| 322 | # as parsefile() (s.b.) is applied to the filename |
| 323 | |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 324 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 325 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 326 | ##################### |
| 327 | # M A I N |
| 328 | ##################### |
| 329 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 330 | #------------------------------------------------------------------------------------------------------------- |
| 331 | # start twig for input and call start tag handler for root and twig handler for each <text> in the VRT |
| 332 | #------------------------------------------------------------------------------------------------------------- |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 333 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 334 | |
| 335 | $twig = new XML::Twig( |
| 336 | keep_spaces => 1, # dadurch auch whitespaces an ehemeligen elementgrenzen im output |
| 337 | keep_atts_order => 1, # requires Tie::IxHash |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 338 | comments => 'drop', |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 339 | start_tag_handlers => { |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 340 | texts => sub{root(@_, $corpusHeader)} |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 341 | }, |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 342 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 343 | twig_handlers => { |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 344 | # text => \&text |
Harald Lüngen | 7abb0b5 | 2024-09-05 16:26:57 +0300 | [diff] [blame] | 345 | text => sub{text(@_, $textHeader->copy)} # copy must be because textHeader will be flushed with $twig in the <text> handler; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 346 | }, |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 347 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 348 | output_encoding => $encoding, |
| 349 | ); |
| 350 | |
| 351 | $twig->parsefile($ARGV[0]); |
| 352 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 353 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 354 | ########### |
| 355 | # END MAIN |
| 356 | ########### |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | ############################## |
| 362 | # S U B R O U T I N E S |
| 363 | ############################## |
| 364 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 365 | sub root { |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 366 | my ($twig, $root, $corpusHeader) =@_; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 367 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 368 | if($TEIFORMAT eq "I5") { |
| 369 | $twig->set_doctype($DTDDECL); # the doctype could probably be set anywhere to the twig |
| 370 | $root->set_gi('idsCorpus'); |
| 371 | $root->set_att('version', "1.0"); |
| 372 | $root->set_att('TEIform', "teiCorpus.2"); |
| 373 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 374 | } |
| 375 | else { |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 376 | $root->set_gi('teiCorpus'); |
| 377 | $root->set_att("xmlns", 'http://www.tei-c.org/ns/1.0'); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 378 | } |
| 379 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 380 | &insertCorpusHeader($root, $corpusHeader); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 384 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 385 | sub insertCorpusHeader{ |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 386 | my ($root, $corpusHeader) =@_; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 387 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 388 | my $ident = "ident"; |
| 389 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 390 | #----------------------- |
| 391 | # set corpus header |
| 392 | #----------------------- |
| 393 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 394 | &set_title($corpusHeader, $srcfullnames{$fnsource}, $fnyear, $kielipankkiCorpus); |
| 395 | |
| 396 | if($TEIFORMAT eq "TEI"){ |
| 397 | &set_sourceDesc($corpusHeader, $srcfullnames{$fnsource}, $fnyear, $kielipankkiCorpus); |
| 398 | } |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 399 | elsif($TEIFORMAT eq "I5"){ |
| 400 | $corpusHeader->get_xpath("fileDesc/titleStmt/korpusSigle",0) ->set_text($corpusids{$fnsource} . $fnYY); |
| 401 | $corpusHeader->get_xpath("fileDesc/publicationStmt/pubDate",0)->set_text((localtime)[5] + 1900); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 402 | $corpusHeader->get_xpath('encodingDesc/editorialDecl/transduction[@n="2"]',0) ->set_text("I5 version by EuReCo using vrt2tei.pl " . localtime->ymd('-')); |
| 403 | &set_sourceDescI5($corpusHeader); |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 404 | $ident="id"; |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 405 | } |
| 406 | else{ |
| 407 | print STDERR "TEIFORMAT is $TEIFORMAT; must be TEI or I5"; |
| 408 | } |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 409 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 410 | $corpusHeader->paste("first_child", $root); |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 411 | $corpusHeader->get_xpath('./profileDesc/langUsage/language', 0) ->set_att($ident, $srctextlangs{$fnsource}); |
| 412 | $corpusHeader->get_xpath('./profileDesc/langUsage/language', 0) ->set_text($expandLang{$srctextlangs{$fnsource}}); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 413 | |
| 414 | if($TEIFORMAT eq "I5"){ |
| 415 | $idsDoc->paste("after", $corpusHeader); |
| 416 | } |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 417 | } |
| 418 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 419 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 420 | #---------------------------- |
| 421 | # handler &text for <text> |
| 422 | #---------------------------- |
| 423 | |
| 424 | sub text { |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 425 | my ($twig, $text, $textHeader) = @_; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 426 | |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 427 | $textcounter++; |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 428 | |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 429 | |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 430 | # ToDo: catch all other, unexpected children of root |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 431 | |
| 432 | #-------------------------------------------------------------------------- |
| 433 | # Get text metadata (attributes of <text>) and create teiHeader for <text> |
| 434 | #-------------------------------------------------------------------------- |
| 435 | |
| 436 | my $textattsref = $text->atts(); # $textattsref is now a reference to a hash and should be used with '->' |
| 437 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 438 | &createIdsDoc($textattsref); # this creation of idsDoc will only be called for the 2nd idsDoc (i.e. february) or higher |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 439 | |
| 440 | |
| 441 | |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 442 | # &createTextHeader returns the $textID: |
| 443 | my $textID = &createTextHeader($text, $textattsref, $textHeader); |
| 444 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 445 | |
| 446 | #---------------------------------------- |
| 447 | # create <TEI> or <idsText> from <text> |
| 448 | #---------------------------------------- |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 449 | |
| 450 | # set vrt <text> to <TEI> and delete all attributes after they were were saved above |
| 451 | $text->del_atts; |
Harald Lüngen | 7abb0b5 | 2024-09-05 16:26:57 +0300 | [diff] [blame] | 452 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 453 | if($TEIFORMAT eq "TEI"){ |
| 454 | $text->set_gi("TEI"); |
| 455 | $text->set_att('xml:id', $textID); |
| 456 | } |
| 457 | else { |
| 458 | $text ->set_gi("idsText"); |
| 459 | $text ->set_att('version', "1.0"); |
| 460 | # $text ->move("last_child", $idsDoc); # does not work because apparently $idsDoc is not under $root at this point |
Harald Lüngen | 7abb0b5 | 2024-09-05 16:26:57 +0300 | [diff] [blame] | 461 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 462 | } |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 463 | |
Harald Lüngen | 7abb0b5 | 2024-09-05 16:26:57 +0300 | [diff] [blame] | 464 | |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 465 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 466 | #------------------------------------------------------------------ |
| 467 | # create the <tei:text>, <body>, <div> elements inside <TEI> |
| 468 | #------------------------------------------------------------------ |
| 469 | |
| 470 | my $ttext_element = XML::Twig::Elt->new('text'); |
| 471 | my $body_element = XML::Twig::Elt->new('body'); |
| 472 | my $div_element = XML::Twig::Elt->new('div'); |
| 473 | |
| 474 | # set atts |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 475 | $div_element ->set_att("type", "page"); # ToDo: this is specific to KLK |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 476 | $ttext_element->set_att("xml:lang", 'fi'); # as in ICC-NOR |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 477 | |
| 478 | # paste |
| 479 | $ttext_element->paste('last_child', $text); |
| 480 | $body_element ->paste('last_child', $ttext_element); |
| 481 | $div_element ->paste('last_child', $body_element); |
| 482 | |
| 483 | |
| 484 | #------------------------------- |
| 485 | # create <p> from <paragraph> |
| 486 | #------------------------------- |
| 487 | |
| 488 | my @paragraphs = $text->children( 'paragraph'); |
| 489 | |
| 490 | foreach my $paragraph (@paragraphs) { |
| 491 | |
| 492 | &setP($paragraph); |
| 493 | |
| 494 | $paragraph->move('last_child', $div_element); |
| 495 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 496 | #------------------------------ |
| 497 | # create <s> from <sentence> |
| 498 | #------------------------------ |
| 499 | |
| 500 | my @sentences = $paragraph->children('sentence'); |
| 501 | foreach my $sentence (@sentences) { |
| 502 | |
| 503 | &setS($sentence); |
| 504 | |
| 505 | |
| 506 | #-------------------------------------- |
| 507 | # create <w> (word) from each $line |
| 508 | #-------------------------------------- |
| 509 | |
| 510 | my @lines = split(/\n+/, $sentence->xml_text); |
| 511 | $sentence->set_text("\n"); |
| 512 | |
| 513 | for my $line (@lines){ # Todo: Reihenfolge checken |
| 514 | if($line ne "" ){ |
| 515 | my $w_element = XML::Twig::Elt->new('w'); |
| 516 | &createW($w_element, $line); |
| 517 | $w_element->paste('last_child', $sentence); |
| 518 | } |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 519 | } # end words |
| 520 | } # end sentences |
| 521 | } # end paragraphs |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 522 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 523 | # $twig->set_pretty_print( 'record'); |
Harald Lüngen | a20e69d | 2024-08-29 13:33:08 +0300 | [diff] [blame] | 524 | # $twig->flush($OUT); |
| 525 | $twig->flush("/dev/stdout"); |
| 526 | } |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 527 | |
| 528 | sub createTextHeader{ |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 529 | my ($text, $textattsref, $textHeader) = @_; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 530 | |
| 531 | # USE 01 binding_id="2246025" |
| 532 | # USE 02 date="2021-01-15" |
| 533 | # 03 datefrom="20210115" |
| 534 | # 04 dateto="20210115" |
| 535 | # 05 elec_date="_" |
| 536 | # 06 file="" |
| 537 | # USE 07 filename_metadata="finclarin_siirto_k2021/0039-5552/2021/alto/2246025_0039-5552_2021-01-15_SK0221_mets.xml" |
| 538 | # USE 08 filename_orig ="finclarin_siirto_k2021/0039-5552/2021/alto/2246025_0039-5552_2021-01-15_SK0221_page-2021011502210030301.xml |
| 539 | # USE 09 id="t-bcd0f3fa-bbd3dac4" |
| 540 | # 10 img_url="" |
| 541 | # USE 11 issue_date="15.01.2021" |
| 542 | # USE 12 issue_no="SK0221" |
| 543 | # USE 13 issue_title="Suomen Kuvalehti" |
| 544 | # USE 14 label="Suomen Kuvalehti no. SK0221 15.01.2021" |
| 545 | # USE 16 language="fi" |
| 546 | # USE 17 page_id="p1" |
| 547 | # USE 18 page_no="None" |
| 548 | # 19 part_name="_" |
| 549 | # 20 publ_id="0039-5552" |
| 550 | # 21 publ_part="" |
| 551 | # USE 22 publ_title="Suomen Kuvalehti" |
| 552 | # USE 23 publ_type="aikakausi" |
| 553 | # USE 24 sentcount="70" |
| 554 | # USE 25 sum_lang="|xxx:44|fin:23|eng:3|" |
| 555 | # 26 timefrom="000000" |
| 556 | # 27 timeto="235959" |
| 557 | # USE 28 tokencount="304" |
| 558 | # 29 version_added="KLK-fi-2021"> |
| 559 | |
| 560 | |
| 561 | my $BID = $textattsref->{'binding_id'}; |
| 562 | my $DATE = $textattsref->{'date'}; |
| 563 | my $METAFILENAME = $textattsref->{'filename_metadata'}; |
| 564 | my $ORIGFILENAME = $textattsref->{'filename_orig'}; |
| 565 | my $ID = $textattsref->{'id'}; |
| 566 | my $ISSUEDATE = $textattsref->{'issue_date'}; |
| 567 | my $ISSUENO = $textattsref->{'issue_no'}; |
| 568 | my $ISSUETITLE = $textattsref->{'issue_title'}; |
| 569 | my $LABEL = $textattsref->{'label'}; |
| 570 | my $LANGUAGE = $textattsref->{'language'}; |
| 571 | my $PAGEID = $textattsref->{'page_id'}; |
| 572 | my $PAGENO = $textattsref->{'page_no'}; |
| 573 | my $PUBLTITLE = $textattsref->{'publ_title'}; |
| 574 | my $PUBLTYPE = $textattsref->{'publ_type'}; |
| 575 | my $SENTCOUNT = $textattsref->{'sentcount'}; |
| 576 | my $SUMLANG = $textattsref->{'sum_lang'}; |
| 577 | my $TOKENCOUNT = $textattsref->{'tokencount'}; |
| 578 | |
Harald Lüngen | ba0354b | 2024-09-11 16:24:08 +0300 | [diff] [blame] | 579 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 580 | #----------------------------- |
| 581 | # Derived Metadata variables |
| 582 | #----------------------------- |
| 583 | |
| 584 | my @datearray = split("-", $DATE); |
| 585 | my @langarray = split("|", $SUMLANG); |
| 586 | my @namearray = split(/[\.\/]/, $ORIGFILENAME); # use $namearray[4] as ID for the page |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 587 | |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 588 | #---------------------------------------------------- |
| 589 | # create textSigle to be returned from this function |
| 590 | #---------------------------------------------------- |
| 591 | |
| 592 | # SUK21.JAN.00001 |
| 593 | |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 594 | my $yy = substr($datearray[0], 2, 2); # substr EXPR,OFFSET,LENGTH |
| 595 | my $mm = $datearray[1]; # substr EXPR,OFFSET,LENGTH |
| 596 | my $MMM = $months{$mm}; |
| 597 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 598 | my $CSIGLE = $corpusids{$fnsource} . $yy; |
| 599 | |
| 600 | my $textID = $CSIGLE . "_" . $MMM . "." . sprintf("%05d", $doccounter{$mm}++); |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 601 | my $textSigle = $textID; |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 602 | |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 603 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 604 | #----------------------------------------------------------------------- |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 605 | # CREATE text-teiHeader ACCORDING TO THE SKELETON in $textHeader |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 606 | #----------------------------------------------------------------------- |
| 607 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 608 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 609 | $textHeader->paste('first_child', $text); |
| 610 | |
| 611 | #----------------------------------------------- |
| 612 | # <teiHeader> |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 613 | # <fileDesc n="EuReCo-KLK-FIN_[$ID]"> |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 614 | # <titleStmt> |
| 615 | # <title>[$LABEL, page $PAGENO]</title> |
| 616 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 617 | $textHeader->first_child("fileDesc") -> set_att('n', "EuReCo-". $kielipankkiCorpus . "-" . $ID); |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 618 | |
| 619 | |
| 620 | #----------------- |
| 621 | # titleStmt |
| 622 | #---------------- |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 623 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 624 | my $title="title"; |
| 625 | my $titleStmt = $textHeader->first_child("fileDesc")->first_child("titleStmt"); |
| 626 | |
| 627 | if($TEIFORMAT eq "I5"){ |
| 628 | $title = "t.title"; |
| 629 | $textSigle =~ s/_/\//g; |
| 630 | $titleStmt->first_child("textSigle")->set_text($textSigle); |
| 631 | }; |
| 632 | |
| 633 | $titleStmt->first_child($title)->set_text($LABEL . ", Text #" . $textcounter); |
| 634 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 635 | # Case KLK: PAGENO scheint meist "None" zu sein |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 636 | |
| 637 | #----------------------------------------------- |
| 638 | # <fileDesc> |
| 639 | # <sourceDesc> |
| 640 | # <biblStruct> |
| 641 | # <analytic> |
| 642 | # <title type="main">[$LABEL, page $PAGENO]</title> |
| 643 | # <date>[$DATE]</date> |
| 644 | # <date type="year">TODO</date> |
| 645 | # <date type="month">TODO</date> |
| 646 | # <date type="day">TODO</date> |
| 647 | # <idno type="PAGEID">$PAGEID</idno> |
| 648 | # <idno type="BINDINGID">$BID</idno> |
| 649 | # <idno type="ID">$ID</idno> |
| 650 | # <idno type="KIELIPANKKI_METAFILENAME">$METAFILENAME</idno> |
| 651 | # <idno type="KIELIPANKKI_ORIGFILENAME">$ORIGFILENAME</idno> |
| 652 | # <textLang>$LANGUAGE</textLang> |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 653 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 654 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 655 | my $analytic = $textHeader->get_xpath("./fileDesc/sourceDesc/biblStruct/analytic", 0); |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 656 | if($TEIFORMAT eq "I5"){$title="h.title"}; |
| 657 | |
| 658 | |
| 659 | $analytic->first_child($title) ->set_text($LABEL . ", Text #" . $textcounter); # Case KLK; PAGENO scheint meist "None" zu sein |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 660 | #$analytic->get_xpath('./idno[@type="PAGEID"]', 0) ->set_text($PAGEID); |
| 661 | #$analytic->get_xpath('./idno[@type="BINDINGID"]', 0) ->set_text($BID); |
| 662 | #$analytic->get_xpath('./idno[@type="ID"]', 0) ->set_text($ID); |
| 663 | #$analytic->get_xpath('./idno[@type="KIELIPANKKI_METAFILENAME"]', 0) ->set_text($METAFILENAME); |
| 664 | #$analytic->get_xpath('./idno[@type="KIELIPANKKI_ORIGFILENAME"]', 0) ->set_text($ORIGFILENAME); |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 665 | if($TEIFORMAT eq "TEI"){ |
| 666 | $analytic->first_child('textLang') ->set_text($LANGUAGE); |
| 667 | } |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 668 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 669 | # <monogr> |
| 670 | # <title>$PUBLTITLE</title> |
| 671 | # <imprint> |
| 672 | # <pubPlace>TODO</pubPlace> |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 673 | # <publisher>TODO</publisher> |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 674 | # </imprint> |
| 675 | # <biblScope unit="ISSUETITLE"/> |
| 676 | # <biblScope unit="ISSUENO"/> |
| 677 | # <biblScope unit="ISSUEDATE"/> |
| 678 | # <biblScope unit="pp">$PAGENO</biblScope> |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 679 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 680 | my $monogr = $textHeader->get_xpath("./fileDesc/sourceDesc/biblStruct/monogr", 0); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 681 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 682 | $monogr->first_child($title) ->set_text($PUBLTITLE); |
| 683 | if($TEIFORMAT eq "TEI"){ |
| 684 | $monogr->get_xpath('./imprint/date[@type="date"]', 0) ->set_text($DATE); |
| 685 | } |
| 686 | my $date = "date"; |
| 687 | if($TEIFORMAT eq "I5"){$date="pubDate"}; |
| 688 | $monogr->get_xpath('./imprint/' . $date . '[@type="year"]', 0) ->set_text($datearray[0]); |
| 689 | $monogr->get_xpath('./imprint/' . $date . '[@type="month"]', 0) ->set_text($datearray[1]); |
| 690 | $monogr->get_xpath('./imprint/' . $date . '[@type="day"]', 0) ->set_text($datearray[2]); |
| 691 | $monogr->first_child("imprint")->first_child("pubPlace") ->set_text($srcpubplaces{$PUBLTITLE}); # imprint is needed for tei validity |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 692 | $monogr->first_child("imprint")->first_child("pubPlace") ->set_att('key', $CountryKey); |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 693 | $monogr->first_child("imprint")->first_child("publisher") ->set_text($srcpublishers{$PUBLTITLE}); # imprint is needed for tei validity |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 694 | #$monogr->get_xpath('./biblScope[@unit="ISSUETITLE"]', 0) ->set_text($ISSUETITLE); |
| 695 | #$monogr->get_xpath('./biblScope[@unit="ISSUENO"]', 0) ->set_text($ISSUENO); |
| 696 | #$monogr->get_xpath('./biblScope[@unit="ISSUEDATE"]', 0) ->set_text($ISSUEDATE); |
| 697 | #$monogr->get_xpath('./biblScope[@unit="pp"]', 0) ->set_text($PAGENO); # Achtung - PAGENO scheint meist "None" zu sein |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 698 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 699 | my $dateNice = $datearray[2] . "." . $datearray[1] . "." . $datearray[0]; |
| 700 | my $dateBackwards = $datearray[0] . "." . $datearray[1] . "." . $datearray[2]; |
| 701 | |
| 702 | if($TEIFORMAT eq "I5"){ |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 703 | my $refCompleteText = $textSigle . " " . $PUBLTITLE . " no. " . $ISSUENO . ", [" . $PUBLTYPE . "], " . $dateNice; |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 704 | my $refShortText = $textSigle . " " . $PUBLTITLE . ", " . $dateNice; |
| 705 | $textHeader->get_xpath('./fileDesc/sourceDesc/reference[@type="complete"]', 0) -> set_text($refCompleteText); |
| 706 | $textHeader->get_xpath('./fileDesc/sourceDesc/reference[@type="short"]' , 0) -> set_text($refShortText); |
| 707 | } |
| 708 | |
| 709 | |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 710 | # <encodingDesc> |
| 711 | # <tagsDecl> |
| 712 | # <namespace name="http://www.tei-c.org/ns/1.0"> |
| 713 | # <tagUsage gi="s" occurs="SENTCOUNT"/> |
| 714 | # <tagUsage gi="w" occurs="TOKENCOUNT"/> |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 715 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 716 | my $namespacePath="./encodingDesc/tagsDecl/namespace/"; |
| 717 | if($TEIFORMAT eq "I5"){$namespacePath="./encodingDesc/tagsDecl/"}; |
| 718 | |
| 719 | $textHeader->get_xpath($namespacePath . 'tagUsage[@gi="s"]', 0) -> set_att('occurs', $SENTCOUNT); |
| 720 | $textHeader->get_xpath($namespacePath . 'tagUsage[@gi="w"]', 0) -> set_att('occurs', $TOKENCOUNT); |
| 721 | |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 722 | # <profileDesc> |
| 723 | # <langUsage> |
| 724 | # <language ident="fi" usage="|xxx:44|fin:23|eng:3|"/> |
| 725 | # </langUsage> |
| 726 | # <textClass> |
| 727 | # <classCode scheme="kielipankki_klk">$PUBLTYPE</classCode> |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 728 | # <classCode scheme="kielipankki_klk_mapped">$mapping{$PUBLTYPE}</classCode> |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 729 | |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 730 | if($TEIFORMAT eq "I5"){ |
| 731 | $textHeader->get_xpath('./profileDesc/creation/creatDate', 0) ->set_text($dateBackwards); |
| 732 | } |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 733 | if($TEIFORMAT eq "TEI"){ |
| 734 | $textHeader->get_xpath('./profileDesc/langUsage/language', 0) ->set_att('ident', $LANGUAGE); |
| 735 | $textHeader->get_xpath('./profileDesc/langUsage/language', 0) ->set_att('usage', $SUMLANG); |
| 736 | } |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 737 | # in @usage muss eigt. ein integer; am besten inhalt von SUMLANG aufdroeseln und mehrere <language> machen |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 738 | |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 739 | $textHeader->get_xpath('./profileDesc/textClass/classCode[@scheme="kielipankki_klk"]', 0) ->set_text($PUBLTYPE); |
Harald Lüngen | 2551a95 | 2024-09-15 08:08:35 +0300 | [diff] [blame] | 740 | $textHeader->get_xpath('./profileDesc/textClass/classCode[@scheme="kielipankki_klk_mapped"]', 0)->set_text($mapping{$PUBLTYPE}); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 741 | |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 742 | # <revisionDesc> |
| 743 | # <change when="TODO" who="HL">TEI version for EuReCo</change> |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 744 | |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 745 | $textHeader->get_xpath('./revisionDesc/change', 0) ->set_att('when', localtime->ymd('-')); |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 746 | |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 747 | return $textID; |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 748 | |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 749 | |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 750 | #----------------------------------- |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 751 | # END OF CREATING TEIHEADER |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 752 | #----------------------------------- |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 753 | |
| 754 | } |
Harald Lüngen | 695ac1d | 2024-09-05 08:55:21 +0300 | [diff] [blame] | 755 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 756 | sub setP { |
| 757 | my ($paragraph) = @_; |
| 758 | |
| 759 | $paragraph->set_gi('p'); |
| 760 | |
| 761 | # <paragraph id="p-bcd0f3fa-bbd3dac4-815ead7a" sum_lang="|fin:1|"> |
| 762 | # atts of <paragraph>: |
| 763 | # @id USE |
| 764 | # @sum_lang USE: put in xml:lang and prefix the value with "x-" for private value |
| 765 | |
| 766 | $paragraph->set_att("xml:lang", "x-" . $paragraph->att("sum_lang")); |
| 767 | $paragraph->del_att("sum_lang"); |
Harald Lüngen | a20e69d | 2024-08-29 13:33:08 +0300 | [diff] [blame] | 768 | # $paragraph->change_att_name('id', 'xml:id'); |
| 769 | $paragraph->del_att("id"); # diese id ist auch nicht eindeutig!! |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 770 | } |
| 771 | sub setS { |
| 772 | my ($sentence) = @_; |
| 773 | |
| 774 | $sentence->set_gi('s'); |
| 775 | |
| 776 | # the atts of <sentence>: |
| 777 | # USE 1 @id="s-bcd0f3fa-bbd3dac4-f7429090" |
| 778 | # USE 2 @lang="fin" -> xml:lang |
| 779 | # ? 3 @lang_conf="0.6734853"> -> ToDo @cert ? |
| 780 | |
| 781 | # set attrs of <s> |
| 782 | $sentence->set_att("xml:lang", $sentence->att("lang")); # ToDo: convert the value / introduce a hash for lookup (input values: "fin", "xxx", ....) |
Harald Lüngen | faf8d48 | 2024-08-27 21:19:47 +0300 | [diff] [blame] | 783 | # $sentence->change_att_name('id', 'xml:id'); # nicht eindeutig |
| 784 | $sentence->del_att('id'); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 785 | $sentence->del_att("lang"); # replaced by xml:lang |
| 786 | $sentence->del_att("lang_conf"); # for the time being |
| 787 | |
| 788 | } |
| 789 | |
| 790 | sub createW { |
| 791 | my ($w_element, $line) = @_; |
| 792 | |
| 793 | #--------------------------- |
| 794 | # Get the tags (=columns) |
| 795 | #--------------------------- |
| 796 | |
| 797 | my @tags = split(/\t/, $line); |
| 798 | |
| 799 | # set content of <w> i.e. the token |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 800 | my $random_w = ""; |
| 801 | # $random_w = Data::Random::String->create_random_string(length=>length($tags[0]), contains=>'alpha'); |
| 802 | $random_w = $tags[0]; |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 803 | $w_element->set_text($random_w); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 804 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 805 | # vrt word and positional-attributes in corpus KLK: |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 806 | # USE [0] word |
| 807 | # USE [1] ref (id for reference of dephead) |
| 808 | # USE [2] lemma |
| 809 | # ? [3] lemmacomp (lemma with compound info - could go in @norm, as tag abuse?) |
| 810 | # USE [4] pos |
| 811 | # USE [5] msd |
| 812 | # USE [6] dephead |
| 813 | # USE [7] deprel |
| 814 | # [8] content (ocr-process) |
| 815 | # [9] vpos (ocr-process) |
| 816 | # [10] ocr (ocr-process) |
| 817 | # [11] cc (ocr-process) |
| 818 | # [12] hyph (ocr-process) |
| 819 | # [13] style (ocr-process) |
| 820 | # [14] lex (korp semantic disambiguation from G"oteborg) |
| 821 | |
| 822 | # set the attributes of <w>: |
| 823 | $w_element->set_att("n", $tags[1]); |
| 824 | # $w_element->set_att("id", "w_" . $namearray[4] . $sentence->att("xml:id") . "_" . $tags[1]); |
| 825 | # so zusammengebaute ID ist auch nicht eindeutig... |
Harald Lüngen | faf8d48 | 2024-08-27 21:19:47 +0300 | [diff] [blame] | 826 | $w_element->del_att("id"); |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 827 | $w_element->set_att("lemma", $tags[2]); |
| 828 | #$w_element->set_att("lemma", $random_w); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 829 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 830 | # $w_element->set_att("norm", $tags[3]); # tag abuse of @norm |
| 831 | $w_element->set_att("pos", $tags[4]); |
| 832 | $w_element->set_att("msd", $tags[5]); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 833 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 834 | if($TEIFORMAT eq "I5"){ # remove condition when part of the official TEI |
| 835 | $w_element->set_att("head", $tags[6]); |
| 836 | $w_element->set_att("deprel", $tags[7]); |
| 837 | } |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 838 | } |
| 839 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 840 | |
| 841 | sub set_title{ |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 842 | my ($corpusHeader, $source, $year, $kielipankkiCorpus) = @_; |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 843 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 844 | my $titleElement = "title"; |
| 845 | |
| 846 | if($TEIFORMAT eq "I5"){ |
| 847 | $titleElement = "c.title"; |
| 848 | } |
| 849 | |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 850 | my $cTitleString = $source . " " . $year . ", from ". $kielipankkiCorpus . " for EuReCo"; |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 851 | |
| 852 | #<teiHeader> |
| 853 | # <fileDesc> |
| 854 | # <titleStmt> |
| 855 | # <title>[Aamulehti2021] from [klk-fi-v2-vrt for] EuReCo</title> |
| 856 | # </titleStmt> |
| 857 | # <!-- ... --> |
| 858 | # </fileDesc> |
| 859 | #</teiHeader> |
| 860 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 861 | my $cTitleNode = $corpusHeader->first_child("fileDesc")->first_child("titleStmt")->first_child($titleElement); |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 862 | |
| 863 | $cTitleNode->set_text($cTitleString); |
| 864 | |
| 865 | } |
| 866 | |
| 867 | sub set_sourceDesc{ |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 868 | my ($corpusHeader, $source, $year, $kielipankkiCorpus) = @_; |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 869 | |
Harald Lüngen | 86cbd93 | 2024-09-10 15:52:18 +0300 | [diff] [blame] | 870 | my $cBiblString = $source . " " . $year . ", from ". $kielipankkiCorpus . " for EuReCo"; |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 871 | |
| 872 | #<teiHeader> |
| 873 | # <fileDesc> |
| 874 | # <!-- ... --> |
| 875 | # <sourceDesc> |
| 876 | # <bibl>[Aamulehti2021] from [klk-fi-v2-vrt]</bibl> |
| 877 | # </sourceDesc> |
| 878 | # <!-- ... --> |
| 879 | # </fileDesc> |
| 880 | #</teiHeader> |
| 881 | |
| 882 | my $cBiblNode = $corpusHeader->first_child("fileDesc")->first_child("sourceDesc")->first_child("bibl"); |
| 883 | |
| 884 | $cBiblNode->set_text($cBiblString); |
| 885 | } |
| 886 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 887 | sub set_sourceDescI5{ |
| 888 | my ($corpusHeader) = @_; |
| 889 | |
| 890 | my $PUBLTITLE = $srcfullnames{$fnsource}; |
| 891 | my $PUBLPLACE = $srcpubplaces{$PUBLTITLE}; |
| 892 | my $PUBLISHER = $srcpublishers{$PUBLTITLE}; |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 893 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 894 | my $YEAR = $fnyear; |
| 895 | my $YY = substr($fnyear, 2, 2); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 896 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 897 | my $CSIGLE = $corpusids{$PUBLTITLE} . $YY; |
| 898 | |
| 899 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 900 | #<idsHeader> |
| 901 | # <fileDesc> |
| 902 | # <!-- ... --> |
| 903 | # <sourceDesc> |
| 904 | # <biblStruct> |
| 905 | # <monogr> |
| 906 | # <h.title type="main">[$PUBLTITLE], [$YEAR]</h.title> |
| 907 | # <imprint> |
| 908 | # <publisher>[$PUBLISHER]</publisher> |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 909 | # <pubPlace key="[$TL]">[$PUBPLACE]</pubPlace> |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 910 | # </imprint> |
| 911 | # </monogr> |
| 912 | # </biblStruct> |
| 913 | # <reference type="super" assemblage="regular">[$KKK] [$PUBLTITLE]; [$PUBPLACE]: [$PUBLISHER], [$YEAR]</reference> |
| 914 | # </sourceDesc> # <sourceDesc> |
| 915 | # <!-- ... --> |
| 916 | # </fileDesc> |
| 917 | #</teiHeader> |
| 918 | |
| 919 | my $cMonogr = $corpusHeader->first_child("fileDesc")->first_child("sourceDesc")->first_child("biblStruct")->first_child("monogr"); |
| 920 | $cMonogr->first_child("h.title")->set_text($PUBLTITLE); |
| 921 | $cMonogr->first_child("imprint")->first_child("publisher")->set_text($PUBLISHER); |
| 922 | $cMonogr->first_child("imprint")->first_child("pubPlace") ->set_text($PUBLPLACE); |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 923 | $cMonogr->first_child("imprint")->first_child("pubPlace") ->set_att('key', $CountryKey); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 924 | |
| 925 | $corpusHeader->first_child("fileDesc")->first_child("sourceDesc")->first_child("reference")->set_text($CSIGLE . " " . $PUBLTITLE . "; " . $PUBLPLACE . ": " . $PUBLISHER . ", " . $YEAR); |
| 926 | |
| 927 | } |
| 928 | |
| 929 | |
| 930 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 931 | sub createIdsDoc{ # will only be called for the second idsDoc (i.e. for february) and higher |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 932 | my ($textattsref) = @_; |
| 933 | my $DATE = $textattsref->{'date'}; |
| 934 | my $PUBLTITLE = $textattsref->{'publ_title'}; |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 935 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 936 | my @datearray = split("-", $DATE); |
| 937 | my $MONTH = $datearray[1]; |
| 938 | my $YEAR = $datearray[0]; |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 939 | my $YY = substr($YEAR, 2, 2); |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 940 | |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 941 | my $CSIGLE = $corpusids{$PUBLTITLE} . $YY; |
| 942 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 943 | my $DOCID = $months{$MONTH}; |
| 944 | my $MONTHNAME = $monthnames{$MONTH}; |
| 945 | |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 946 | my $idsDocString=""; |
| 947 | if($TEIFORMAT eq "I5"){ |
| 948 | $idsDocString = " |
Harald Lüngen | 8162ad5 | 2024-09-19 10:54:24 +0300 | [diff] [blame^] | 949 | <idsDoc version=\"1.0\" TEIform=\"TEI.2\"> |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 950 | <idsHeader type=\"document\" pattern=\"text\" version=\"1.1\" TEIform=\"teiHeader\"> |
| 951 | <fileDesc> |
| 952 | <titleStmt> |
| 953 | <dokumentSigle>$CSIGLE/$DOCID</dokumentSigle> |
| 954 | <d.title>$PUBLTITLE, $MONTHNAME $YEAR</d.title> |
| 955 | </titleStmt> |
| 956 | <publicationStmt> |
| 957 | <distributor/> |
| 958 | <pubAddress/> |
| 959 | <availability region=\"world\">$kielipankkiLicense</availability> |
| 960 | <pubDate/> |
| 961 | </publicationStmt> |
| 962 | <sourceDesc> |
| 963 | <biblStruct> |
| 964 | <monogr> |
| 965 | <h.title/> |
| 966 | <imprint/> |
| 967 | </monogr> |
| 968 | </biblStruct> |
| 969 | </sourceDesc> |
| 970 | </fileDesc> |
| 971 | </idsHeader> |
| 972 | </idsDoc>\n"; |
| 973 | } |
| 974 | if($MONTH + 0 == $LASTMONTH + 1){ |
| 975 | if($MONTH+0 > 1){ |
| 976 | printf("%s\n", $idsDocString); |
| 977 | } |
| 978 | $LASTMONTH++; |
| 979 | } |
Harald Lüngen | 381c2a2 | 2024-09-17 09:06:39 +0300 | [diff] [blame] | 980 | } |
| 981 | |
Harald Lüngen | db5e6e7 | 2024-09-04 17:41:18 +0300 | [diff] [blame] | 982 | |
| 983 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 984 | ################# |
| 985 | ## usage_message |
| 986 | ################# |
| 987 | |
| 988 | |
| 989 | sub usage_message { |
Harald Lüngen | a7e9162 | 2024-08-23 17:33:11 +0300 | [diff] [blame] | 990 | print " Usage: ./vrt2tei.pl <file.vrt.xml> <outfile>\n"; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 991 | print " <file.vrt.xml> is a VRT file converted to proper XML\n"; |
| 992 | exit; |
| 993 | } |
| 994 | |
| 995 | |