blob: 0db0f315959c99c538dc4244b021f139181a10f1 [file] [log] [blame]
Akron9cb13942020-02-14 07:39:54 +01001#!/usr/bin/env perl
Peter Hardersd892a582020-02-12 15:45:22 +01002use strict;
3use warnings;
Peter Harders6f526a32020-06-29 21:44:41 +02004
5use Pod::Usage;
6use Getopt::Long qw(GetOptions :config no_auto_abbrev);
7
8use File::Basename qw(dirname);
Peter Hardersd892a582020-02-12 15:45:22 +01009
10use open qw(:std :utf8); # assume utf-8 encoding
11use Encode qw(encode_utf8 decode_utf8);
12
Peter Hardersd892a582020-02-12 15:45:22 +010013use XML::CompactTree::XS;
14use XML::LibXML::Reader;
Peter Hardersd892a582020-02-12 15:45:22 +010015
Akron4f67cd42020-07-02 12:27:58 +020016use FindBin;
17BEGIN {
18 unshift @INC, "$FindBin::Bin/../lib";
19};
20
21use KorAP::XML::TEI;
Akron8b511f92020-07-09 17:28:08 +020022use KorAP::XML::TEI::Tokenizer::External;
Akrond9627472020-07-09 16:53:09 +020023use KorAP::XML::TEI::Tokenizer::Conservative;
24use KorAP::XML::TEI::Tokenizer::Aggressive;
Akron85717512020-07-08 11:19:19 +020025use KorAP::XML::TEI::Zipper;
Peter Hardersd892a582020-02-12 15:45:22 +010026
Akrond949e182020-02-14 12:23:57 +010027our $VERSION = '0.01';
Peter Harders6f526a32020-06-29 21:44:41 +020028
Akrond949e182020-02-14 12:23:57 +010029our $VERSION_MSG = "\ntei2korapxml - v$VERSION\n";
30
Peter Hardersd892a582020-02-12 15:45:22 +010031
Peter Harders6f526a32020-06-29 21:44:41 +020032# Parse options from the command line
Peter Hardersd892a582020-02-12 15:45:22 +010033GetOptions(
Peter Harders6f526a32020-06-29 21:44:41 +020034 "root|r=s" => \(my $_root_dir = '.'), # name of root directory inside zip file
35 "input|i=s" => \(my $input_fname = ''), # input file (yet only TEI I5 Format accepted)
Akron8b511f92020-07-09 17:28:08 +020036 'tokenizer-call|tc=s' => \(my $tokenizer_call), # Temporary argument for testing purposes
37 'help|h' => sub {
Akrond949e182020-02-14 12:23:57 +010038 pod2usage(
39 -verbose => 99,
40 -sections => 'NAME|DESCRIPTION|SYNOPSIS|ARGUMENTS|OPTIONS',
41 -msg => $VERSION_MSG,
42 -output => '-'
43 )
44 },
45 'version|v' => sub {
46 pod2usage(
47 -verbose => 0,
48 -msg => $VERSION_MSG,
49 -output => '-'
50 )
51 }
Peter Hardersd892a582020-02-12 15:45:22 +010052);
53
Peter Harders6f526a32020-06-29 21:44:41 +020054#
55# ~~~ parameter (mandatory) ~~~
56#
Peter Hardersd892a582020-02-12 15:45:22 +010057
Peter Harders6f526a32020-06-29 21:44:41 +020058 # optional
59my $_CORP_SIGLE = "korpusSigle"; # opening and closing tags (without attributes) have to be in one line
60 # (e.g.: <korpusSigle>GOE</korpusSigle>)
61 # optional
62my $_DOC_SIGLE = "dokumentSigle"; # analog
63 # mandatory
64my $_TEXT_SIGLE = "textSigle"; # analog
65 # mandatory
66my $_TEXT_BODY = "text"; # tag (without attributes), which contains the primary text
67 # optional
68my $_CORP_HEADER_BEG = "idsHeader type=\"corpus\""; # just keep the correct order of the attributes and evtl. add an '.*' between them
69 # optional
70my $_DOC_HEADER_BEG = "idsHeader type=\"document\""; # analog
71 # mandatory
72my $_TEXT_HEADER_BEG = "idsHeader type=\"text\""; # analog
73
74#
75# ~~~ constants ~~~
76#
Peter Hardersd892a582020-02-12 15:45:22 +010077
Akron8b511f92020-07-09 17:28:08 +020078my $_GEN_TOK_EXT = $tokenizer_call ? 1 : 0; # (used for IDS internal tokenization)
79
80 # TODO:
81 # Read tokenizer call from configuration file.
82 # was 'java -cp '. join(":", ".", glob(&dirname(__FILE__)."/../target/*.jar")). " de.ids_mannheim.korap.tokenizer.KorAPTokenizerImpl";
83 my $ext_tok;
84 if ($tokenizer_call) {
85 $ext_tok = KorAP::XML::TEI::Tokenizer::External->new($tokenizer_call);
86 };
87 my $_tok_file_ext = "tokens.xml";
Peter Harders6f526a32020-06-29 21:44:41 +020088##
89
Akron8b511f92020-07-09 17:28:08 +020090## intern tokenization
91my $_GEN_TOK_INT = 1; # this simple tokenization can be used for testing (base tokenization is normally done by external tools)
Peter Harders6f526a32020-06-29 21:44:41 +020092 my $_tok_file_con = "tokens_conservative.xml";
93 my $_tok_file_agg = "tokens_aggressive.xml";
Akrond9627472020-07-09 16:53:09 +020094 my $aggr_tok = KorAP::XML::TEI::Tokenizer::Aggressive->new;
95 my $cons_tok = KorAP::XML::TEI::Tokenizer::Conservative->new;
96 my ( $txt, $offset );
Akron8b511f92020-07-09 17:28:08 +020097my $_tok_dir = "base"; # name of directory for storing tokenization files
Peter Harders6f526a32020-06-29 21:44:41 +020098
Peter Harders6f526a32020-06-29 21:44:41 +020099my $_DEBUG = 0; # set to 1 for minimal more debug output (no need to be parametrized)
100my $_XCT_LN = 0; # only for debugging: include line numbers in elements of $tree_data
101 # (see also manpage of XML::CompactTree::XS)
102
103my $_header_file = "header.xml"; # name of files containing the text, document and corpus header
104my $_data_file = "data.xml"; # name of file containing the primary text data (tokens)
105my $_structure_dir = "struct"; # name of directory containing the $_structure_file
106my $_structure_file = "structure.xml"; # name of file containing all tags (except ${_TOKEN_TAG}'s) related information
107 # (= their names and byte offsets in $_data)
108## TODO: optional (different annotation tools can produce more zip-files for feeding into KorAP-XML-Krill)
109my $_TOKENS_PROC = 1; # on/off: processing of ${_TOKEN_TAG}'s (default: 1)
110my $_tokens_dir = "tokens"; # name of directory containing the $_tokens_file
111my $_tokens_file = "morpho.xml"; # name of file containing all ${_TOKEN_TAG}'s related information (=their byte offsets in $_data)
112 # - evtl. with additional inline annotations
113my $_TOKENS_TAG = "w"; # name of tag containing all information stored in $_tokens_file
114
115## TODO: optional
116# handling inline annotations (inside $_TOKENS_TAG)
117my $_INLINE_ANNOT = 0; # on/off: set to 1 if inline annotations are present and should be processed (default: 0)
118my $_INLINE_LEM_RD = "lemma"; # from which attribute to read LEMMA information
119my $_INLINE_ATT_RD = "ana"; # from which attribute to read POS information (and evtl. additional MSD - Morphosyntactic Descriptions)
120 # TODO: The format for the POS and MSD information has to suffice the regular expression ([^ ]+)( (.+))?
121 # - which means, that the POS information can be followed by an optional blank with additional
122 # MSD information; unlike the MSD part, the POS part may not contain any blanks.
123my $_INLINE_POS_WR = "pos"; # name (inside $_tokens_file) referring to POS information
124my $_INLINE_MSD_WR = "msd"; # name (inside $_tokens_file) referring to MSD information
125my $_INLINE_LEM_WR = "lemma"; # name (inside $_tokens_file) referring to LEMMA information
126##
127
128
129#
130# ~~~ variables ~~~
131#
132
Akron85717512020-07-08 11:19:19 +0200133# Initialize zipper
134my $zipper = KorAP::XML::TEI::Zipper->new;
Peter Harders6f526a32020-06-29 21:44:41 +0200135my $input_fh; # input file handle (default: stdin)
136
137my $buf_in; # text body data extracted from input document ($input_fh), further processed by XML::LibXML::Reader
138my $data; # contains the primary text (created by func. 'retr_info' from $buf_in), which is written to '$data_file'
139
140my $dir; # text directory (below $_root_dir)
141my $dir_crp; # corpus directory (below $_root_dir)
142my $dir_doc; # document directory (below $_root_dir)
143
144my ( $text_id, $text_id_esc ); # '$text_id_esc' = escaped version of $text_id (see %ent)
145
146my %ent = ('"', '&quot;', '&','&amp;', # convert '&', '<' and '>' into their corresponding sgml-entities
147 '<','&lt;','>','&gt;');
148 # note: the index still refers to the 'single character'-versions, which are counted as 1
149 # (search for '&amp;' in data.xml and see corresponding indices in $_tokens_file)
150
151my $header_txt; # raw text header (written to '$_root_dir$dir/$_header_file')
152my $header_doc; # raw document header (written to '$_root_dir$dir_doc/$_header_file')
153my $header_crp; # raw corpus header (written to '$_root_dir$dir_crp/$_header_file')
154
155my ( $header_fl_crp, $header_fl_doc, # flags for tracking where we are in the input document
156 $header_fl_txt, $data_fl );
157
158my ( $header_prfx, $data_prfx1, # $header_prfx is written to $_header_file, $data_* are written to $_data_file
159 $data_prfx2, $data_sfx );
160
161my @structures; # list of arrays, where each array represents a TEI I5 tag (except $_TOKENS_TAG) from the input document
162 # - the input of this array is written in func. 'write_structures' into the file '$_structure_file'
163
164my @tokens; # list of arrays, where each array represents a $_TOKENS_TAG from the input document
165 # - the input of this array is written in func. 'write_tokens' into the file '$_tokens_file'
166
167my ( $ref, $idx, $att_idx ); # needed in func. 'write_structures' and 'write_tokens'
168
169my ( $reader, # instance of 'XML::LibXML::Reader->new' (on input '$buf_in')
170 $tree_data ); # instance of 'XML::CompactTree::XS::readSubtreeToPerl' (on input '$reader')
171
172# these are only used inside recursive function 'retr_info'
173my ( $_IDX, # value is set dependent on $_XCT_LN - for extracting array of child elements from element in $tree_data
174 $e, # element from $tree_data
175 $n, # tag name of actual processed element $e
176 $rl, # recursion level
177 $dl, # actual length of string $data
178 @oti, # oti='open tags indizes' - a stack of indizes into @structures, where the top index in @oti
179 # represents the actual processed element from @structures
180 @oti2, # analogously to @oti, but with reference to array @tokens
181 $inside_tokens_tag, # flag is set, when inside $_TOKENS_TAG
182 ## variables for handling ~ whitespace related issue ~ (it is sometimes necessary, to correct the from-values for some tags)
183 $add_one, # ...
184 $fval, $fval2, # ...
185 %ws); # hash for indices of whitespace nodes (needed to recorrect from-values)
186 # idea: when closing element, check if it's from-index minus 1 refers to a whitespace node
187 # (means: 'from-index - 1' is a key in %ws).
188 # if this is _not_ the case, then the from-value is one to high => correct it by substracting 1
189
190my $output; # temporary variable needed in 'write_*'-functions for writing output to zip-stream $zip)
191
192my ( $i, $c ); # index variables used in loops
193
Peter Harders6f526a32020-06-29 21:44:41 +0200194my ( $_CORP_HEADER_END, $_DOC_HEADER_END, $_TEXT_HEADER_END );
195
196
197#
198# ~~~ main ~~~
199#
200
201# ~ initializations ~
202
203($_XCT_LN)?($_IDX=5):($_IDX=4);
204
205$header_prfx = $data_prfx1 = $data_prfx2 = $data_sfx = "";
206
207$header_fl_txt = $header_fl_doc = $header_fl_crp = 0;
208
209$inside_tokens_tag = -1;
210
211$fval = $fval2 = 0;
212
213$_root_dir .= '/'; # base dir must always end with a slash
214$_root_dir =~ s/^\.?\///; # remove leading / (only relative paths allowed in IO::Compress::Zip) and redundant ./
215
216$_CORP_HEADER_BEG =~ s#^([^\s]+)(.*)$#$1\[\^>\]*$2#; $_CORP_HEADER_END = $1;
217$_DOC_HEADER_BEG =~ s#^([^\s]+)(.*)$#$1\[\^>\]*$2#; $_DOC_HEADER_END = $1;
218$_TEXT_HEADER_BEG =~ s#^([^\s]+)(.*)$#$1\[\^>\]*$2#; $_TEXT_HEADER_END = $1;
219
220## TODO: remove this, because it's IDS-specific
Peter Hardersd892a582020-02-12 15:45:22 +0100221$header_prfx = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
222$header_prfx .= "<?xml-model href=\"header.rng\" type=\"application/xml\" schematypens=\"http://relaxng.org/ns/structure/1.0\"?>\n";
223$header_prfx .= "<!DOCTYPE idsCorpus PUBLIC \"-//IDS//DTD IDS-XCES 1.0//EN\" \"http://corpora.ids-mannheim.de/idsxces1/DTD/ids.xcesdoc.dtd\">\n";
Peter Harders6f526a32020-06-29 21:44:41 +0200224##
Peter Hardersd892a582020-02-12 15:45:22 +0100225
226$data_prfx1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
227$data_prfx1 .= "<?xml-model href=\"text.rng\" type=\"application/xml\" schematypens=\"http://relaxng.org/ns/structure/1.0\"?>\n\n";
228$data_prfx1 .= "<raw_text docid=\"";
229$data_prfx2 .= "\" xmlns=\"http://ids-mannheim.de/ns/KorAP\">\n";
Peter Harders6f526a32020-06-29 21:44:41 +0200230## TODO: can 'metadata.xml' change or is it constant?
Peter Hardersd892a582020-02-12 15:45:22 +0100231$data_prfx2 .= " <metadata file=\"metadata.xml\" />\n";
Peter Harders6f526a32020-06-29 21:44:41 +0200232##
Peter Hardersd892a582020-02-12 15:45:22 +0100233$data_prfx2 .= " <text>";
234$data_sfx = "</text>\n</raw_text>";
235
Peter Hardersd892a582020-02-12 15:45:22 +0100236
Peter Harders6f526a32020-06-29 21:44:41 +0200237# ~ read input and write output (text by text) ~
Peter Harders90157342020-07-01 21:05:14 +0200238process();
Peter Hardersd892a582020-02-12 15:45:22 +0100239
Peter Hardersd892a582020-02-12 15:45:22 +0100240
Peter Harders6f526a32020-06-29 21:44:41 +0200241#
242# ~~~ subs ~~~
243#
Peter Hardersd892a582020-02-12 15:45:22 +0100244
Peter Hardersd892a582020-02-12 15:45:22 +0100245
Peter Harders90157342020-07-01 21:05:14 +0200246sub process {
Peter Hardersd892a582020-02-12 15:45:22 +0100247
Peter Harders6f526a32020-06-29 21:44:41 +0200248 my ( $pfx, $sfx );
Peter Hardersd892a582020-02-12 15:45:22 +0100249
Peter Harders6f526a32020-06-29 21:44:41 +0200250 my $lc = 0; # line counter
251
252 my $tc = 0; # text counter
253
254 $input_fh = *STDIN; # input file handle (default: stdin)
255
Akron85717512020-07-08 11:19:19 +0200256 $data_fl = 0;
Peter Harders6f526a32020-06-29 21:44:41 +0200257
258 $buf_in = $data = $dir = $dir_doc = $dir_crp = "";
259 $header_txt = $header_doc = $header_crp = "";
260
261
262 if ( $input_fname ne '' ){
263
264 open ( $input_fh, "<", "$input_fname") || die "File \'$input_fname\' could not be opened.\n";
265
266 }
267
268
Peter Harders90157342020-07-01 21:05:14 +0200269 # prevents segfaulting of 'XML::LibXML::Reader' inside 'process()' - see notes on 'PerlIO layers' in 'man XML::LibXML')
270 # removing 'use open qw(:std :utf8)' would fix this problem too, but using binmode on input is more granular
271 binmode $input_fh;
272
273
Peter Harders6f526a32020-06-29 21:44:41 +0200274 # ~ loop (reading input document) ~
275
276 while ( <$input_fh> ){
277
278 $lc++; # line counter
279
280 # TODO: yet not tested fo big amounts of data
281 # must-have, otherwise comments in input could be fatal (e.g.: ...<!--\n<idsHeader...\n-->...)
Akron4f67cd42020-07-02 12:27:58 +0200282 KorAP::XML::TEI::delHTMLcom ( $input_fh, $_ ); # remove HTML comments (<!--...-->)
Peter Harders6f526a32020-06-29 21:44:41 +0200283
284 if ( $data_fl && m#^(.*)</${_TEXT_BODY}>(.*)$# ){
285
286
287 # ~ end of text body ~
288
289
Akron8b511f92020-07-09 17:28:08 +0200290 # write data.xml, structure.xml and evtl. morpho.xml and/or tokenization files (s.a.: $_tok_file_ext, $_tok_file_con, $_tok_file_agg)
Peter Harders6f526a32020-06-29 21:44:41 +0200291
292 $pfx = $1; $sfx = $2;
293
294 die "ERROR ($0): main(): input line number $lc: line with closing text-body tag '${_TEXT_BODY}'"
295 ." contains additional information ... => Aborting\n\tline=$_"
296 if $pfx !~ /^\s*$/ || $sfx !~ /^\s*$/;
297
298 if ( $dir ne "" ){
299
Peter Harders6f526a32020-06-29 21:44:41 +0200300 $reader = XML::LibXML::Reader->new( string => "<text>$buf_in</text>", huge => 1 );
Peter Harders6f526a32020-06-29 21:44:41 +0200301
302 if ( $_XCT_LN ){ # _XCT_LINE_NUMBERS is only for debugging
303 $tree_data = XML::CompactTree::XS::readSubtreeToPerl( $reader, XCT_DOCUMENT_ROOT | XCT_IGNORE_COMMENTS | XCT_ATTRIBUTE_ARRAY | XCT_LINE_NUMBERS );
304 } else {
305 $tree_data = XML::CompactTree::XS::readSubtreeToPerl( $reader, XCT_DOCUMENT_ROOT | XCT_IGNORE_COMMENTS | XCT_ATTRIBUTE_ARRAY );
306 }
307
308 @structures = (); @oti = ();
309
310 if ( $_TOKENS_PROC ){
311 @tokens = (); @oti2 = ()
312 }
313
314 $dl = $rl = 0;
315
316 # ~ whitespace related issue ~
317 $add_one = 0;
318 %ws = ();
319
320
321 # ~ recursion ~
322
323 retr_info( \$tree_data->[2] ); # parse input data
324
325 $rl--;
326
327
328 # ~ write data.xml ~
329
330 $data =~ tr/\n\r/ /; # note: 2 blanks - otherwise offset data would become corrupt
331
332 $data = encode_utf8( $data );
333
Akron8b511f92020-07-09 17:28:08 +0200334 if ( $_GEN_TOK_EXT ){
335 # TODO: $offset is only necessary for $cons_tok and $aggr_tok and as long as they're part of 'retr_info'
336 $ext_tok->tokenize($data, $offset);
Peter Harders6f526a32020-06-29 21:44:41 +0200337 }
Akron8b511f92020-07-09 17:28:08 +0200338
Peter Harders6f526a32020-06-29 21:44:41 +0200339 print STDERR "DEBUG ($0): main(): Writing (utf8-formatted) xml file $_root_dir$dir/$_data_file\n" if $_DEBUG;
340
Peter Harders6f526a32020-06-29 21:44:41 +0200341
342 $data =~ s/(&|<|>)/$ent{$1}/g;
343
Akron85717512020-07-08 11:19:19 +0200344 $zipper->new_stream("$_root_dir$dir/$_data_file")
345 ->print("$data_prfx1$text_id_esc$data_prfx2$data$data_sfx");
Peter Harders6f526a32020-06-29 21:44:41 +0200346
347 # ~ write structures ~
348
349 write_structures() if @structures;
350
351
352 # ~ write tokens ~
353
354 write_tokens() if $_TOKENS_PROC && @tokens;
355
356
Akron8b511f92020-07-09 17:28:08 +0200357 # ~ tokenization ~
Peter Harders6f526a32020-06-29 21:44:41 +0200358
Akron8b511f92020-07-09 17:28:08 +0200359 if ( $_GEN_TOK_EXT || $_GEN_TOK_INT ){
Peter Harders6f526a32020-06-29 21:44:41 +0200360
Akron997e9402020-07-11 12:06:13 +0200361 if ( $_GEN_TOK_EXT ) {
Peter Harders6f526a32020-06-29 21:44:41 +0200362
Akron997e9402020-07-11 12:06:13 +0200363 $ext_tok->to_zip(
364 $zipper->new_stream("$_root_dir$dir/$_tok_dir/$_tok_file_ext"),
365 $text_id_esc
366 );
367
368 } elsif ( $_GEN_TOK_INT ){
369
370 # Output token streams to zip streams
371 $cons_tok->to_zip(
372 $zipper->new_stream("$_root_dir$dir/$_tok_dir/$_tok_file_con"),
373 $text_id_esc
374 );
375 $aggr_tok->to_zip(
376 $zipper->new_stream("$_root_dir$dir/$_tok_dir/$_tok_file_agg"),
377 $text_id_esc
378 );
Akrond9627472020-07-09 16:53:09 +0200379 $offset = 0;
380 $aggr_tok->reset;
381 $cons_tok->reset;
Peter Harders6f526a32020-06-29 21:44:41 +0200382 }
Akron997e9402020-07-11 12:06:13 +0200383
384 #print STDERR "$0: write_tokenization(): DONE\n";
Peter Harders6f526a32020-06-29 21:44:41 +0200385 }
386
387 $data_fl = 0; $buf_in = $data = $dir = ""; # reinit.
388
389 } else { # $dir eq ""
390
391 print STDERR "WARNING ($0): main(): maybe empty textSigle => skipping this text ...\n";
392 print STDERR "WARNING ($0): main(): text header=$header_txt\n";
393 print STDERR "WARNING ($0): main(): data=$data\n";
Peter Hardersd892a582020-02-12 15:45:22 +0100394 }
395
Peter Harders6f526a32020-06-29 21:44:41 +0200396 } elsif ( $data_fl ){
Peter Hardersd892a582020-02-12 15:45:22 +0100397
Peter Hardersd892a582020-02-12 15:45:22 +0100398
Peter Harders6f526a32020-06-29 21:44:41 +0200399 # ~ inside text body ~
Peter Hardersd892a582020-02-12 15:45:22 +0100400
Peter Hardersd892a582020-02-12 15:45:22 +0100401
Peter Harders6f526a32020-06-29 21:44:41 +0200402 #print STDERR "inside text body (\$data_fl set)\n";
403
404 # ~ whitespace handling ~
405
406 # remove consecutive whitespace at beginning and end (mostly one newline)
407 # to let 'XML::CompactTree::XS' recognize these blanks as 'text-nodes', the option 'XCT_IGNORE_WS' may not be used (see above).
408 s/^\s+//; s/\s+$//;
409
410 # There's nothing wrong with inserting an additional blank at the start of the 2nd and all consecutive lines (which contain at least one tag),
411 # because it helps for better readability of the text in the '$_data_file' (e.g.: assure blanks between sentences).
412 # Furthermore, the input lines should avoid primary text tokens, which span across several lines, unless the line breaks doesn't lead
413 # to a situation which produces unwanted blanks - e.g.: '...<w>end</w>\n<w>.</w>...' would lead to '...<w>end</w> <w>.</w>...', or
414 # '...<w>,</w>\n<w>this</w>\n<w>is</w>\n<w>it</w>\n<w>!</w>...' to '<w>,<w> <w>this</w> <w>is</w> <w>it</w> <w>!</w>'. Even when considering
415 # to correct those unwanted effects, there would be lots of examples aside punctuation, where there would not exist an easy way or unarbitrary
416 # solution regarding the elimination of the false blanks.
Peter Hardersd892a582020-02-12 15:45:22 +0100417 #
Peter Harders6f526a32020-06-29 21:44:41 +0200418 # So, the best way to avoid having false blanks in the output, is to assure that linebreaks between word-tags doesn't occur in the input
419 # (see also comments on 'input restrictions' at the top of this script).
Peter Hardersd892a582020-02-12 15:45:22 +0100420
Peter Harders6f526a32020-06-29 21:44:41 +0200421 if ( m/<[^>]+>[^<]/ ){ # line contains at least one tag with at least one character contents
Peter Hardersd892a582020-02-12 15:45:22 +0100422
Peter Harders6f526a32020-06-29 21:44:41 +0200423 $tc++; # text counter
Peter Hardersd892a582020-02-12 15:45:22 +0100424
Peter Harders6f526a32020-06-29 21:44:41 +0200425 s/^(.)/ $1/ if $tc > 1; # add blank before 1st character for 2nd line and consecutive lines (which contain at least one tag)
Peter Hardersd892a582020-02-12 15:45:22 +0100426 }
427
Peter Harders6f526a32020-06-29 21:44:41 +0200428 # add line to buffer
429 $buf_in .= $_;
430
431 } elsif ( $header_fl_txt && m#^(.*</${_TEXT_HEADER_END}>)(.*)$# ){
432
433
434 # ~ end of text header ~
435
436
437 #print STDERR "end of text header\n";
438
439 # write it to header.xml
440
441 $sfx = $2;
442
443 $header_txt .= $1; $header_fl_txt = 0;
444
445
446 die "ERROR ($0): main(): input line number $lc: line with closing text-header tag '${_TEXT_HEADER_END}'"
447 ." contains additional information ... => Aborting\n\tline=$_"
448 if $sfx !~ /^\s*$/;
449
450 if ( $dir eq "" ){
451
452 print STDERR "WARNING ($0): main(): input line number $lc: empty textSigle in text header => nothing to do ...\ntext header=$header_txt\n";
453
454 } else {
455
456 print STDERR "DEBUG ($0): Writing file $_root_dir$dir/$_header_file\n" if $_DEBUG;
457
Peter Harders6f526a32020-06-29 21:44:41 +0200458 $header_txt = encode_utf8( $header_txt );
459
Akron85717512020-07-08 11:19:19 +0200460 $zipper->new_stream("$_root_dir$dir/$_header_file")
461 ->print("$header_prfx$header_txt");
Peter Harders6f526a32020-06-29 21:44:41 +0200462
463 $header_txt = "";
Peter Hardersd892a582020-02-12 15:45:22 +0100464 }
Peter Hardersd892a582020-02-12 15:45:22 +0100465
Peter Harders6f526a32020-06-29 21:44:41 +0200466 } elsif ( $header_fl_txt ){
Peter Hardersd892a582020-02-12 15:45:22 +0100467
Peter Harders6f526a32020-06-29 21:44:41 +0200468 # ~ inside text header ~
Peter Hardersd892a582020-02-12 15:45:22 +0100469
Peter Harders6f526a32020-06-29 21:44:41 +0200470
471 #print STDERR "inside text header\n";
472
473 if( m#^(.*)<${_TEXT_SIGLE}(?: [^>]*)?>([^<]*)(.*)$# ){
474
475 $pfx = $1; $sfx = $3;
476
477 $dir = $2; $text_id = $dir;
478
479 $text_id =~ tr/\//_/; $dir =~ s/("|&|<|>)/$ent{$1}/g;
480
481 $text_id = encode_utf8( $text_id );
482
483 die "ERROR ($0): main(): input line number $lc: line with text-sigle tag '$_TEXT_SIGLE' is not in expected format ... => Aborting\n\tline=$_"
484 if $pfx !~ /^\s*$/ || $sfx !~ m#^</${_TEXT_SIGLE}>\s*$# || $dir =~ /^\s*$/;
485
486 # log output for seeing progression
487 print STDERR "$0: main(): text_id=".decode_utf8( $text_id )."\n";
488
489 $text_id_esc = $text_id;
490
491 s#(<${_TEXT_SIGLE}(?: [^>]*)?>)[^<]+(</${_TEXT_SIGLE}>)#$1$dir$2# # to be consistent with escaping, escape also textSigle in text-header
492 if $text_id_esc =~ s/("|&|<|>)/$ent{$1}/g;
493
494 $dir =~ tr/\./\//;
495 }
496
497 $header_txt .= $_;
498
499 } elsif ( $header_fl_doc && m#^(.*</${_DOC_HEADER_END}>)(.*)$# ){
500
501
502 # ~ end of document header ~
503
Peter Harders6f526a32020-06-29 21:44:41 +0200504 #print STDERR "end of doc header\n";
505
506 # write it to header.xml
507
508 $sfx = $2;
509
510 $header_doc .= $1; $header_fl_doc = 0;
511
512 die "ERROR ($0): main(): input line number $lc: line with closing document-header tag '${_DOC_HEADER_END}'"
513 ." contains additional information ... => Aborting\n\tline=$_"
514 if $sfx !~ /^\s*$/;
515
516 if( $dir_doc eq "" ){
517
518 print STDERR "WARNING ($0): main(): input line number $lc: empty document sigle in document header"
519 ." => nothing to do ...\ndocument header=$header_doc\n";
520
521 } else {
522
523 print STDERR "DEBUG ($0): Writing file $_root_dir$dir_doc/$_header_file\n" if $_DEBUG;
524
Peter Harders6f526a32020-06-29 21:44:41 +0200525 $header_doc = encode_utf8( $header_doc );
526
Akron85717512020-07-08 11:19:19 +0200527 $zipper->new_stream("$_root_dir$dir_doc/$_header_file")
528 ->print("$header_prfx$header_doc");
Peter Harders6f526a32020-06-29 21:44:41 +0200529
530 $header_doc = $dir_doc = "";
531 }
532
533 } elsif ( $header_fl_doc ){
534
535
536 # ~ inside document header ~
537
538
539 #print STDERR "inside doc header\n";
540
541 if ( m#^(.*)<${_DOC_SIGLE}(?: [^>]*)?>([^<]*)(.*)$# ){
542
543 $pfx = $1; $sfx = $3;
544
545 $dir_doc = $2;
546
547 die "ERROR ($0): main(): input line number $lc: line with document-sigle tag '$_DOC_SIGLE' is not in expected format ... => Aborting\n\tline=$_"
548 if $pfx !~ /^\s*$/ || $sfx !~ m#^</${_DOC_SIGLE}>\s*$# || $dir_doc =~ /^\s*$/;
549
550 s#(<${_DOC_SIGLE}(?: [^>]*)?>)[^<]+(</${_DOC_SIGLE}>)#$1$dir_doc$2# # to be consistent with escaping, escape also textSigle in Document-Header
551 if $dir_doc =~ s/("|&|<|>)/$ent{$1}/g;
552 }
553
554 $header_doc .= $_;
555
556 } elsif ( m#^(.*)(<${_TEXT_HEADER_BEG}.*)$# ){
557
558 # ~ start of text header ~
559
560
561 #print STDERR "begin of text header\n";
562
563 $header_txt = $_; $header_fl_txt = 1; $pfx = $1;
564
565 $tc = 0; # reset (needed for ~ whitespace handling ~)
566
567 die "ERROR ($0): main(): input line number $lc: line with opening text-header tag '${_TEXT_HEADER_BEG}'"
568 ." is not in expected format ... => Aborting\n\tline=$_"
569 if $pfx !~ /^\s*$/;
570
571 } elsif ( m#^(.*)<${_TEXT_BODY}(?: [^>]*)?>(.*)$# ){
572
573
574 # ~ start of text body ~
575
576
577 #print STDERR "inside text body\n";
578
579 $pfx = $1; $sfx = $2;
580
581 $data_fl = 1;
582
583 die "ERROR ($0): main(): input line number $lc: line with opening text-body tag '${_TEXT_BODY}'"
584 ." contains additional information ... => Aborting\n\tline=$_"
585 if $pfx !~ /^\s*$/ || $sfx !~ /^\s*$/;
586
587 } elsif ( m#^(.*)(<${_DOC_HEADER_BEG}.*)$# ){
588
589
590 # ~ start of document header ~
591
592
593 #print STDERR "begin of doc header\n";
594
595 $header_doc = "$2\n"; $header_fl_doc = 1; $pfx = $1;
596
597 die "ERROR ($0): main(): input line number $lc: line with opening document-header tag '${_DOC_HEADER_BEG}'"
598 ."is not in expected format ... => Aborting\n\tline=$_"
599 if $pfx !~ /^\s*$/;
600
601 } elsif ( $header_fl_crp && m#^(.*</${_CORP_HEADER_END}>)(.*)$# ){
602
603
604 # ~ end of corpus header ~
605
606
607 #print STDERR "end of corp header\n";
608
609 $sfx = $2;
610
611 $header_crp .= $1; $header_fl_crp = 0;
612
613 die "ERROR ($0): main(): input line number $lc: line with closing corpus-header tag '${_CORP_HEADER_END}'"
614 ." contains additional information ... => Aborting\n\tline=$_"
615 if $sfx !~ /^\s*$/;
616
617 if ( $dir_crp eq "" ){
618
619 print STDERR "WARNING ($0): main(): input line number $lc: empty corpus sigle in corpus header => nothing to do ...\ncorpus header=$header_crp\n";
620
621 } else {
622
623 print STDERR "DEBUG ($0): Writing file $_root_dir$dir_crp/$_header_file\n" if $_DEBUG;
624
Peter Harders6f526a32020-06-29 21:44:41 +0200625 $header_crp = encode_utf8( $header_crp );
626
Akron85717512020-07-08 11:19:19 +0200627 $zipper->new_stream("$_root_dir$dir_crp/$_header_file")
628 ->print("$header_prfx$header_crp");
Peter Harders6f526a32020-06-29 21:44:41 +0200629
630 $header_crp = $dir_crp = "";
631 }
632
633 } elsif ( $header_fl_crp ){
634
635
636 # ~ inside corpus header ~
637
638
639 #print STDERR "inside corp header\n";
640
641 if ( m#^(.*)<${_CORP_SIGLE}(?: [^>]*)?>([^<]*)(.*)$# ){
642
643 $pfx = $1; $sfx = $3;
644
645 $dir_crp = $2;
646
647 die "ERROR ($0): main(): input line number $lc: line with korpusSigle-tag is not in expected format ... => Aborting\n\tline=$_"
648 if $pfx !~ /^\s*$/ || $sfx !~ m#^</${_CORP_SIGLE}>\s*$# || $dir_crp =~ /^\s*$/;
649
650 if ( $dir_crp =~ s/("|&|<|>)/$ent{$1}/g ){
651
652 s#(<${_CORP_SIGLE}(?: [^>]*)?>)[^<]+(</${_CORP_SIGLE}>)#$1$dir_crp$2# # to be consistent with escaping, escape also textSigle in Corpus-Header
Peter Hardersd892a582020-02-12 15:45:22 +0100653 }
654 }
655
Peter Harders6f526a32020-06-29 21:44:41 +0200656 $header_crp .= $_;
Peter Hardersd892a582020-02-12 15:45:22 +0100657
Peter Harders6f526a32020-06-29 21:44:41 +0200658 } elsif ( m#^(.*)(<${_CORP_HEADER_BEG}.*)$# ){
Peter Hardersd892a582020-02-12 15:45:22 +0100659
Peter Hardersd892a582020-02-12 15:45:22 +0100660
Peter Harders6f526a32020-06-29 21:44:41 +0200661 # ~ start of corpus header ~
Peter Hardersd892a582020-02-12 15:45:22 +0100662
Peter Harders6f526a32020-06-29 21:44:41 +0200663
664 #print STDERR "begin of corp header\n";
665
666 $header_crp = $2; $header_fl_crp = 1; $pfx = $1;
667
668 die "ERROR ($0): main(): input line number $lc: line with opening corpus-header tag '${_CORP_HEADER_BEG}'"
669 ." is not in expected format ... => Aborting\n\tline=$_"
670 if $pfx !~ /^\s*$/;
Peter Hardersd892a582020-02-12 15:45:22 +0100671 }
672
Peter Harders6f526a32020-06-29 21:44:41 +0200673 } #end: while
Peter Hardersd892a582020-02-12 15:45:22 +0100674
Akron85717512020-07-08 11:19:19 +0200675 $zipper->close;
Peter Harders6f526a32020-06-29 21:44:41 +0200676
Akron8b511f92020-07-09 17:28:08 +0200677 if( $_GEN_TOK_EXT ){
678 $ext_tok->close;
Peter Hardersd892a582020-02-12 15:45:22 +0100679 }
Peter Hardersd892a582020-02-12 15:45:22 +0100680
Peter Harders90157342020-07-01 21:05:14 +0200681} # end: sub process
Peter Hardersd892a582020-02-12 15:45:22 +0100682
Peter Hardersd892a582020-02-12 15:45:22 +0100683
Peter Harders6f526a32020-06-29 21:44:41 +0200684sub retr_info { # called from process()
Peter Hardersd892a582020-02-12 15:45:22 +0100685
Peter Harders6f526a32020-06-29 21:44:41 +0200686 # EXAMPLE: <node a="v"><node1>some <n/> text</node1><node2>more-text</node2></node>
687 #
688 # print out values of above example:
689 # echo '<node a="v"><node1>some <n/> text</node1><node2>more-text</node2></node>' | perl -e 'use XML::CompactTree::XS; use XML::LibXML::Reader; $reader = XML::LibXML::Reader->new(IO => STDIN); $data = XML::CompactTree::XS::readSubtreeToPerl( $reader, XCT_DOCUMENT_ROOT | XCT_IGNORE_COMMENTS | XCT_LINE_NUMBERS ); print $data->[2]->[0]->[5]->[1]->[1]'
690 #
691 # $data = reference to below array
692 #
693 # [ 0: XML_READER_TYPE_DOCUMENT,
694 # 1: ?
695 # 2: [ 0: [ 0: XML_READER_TYPE_ELEMENT <- start recursion with array '$data->[2]' (see process(): retr_info( \$tree_data->[2] ))
696 # 1: 'node'
697 # 2: ?
698 # 3: HASH (attributes)
699 # 4: 1 (line number)
700 # 5: [ 0: [ 0: XML_READER_TYPE_ELEMENT
701 # 1: 'node1'
702 # 2: ?
703 # 3: undefined (no attributes)
704 # 4: 1 (line number)
705 # 5: [ 0: [ 0: XML_READER_TYPE_TEXT
706 # 1: 'some '
707 # ]
708 # 1: [ 0: XML_READER_TYPE_ELEMENT
709 # 1: 'n'
710 # 2: ?
711 # 3: undefined (no attributes)
712 # 4: 1 (line number)
713 # 5: undefined (no child nodes)
714 # ]
715 # 2: [ 0: XML_READER_TYPE_TEXT
716 # 1: ' text'
717 # ]
718 # ]
719 # ]
720 # 1: [ 0: XML_READER_TYPE_ELEMENT
721 # 1: 'node2'
722 # 2: ?
723 # 3: undefined (not attributes)
724 # 4: 1 (line number)
725 # 5: [ 0: [ 0: XML_READER_TYPE_TEXT
726 # 1: 'more-text'
727 # ]
728 # ]
729 # ]
730 # ]
731 # ]
732 # ]
733 # ]
734 #
735 # $data->[0] = 9 (=> type == XML_READER_TYPE_DOCUMENT)
736 #
737 # ref($data->[2]) == ARRAY (with 1 element for 'node')
738 # ref($data->[2]->[0]) == ARRAY (with 6 elements)
739 #
740 # $data->[2]->[0]->[0] == 1 (=> type == XML_READER_TYPE_ELEMENT)
741 # $data->[2]->[0]->[1] == 'node'
742 # ref($data->[2]->[0]->[3]) == HASH (=> ${$data->[2]->[0]->[3]}{a} == 'v')
743 # $data->[2]->[0]->[4] == 1 (line number)
744 # ref($data->[2]->[0]->[5]) == ARRAY (with 2 elements for 'node1' and 'node2')
745 # # child nodes of actual node (see $_IDX)
746 #
747 # ref($data->[2]->[0]->[5]->[0]) == ARRAY (with 6 elements)
748 # $data->[2]->[0]->[5]->[0]->[0] == 1 (=> type == XML_READER_TYPE_ELEMENT)
749 # $data->[2]->[0]->[5]->[0]->[1] == 'node1'
750 # $data->[2]->[0]->[5]->[0]->[3] == undefined (=> no attribute)
751 # $data->[2]->[0]->[5]->[0]->[4] == 1 (line number)
752 # ref($data->[2]->[0]->[5]->[0]->[5]) == ARRAY (with 3 elements for 'some ', '<n/>' and ' text')
753 #
754 # ref($data->[2]->[0]->[5]->[0]->[5]->[0]) == ARRAY (with 2 elements)
755 # $data->[2]->[0]->[5]->[0]->[5]->[0]->[0] == 3 (=> type == XML_READER_TYPE_TEXT)
756 # $data->[2]->[0]->[5]->[0]->[5]->[0]->[1] == 'some '
757 #
758 # ref($data->[2]->[0]->[5]->[0]->[5]->[1]) == ARRAY (with 5 elements)
759 # $data->[2]->[0]->[5]->[0]->[5]->[1]->[0] == 1 (=> type == XML_READER_TYPE_ELEMENT)
760 # $data->[2]->[0]->[5]->[0]->[5]->[1]->[1] == 'n'
761 # $data->[2]->[0]->[5]->[0]->[5]->[1]->[3] == undefined (=> no attribute)
762 # $data->[2]->[0]->[5]->[0]->[5]->[1]->[4] == 1 (line number)
763 # $data->[2]->[0]->[5]->[0]->[5]->[1]->[5] == undefined (=> no child nodes)
764 #
765 # ref($data->[2]->[0]->[5]->[0]->[5]->[2]) == ARRAY (with 2 elements)
766 # $data->[2]->[0]->[5]->[0]->[5]->[2]->[0] == 3 (=> type == XML_READER_TYPE_TEXT)
767 # $data->[2]->[0]->[5]->[0]->[5]->[2]->[1] == ' text'
768 #
769 #
770 # retr_info() starts with the array reference ${$_[0]} (= \$tree_data->[2]), which corresponds to ${\$data->[2]} in the above example.
771 # Hence, the expression @{${$_[0]}} corresponds to @{${\$data->[2]}}, $e to ${${\$data->[2]}}[0] (= $data->[2]->[0]) and $e->[0] to
772 # ${${\$data->[2]}}[0]->[0] (= $data->[2]->[0]->[0]).
Peter Hardersd892a582020-02-12 15:45:22 +0100773
Peter Harders6f526a32020-06-29 21:44:41 +0200774 $rl++; # recursion level (1 = topmost level inside retr_info() = should always be level of tag $_TEXT_BODY)
Peter Hardersd892a582020-02-12 15:45:22 +0100775
Peter Hardersd892a582020-02-12 15:45:22 +0100776
Peter Harders6f526a32020-06-29 21:44:41 +0200777 foreach $e ( @{${$_[0]}} ){ # iteration through all array elements ($_[0] is a reference to an array reference)
Peter Hardersd892a582020-02-12 15:45:22 +0100778
Peter Hardersd892a582020-02-12 15:45:22 +0100779
Peter Harders6f526a32020-06-29 21:44:41 +0200780 if ( $e->[0] == XML_READER_TYPE_ELEMENT ){ # element node (see 'NODE TYPES' in manpage of XML::LibXML::Reader)
Peter Hardersd892a582020-02-12 15:45:22 +0100781
Peter Hardersd892a582020-02-12 15:45:22 +0100782
Peter Harders6f526a32020-06-29 21:44:41 +0200783 #~~~~
784 # from here: opening tag
785 #~~~~
Peter Hardersd892a582020-02-12 15:45:22 +0100786
Peter Hardersd892a582020-02-12 15:45:22 +0100787
Peter Harders6f526a32020-06-29 21:44:41 +0200788 # insert new array (for new tag) into @structures with tag-name and tag-attributes (if present)
789 # update @oti (open tags indizes) with @structures highest index (= $#structures); e.g.: @a=(1,2,3) => $#a = 2
Peter Hardersd892a582020-02-12 15:45:22 +0100790
Peter Harders6f526a32020-06-29 21:44:41 +0200791 # ~ tag name ~
Peter Hardersd892a582020-02-12 15:45:22 +0100792
Peter Harders6f526a32020-06-29 21:44:41 +0200793 $n = $e->[1];
Peter Hardersd892a582020-02-12 15:45:22 +0100794
Peter Hardersd892a582020-02-12 15:45:22 +0100795
Peter Harders6f526a32020-06-29 21:44:41 +0200796 # ~ handle structures ~
Peter Hardersd892a582020-02-12 15:45:22 +0100797
Peter Harders6f526a32020-06-29 21:44:41 +0200798 my @array;
799 push @array, $n;
800 push @structures, \@array;
801 push @oti, $#structures; # add highest index of @structures to @oti
Peter Hardersd892a582020-02-12 15:45:22 +0100802
Peter Hardersd892a582020-02-12 15:45:22 +0100803
Peter Harders6f526a32020-06-29 21:44:41 +0200804 # ~ handle tokens ~
Peter Hardersd892a582020-02-12 15:45:22 +0100805
Peter Harders6f526a32020-06-29 21:44:41 +0200806 $inside_tokens_tag = $rl if $_TOKENS_PROC && $n eq $_TOKENS_TAG; # wether to push entry also into @tokens array
Peter Hardersd892a582020-02-12 15:45:22 +0100807
Peter Harders6f526a32020-06-29 21:44:41 +0200808 if ( $_TOKENS_PROC && $inside_tokens_tag == $rl ){
Peter Hardersd892a582020-02-12 15:45:22 +0100809
Peter Harders6f526a32020-06-29 21:44:41 +0200810 my @array2;
811 push @array2, $n;
812 push @tokens, \@array2;
813 push @oti2, $#tokens;
814 }
Peter Hardersd892a582020-02-12 15:45:22 +0100815
Peter Hardersd892a582020-02-12 15:45:22 +0100816
Peter Harders6f526a32020-06-29 21:44:41 +0200817 # ~ handle attributes ~
Peter Hardersd892a582020-02-12 15:45:22 +0100818
Peter Harders6f526a32020-06-29 21:44:41 +0200819 if ( defined $e->[3] ){ # only if attributes exist
Peter Hardersd892a582020-02-12 15:45:22 +0100820
Peter Harders6f526a32020-06-29 21:44:41 +0200821 for ( $c = 0; $c < @{$e->[3]}; $c += 2 ){ # with 'XCT_ATTRIBUTE_ARRAY', $node->[3] is an array reference of the form
822 # [ name1, value1, name2, value2, ....] of attribute names and corresponding values.
823 # note: arrays are faster (see: http://makepp.sourceforge.net/2.0/perl_performance.html)
Peter Hardersd892a582020-02-12 15:45:22 +0100824
Peter Harders6f526a32020-06-29 21:44:41 +0200825 # '$c' references the 'key' and '$c+1' the 'value'
826 push @{$structures[$#structures]}, ${$e->[3]}[$c], ${$e->[3]}[$c+1];
Peter Hardersd892a582020-02-12 15:45:22 +0100827
Peter Harders6f526a32020-06-29 21:44:41 +0200828 if ( $_TOKENS_PROC && $inside_tokens_tag == $rl ){
Peter Hardersd892a582020-02-12 15:45:22 +0100829
Peter Harders6f526a32020-06-29 21:44:41 +0200830 push @{$tokens[$#tokens]}, ${$e->[3]}[$c], ${$e->[3]}[$c+1];
831 }
832
833 }
834 }
835
836
837 # ~ index 'from' ~
838
839 # this is, where a normal tag or tokens-tag ($_TOKENS_TAG) starts
840
841 push @{$structures[$#structures]}, ( $dl + $add_one ); # see below (text and whitespace nodes) for explanation on '$add_one'
842
843 if ( $_TOKENS_PROC && $inside_tokens_tag == $rl ){
844
845 push @{$tokens[$#tokens]}, ( $dl + $add_one );
846 }
847
848
849 #~~~~
850 # until here: opening tag
851 #~~~~
852
853
854 # ~~ RECURSION ~~
855
856 if ( defined $e->[$_IDX] ){ # do no recursion, if $e->[$_IDX] is not defined (because we have no array of child nodes, e.g.: <back/>)
857
858 retr_info( \$e->[$_IDX] ); # recursion with array of child nodes
859
860 $rl--; # return from recursion
861 }
862
863
864 #~~~~~
865 # from here: closing tag
866 #~~~~~
867
868
869 # ~ handle structures ~
870
871 {
872 my $ix = pop @oti; # index of just closed tag
873
874 my $aix = $#{$structures[$ix]}; # determine highest index from 'array referring to last closed tag' ...
875
876 $fval = ${$structures[$ix]}[ $aix ]; # ... and get it's from-value
877
878 if ( $fval > 0 && not exists $ws{ $fval - 1 } ){ # ~ whitespace related issue ~
879
880 # previous node was a text-node
881
882 ${$structures[$ix]}[ $aix ] = $fval - 1; # recorrect from-value (see below: notes on ~ whitespace related issue ~)
883 }
884
885 # in case this fails, check input
886 die "ERROR ($0, retr_info()): text_id='$text_id', processing of \@structures: from-value ($fval) is 2 or more greater"
887 ." than to-value ($dl) => please check. aborting ...\n"
888 if ( $fval - 1 ) > $dl;
889
890 # TODO: construct example for which this case applies
891 # maybe this is not necessary anymore, because the above recorrection of the from-value suffices
892 # TODO: check, if it's better to remove this line and change above check to 'if ( $fval - 1) >= $dl;
893 ${$structures[$ix]}[ $aix ] = $dl if $fval == $dl + 1; # correct from-value (same as ... if $fval-1 == $dl)
894
895 push @{$structures[$ix]}, $dl, $rl; # to-value and recursion-level
896
897 # note: use $dl, because the offsets are _between_ the characters (e.g.: word = 'Hello' => from = 0 (before 'H'), to = 5 (after 'o'))
898 }
899
900
901 # ~ handle tokens ~
902
903
904 if ( $_TOKENS_PROC && $inside_tokens_tag == $rl ){
905
906 my $ix = pop @oti2;
907
908 my $aix = $#{$tokens[$ix]};
909
910 $fval2 = ${$tokens[$ix]}[ $aix ]; # from-value
911
912 if( $fval2 > 0 && not exists $ws{ $fval2 - 1 } ){ # ~ whitespace related issue ~
913
914 # previous node was a text-node
915
916 ${$tokens[$ix]}[ $aix ] = $fval2 - 1; # recorrect from-value
917 }
918
919 # in case this fails, check input
920 die "ERROR ($0, retr_info()): text_id='$text_id', processing of \@tokens: from-value ($fval2) is 2 or more greater"
921 ." than to-value ($dl) => please check. aborting ...\n"
922 if ( $fval2 - 1 ) > $dl;
923
924 # TODO: construct example for which this case applies
925 # maybe this is not necessary anymore, because the above recorrection of the from-value suffices
926 # TODO: check, if it's better to remove this line and change above check to 'if ( $fval2 - 1) >= $dl;
927 ${$tokens[$ix]}[ $aix ] = $dl if $fval2 == $dl + 1; # correct from-value (same as ... if $fval-1 == $dl)
928
929 push @{$tokens[$ix]}, $dl, $rl; # to-value and recursion-level
930
931 $inside_tokens_tag = -1; # reset
932 }
933
934 # ~ whitespace related issue ~
Peter Hardersd892a582020-02-12 15:45:22 +0100935 # clean up
Peter Harders6f526a32020-06-29 21:44:41 +0200936 delete $ws{ $fval - 1 } if $fval > 0 && exists $ws{ $fval - 1 };
937 delete $ws{ $fval2 - 1 } if $_TOKENS_PROC && $fval2 > 0 && exists $ws{ $fval2 - 1 };
Peter Hardersd892a582020-02-12 15:45:22 +0100938
939
Peter Harders6f526a32020-06-29 21:44:41 +0200940 #~~~~~
941 # from here: text (and whitespace) nodes
942 #~~~~~
Peter Hardersd892a582020-02-12 15:45:22 +0100943
944
Peter Harders6f526a32020-06-29 21:44:41 +0200945 # the 3rd form of nodes, next to text-nodes (XML_READER_TYPE_TEXT) and tag-nodes (XML_READER_TYPE_ELEMENT) are nodes
946 # of the type 'XML_READER_TYPE_SIGNIFICANT_WHITESPACE'
947 #
948 # when modifiying the above example (at the top of this sub) by inserting an additional blank between '</node1>' and '<node2>',
949 # the output for '$data->[2]->[0]->[5]->[1]->[1]' becomes a blank (' ') and it's type is '14' (see manpage of XML::LibXML::Reader):
950 #
951 # echo '<node a="v"><node1>some <n/> text</node1> <node2>more-text</node2></node>' | perl -e 'use XML::CompactTree::XS; use XML::LibXML::Reader; $reader = XML::LibXML::Reader->new(IO => STDIN); $data = XML::CompactTree::XS::readSubtreeToPerl( $reader, XCT_DOCUMENT_ROOT | XCT_IGNORE_COMMENTS | XCT_LINE_NUMBERS ); print "node=".$data->[2]->[0]->[5]->[1]->[1].", type=".$data->[2]->[0]->[5]->[1]->[0]."\n"'
Peter Hardersd892a582020-02-12 15:45:22 +0100952
Peter Harders6f526a32020-06-29 21:44:41 +0200953 } elsif ( $e->[0] == XML_READER_TYPE_TEXT || $e->[0] == XML_READER_TYPE_SIGNIFICANT_WHITESPACE ){
Peter Hardersd892a582020-02-12 15:45:22 +0100954
Peter Harders6f526a32020-06-29 21:44:41 +0200955 # notes on ~ whitespace related issue ~ (see below source code)
956 #
957 # example: '... <head type="main"><s>Campagne in Frankreich</s></head><head type="sub"> <s>1792</s> ...'
958 #
959 # Two text-nodes should normally be separated by a blank. In the above example, that would be the 2 text-nodes
960 # 'Campagne in Frankreich' and '1792', which are separated by the whitespace-node ' '.
961 #
962 # Assumed, that the above example marks the general case, then the text-node 'Campagne in Frankreich' leads to the
963 # setting of '$add_one' to 1, so that when opening the 2nd 'head'-tag and setting it's from-index, it gets the right
964 # offset, which is the start-index of '1792'.
965 #
966 # To check, that the above consideration holds, we save the from-index of a read whitespace-node into the hash %ws.
967 # By this, it can be checked when closing a tag, if the 'non-tag'-node (text or whitespace) before the last 'non-tag'-
968 # node was actually a whitespace-node ($ws{ $fval - 1 }).
969 #
970 # For whitespace-nodes, also $add_one has to be set to 0, so when opening the next tag (in the above example the 2nd
971 # 's'-tag), no additional 1 is added, because this was already done by the whitespace-node itself (by incrementing the
972 # variable $dl).
973 #
974 # Now, what happens, when 2 text-nodes are not seperated by a whitespace-node (blank)? (e.g.: <w>Augen<c>,</c></w>)
975 #
976 # In this case, the falsely increased from-value has to be decreased again by 1 when closing the referring tag
977 # (...$fval - 1; # recorrect).
978 #
979 # Comparing the 2 examples '<w>fu</w> <w>bar</w>' and '<w>fu</w><w> </w><w>bar</w>' (even though, the 2nd one makes less
980 # sense, because of '<w> </w>'), in both the ' ' is handled as a whitespace-node (XML_READER_TYPE_SIGNIFICANT_WHITESPACE).
981 #
982 # So the from-index of the 2nd w-tag (in the second example) would refer to 'bar', which may not have been the intention
983 # (even, if '<w> </w>' doesn't make a lot of sense). TODO: could this be a bug, which needs to be fixed?
984 #
985 # Empty tags also cling to the next text-token - e.g. in '...<w>tok1</w> <w>tok2</w><a><b/></a><w>tok3</w>...' the from-
986 # and to-indizes for the tags 'a' and 'b' are both 9, which is the start-index of the token 'tok3'.
987
988 if( $e->[0] == XML_READER_TYPE_SIGNIFICANT_WHITESPACE ){
989
990 # ~ whitespace related issue ~
991
992 $add_one = 0;
993
994 $ws{ $dl }++; # '++' does not mean a thing here (could be used for consistency checking)
995
996 }else{
997
998 # ~ text-node ~
999
1000 $add_one = 1;
1001 }
1002
1003
1004 # ~ update $data and $dl ~
1005
1006 $data .= $e->[1];
1007
1008 $dl += length( $e->[1] ); # update length of $data
1009
1010
1011
1012 #~~~~~
Akron8b511f92020-07-09 17:28:08 +02001013 # from here (until end): intern tokenization
Peter Harders6f526a32020-06-29 21:44:41 +02001014 #~~~~~
1015
Akron8b511f92020-07-09 17:28:08 +02001016 if ( $_GEN_TOK_INT ){
Peter Harders6f526a32020-06-29 21:44:41 +02001017
1018 $txt = $e->[1];
1019
Akroneac374d2020-07-07 09:00:44 +02001020
Peter Harders6f526a32020-06-29 21:44:41 +02001021 if ( substr( $txt, 0, 1 ) ne ' ' || substr( $txt, 1, 1) ne ' ' ){ # $txt has at least 2 chars, if it's not empty or equal to ' '
1022
Akron8b511f92020-07-09 17:28:08 +02001023 # TODO: implement outside retr_info() (like $ext_tok) on whole $data, instead on every text-node (more efficient and $offset not needed anymore)
Akrond9627472020-07-09 16:53:09 +02001024 $cons_tok->tokenize($txt, $offset);
1025 $aggr_tok->tokenize($txt, $offset);
Peter Harders6f526a32020-06-29 21:44:41 +02001026
1027 $offset = $dl;
1028
1029 } # fi
1030
Akron8b511f92020-07-09 17:28:08 +02001031 } # fi: $_GEN_TOK_INT
Peter Harders6f526a32020-06-29 21:44:41 +02001032
1033
1034 #elsif ( $e->[0] == XML_READER_TYPE_ATTRIBUTE ) # attribute node
1035 # note: attributes cannot be processed like this ( => use 'XCT_ATTRIBUTE_ARRAY' - see above )
1036
1037
1038 }else{ # not yet handled type
1039
1040 die "ERROR ($0): Not yet handled type (\$e->[0]=".$e->[0].") ... => Aborting\n";
1041 }
1042
1043 } # end: foreach iteration
1044
1045} # end: sub retr_info
1046
1047
Peter Harders6f526a32020-06-29 21:44:41 +02001048sub write_structures { # called from process()
1049
1050 # ~ write @structures ~
Peter Hardersd892a582020-02-12 15:45:22 +01001051
1052 #print STDERR "$0: write_structures(): ...\n";
1053
Peter Harders6f526a32020-06-29 21:44:41 +02001054 if ( $dir eq "" ){
1055
1056 print STDERR "WARNING ($0): write_structures(): empty textSigle => nothing to do ...\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001057 return;
1058 }
1059
Peter Harders6f526a32020-06-29 21:44:41 +02001060 $output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-model href=\"span.rng\" type=\"application/xml\""
1061 ." schematypens=\"http://relaxng.org/ns/structure/1.0\"?>\n\n<layer docid=\""
1062 .decode_utf8($text_id_esc)."\" xmlns=\"http://ids-mannheim.de/ns/KorAP\" version=\"KorAP-0.4\">\n <spanList>\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001063
1064 $c = 0;
1065
Peter Harders6f526a32020-06-29 21:44:41 +02001066 foreach $ref ( @structures ){
Peter Hardersd892a582020-02-12 15:45:22 +01001067
Peter Harders6f526a32020-06-29 21:44:41 +02001068 ( @{$ref} == 4 )?( $idx = 1 ):( $idx = @{$ref}-3 ); # if array '@{$ref}' doesn't contain attributes, then the number of elements in this array is 4
1069 # (name, from, to, rec_level), otherwise >4
Peter Hardersd892a582020-02-12 15:45:22 +01001070
Peter Harders6f526a32020-06-29 21:44:41 +02001071 # correct last from-value ( if the 'second to last' from-value refers to an s-tag, then the last from-value is one to big - see retr_info )
1072
1073 if( $#structures == $c && ${$ref}[ $idx ] == ${$ref}[ $idx+1 ] + 1 ){
1074
1075 ${$ref}[$idx] = ${$ref}[ $idx+1 ];
Peter Hardersd892a582020-02-12 15:45:22 +01001076 }
Peter Hardersd892a582020-02-12 15:45:22 +01001077
Peter Harders6f526a32020-06-29 21:44:41 +02001078 # this consistency check is already done in 'retr_info()'
1079 #elsif( ${$ref}[$idx] > ${$ref}[$idx+1] ){ # consistency check: abort, if this doesn't hold
1080 # die "ERROR ($0: write_structures(): \$text_id=$text_id, \$c=$c, tag-name=${$ref}[0]):"
1081 # ." 'from-index=${$ref}[$idx]' > 'to-index=${$ref}[$idx+1]' => please check! aborting ...\n";
1082 # die "ERROR ($0: write_structures(): \$text_id=$text_id, \$c=$c, tag-name=${$ref}[0]):"
1083 # ." 'from-index=${$ref}[$idx]' > 'to-index=${$ref}[$idx+1]' => please check! aborting ...\n\n$output" }
Peter Hardersd892a582020-02-12 15:45:22 +01001084
Peter Harders6f526a32020-06-29 21:44:41 +02001085 # at least 'POS' should always be there => remove constraint '$_TOKENS_PROC'
1086 #if( $_TOKENS_PROC && ${$ref}[0] ne $_TOKENS_TAG )
Peter Hardersd892a582020-02-12 15:45:22 +01001087
Peter Harders6f526a32020-06-29 21:44:41 +02001088 if( ${$ref}[0] ne $_TOKENS_TAG ){ # $_TOKENS_TAG is already written in 'write_tokens'
Peter Hardersd892a582020-02-12 15:45:22 +01001089
Peter Harders6f526a32020-06-29 21:44:41 +02001090 # l (level): insert information about depth of element in XML-tree (top element = level 1)
1091 $output .= " <span id=\"s$c\" from=\"${$ref}[ $idx ]\" to=\"${$ref}[ $idx+1 ]\" l=\"${$ref}[ $idx+2 ]\">\n"
1092 ." <fs type=\"struct\" xmlns=\"http://www.tei-c.org/ns/1.0\">\n"
1093 ." <f name=\"name\">${$ref}[ 0 ]</f>\n";
1094
1095 if ( $idx > 2 ) # attributes
1096 {
1097 $output .= " <f name=\"attr\">\n <fs type=\"attr\">\n";
1098
1099 for ( $att_idx = 1; $att_idx < $idx; $att_idx += 2 ){
1100
1101 ${$ref}[ $att_idx+1 ] =~ s/(&|<|>)/$ent{$1}/g; # see explanation in func. 'write_tokens'
1102
1103 # attribute (at index $att_idx) with value (at index $att_idx+1)
1104 $output .= " <f name=\"${$ref}[ $att_idx ]\">${$ref}[ $att_idx+1 ]</f>\n";
1105 }
1106
1107 $output .= " </fs>\n </f>\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001108 }
1109
Peter Harders6f526a32020-06-29 21:44:41 +02001110 $output .= " </fs>\n </span>\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001111
Peter Harders6f526a32020-06-29 21:44:41 +02001112 } # fi: ... ne $_TOKENS_TAG
Peter Hardersd892a582020-02-12 15:45:22 +01001113
1114 $c++;
1115
Peter Harders6f526a32020-06-29 21:44:41 +02001116 } # end: foreach
Peter Hardersd892a582020-02-12 15:45:22 +01001117
1118 $output .= " </spanList>\n</layer>";
1119
Peter Harders6f526a32020-06-29 21:44:41 +02001120 $output = encode_utf8( $output );
Peter Hardersd892a582020-02-12 15:45:22 +01001121
Akron85717512020-07-08 11:19:19 +02001122 $zipper->new_stream("$_root_dir$dir/$_structure_dir/$_structure_file")
1123 ->print($output);
Peter Hardersd892a582020-02-12 15:45:22 +01001124
1125 #print STDERR "$0: write_structures(): DONE\n";
Peter Harders6f526a32020-06-29 21:44:41 +02001126
Peter Hardersd892a582020-02-12 15:45:22 +01001127} # end: sub write_structures
1128
1129
Peter Harders6f526a32020-06-29 21:44:41 +02001130sub write_tokens { # called from process()
1131
1132 # ~ write @tokens ~
1133
1134 #print STDERR "$0: write_tokens(): ...\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001135
1136 if( $dir eq "" ){
Peter Harders6f526a32020-06-29 21:44:41 +02001137
1138 print STDERR "WARNING ($0): write_tokens(): empty textSigle => nothing to do ...\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001139 return;
1140 }
1141
Peter Harders6f526a32020-06-29 21:44:41 +02001142 $output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-model href=\"span.rng\" type=\"application/xml\""
1143 ." schematypens=\"http://relaxng.org/ns/structure/1.0\"?>\n\n<layer docid=\""
1144 .decode_utf8($text_id_esc)."\" xmlns=\"http://ids-mannheim.de/ns/KorAP\" version=\"KorAP-0.4\">\n <spanList>\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001145
1146 $c = 0;
1147
Peter Harders6f526a32020-06-29 21:44:41 +02001148 foreach $ref ( @tokens ){
Peter Hardersd892a582020-02-12 15:45:22 +01001149
Peter Harders6f526a32020-06-29 21:44:41 +02001150 # if array '@{$ref}' doesn't contain attributes, then the number of elements in this array is 4 (name, from, to, rec_level), otherwise >4
1151 ( @{$ref} == 4 )?( $idx = 1 ):( $idx = @{$ref}-3 );
Peter Hardersd892a582020-02-12 15:45:22 +01001152
Peter Harders6f526a32020-06-29 21:44:41 +02001153 # correct last from-value (if the 'second to last' from-value refers to an s-tag, then the last from-value is one to big - see retr_info())
1154 if ( $#tokens == $c && ${$ref}[ $idx ] == ${$ref}[ $idx+1 ] + 1 ){
1155
1156 ${$ref}[ $idx ] = ${$ref}[ $idx+1 ]; # TODO: check
Peter Hardersd892a582020-02-12 15:45:22 +01001157 }
Peter Hardersd892a582020-02-12 15:45:22 +01001158
Peter Harders6f526a32020-06-29 21:44:41 +02001159 # l (level): insert information about depth of element in XML-tree (top element = level 1)
1160 $output .= " <span id=\"s$c\" from=\"${$ref}[ $idx ]\" to=\"${$ref}[ $idx+1 ]\" l=\"${$ref}[ $idx+2 ]\">\n"
1161 ." <fs type=\"lex\" xmlns=\"http://www.tei-c.org/ns/1.0\">\n"
1162 ." <f name=\"lex\">\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001163
Peter Harders6f526a32020-06-29 21:44:41 +02001164 if ( $idx > 2 ){ # attributes
1165
Peter Hardersd892a582020-02-12 15:45:22 +01001166 $output .= " <fs>\n";
1167
Peter Harders6f526a32020-06-29 21:44:41 +02001168 for ( $att_idx = 1; $att_idx < $idx; $att_idx += 2 ){
Peter Hardersd892a582020-02-12 15:45:22 +01001169
Peter Harders6f526a32020-06-29 21:44:41 +02001170 ${$ref}[ $att_idx+1 ] =~ s/(&|<|>)/$ent{$1}/g; # ... <w lemma="&gt;" ana="PUNCTUATION">&gt;</w> ...
1171 # the '&gt;' is translated to '>' and hence the result would be '<f name="lemma">></f>'
Peter Hardersd892a582020-02-12 15:45:22 +01001172
Peter Harders6f526a32020-06-29 21:44:41 +02001173 if ( $_INLINE_ANNOT && ${$ref}[ $att_idx ] eq "$_INLINE_ATT_RD" ){
Peter Hardersd892a582020-02-12 15:45:22 +01001174
Peter Harders6f526a32020-06-29 21:44:41 +02001175 ${$ref}[ $att_idx+1 ] =~ /^([^ ]+)(?: (.+))?$/;
1176
1177 die "ERROR (write_tokens()): unexpected format! => Aborting ... (att: ${$ref}[ $att_idx+1 ])\n"
1178 if ( $_INLINE_POS_WR && not defined $1 ) || ( $_INLINE_MSD_WR && not defined $2 );
1179
1180 if ( "$_INLINE_POS_WR" ){
1181
1182 $output .= " <f name=\"$_INLINE_POS_WR\">";
Peter Hardersd892a582020-02-12 15:45:22 +01001183 $output .= "$1" if defined $1;
1184 $output .= "</f>\n";
1185 }
Peter Harders6f526a32020-06-29 21:44:41 +02001186
1187 if ( "$_INLINE_MSD_WR" ){
1188
1189 $output .= " <f name=\"$_INLINE_MSD_WR\">";
Peter Hardersd892a582020-02-12 15:45:22 +01001190 $output .= "$2" if defined $2;
1191 $output .= "</f>\n";
1192 }
1193
Peter Harders6f526a32020-06-29 21:44:41 +02001194 } elsif ( $_INLINE_ANNOT && "$_INLINE_LEM_RD" && ${$ref}[ $att_idx ] eq "$_INLINE_LEM_RD" ){
Peter Hardersd892a582020-02-12 15:45:22 +01001195
Peter Harders6f526a32020-06-29 21:44:41 +02001196 $output .= " <f name=\"$_INLINE_LEM_WR\">${$ref}[ $att_idx+1 ]</f>\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001197
Peter Harders6f526a32020-06-29 21:44:41 +02001198 } else { # all other attributes
Peter Hardersd892a582020-02-12 15:45:22 +01001199
Peter Harders6f526a32020-06-29 21:44:41 +02001200 $output .= " <f name=\"${$ref}[$att_idx]\">${$ref}[ $att_idx+1 ]</f>\n"; # attribute (at index $att_idx) with value (at index $att_idx+1)
Peter Hardersd892a582020-02-12 15:45:22 +01001201 }
1202
Peter Harders6f526a32020-06-29 21:44:41 +02001203 } # end: for
Peter Hardersd892a582020-02-12 15:45:22 +01001204
1205 $output .= " </fs>\n";
Peter Harders6f526a32020-06-29 21:44:41 +02001206
1207 } # fi: attributes
Peter Hardersd892a582020-02-12 15:45:22 +01001208
1209 $output .= " </f>\n </fs>\n </span>\n";
1210
1211 $c++;
1212
Peter Harders6f526a32020-06-29 21:44:41 +02001213 } # end: foreach
Peter Hardersd892a582020-02-12 15:45:22 +01001214
1215 $output .= " </spanList>\n</layer>";
1216
Peter Harders6f526a32020-06-29 21:44:41 +02001217 $output = encode_utf8( $output );
Peter Hardersd892a582020-02-12 15:45:22 +01001218
Akron85717512020-07-08 11:19:19 +02001219 $zipper->new_stream("$_root_dir$dir/$_tokens_dir/$_tokens_file")
1220 ->print($output);
Peter Hardersd892a582020-02-12 15:45:22 +01001221
Peter Harders6f526a32020-06-29 21:44:41 +02001222 #print STDERR "$0: write_tokens(): DONE\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001223
Peter Harders6f526a32020-06-29 21:44:41 +02001224} # end: sub write_tokens
Peter Hardersd892a582020-02-12 15:45:22 +01001225
Peter Hardersd892a582020-02-12 15:45:22 +01001226
Akrond949e182020-02-14 12:23:57 +01001227__END__
1228
1229=pod
1230
1231=encoding utf8
1232
1233=head1 NAME
1234
1235tei2korapxml - Conversion of TEI P5 based formats to KorAP-XML
1236
1237=head1 SYNOPSIS
1238
1239 cat corpus.i5.xml | tei2korapxml > corpus.korapxml.zip
1240
1241=head1 DESCRIPTION
1242
Akronee434b12020-07-08 12:53:01 +02001243C<tei2korapxml> is a script to convert TEI P5 and
1244L<I5|https://www1.ids-mannheim.de/kl/projekte/korpora/textmodell.html>
1245based documents to the
1246L<KorAP-XML format|https://github.com/KorAP/KorAP-XML-Krill#about-korap-xml>.
1247If no specific input is defined, data is
Akrond949e182020-02-14 12:23:57 +01001248read from C<STDIN>. If no specific output is defined, data is written
1249to C<STDOUT>.
Peter Harders6f526a32020-06-29 21:44:41 +02001250
Akrond949e182020-02-14 12:23:57 +01001251This program is usually called from inside another script.
1252
Akronee434b12020-07-08 12:53:01 +02001253=head1 FORMATS
1254
1255=head2 Input restrictions
1256
1257=over 2
1258
1259=item
1260
1261utf8 encoded
1262
1263=item
1264
1265TEI P5 formatted input with certain restrictions:
1266
1267=over 4
1268
1269=item
1270
1271B<mandatory>: text-header with integrated textsigle, text-body
1272
1273=item
1274
1275B<optional>: corp-header with integrated corpsigle,
1276doc-header with integrated docsigle
1277
1278=back
1279
1280=item
1281
1282all tokens inside the primary text (inside $data) may not be
1283newline seperated, because newlines are removed
1284(see code section C<~ inside text body ~>) and a conversion of newlines
1285into blanks between 2 tokens could lead to additional blanks,
1286where there should be none (e.g.: punctuation characters like C<,> or
1287C<.> should not be seperated from their predecessor token).
1288(see also code section C<~ whitespace handling ~>).
1289
1290=back
1291
1292=head2 Notes on the output
1293
1294=over 2
1295
1296=item
1297
1298zip file output (default on C<stdout>) with utf8 encoded entries
1299(which together form the KorAP-XML format)
1300
1301=back
1302
Akrond949e182020-02-14 12:23:57 +01001303=head1 INSTALLATION
1304
1305C<tei2korapxml> requires L<libxml2-dev> bindings to build. When
1306these bindings are available, the preferred way to install the script is
1307to use L<cpanm|App::cpanminus>.
1308
1309 $ cpanm https://github.com/KorAP/KorAP-XML-TEI.git
1310
1311In case everything went well, the C<tei2korapxml> tool will
1312be available on your command line immediately.
Peter Harders6f526a32020-06-29 21:44:41 +02001313
Akrond949e182020-02-14 12:23:57 +01001314Minimum requirement for L<KorAP::XML::TEI> is Perl 5.16.
1315
1316=head1 OPTIONS
1317
1318=over 2
1319
1320=item B<--base|-b>
1321
1322The base directory for output. Defaults to C<.>.
1323
1324=item B<--help|-h>
1325
1326Print help information.
1327
1328=item B<--version|-v>
1329
1330Print version information.
1331
1332=back
1333
1334=head1 COPYRIGHT AND LICENSE
1335
1336Copyright (C) 2020, L<IDS Mannheim|https://www.ids-mannheim.de/>
1337
1338Author: Peter Harders
1339
1340Contributors: Marc Kupietz, Carsten Schnober, Nils Diewald
1341
1342L<KorAP::XML::TEI> is developed as part of the L<KorAP|https://korap.ids-mannheim.de/>
1343Corpus Analysis Platform at the
1344L<Leibniz Institute for the German Language (IDS)|http://ids-mannheim.de/>,
1345member of the
1346L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/>.
1347
1348This program is free software published under the
1349L<BSD-2 License|https://raw.githubusercontent.com/KorAP/KorAP-XML-TEI/master/LICENSE>.
1350
1351=cut