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