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