Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 1 | #! /usr/bin/perl -w |
| 2 | |
| 3 | |
| 4 | ########################################################################################################################################################### |
| 5 | # vrt2tei.pl |
| 6 | # eureco |
| 7 | # leibniz-institut fuer deutsche sprache / csc finland esbo |
| 8 | # august 2024 |
| 9 | # |
| 10 | # |
| 11 | # using XML::Twig , see http://www.xmltwig.org/, https://metacpan.org/pod/XML::Twiga |
| 12 | # |
Harald Lüngen | ccd8490 | 2024-08-27 16:03:47 +0300 | [diff] [blame] | 13 | # usage: see below the usage fugnction |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 14 | # Usage: ./vrt2tei.pl <vrtxmlfile.xml> <outfile> |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 15 | # <vrtxmlfile>: xml-ised vrt file |
| 16 | # |
| 17 | # |
| 18 | # TODO: |
| 19 | # 1 insert dtd spec, or ref to TEI |
| 20 | |
| 21 | # 3a UPLOAD in GITHUB |
| 22 | # 3b add @head and @deprel to I5 sowie auch @msd |
| 23 | # 3c bearbeitung von @head und @deprel in tei2korapxml durch Nils? |
| 24 | # 3d build 30 billion corpus |
| 25 | |
| 26 | # 4a take care of IDs |
| 27 | # 4b see to the values of @xml:lang |
| 28 | # 5 abfangen von unerwarteten elementen dh andere als <sentence> und <paragraph> |
| 29 | # 5a wort reihenfolge nochmal checken |
| 30 | # 6 checks and balances |
| 31 | # 6a output nach stdout machen |
| 32 | # 7 How to encode Kielipankki and National Library of Finland? in teiCorpus Header |
| 33 | # 8 construct <idsDoc>s for the months (or go for TEI) |
| 34 | # 9 parallelisation in bash and application on sub corpora of KLK |
| 35 | # 10 re-implementation of the gawk code in the perl script |
| 36 | # 12 re-implement creation of text header from xml file in another twig / parametrize TEI vs I5 |
| 37 | |
| 38 | |
| 39 | |
| 40 | #remember |
| 41 | #formatted.xml:105613: element w: validity error : No declaration for attribute deprel of element w |
| 42 | #formatted.xml:105613: element w: validity error : No declaration for attribute head of element w |
| 43 | |
| 44 | |
| 45 | # |
| 46 | # |
| 47 | ############################################################################################################################################################ |
| 48 | |
| 49 | |
| 50 | use strict; |
| 51 | use warnings; |
| 52 | |
| 53 | use XML::Twig; |
| 54 | use XML::Generator ':pretty'; # apparently no effect when using flush(); |
| 55 | |
| 56 | |
| 57 | use locale; # diese drei Zeilen, damit \b im regex nicht Umlaute und ß matcht. |
| 58 | use POSIX qw(locale_h); # to be able to use setlocale() |
| 59 | #setlocale(LC_ALL,'de_DE'); |
| 60 | setlocale(LC_ALL, "fi_FI"); |
| 61 | use utf8; |
| 62 | use open qw( :std :encoding(UTF-8) ); |
| 63 | |
| 64 | use Time::Piece; |
| 65 | use Tie::IxHash; |
| 66 | |
| 67 | #---------------------- |
| 68 | # check file arguments: |
| 69 | #---------------------- |
| 70 | |
| 71 | # arg0 infile: vrt-xml |
| 72 | # arg1 outfile: tei |
| 73 | |
| 74 | unless($ARGV[1]) {&usage_message()}; # min arg0 und arg1 |
| 75 | if ($ARGV[2]) {&usage_message()}; # max arg1 |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | #################### |
| 81 | # GLOBAL VARIABLES |
| 82 | #################### |
| 83 | |
| 84 | my $encoding = "UTF-8"; |
| 85 | #my $encoding = "iso-8859-1"; # dieses $encoding ist NUR fuer das output s.u. twig funktion |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 86 | my $textcounter = 0; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 87 | |
| 88 | |
| 89 | ##################### |
| 90 | # M A I N |
| 91 | ##################### |
| 92 | |
| 93 | |
| 94 | # open result file and initialise filehandle |
Harald Lüngen | ccd8490 | 2024-08-27 16:03:47 +0300 | [diff] [blame] | 95 | open(my $OUT, "> $ARGV[1]") || die("cannot open file: $ARGV[1]"); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 96 | |
| 97 | |
| 98 | |
| 99 | #----------------------------------------------------------------------------------- |
| 100 | # start twig and call start tag handler for root and twig handler for each <text> |
| 101 | #----------------------------------------------------------------------------------- |
| 102 | |
| 103 | my $twig=""; |
| 104 | |
| 105 | $twig = new XML::Twig( |
| 106 | keep_spaces => 1, # dadurch auch whitespaces an ehemeligen elementgrenzen im output |
| 107 | keep_atts_order => 1, # requires Tie::IxHash |
| 108 | pretty_print => 'indented', |
| 109 | start_tag_handlers => { |
| 110 | texts => \&root |
| 111 | }, |
| 112 | twig_handlers => { |
| 113 | text => \&text |
| 114 | }, |
| 115 | # dtd_handlers => { # ToDo for I5 |
| 116 | # \&set_dtd; |
| 117 | # } |
| 118 | output_encoding => $encoding, |
| 119 | ); |
| 120 | |
| 121 | $twig->parsefile($ARGV[0]); |
| 122 | |
| 123 | close($OUT); |
| 124 | |
| 125 | |
| 126 | ########### |
| 127 | # END MAIN |
| 128 | ########### |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | ############################## |
| 134 | # S U B R O U T I N E S |
| 135 | ############################## |
| 136 | |
| 137 | # sub set_dtd [ |
| 138 | # my $twig, $dtd = @_; |
| 139 | # my $internal = qq|\nPUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n"DTD/xhtml1-strict.dtd"|; |
| 140 | # |
| 141 | # $twig->twig_doctype('html', undef, undef, $internal); |
| 142 | # } |
| 143 | |
| 144 | |
| 145 | |
| 146 | sub root { |
| 147 | my ($twig, $root) =@_; |
| 148 | |
| 149 | $root->set_gi('teiCorpus'); |
| 150 | $root->set_att("xmlns", 'http://www.tei-c.org/ns/1.0'); |
| 151 | |
| 152 | &insertCorpusHeader($root); |
| 153 | } |
| 154 | |
| 155 | |
| 156 | sub insertCorpusHeader{ |
| 157 | my ($root) =@_; |
| 158 | |
Harald Lüngen | ccd8490 | 2024-08-27 16:03:47 +0300 | [diff] [blame] | 159 | my @array = split(/\//, $ARGV[0]); |
| 160 | my $l = scalar(@array); |
| 161 | my $source = $array[$l-1]; |
| 162 | $source =~ s/\.xml//; |
Harald Lüngen | 5bebb0c | 2024-08-27 16:44:34 +0300 | [diff] [blame^] | 163 | $source = $source . " from klk-fi-v2-vrt"; # for the time being; TODO |
Harald Lüngen | ccd8490 | 2024-08-27 16:03:47 +0300 | [diff] [blame] | 164 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 165 | my $teiHeader = $root ->insert_new_elt("first_child", 'teiHeader'); |
| 166 | my $fileDesc = $teiHeader ->insert_new_elt("last_child", 'fileDesc'); |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 167 | my $profileDesc = $teiHeader ->insert_new_elt("last_child", 'profileDesc'); |
| 168 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 169 | my $titleStmt = $fileDesc ->insert_new_elt("last_child", 'titleStmt'); |
| 170 | my $title = $titleStmt ->insert_new_elt("last_child", 'title'); |
Harald Lüngen | ccd8490 | 2024-08-27 16:03:47 +0300 | [diff] [blame] | 171 | $title ->set_text($source . " from KLK-fi-2021 for EuReCo"); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 172 | |
| 173 | my $publicationStmt = $fileDesc ->insert_new_elt("last_child", 'publicationStmt'); |
| 174 | my $distributor = $publicationStmt->insert_new_elt("last_child", 'distributor'); |
| 175 | $distributor ->set_text("NOT FOR DISTRIBUTION - to be used locally in EuReCo"); |
| 176 | |
| 177 | my $sourceDesc = $fileDesc ->insert_new_elt("last_child", 'sourceDesc'); |
| 178 | my $bibl = $sourceDesc ->insert_new_elt("last_child", 'bibl'); |
Harald Lüngen | ccd8490 | 2024-08-27 16:03:47 +0300 | [diff] [blame] | 179 | $bibl ->set_text($source); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 180 | |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 181 | my $langUsage = $profileDesc ->insert_new_elt("last_child", 'langUsage'); |
| 182 | my $language = $langUsage ->insert_new_elt("last_child", 'language'); |
| 183 | $language ->set_att("ident",'fi'); |
| 184 | $language ->set_text("Finnish"); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
| 188 | #---------------------------- |
| 189 | # handler &text for <text> |
| 190 | #---------------------------- |
| 191 | |
| 192 | sub text { |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 193 | my ($twig, $text) = @_; |
| 194 | |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 195 | $textcounter++; # global variable |
| 196 | |
| 197 | # ToDo: catch all other, unexpected children of root |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 198 | |
| 199 | #-------------------------------------------------------------------------- |
| 200 | # Get text metadata (attributes of <text>) and create teiHeader for <text> |
| 201 | #-------------------------------------------------------------------------- |
| 202 | |
| 203 | my $textattsref = $text->atts(); # $textattsref is now a reference to a hash and should be used with '->' |
| 204 | |
| 205 | &createTextHeader($text, $textattsref); |
| 206 | |
| 207 | #-------------------------- |
| 208 | # create <TEI> from <text> |
| 209 | #-------------------------- |
| 210 | |
| 211 | # set vrt <text> to <TEI> and delete all attributes after they were were saved above |
| 212 | $text->del_atts; |
| 213 | $text->set_gi("TEI"); |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 214 | |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 215 | #------------------------------------------------------------------ |
| 216 | # create the <tei:text>, <body>, <div> elements inside <TEI> |
| 217 | #------------------------------------------------------------------ |
| 218 | |
| 219 | my $ttext_element = XML::Twig::Elt->new('text'); |
| 220 | my $body_element = XML::Twig::Elt->new('body'); |
| 221 | my $div_element = XML::Twig::Elt->new('div'); |
| 222 | |
| 223 | # set atts |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 224 | $div_element ->set_att("type", "page"); # ToDo: this is specific to KLK |
| 225 | $ttext_element->set_att("xml:lang", 'fi'); # as in ICC-NOR |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 226 | |
| 227 | # paste |
| 228 | $ttext_element->paste('last_child', $text); |
| 229 | $body_element ->paste('last_child', $ttext_element); |
| 230 | $div_element ->paste('last_child', $body_element); |
| 231 | |
| 232 | |
| 233 | #------------------------------- |
| 234 | # create <p> from <paragraph> |
| 235 | #------------------------------- |
| 236 | |
| 237 | my @paragraphs = $text->children( 'paragraph'); |
| 238 | |
| 239 | foreach my $paragraph (@paragraphs) { |
| 240 | |
| 241 | &setP($paragraph); |
| 242 | |
| 243 | $paragraph->move('last_child', $div_element); |
| 244 | |
| 245 | |
| 246 | #------------------------------ |
| 247 | # create <s> from <sentence> |
| 248 | #------------------------------ |
| 249 | |
| 250 | my @sentences = $paragraph->children('sentence'); |
| 251 | foreach my $sentence (@sentences) { |
| 252 | |
| 253 | &setS($sentence); |
| 254 | |
| 255 | |
| 256 | #-------------------------------------- |
| 257 | # create <w> (word) from each $line |
| 258 | #-------------------------------------- |
| 259 | |
| 260 | my @lines = split(/\n+/, $sentence->xml_text); |
| 261 | $sentence->set_text("\n"); |
| 262 | |
| 263 | for my $line (@lines){ # Todo: Reihenfolge checken |
| 264 | if($line ne "" ){ |
| 265 | my $w_element = XML::Twig::Elt->new('w'); |
| 266 | &createW($w_element, $line); |
| 267 | $w_element->paste('last_child', $sentence); |
| 268 | } |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 269 | } # end words |
| 270 | } # end sentences |
| 271 | } # end paragraphs |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 272 | |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 273 | $twig->flush($OUT); |
| 274 | } # end texts |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 275 | |
| 276 | |
| 277 | sub createTextHeader{ |
| 278 | my ($text, $textattsref) = @_; |
| 279 | |
| 280 | # USE 01 binding_id="2246025" |
| 281 | # USE 02 date="2021-01-15" |
| 282 | # 03 datefrom="20210115" |
| 283 | # 04 dateto="20210115" |
| 284 | # 05 elec_date="_" |
| 285 | # 06 file="" |
| 286 | # USE 07 filename_metadata="finclarin_siirto_k2021/0039-5552/2021/alto/2246025_0039-5552_2021-01-15_SK0221_mets.xml" |
| 287 | # USE 08 filename_orig ="finclarin_siirto_k2021/0039-5552/2021/alto/2246025_0039-5552_2021-01-15_SK0221_page-2021011502210030301.xml |
| 288 | # USE 09 id="t-bcd0f3fa-bbd3dac4" |
| 289 | # 10 img_url="" |
| 290 | # USE 11 issue_date="15.01.2021" |
| 291 | # USE 12 issue_no="SK0221" |
| 292 | # USE 13 issue_title="Suomen Kuvalehti" |
| 293 | # USE 14 label="Suomen Kuvalehti no. SK0221 15.01.2021" |
| 294 | # USE 16 language="fi" |
| 295 | # USE 17 page_id="p1" |
| 296 | # USE 18 page_no="None" |
| 297 | # 19 part_name="_" |
| 298 | # 20 publ_id="0039-5552" |
| 299 | # 21 publ_part="" |
| 300 | # USE 22 publ_title="Suomen Kuvalehti" |
| 301 | # USE 23 publ_type="aikakausi" |
| 302 | # USE 24 sentcount="70" |
| 303 | # USE 25 sum_lang="|xxx:44|fin:23|eng:3|" |
| 304 | # 26 timefrom="000000" |
| 305 | # 27 timeto="235959" |
| 306 | # USE 28 tokencount="304" |
| 307 | # 29 version_added="KLK-fi-2021"> |
| 308 | |
| 309 | |
| 310 | my $BID = $textattsref->{'binding_id'}; |
| 311 | my $DATE = $textattsref->{'date'}; |
| 312 | my $METAFILENAME = $textattsref->{'filename_metadata'}; |
| 313 | my $ORIGFILENAME = $textattsref->{'filename_orig'}; |
| 314 | my $ID = $textattsref->{'id'}; |
| 315 | my $ISSUEDATE = $textattsref->{'issue_date'}; |
| 316 | my $ISSUENO = $textattsref->{'issue_no'}; |
| 317 | my $ISSUETITLE = $textattsref->{'issue_title'}; |
| 318 | my $LABEL = $textattsref->{'label'}; |
| 319 | my $LANGUAGE = $textattsref->{'language'}; |
| 320 | my $PAGEID = $textattsref->{'page_id'}; |
| 321 | my $PAGENO = $textattsref->{'page_no'}; |
| 322 | my $PUBLTITLE = $textattsref->{'publ_title'}; |
| 323 | my $PUBLTYPE = $textattsref->{'publ_type'}; |
| 324 | my $SENTCOUNT = $textattsref->{'sentcount'}; |
| 325 | my $SUMLANG = $textattsref->{'sum_lang'}; |
| 326 | my $TOKENCOUNT = $textattsref->{'tokencount'}; |
| 327 | |
| 328 | |
| 329 | #----------------------------- |
| 330 | # Derived Metadata variables |
| 331 | #----------------------------- |
| 332 | |
| 333 | my @datearray = split("-", $DATE); |
| 334 | my @langarray = split("|", $SUMLANG); |
| 335 | my @namearray = split(/[\.\/]/, $ORIGFILENAME); # use $namearray[4] as ID for the page |
| 336 | |
| 337 | |
| 338 | #----------------------------------------------------------------------- |
| 339 | # CREATE text-teiHeader ACCORDING TO THE SKELETON in klk-header.tei.xml |
| 340 | #----------------------------------------------------------------------- |
| 341 | |
| 342 | # create <teiHeader> inside <TEI> |
| 343 | my $teiHeader = XML::Twig::Elt->new('teiHeader'); |
| 344 | $teiHeader->paste('first_child', $text); |
| 345 | |
| 346 | ## insert_new_elt is a combo of new and paste, cf. xml::twig docu: |
| 347 | ## insert_new_elt ($opt_position, $gi, $opt_atts_hashref, @opt_content) |
| 348 | |
| 349 | my $fileDesc = $teiHeader->insert_new_elt('fileDesc' => {n => "EuReCo_KLK-fi_" . $namearray[4]}); |
| 350 | my $encodingDesc = $teiHeader->insert_new_elt("last_child", 'encodingDesc'); |
| 351 | my $profileDesc = $teiHeader->insert_new_elt("last_child", 'profileDesc'); |
| 352 | my $revisionDesc = $teiHeader->insert_new_elt("last_child", 'revisionDesc'); |
| 353 | |
| 354 | #--------------------- |
| 355 | # fileDesc/titleStmt |
| 356 | #--------------------- |
| 357 | my $titleStmt = $fileDesc ->insert_new_elt('titleStmt'); |
| 358 | my $title = $titleStmt->insert_new_elt("last_child", 'title'); |
| 359 | my $respStmt = $titleStmt->insert_new_elt("last_child", 'respStmt'); |
| 360 | my $resp = $respStmt ->insert_new_elt("last_child", 'resp'); |
| 361 | my $name = $respStmt ->insert_new_elt("last_child", 'name'); |
| 362 | |
| 363 | # set texts for titleStmt |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 364 | # $title->set_text($LABEL . ", page " . $PAGENO); # Achtung - PAGENO scheint meist "None" zu sein |
| 365 | $title->set_text($LABEL . ", Text #" . $textcounter); # at least for Suomen Kuvalehti |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 366 | $resp ->set_text("compiled by EuReCo"); |
| 367 | $name ->set_text("EuReCo: HL"); |
| 368 | |
| 369 | #-------------------------- |
| 370 | # fileDesc/publicationStmt |
| 371 | #-------------------------- |
| 372 | my $publicationStmt = $fileDesc ->insert_new_elt("last_child", 'publicationStmt'); |
| 373 | my $distributor = $publicationStmt->insert_new_elt("last_child", 'distributor'); |
| 374 | my $note = $distributor ->insert_new_elt("last_child", 'note'); |
| 375 | my $availability = $publicationStmt->insert_new_elt("last_child", 'availability'); |
| 376 | my $licence = $availability ->insert_new_elt("last_child", 'licence'); |
| 377 | |
| 378 | # set texts for publicationStmt |
| 379 | $note ->set_text("NOT FOR DISTRIBUTION - to be used locally in EuReCo"); |
| 380 | $licence->set_text("CLARIN-RES"); # TODO: Ausfuherlichere Licence info in KLK Metadata Record |
| 381 | |
| 382 | #------------------------------ |
| 383 | # fileDesc/sourceDesc/biblStruct |
| 384 | #------------------------------ |
| 385 | my $sourceDesc = $fileDesc ->insert_new_elt("last_child", 'sourceDesc'); |
| 386 | my $biblStruct = $sourceDesc->insert_new_elt("last_child", 'biblStruct'); |
| 387 | |
| 388 | # fileDesc/sourceDesc/biblStruct/analytic |
| 389 | my $analytic = $biblStruct->insert_new_elt("last_child", 'analytic'); |
| 390 | my $analytic_title = $analytic->insert_new_elt("last_child", 'title' => {type => "main"} ); |
| 391 | # my $analytic_date = $analytic->insert_new_elt("last_child", 'date'); |
| 392 | my $analytic_date_year = $analytic->insert_new_elt("last_child", 'date' => {type => "year"}); |
| 393 | my $analytic_date_month = $analytic->insert_new_elt("last_child", 'date' => {type => "month"}); |
| 394 | my $analytic_date_day = $analytic->insert_new_elt("last_child", 'date' => {type => "day"}); |
| 395 | my $analytic_idno_pageid = $analytic->insert_new_elt("last_child", 'idno' => {type => "PAGEID"}); |
| 396 | my $analytic_idno_bindingid = $analytic->insert_new_elt("last_child", 'idno' => {type => "BINDINGID"}); |
| 397 | my $analytic_idno_id = $analytic->insert_new_elt("last_child", 'idno' => {type => "ID"}); |
| 398 | my $analytic_idno_metafile = $analytic->insert_new_elt("last_child", 'idno' => {type => "KIELIPANKKI_METAFILENAME"}); |
| 399 | my $analytic_idno_origfile = $analytic->insert_new_elt("last_child", 'idno' => {type => "KIELIPANKKI_ORIGFILENAME"}); |
| 400 | my $analytic_textlang = $analytic->insert_new_elt("last_child", 'textLang'); |
| 401 | |
| 402 | # set texts for analytic |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 403 | # $analytic_title ->set_text($LABEL . ", page " . $PAGENO); # Achtung $PAGENO scheint meist "None zu sein" |
| 404 | $analytic_title ->set_text($LABEL . ", Text #" . $textcounter); # Achtung $PAGENO scheint meist "None zu sein" |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 405 | # $analytic_date ->set_text($DATE); |
| 406 | $analytic_date_year ->set_text($datearray[0]); |
| 407 | $analytic_date_month ->set_text($datearray[1]); |
| 408 | $analytic_date_day ->set_text($datearray[2]); |
| 409 | $analytic_idno_pageid ->set_text($PAGEID); |
| 410 | $analytic_idno_bindingid->set_text($BID); |
| 411 | $analytic_idno_id ->set_text($ID); |
| 412 | $analytic_idno_metafile ->set_text($METAFILENAME); |
| 413 | $analytic_idno_origfile ->set_text($ORIGFILENAME); |
| 414 | $analytic_textlang ->set_text($LANGUAGE); |
| 415 | |
| 416 | #------------------------------------- |
| 417 | # fileDesc/sourceDesc/biblStruct/monogr |
| 418 | #------------------------------------- |
| 419 | my $monogr = $biblStruct->insert_new_elt("last_child", 'monogr'); |
| 420 | my $monogr_title = $monogr ->insert_new_elt("last_child", 'title'); |
| 421 | my $imprint = $monogr ->insert_new_elt("last_child", 'imprint'); # imprint is needed for valididty |
| 422 | my $pubPlace = $imprint ->insert_new_elt("last_child", 'pubPlace'); # imprint is needed for validity |
| 423 | my $publisher = $imprint ->insert_new_elt("last_child", 'publisher'); # imprint is needed for validity |
| 424 | my $biblScope_issuetitle = $monogr ->insert_new_elt("last_child", 'biblScope' => {unit => 'ISSUETITLE'} ); |
| 425 | my $biblScope_issueno = $monogr ->insert_new_elt("last_child", 'biblScope' => {unit => 'ISSUENO'} ); |
| 426 | my $biblScope_issuedate = $monogr ->insert_new_elt("last_child", 'biblScope' => {unit => 'ISSUEDATE'} ); |
| 427 | my $biblScope_pp = $monogr ->insert_new_elt("last_child", 'biblScope' => {unit => 'PAGENO'} ); # Achtung PAGENO ist meist "None" ? |
| 428 | |
| 429 | # set texts for monogr |
| 430 | $monogr_title ->set_text($PUBLTITLE); |
| 431 | $pubPlace ->set_text("TODO"); |
Harald Lüngen | caab080 | 2024-08-23 17:28:22 +0300 | [diff] [blame] | 432 | $pubPlace ->set_att("key",'FI'); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 433 | $publisher ->set_text("TODO"); |
| 434 | $biblScope_issuetitle->set_text($ISSUETITLE); |
| 435 | $biblScope_issueno ->set_text($ISSUENO); |
| 436 | $biblScope_issuedate ->set_text($ISSUEDATE); |
| 437 | $biblScope_pp ->set_text($PAGENO); |
| 438 | |
| 439 | #--------------- |
| 440 | # encodingDesc |
| 441 | #--------------- |
| 442 | my $tagsDecl = $encodingDesc->insert_new_elt("last_child", 'tagsDecl'); |
| 443 | my $namespace = $tagsDecl ->insert_new_elt("last_child", 'namespace' => {name => 'http://www.tei-c.org/ns/1.0'}); |
| 444 | my $tagUsage_s = $namespace ->insert_new_elt("last_child", 'tagUsage' => {gi => 's', occurs => $SENTCOUNT}); |
| 445 | my $tagUsage_w = $namespace ->insert_new_elt("last_child", 'tagUsage' => {gi => 'w', occurs => $TOKENCOUNT}); |
| 446 | |
| 447 | #------------- |
| 448 | # profileDesc |
| 449 | #------------- |
| 450 | my $langUsage = $profileDesc ->insert_new_elt("last_child", 'langUsage'); |
| 451 | my $language = $langUsage ->insert_new_elt("last_child", 'language' => {ident => $LANGUAGE, usage => $SUMLANG}); |
| 452 | # Achtung in @usage muss eigt. ein integer; am besten inhalt von SUMLANG aufdroeseln und mehrere <language> machen |
| 453 | my $textClass = $profileDesc ->insert_new_elt("last_child", 'textClass'); |
| 454 | my $classCode_fi = $textClass ->insert_new_elt("last_child", 'classCode' => {scheme => "KLK_PUBLTYPE"}); |
| 455 | # my $classCode_en = $textClass ->insert_new_elt("last_child", 'classCode' => {scheme => "KLK_PUBLTYPE_MAPPED"}); |
| 456 | |
| 457 | #--------------------------- |
| 458 | # set texts for profileDesc |
| 459 | #--------------------------- |
| 460 | $classCode_fi ->set_text($PUBLTYPE); |
| 461 | # $classCode_en->set_text($PUBLTYPETRANSL); |
| 462 | |
| 463 | #--------------- |
| 464 | # revisionDesc |
| 465 | #--------------- |
| 466 | my $change = $revisionDesc ->insert_new_elt("last_child", 'change' => {when => localtime->ymd('-'), who => 'HL' }); |
| 467 | |
| 468 | # set texts for revisionDesc |
| 469 | $change->set_text("TEI version for EuReCo"); |
| 470 | |
| 471 | |
| 472 | ################################### |
| 473 | # END OF CREATING TEIHEADER |
| 474 | ################################### |
| 475 | |
| 476 | } |
| 477 | |
| 478 | sub setP { |
| 479 | my ($paragraph) = @_; |
| 480 | |
| 481 | $paragraph->set_gi('p'); |
| 482 | |
| 483 | # <paragraph id="p-bcd0f3fa-bbd3dac4-815ead7a" sum_lang="|fin:1|"> |
| 484 | # atts of <paragraph>: |
| 485 | # @id USE |
| 486 | # @sum_lang USE: put in xml:lang and prefix the value with "x-" for private value |
| 487 | |
| 488 | $paragraph->set_att("xml:lang", "x-" . $paragraph->att("sum_lang")); |
| 489 | $paragraph->del_att("sum_lang"); |
| 490 | $paragraph->change_att_name('id', 'xml:id'); |
| 491 | } |
| 492 | sub setS { |
| 493 | my ($sentence) = @_; |
| 494 | |
| 495 | $sentence->set_gi('s'); |
| 496 | |
| 497 | # the atts of <sentence>: |
| 498 | # USE 1 @id="s-bcd0f3fa-bbd3dac4-f7429090" |
| 499 | # USE 2 @lang="fin" -> xml:lang |
| 500 | # ? 3 @lang_conf="0.6734853"> -> ToDo @cert ? |
| 501 | |
| 502 | # set attrs of <s> |
| 503 | $sentence->set_att("xml:lang", $sentence->att("lang")); # ToDo: convert the value / introduce a hash for lookup (input values: "fin", "xxx", ....) |
| 504 | $sentence->change_att_name('id', 'xml:id'); |
| 505 | $sentence->del_att("lang"); # replaced by xml:lang |
| 506 | $sentence->del_att("lang_conf"); # for the time being |
| 507 | |
| 508 | } |
| 509 | |
| 510 | sub createW { |
| 511 | my ($w_element, $line) = @_; |
| 512 | |
| 513 | #--------------------------- |
| 514 | # Get the tags (=columns) |
| 515 | #--------------------------- |
| 516 | |
| 517 | my @tags = split(/\t/, $line); |
| 518 | |
| 519 | # set content of <w> i.e. the token |
| 520 | $w_element->set_text($tags[0]); |
| 521 | |
| 522 | # vrt positional-attributes in corpus KLK: |
| 523 | # USE [0] word |
| 524 | # USE [1] ref (id for reference of dephead) |
| 525 | # USE [2] lemma |
| 526 | # ? [3] lemmacomp (lemma with compound info - could go in @norm, as tag abuse?) |
| 527 | # USE [4] pos |
| 528 | # USE [5] msd |
| 529 | # USE [6] dephead |
| 530 | # USE [7] deprel |
| 531 | # [8] content (ocr-process) |
| 532 | # [9] vpos (ocr-process) |
| 533 | # [10] ocr (ocr-process) |
| 534 | # [11] cc (ocr-process) |
| 535 | # [12] hyph (ocr-process) |
| 536 | # [13] style (ocr-process) |
| 537 | # [14] lex (korp semantic disambiguation from G"oteborg) |
| 538 | |
| 539 | # set the attributes of <w>: |
| 540 | $w_element->set_att("n", $tags[1]); |
| 541 | # $w_element->set_att("id", "w_" . $namearray[4] . $sentence->att("xml:id") . "_" . $tags[1]); |
| 542 | # so zusammengebaute ID ist auch nicht eindeutig... |
| 543 | $w_element->change_att_name('id', 'xml:id'); |
| 544 | $w_element->set_att("lemma", $tags[2]); |
| 545 | # $w_element->set_att("norm", $tags[3]); # tag abuse of @norm |
| 546 | $w_element->set_att("pos", $tags[4]); |
| 547 | $w_element->set_att("msd", $tags[5]); |
Harald Lüngen | ccd8490 | 2024-08-27 16:03:47 +0300 | [diff] [blame] | 548 | #TMP $w_element->set_att("head", $tags[6]); |
| 549 | #TMP $w_element->set_att("deprel", $tags[7]); |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 550 | |
| 551 | } |
| 552 | |
| 553 | ################# |
| 554 | ## usage_message |
| 555 | ################# |
| 556 | |
| 557 | |
| 558 | sub usage_message { |
Harald Lüngen | a7e9162 | 2024-08-23 17:33:11 +0300 | [diff] [blame] | 559 | print " Usage: ./vrt2tei.pl <file.vrt.xml> <outfile>\n"; |
Harald Lüngen | 9d4e046 | 2024-08-23 09:34:22 +0300 | [diff] [blame] | 560 | print " <file.vrt.xml> is a VRT file converted to proper XML\n"; |
| 561 | exit; |
| 562 | } |
| 563 | |
| 564 | |