blob: 5d2d9ff429a889494fa5469ef831ec63f23385b9 [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
Akron95bc98a2020-07-11 12:00:12 +020021use KorAP::XML::TEI qw'remove_xml_comments';
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;
Akronf57ed812020-07-27 10:37:52 +020026use KorAP::XML::TEI::Header;
Peter Hardersd892a582020-02-12 15:45:22 +010027
Akrond949e182020-02-14 12:23:57 +010028our $VERSION = '0.01';
Peter Harders6f526a32020-06-29 21:44:41 +020029
Akrond949e182020-02-14 12:23:57 +010030our $VERSION_MSG = "\ntei2korapxml - v$VERSION\n";
31
Peter Hardersd892a582020-02-12 15:45:22 +010032
Peter Harders6f526a32020-06-29 21:44:41 +020033# Parse options from the command line
Peter Hardersd892a582020-02-12 15:45:22 +010034GetOptions(
Peter Harders6f526a32020-06-29 21:44:41 +020035 "root|r=s" => \(my $_root_dir = '.'), # name of root directory inside zip file
36 "input|i=s" => \(my $input_fname = ''), # input file (yet only TEI I5 Format accepted)
Akron8b511f92020-07-09 17:28:08 +020037 'tokenizer-call|tc=s' => \(my $tokenizer_call), # Temporary argument for testing purposes
Peter Hardersf9c51242020-07-21 02:37:44 +020038 'use-intern-tokenization|ti' => \(my $tokenizer_intern), # use intern tokenization (default = no)
Akron8b511f92020-07-09 17:28:08 +020039 'help|h' => sub {
Akrond949e182020-02-14 12:23:57 +010040 pod2usage(
41 -verbose => 99,
42 -sections => 'NAME|DESCRIPTION|SYNOPSIS|ARGUMENTS|OPTIONS',
43 -msg => $VERSION_MSG,
44 -output => '-'
45 )
46 },
47 'version|v' => sub {
48 pod2usage(
49 -verbose => 0,
50 -msg => $VERSION_MSG,
51 -output => '-'
52 )
53 }
Peter Hardersd892a582020-02-12 15:45:22 +010054);
55
Peter Harders6f526a32020-06-29 21:44:41 +020056#
57# ~~~ parameter (mandatory) ~~~
58#
Peter Harders6f526a32020-06-29 21:44:41 +020059my $_TEXT_BODY = "text"; # tag (without attributes), which contains the primary text
60 # optional
61my $_CORP_HEADER_BEG = "idsHeader type=\"corpus\""; # just keep the correct order of the attributes and evtl. add an '.*' between them
62 # optional
63my $_DOC_HEADER_BEG = "idsHeader type=\"document\""; # analog
64 # mandatory
65my $_TEXT_HEADER_BEG = "idsHeader type=\"text\""; # analog
66
67#
68# ~~~ constants ~~~
69#
Peter Hardersd892a582020-02-12 15:45:22 +010070
Peter Harders41c35622020-07-12 01:16:22 +020071## extern tokenization
Peter Hardersf9c51242020-07-21 02:37:44 +020072my $_GEN_TOK_EXT = $tokenizer_call ? 1 : 0;
Akron8b511f92020-07-09 17:28:08 +020073 # TODO:
74 # Read tokenizer call from configuration file.
75 # was 'java -cp '. join(":", ".", glob(&dirname(__FILE__)."/../target/*.jar")). " de.ids_mannheim.korap.tokenizer.KorAPTokenizerImpl";
76 my $ext_tok;
77 if ($tokenizer_call) {
78 $ext_tok = KorAP::XML::TEI::Tokenizer::External->new($tokenizer_call);
79 };
Peter Harders41c35622020-07-12 01:16:22 +020080 my $_tok_file_ext = "tokens.xml";
Peter Harders6f526a32020-06-29 21:44:41 +020081##
82
Akron8b511f92020-07-09 17:28:08 +020083## intern tokenization
Peter Hardersf9c51242020-07-21 02:37:44 +020084my $_GEN_TOK_INT = $tokenizer_intern; # simple tokenization (recommended for testing)
Peter Harders41c35622020-07-12 01:16:22 +020085 my $_tok_file_con = "tokens_conservative.xml";
86 my $_tok_file_agg = "tokens_aggressive.xml";
87 my $aggr_tok = KorAP::XML::TEI::Tokenizer::Aggressive->new;
88 my $cons_tok = KorAP::XML::TEI::Tokenizer::Conservative->new;
Peter Harders41c35622020-07-12 01:16:22 +020089##
90
91my $_tok_dir = "base"; # name of directory for storing tokenization files
Peter Harders6f526a32020-06-29 21:44:41 +020092
Peter Harders6f526a32020-06-29 21:44:41 +020093my $_DEBUG = 0; # set to 1 for minimal more debug output (no need to be parametrized)
94my $_XCT_LN = 0; # only for debugging: include line numbers in elements of $tree_data
95 # (see also manpage of XML::CompactTree::XS)
96
97my $_header_file = "header.xml"; # name of files containing the text, document and corpus header
98my $_data_file = "data.xml"; # name of file containing the primary text data (tokens)
99my $_structure_dir = "struct"; # name of directory containing the $_structure_file
100my $_structure_file = "structure.xml"; # name of file containing all tags (except ${_TOKEN_TAG}'s) related information
101 # (= their names and byte offsets in $_data)
102## TODO: optional (different annotation tools can produce more zip-files for feeding into KorAP-XML-Krill)
103my $_TOKENS_PROC = 1; # on/off: processing of ${_TOKEN_TAG}'s (default: 1)
104my $_tokens_dir = "tokens"; # name of directory containing the $_tokens_file
105my $_tokens_file = "morpho.xml"; # name of file containing all ${_TOKEN_TAG}'s related information (=their byte offsets in $_data)
106 # - evtl. with additional inline annotations
107my $_TOKENS_TAG = "w"; # name of tag containing all information stored in $_tokens_file
108
109## TODO: optional
110# handling inline annotations (inside $_TOKENS_TAG)
111my $_INLINE_ANNOT = 0; # on/off: set to 1 if inline annotations are present and should be processed (default: 0)
112my $_INLINE_LEM_RD = "lemma"; # from which attribute to read LEMMA information
113my $_INLINE_ATT_RD = "ana"; # from which attribute to read POS information (and evtl. additional MSD - Morphosyntactic Descriptions)
114 # TODO: The format for the POS and MSD information has to suffice the regular expression ([^ ]+)( (.+))?
115 # - which means, that the POS information can be followed by an optional blank with additional
116 # MSD information; unlike the MSD part, the POS part may not contain any blanks.
117my $_INLINE_POS_WR = "pos"; # name (inside $_tokens_file) referring to POS information
118my $_INLINE_MSD_WR = "msd"; # name (inside $_tokens_file) referring to MSD information
119my $_INLINE_LEM_WR = "lemma"; # name (inside $_tokens_file) referring to LEMMA information
120##
121
122
123#
124# ~~~ variables ~~~
125#
126
Akron85717512020-07-08 11:19:19 +0200127# Initialize zipper
128my $zipper = KorAP::XML::TEI::Zipper->new;
Peter Harders6f526a32020-06-29 21:44:41 +0200129my $input_fh; # input file handle (default: stdin)
130
131my $buf_in; # text body data extracted from input document ($input_fh), further processed by XML::LibXML::Reader
132my $data; # contains the primary text (created by func. 'retr_info' from $buf_in), which is written to '$data_file'
133
134my $dir; # text directory (below $_root_dir)
Peter Harders6f526a32020-06-29 21:44:41 +0200135
136my ( $text_id, $text_id_esc ); # '$text_id_esc' = escaped version of $text_id (see %ent)
137
138my %ent = ('"', '&quot;', '&','&amp;', # convert '&', '<' and '>' into their corresponding sgml-entities
139 '<','&lt;','>','&gt;');
140 # note: the index still refers to the 'single character'-versions, which are counted as 1
141 # (search for '&amp;' in data.xml and see corresponding indices in $_tokens_file)
142
Akronf57ed812020-07-27 10:37:52 +0200143my ( $data_fl );
Peter Harders6f526a32020-06-29 21:44:41 +0200144
Akronf57ed812020-07-27 10:37:52 +0200145my ( $data_prfx1, $data_prfx2, $data_sfx ); # $data_* are written to $_data_file
Peter Harders6f526a32020-06-29 21:44:41 +0200146
Peter Harders6f526a32020-06-29 21:44:41 +0200147
148my @structures; # list of arrays, where each array represents a TEI I5 tag (except $_TOKENS_TAG) from the input document
149 # - the input of this array is written in func. 'write_structures' into the file '$_structure_file'
150
151my @tokens; # list of arrays, where each array represents a $_TOKENS_TAG from the input document
152 # - the input of this array is written in func. 'write_tokens' into the file '$_tokens_file'
153
154my ( $ref, $idx, $att_idx ); # needed in func. 'write_structures' and 'write_tokens'
155
156my ( $reader, # instance of 'XML::LibXML::Reader->new' (on input '$buf_in')
157 $tree_data ); # instance of 'XML::CompactTree::XS::readSubtreeToPerl' (on input '$reader')
158
159# these are only used inside recursive function 'retr_info'
160my ( $_IDX, # value is set dependent on $_XCT_LN - for extracting array of child elements from element in $tree_data
161 $e, # element from $tree_data
162 $n, # tag name of actual processed element $e
163 $rl, # recursion level
164 $dl, # actual length of string $data
165 @oti, # oti='open tags indizes' - a stack of indizes into @structures, where the top index in @oti
166 # represents the actual processed element from @structures
167 @oti2, # analogously to @oti, but with reference to array @tokens
168 $inside_tokens_tag, # flag is set, when inside $_TOKENS_TAG
169 ## variables for handling ~ whitespace related issue ~ (it is sometimes necessary, to correct the from-values for some tags)
170 $add_one, # ...
171 $fval, $fval2, # ...
Peter Harders41c35622020-07-12 01:16:22 +0200172 %ws); # hash for indices of whitespace-nodes (needed to recorrect from-values)
173 # idea: when closing element, check if it's from-index minus 1 refers to a whitespace-node
Peter Harders6f526a32020-06-29 21:44:41 +0200174 # (means: 'from-index - 1' is a key in %ws).
175 # if this is _not_ the case, then the from-value is one to high => correct it by substracting 1
176
177my $output; # temporary variable needed in 'write_*'-functions for writing output to zip-stream $zip)
178
179my ( $i, $c ); # index variables used in loops
180
Peter Harders6f526a32020-06-29 21:44:41 +0200181
182#
183# ~~~ main ~~~
184#
185
186# ~ initializations ~
187
188($_XCT_LN)?($_IDX=5):($_IDX=4);
189
Akronf57ed812020-07-27 10:37:52 +0200190$data_prfx1 = $data_prfx2 = $data_sfx = "";
Peter Harders6f526a32020-06-29 21:44:41 +0200191
192$inside_tokens_tag = -1;
193
194$fval = $fval2 = 0;
195
196$_root_dir .= '/'; # base dir must always end with a slash
197$_root_dir =~ s/^\.?\///; # remove leading / (only relative paths allowed in IO::Compress::Zip) and redundant ./
198
Akronf57ed812020-07-27 10:37:52 +0200199$_CORP_HEADER_BEG =~ s#^([^\s]+)(.*)$#$1\[\^>\]*$2#;
200$_DOC_HEADER_BEG =~ s#^([^\s]+)(.*)$#$1\[\^>\]*$2#;
201$_TEXT_HEADER_BEG =~ s#^([^\s]+)(.*)$#$1\[\^>\]*$2#;
Peter Hardersd892a582020-02-12 15:45:22 +0100202
203$data_prfx1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
204$data_prfx1 .= "<?xml-model href=\"text.rng\" type=\"application/xml\" schematypens=\"http://relaxng.org/ns/structure/1.0\"?>\n\n";
205$data_prfx1 .= "<raw_text docid=\"";
206$data_prfx2 .= "\" xmlns=\"http://ids-mannheim.de/ns/KorAP\">\n";
Peter Harders6f526a32020-06-29 21:44:41 +0200207## TODO: can 'metadata.xml' change or is it constant?
Peter Hardersd892a582020-02-12 15:45:22 +0100208$data_prfx2 .= " <metadata file=\"metadata.xml\" />\n";
Peter Harders6f526a32020-06-29 21:44:41 +0200209##
Peter Hardersd892a582020-02-12 15:45:22 +0100210$data_prfx2 .= " <text>";
211$data_sfx = "</text>\n</raw_text>";
212
Peter Hardersd892a582020-02-12 15:45:22 +0100213
Peter Harders6f526a32020-06-29 21:44:41 +0200214# ~ read input and write output (text by text) ~
Peter Harders41c35622020-07-12 01:16:22 +0200215main();
Peter Hardersd892a582020-02-12 15:45:22 +0100216
Peter Hardersd892a582020-02-12 15:45:22 +0100217
Peter Harders6f526a32020-06-29 21:44:41 +0200218#
219# ~~~ subs ~~~
220#
Peter Hardersd892a582020-02-12 15:45:22 +0100221
Peter Hardersd892a582020-02-12 15:45:22 +0100222
Peter Harders41c35622020-07-12 01:16:22 +0200223sub main {
Peter Hardersd892a582020-02-12 15:45:22 +0100224
Peter Harders6f526a32020-06-29 21:44:41 +0200225 my ( $pfx, $sfx );
Peter Hardersd892a582020-02-12 15:45:22 +0100226
Akron95bc98a2020-07-11 12:00:12 +0200227 # TODO:
228 # Replace all calls of $lc with $. or $input_fh->input_line_number,
229 # because otherwise remove_html_comments will
230 # move the lines forward without incrementing.
Peter Harders41c35622020-07-12 01:16:22 +0200231 my $lc = 0; # line counter (only for error handling and debugging)
Peter Harders6f526a32020-06-29 21:44:41 +0200232
Peter Harders41c35622020-07-12 01:16:22 +0200233 my $tl = 0; # text line (needed for whitespace handling)
Peter Harders6f526a32020-06-29 21:44:41 +0200234
235 $input_fh = *STDIN; # input file handle (default: stdin)
236
Akron85717512020-07-08 11:19:19 +0200237 $data_fl = 0;
Peter Harders6f526a32020-06-29 21:44:41 +0200238
Akronf57ed812020-07-27 10:37:52 +0200239 $buf_in = $data = $dir = "";
Peter Harders6f526a32020-06-29 21:44:41 +0200240
241
242 if ( $input_fname ne '' ){
243
244 open ( $input_fh, "<", "$input_fname") || die "File \'$input_fname\' could not be opened.\n";
245
246 }
247
248
Peter Harders41c35622020-07-12 01:16:22 +0200249 # prevents segfaulting of 'XML::LibXML::Reader' inside 'main()' - see notes on 'PerlIO layers' in 'man XML::LibXML')
Peter Harders90157342020-07-01 21:05:14 +0200250 # removing 'use open qw(:std :utf8)' would fix this problem too, but using binmode on input is more granular
251 binmode $input_fh;
252
253
Peter Harders6f526a32020-06-29 21:44:41 +0200254 # ~ loop (reading input document) ~
255
256 while ( <$input_fh> ){
257
258 $lc++; # line counter
259
260 # TODO: yet not tested fo big amounts of data
261 # must-have, otherwise comments in input could be fatal (e.g.: ...<!--\n<idsHeader...\n-->...)
Akron95bc98a2020-07-11 12:00:12 +0200262 remove_xml_comments( $input_fh, $_ ); # remove HTML comments (<!--...-->)
Peter Harders6f526a32020-06-29 21:44:41 +0200263
264 if ( $data_fl && m#^(.*)</${_TEXT_BODY}>(.*)$# ){
265
266
267 # ~ end of text body ~
268
269
Akron8b511f92020-07-09 17:28:08 +0200270 # 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 +0200271
272 $pfx = $1; $sfx = $2;
273
274 die "ERROR ($0): main(): input line number $lc: line with closing text-body tag '${_TEXT_BODY}'"
275 ." contains additional information ... => Aborting\n\tline=$_"
276 if $pfx !~ /^\s*$/ || $sfx !~ /^\s*$/;
277
278 if ( $dir ne "" ){
279
Peter Harders6f526a32020-06-29 21:44:41 +0200280 $reader = XML::LibXML::Reader->new( string => "<text>$buf_in</text>", huge => 1 );
Peter Harders6f526a32020-06-29 21:44:41 +0200281
Peter Harders41c35622020-07-12 01:16:22 +0200282 # ~ whitespace handling ~
283 #
284 # Every whitespace inside the processed text is 'significant' and recognized as a node of type 'XML_READER_TYPE_SIGNIFICANT_WHITESPACE'
285 # (see function 'retr_info()').
286 #
287 # Definition of significant and insignificant whitespace
288 # (source: https://www.oracle.com/technical-resources/articles/wang-whitespace.html):
289 #
290 # Significant whitespace is part of the document content and should be preserved.
291 # Insignificant whitespace is used when editing XML documents for readability.
292 # These whitespaces are typically not intended for inclusion in the delivery of the document.
293 #
Peter Harders6f526a32020-06-29 21:44:41 +0200294 if ( $_XCT_LN ){ # _XCT_LINE_NUMBERS is only for debugging
295 $tree_data = XML::CompactTree::XS::readSubtreeToPerl( $reader, XCT_DOCUMENT_ROOT | XCT_IGNORE_COMMENTS | XCT_ATTRIBUTE_ARRAY | XCT_LINE_NUMBERS );
296 } else {
297 $tree_data = XML::CompactTree::XS::readSubtreeToPerl( $reader, XCT_DOCUMENT_ROOT | XCT_IGNORE_COMMENTS | XCT_ATTRIBUTE_ARRAY );
298 }
299
300 @structures = (); @oti = ();
301
302 if ( $_TOKENS_PROC ){
303 @tokens = (); @oti2 = ()
304 }
305
306 $dl = $rl = 0;
307
308 # ~ whitespace related issue ~
309 $add_one = 0;
310 %ws = ();
311
312
313 # ~ recursion ~
314
315 retr_info( \$tree_data->[2] ); # parse input data
316
317 $rl--;
318
319
320 # ~ write data.xml ~
321
Peter Harders41c35622020-07-12 01:16:22 +0200322 # TODO: should not be necessary, because whitespace at the end of every input line is removed: see 'whitespace handling' inside text body
323 # (...elsif ( $data_fl )....)
Peter Harders6f526a32020-06-29 21:44:41 +0200324 $data =~ tr/\n\r/ /; # note: 2 blanks - otherwise offset data would become corrupt
Peter Harders41c35622020-07-12 01:16:22 +0200325 #
Peter Harders6f526a32020-06-29 21:44:41 +0200326
Peter Harders6f526a32020-06-29 21:44:41 +0200327
Akron8b511f92020-07-09 17:28:08 +0200328 if ( $_GEN_TOK_EXT ){
Peter Hardersb1227172020-07-21 02:12:10 +0200329
330 $ext_tok->tokenize($data);
331
332 } elsif ( $_GEN_TOK_INT ){
333
334 $cons_tok->tokenize($data);
335 $aggr_tok->tokenize($data);
Peter Harders6f526a32020-06-29 21:44:41 +0200336 }
Akron8b511f92020-07-09 17:28:08 +0200337
Peter Hardersb1227172020-07-21 02:12:10 +0200338 $data = encode_utf8( $data );
339
Peter Harders6f526a32020-06-29 21:44:41 +0200340 print STDERR "DEBUG ($0): main(): Writing (utf8-formatted) xml file $_root_dir$dir/$_data_file\n" if $_DEBUG;
341
Peter Harders6f526a32020-06-29 21:44:41 +0200342
343 $data =~ s/(&|<|>)/$ent{$1}/g;
344
Akron85717512020-07-08 11:19:19 +0200345 $zipper->new_stream("$_root_dir$dir/$_data_file")
346 ->print("$data_prfx1$text_id_esc$data_prfx2$data$data_sfx");
Peter Harders6f526a32020-06-29 21:44:41 +0200347
348 # ~ write structures ~
349
350 write_structures() if @structures;
351
352
353 # ~ write tokens ~
354
355 write_tokens() if $_TOKENS_PROC && @tokens;
356
357
Akron8b511f92020-07-09 17:28:08 +0200358 # ~ tokenization ~
Peter Harders6f526a32020-06-29 21:44:41 +0200359
Peter Hardersb1227172020-07-21 02:12:10 +0200360 if ( $_GEN_TOK_EXT ) {
Peter Harders6f526a32020-06-29 21:44:41 +0200361
Peter Hardersb1227172020-07-21 02:12:10 +0200362 $ext_tok->to_zip(
363 $zipper->new_stream("$_root_dir$dir/$_tok_dir/$_tok_file_ext"),
364 $text_id_esc
365 )
Peter Harders6f526a32020-06-29 21:44:41 +0200366
Peter Hardersb1227172020-07-21 02:12:10 +0200367 } elsif ( $_GEN_TOK_INT ){
Akron997e9402020-07-11 12:06:13 +0200368
Peter Hardersb1227172020-07-21 02:12:10 +0200369 # Output token streams to zip streams
370 $cons_tok->to_zip(
371 $zipper->new_stream("$_root_dir$dir/$_tok_dir/$_tok_file_con"),
372 $text_id_esc
373 );
374 $aggr_tok->to_zip(
375 $zipper->new_stream("$_root_dir$dir/$_tok_dir/$_tok_file_agg"),
376 $text_id_esc
377 );
378 $aggr_tok->reset;
379 $cons_tok->reset;
Peter Harders6f526a32020-06-29 21:44:41 +0200380 }
381
Peter Hardersb1227172020-07-21 02:12:10 +0200382 #print STDERR "$0: write_tokenization(): DONE\n";
383
Peter Harders6f526a32020-06-29 21:44:41 +0200384 $data_fl = 0; $buf_in = $data = $dir = ""; # reinit.
385
386 } else { # $dir eq ""
387
388 print STDERR "WARNING ($0): main(): maybe empty textSigle => skipping this text ...\n";
Akronf57ed812020-07-27 10:37:52 +0200389 # print STDERR "WARNING ($0): main(): text header=$header_txt\n";
Peter Harders6f526a32020-06-29 21:44:41 +0200390 print STDERR "WARNING ($0): main(): data=$data\n";
Peter Hardersd892a582020-02-12 15:45:22 +0100391 }
392
Peter Harders6f526a32020-06-29 21:44:41 +0200393 } elsif ( $data_fl ){
Peter Hardersd892a582020-02-12 15:45:22 +0100394
Peter Hardersd892a582020-02-12 15:45:22 +0100395
Peter Harders6f526a32020-06-29 21:44:41 +0200396 # ~ inside text body ~
Peter Hardersd892a582020-02-12 15:45:22 +0100397
Peter Hardersd892a582020-02-12 15:45:22 +0100398
Peter Harders6f526a32020-06-29 21:44:41 +0200399 #print STDERR "inside text body (\$data_fl set)\n";
400
401 # ~ whitespace handling ~
402
Peter Harders41c35622020-07-12 01:16:22 +0200403 # The idea for the below code fragment was to fix (recreate) missing whitespace in a poorly created corpus, in which linebreaks where inserted
404 # into the text with the addition that maybe (or not) whitespace before those linebreaks was unintenionally stripped.
Peter Hardersd892a582020-02-12 15:45:22 +0100405 #
Peter Harders41c35622020-07-12 01:16:22 +0200406 # It soon turned out, that it was best to suggest considering just avoiding linebreaks and putting all primary text tokens into one line (see
407 # example further down and notes on 'Input restrictions' in the manpage).
408 #
409 # Somehow an old first very poor approach remained, which is not stringent, but also doesn't affect one-line text.
410 #
411 # TODO: Maybe it's best, to keep the stripping of whitespace and to just remove the if-clause and to insert a blank by default (with possibly
412 # an option on how newlines in primary text should be handled (stripped or replaced by a whitespace)).
413 #
414 # Examples (how primary text with linebreaks would be converted by below code):
415 #
416 # '...<w>end</w>\n<w>.</w>...' -> '...<w>end</w> <w>.</w>...'
417 # '...<w>,</w>\n<w>this</w>\n<w>is</w>\n<w>it</w>\n<w>!</w>...' -> '<w>,<w> <w>this</w> <w>is</w> <w>it</w> <w>!</w>'.
Peter Hardersd892a582020-02-12 15:45:22 +0100418
Peter Harders41c35622020-07-12 01:16:22 +0200419 s/^\s+//; s/\s+$//; # remove consecutive whitespace at beginning and end (mostly one newline)
420
421 ### NOTE: this is only relevant, if a text consists of more than one line
422 ### TODO: find a better solution, or create a warning, if a text has more than one line ($tl > 1)
423 ### do testing with 2 different corpora (one with only one-line texts, the other with several lines per text)
Peter Harders6f526a32020-06-29 21:44:41 +0200424 if ( m/<[^>]+>[^<]/ ){ # line contains at least one tag with at least one character contents
Peter Hardersd892a582020-02-12 15:45:22 +0100425
Peter Harders41c35622020-07-12 01:16:22 +0200426 # NOTE: not stringent ('...' stands for text):
427 #
428 # beg1............................end1 => no blank before 'beg1'
429 # beg2....<pb/>...................end2 => no blank before 'beg2'
430 # beg3....<info attr1="val1"/>....end3 => no blank before 'beg3'
431 # beg4....<test>ok</test>.........end4 => blank before 'beg4'
432 #
433 # => beg1....end1beg2...<pb/>...end2beg3....<info attr1="val1"/>....end3 beg4...<test>ok</test>....end4
434 # ^
435 # |_blank between 'end3' and 'beg4'
Peter Hardersd892a582020-02-12 15:45:22 +0100436
Peter Harders41c35622020-07-12 01:16:22 +0200437 $tl++; # counter for text lines
438
439 s/^(.)/ $1/ if $tl > 1; # insert blank before 1st character (for 2nd line and consecutive lines)
Peter Hardersd892a582020-02-12 15:45:22 +0100440 }
Peter Harders41c35622020-07-12 01:16:22 +0200441 ###
Peter Hardersd892a582020-02-12 15:45:22 +0100442
Peter Harders6f526a32020-06-29 21:44:41 +0200443 # add line to buffer
444 $buf_in .= $_;
445
Peter Harders6f526a32020-06-29 21:44:41 +0200446 } elsif ( m#^(.*)<${_TEXT_BODY}(?: [^>]*)?>(.*)$# ){
447
Peter Harders6f526a32020-06-29 21:44:41 +0200448 # ~ start of text body ~
449
Peter Harders6f526a32020-06-29 21:44:41 +0200450 #print STDERR "inside text body\n";
451
452 $pfx = $1; $sfx = $2;
453
454 $data_fl = 1;
455
456 die "ERROR ($0): main(): input line number $lc: line with opening text-body tag '${_TEXT_BODY}'"
457 ." contains additional information ... => Aborting\n\tline=$_"
458 if $pfx !~ /^\s*$/ || $sfx !~ /^\s*$/;
459
Akronf57ed812020-07-27 10:37:52 +0200460 } elsif ( m#^(.*)(<(?:${_TEXT_HEADER_BEG}|${_DOC_HEADER_BEG}|${_CORP_HEADER_BEG}).*)$# ){
Peter Harders6f526a32020-06-29 21:44:41 +0200461
Akronf57ed812020-07-27 10:37:52 +0200462 # ~ start of header ~
463 $pfx = $1;
464 my $content = "$2\n";
Peter Harders6f526a32020-06-29 21:44:41 +0200465
Akronf57ed812020-07-27 10:37:52 +0200466 die "ERROR ($0): main(): input line number $lc: line with opening header tag"
Peter Harders6f526a32020-06-29 21:44:41 +0200467 ." is not in expected format ... => Aborting\n\tline=$_"
468 if $pfx !~ /^\s*$/;
Peter Hardersd892a582020-02-12 15:45:22 +0100469
Akronf57ed812020-07-27 10:37:52 +0200470 # Parse header
471 my $header = KorAP::XML::TEI::Header->new($content)->parse($input_fh);
472
473 # Header was parseable
474 if ($header) {
475
476 # Write header to zip
477 my $file = $_root_dir . $header->dir . '/' . $_header_file;
478
479 print STDERR "DEBUG ($0): Writing file $file\n" if $_DEBUG;
480
481 $header->to_zip($zipper->new_stream($file));
482
483 # Header is for text level
484 if ($header->type eq 'text') {
485
486 # Remember dir and sigles
487 $dir = $header->dir;
488 $text_id = $header->id;
489 $text_id_esc = $header->id_esc;
490
491 # log output for seeing progression
492 print STDERR "$0: main(): text_id=".decode_utf8( $text_id )."\n";
493
494 $tl = 0; # reset (needed for ~ whitespace handling ~)
495 };
496 }
497 }
Peter Harders6f526a32020-06-29 21:44:41 +0200498 } #end: while
Peter Hardersd892a582020-02-12 15:45:22 +0100499
Akron85717512020-07-08 11:19:19 +0200500 $zipper->close;
Peter Harders6f526a32020-06-29 21:44:41 +0200501
Akron8b511f92020-07-09 17:28:08 +0200502 if( $_GEN_TOK_EXT ){
503 $ext_tok->close;
Peter Hardersd892a582020-02-12 15:45:22 +0100504 }
Peter Hardersd892a582020-02-12 15:45:22 +0100505
Peter Harders41c35622020-07-12 01:16:22 +0200506} # end: sub main
Peter Hardersd892a582020-02-12 15:45:22 +0100507
Peter Hardersd892a582020-02-12 15:45:22 +0100508
Peter Harders41c35622020-07-12 01:16:22 +0200509sub retr_info { # called from main()
Peter Hardersd892a582020-02-12 15:45:22 +0100510
Peter Harders41c35622020-07-12 01:16:22 +0200511 # Notes on how 'XML::CompactTree::XS' works
Peter Harders6f526a32020-06-29 21:44:41 +0200512 #
Peter Harders41c35622020-07-12 01:16:22 +0200513 # Example: <node a="v"><node1>some <n/> text</node1><node2>more-text</node2></node>
Peter Harders6f526a32020-06-29 21:44:41 +0200514 #
Peter Harders41c35622020-07-12 01:16:22 +0200515 # Print out name of 'node2' for the above example:
516 #
517 # 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 "\x27".$data->[2]->[0]->[5]->[1]->[1]."\x27\n"'
518 #
519 # Exploring the structure of $data ( = reference to below array ):
Peter Harders6f526a32020-06-29 21:44:41 +0200520 #
521 # [ 0: XML_READER_TYPE_DOCUMENT,
522 # 1: ?
Peter Harders41c35622020-07-12 01:16:22 +0200523 # 2: [ 0: [ 0: XML_READER_TYPE_ELEMENT <- start recursion with array '$data->[2]' (see main(): retr_info( \$tree_data->[2] ))
Peter Harders6f526a32020-06-29 21:44:41 +0200524 # 1: 'node'
525 # 2: ?
526 # 3: HASH (attributes)
527 # 4: 1 (line number)
528 # 5: [ 0: [ 0: XML_READER_TYPE_ELEMENT
529 # 1: 'node1'
530 # 2: ?
531 # 3: undefined (no attributes)
532 # 4: 1 (line number)
533 # 5: [ 0: [ 0: XML_READER_TYPE_TEXT
534 # 1: 'some '
535 # ]
536 # 1: [ 0: XML_READER_TYPE_ELEMENT
537 # 1: 'n'
538 # 2: ?
539 # 3: undefined (no attributes)
540 # 4: 1 (line number)
Peter Harders41c35622020-07-12 01:16:22 +0200541 # 5: undefined (no child-nodes)
Peter Harders6f526a32020-06-29 21:44:41 +0200542 # ]
543 # 2: [ 0: XML_READER_TYPE_TEXT
544 # 1: ' text'
545 # ]
546 # ]
547 # ]
548 # 1: [ 0: XML_READER_TYPE_ELEMENT
549 # 1: 'node2'
550 # 2: ?
551 # 3: undefined (not attributes)
552 # 4: 1 (line number)
553 # 5: [ 0: [ 0: XML_READER_TYPE_TEXT
554 # 1: 'more-text'
555 # ]
556 # ]
557 # ]
558 # ]
559 # ]
560 # ]
561 # ]
562 #
563 # $data->[0] = 9 (=> type == XML_READER_TYPE_DOCUMENT)
564 #
565 # ref($data->[2]) == ARRAY (with 1 element for 'node')
566 # ref($data->[2]->[0]) == ARRAY (with 6 elements)
567 #
568 # $data->[2]->[0]->[0] == 1 (=> type == XML_READER_TYPE_ELEMENT)
569 # $data->[2]->[0]->[1] == 'node'
570 # ref($data->[2]->[0]->[3]) == HASH (=> ${$data->[2]->[0]->[3]}{a} == 'v')
571 # $data->[2]->[0]->[4] == 1 (line number)
572 # ref($data->[2]->[0]->[5]) == ARRAY (with 2 elements for 'node1' and 'node2')
Peter Harders41c35622020-07-12 01:16:22 +0200573 # # child-nodes of actual node (see $_IDX)
Peter Harders6f526a32020-06-29 21:44:41 +0200574 #
575 # ref($data->[2]->[0]->[5]->[0]) == ARRAY (with 6 elements)
576 # $data->[2]->[0]->[5]->[0]->[0] == 1 (=> type == XML_READER_TYPE_ELEMENT)
577 # $data->[2]->[0]->[5]->[0]->[1] == 'node1'
578 # $data->[2]->[0]->[5]->[0]->[3] == undefined (=> no attribute)
579 # $data->[2]->[0]->[5]->[0]->[4] == 1 (line number)
580 # ref($data->[2]->[0]->[5]->[0]->[5]) == ARRAY (with 3 elements for 'some ', '<n/>' and ' text')
581 #
582 # ref($data->[2]->[0]->[5]->[0]->[5]->[0]) == ARRAY (with 2 elements)
583 # $data->[2]->[0]->[5]->[0]->[5]->[0]->[0] == 3 (=> type == XML_READER_TYPE_TEXT)
584 # $data->[2]->[0]->[5]->[0]->[5]->[0]->[1] == 'some '
585 #
586 # ref($data->[2]->[0]->[5]->[0]->[5]->[1]) == ARRAY (with 5 elements)
587 # $data->[2]->[0]->[5]->[0]->[5]->[1]->[0] == 1 (=> type == XML_READER_TYPE_ELEMENT)
588 # $data->[2]->[0]->[5]->[0]->[5]->[1]->[1] == 'n'
589 # $data->[2]->[0]->[5]->[0]->[5]->[1]->[3] == undefined (=> no attribute)
590 # $data->[2]->[0]->[5]->[0]->[5]->[1]->[4] == 1 (line number)
Peter Harders41c35622020-07-12 01:16:22 +0200591 # $data->[2]->[0]->[5]->[0]->[5]->[1]->[5] == undefined (=> no child-nodes)
Peter Harders6f526a32020-06-29 21:44:41 +0200592 #
593 # ref($data->[2]->[0]->[5]->[0]->[5]->[2]) == ARRAY (with 2 elements)
594 # $data->[2]->[0]->[5]->[0]->[5]->[2]->[0] == 3 (=> type == XML_READER_TYPE_TEXT)
595 # $data->[2]->[0]->[5]->[0]->[5]->[2]->[1] == ' text'
596 #
597 #
598 # retr_info() starts with the array reference ${$_[0]} (= \$tree_data->[2]), which corresponds to ${\$data->[2]} in the above example.
599 # Hence, the expression @{${$_[0]}} corresponds to @{${\$data->[2]}}, $e to ${${\$data->[2]}}[0] (= $data->[2]->[0]) and $e->[0] to
600 # ${${\$data->[2]}}[0]->[0] (= $data->[2]->[0]->[0]).
Peter Hardersd892a582020-02-12 15:45:22 +0100601
Peter Harders41c35622020-07-12 01:16:22 +0200602
Peter Harders6f526a32020-06-29 21:44:41 +0200603 $rl++; # recursion level (1 = topmost level inside retr_info() = should always be level of tag $_TEXT_BODY)
Peter Hardersd892a582020-02-12 15:45:22 +0100604
Peter Hardersd892a582020-02-12 15:45:22 +0100605
Peter Harders6f526a32020-06-29 21:44:41 +0200606 foreach $e ( @{${$_[0]}} ){ # iteration through all array elements ($_[0] is a reference to an array reference)
Peter Hardersd892a582020-02-12 15:45:22 +0100607
Peter Hardersd892a582020-02-12 15:45:22 +0100608
Peter Harders41c35622020-07-12 01:16:22 +0200609 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 +0100610
Peter Hardersd892a582020-02-12 15:45:22 +0100611
Peter Harders6f526a32020-06-29 21:44:41 +0200612 #~~~~
Peter Harders41c35622020-07-12 01:16:22 +0200613 # from here: tag-node (opening)
Peter Harders6f526a32020-06-29 21:44:41 +0200614 #~~~~
Peter Hardersd892a582020-02-12 15:45:22 +0100615
Peter Hardersd892a582020-02-12 15:45:22 +0100616
Peter Harders6f526a32020-06-29 21:44:41 +0200617 # insert new array (for new tag) into @structures with tag-name and tag-attributes (if present)
618 # 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 +0100619
Peter Harders6f526a32020-06-29 21:44:41 +0200620 # ~ tag name ~
Peter Hardersd892a582020-02-12 15:45:22 +0100621
Peter Harders6f526a32020-06-29 21:44:41 +0200622 $n = $e->[1];
Peter Hardersd892a582020-02-12 15:45:22 +0100623
Peter Hardersd892a582020-02-12 15:45:22 +0100624
Peter Harders6f526a32020-06-29 21:44:41 +0200625 # ~ handle structures ~
Peter Hardersd892a582020-02-12 15:45:22 +0100626
Peter Harders6f526a32020-06-29 21:44:41 +0200627 my @array;
628 push @array, $n;
629 push @structures, \@array;
630 push @oti, $#structures; # add highest index of @structures to @oti
Peter Hardersd892a582020-02-12 15:45:22 +0100631
Peter Hardersd892a582020-02-12 15:45:22 +0100632
Peter Harders6f526a32020-06-29 21:44:41 +0200633 # ~ handle tokens ~
Peter Hardersd892a582020-02-12 15:45:22 +0100634
Peter Harders6f526a32020-06-29 21:44:41 +0200635 $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 +0100636
Peter Harders6f526a32020-06-29 21:44:41 +0200637 if ( $_TOKENS_PROC && $inside_tokens_tag == $rl ){
Peter Hardersd892a582020-02-12 15:45:22 +0100638
Peter Harders6f526a32020-06-29 21:44:41 +0200639 my @array2;
640 push @array2, $n;
641 push @tokens, \@array2;
642 push @oti2, $#tokens;
643 }
Peter Hardersd892a582020-02-12 15:45:22 +0100644
Peter Hardersd892a582020-02-12 15:45:22 +0100645
Peter Harders6f526a32020-06-29 21:44:41 +0200646 # ~ handle attributes ~
Peter Hardersd892a582020-02-12 15:45:22 +0100647
Peter Harders6f526a32020-06-29 21:44:41 +0200648 if ( defined $e->[3] ){ # only if attributes exist
Peter Hardersd892a582020-02-12 15:45:22 +0100649
Peter Harders6f526a32020-06-29 21:44:41 +0200650 for ( $c = 0; $c < @{$e->[3]}; $c += 2 ){ # with 'XCT_ATTRIBUTE_ARRAY', $node->[3] is an array reference of the form
651 # [ name1, value1, name2, value2, ....] of attribute names and corresponding values.
652 # note: arrays are faster (see: http://makepp.sourceforge.net/2.0/perl_performance.html)
Peter Hardersd892a582020-02-12 15:45:22 +0100653
Peter Harders6f526a32020-06-29 21:44:41 +0200654 # '$c' references the 'key' and '$c+1' the 'value'
655 push @{$structures[$#structures]}, ${$e->[3]}[$c], ${$e->[3]}[$c+1];
Peter Hardersd892a582020-02-12 15:45:22 +0100656
Peter Harders6f526a32020-06-29 21:44:41 +0200657 if ( $_TOKENS_PROC && $inside_tokens_tag == $rl ){
Peter Hardersd892a582020-02-12 15:45:22 +0100658
Peter Harders6f526a32020-06-29 21:44:41 +0200659 push @{$tokens[$#tokens]}, ${$e->[3]}[$c], ${$e->[3]}[$c+1];
660 }
661
662 }
663 }
664
665
666 # ~ index 'from' ~
667
668 # this is, where a normal tag or tokens-tag ($_TOKENS_TAG) starts
669
Peter Harders41c35622020-07-12 01:16:22 +0200670 push @{$structures[$#structures]}, ( $dl + $add_one ); # see below (text- and whitespace-nodes) for explanation on '$add_one'
Peter Harders6f526a32020-06-29 21:44:41 +0200671
672 if ( $_TOKENS_PROC && $inside_tokens_tag == $rl ){
673
674 push @{$tokens[$#tokens]}, ( $dl + $add_one );
675 }
676
677
678 #~~~~
Peter Harders41c35622020-07-12 01:16:22 +0200679 # until here: tag-node (opening)
Peter Harders6f526a32020-06-29 21:44:41 +0200680 #~~~~
681
682
683 # ~~ RECURSION ~~
684
Peter Harders41c35622020-07-12 01:16:22 +0200685 if ( defined $e->[$_IDX] ){ # do no recursion, if $e->[$_IDX] is not defined (because we have no array of child-nodes, e.g.: <back/>)
Peter Harders6f526a32020-06-29 21:44:41 +0200686
Peter Harders41c35622020-07-12 01:16:22 +0200687 retr_info( \$e->[$_IDX] ); # recursion with array of child-nodes
Peter Harders6f526a32020-06-29 21:44:41 +0200688
689 $rl--; # return from recursion
690 }
691
692
693 #~~~~~
Peter Harders41c35622020-07-12 01:16:22 +0200694 # from here: tag-node (closing)
Peter Harders6f526a32020-06-29 21:44:41 +0200695 #~~~~~
696
697
698 # ~ handle structures ~
699
700 {
701 my $ix = pop @oti; # index of just closed tag
702
703 my $aix = $#{$structures[$ix]}; # determine highest index from 'array referring to last closed tag' ...
704
705 $fval = ${$structures[$ix]}[ $aix ]; # ... and get it's from-value
706
707 if ( $fval > 0 && not exists $ws{ $fval - 1 } ){ # ~ whitespace related issue ~
708
Peter Harders41c35622020-07-12 01:16:22 +0200709 # ~ previous node was a text-node ~
Peter Harders6f526a32020-06-29 21:44:41 +0200710
Peter Harders41c35622020-07-12 01:16:22 +0200711 ${$structures[$ix]}[ $aix ] = $fval - 1; # recorrect from-value (see below: Notes on ~ whitespace related issue ~)
Peter Harders6f526a32020-06-29 21:44:41 +0200712 }
713
714 # in case this fails, check input
715 die "ERROR ($0, retr_info()): text_id='$text_id', processing of \@structures: from-value ($fval) is 2 or more greater"
716 ." than to-value ($dl) => please check. aborting ...\n"
717 if ( $fval - 1 ) > $dl;
718
Peter Harders41c35622020-07-12 01:16:22 +0200719 # TODO: find example for which this case applies
Peter Harders6f526a32020-06-29 21:44:41 +0200720 # maybe this is not necessary anymore, because the above recorrection of the from-value suffices
721 # TODO: check, if it's better to remove this line and change above check to 'if ( $fval - 1) >= $dl;
Peter Harders41c35622020-07-12 01:16:22 +0200722 # do testing with bigger corpus excerpt (wikipedia?)
Peter Harders6f526a32020-06-29 21:44:41 +0200723 ${$structures[$ix]}[ $aix ] = $dl if $fval == $dl + 1; # correct from-value (same as ... if $fval-1 == $dl)
724
725 push @{$structures[$ix]}, $dl, $rl; # to-value and recursion-level
726
727 # note: use $dl, because the offsets are _between_ the characters (e.g.: word = 'Hello' => from = 0 (before 'H'), to = 5 (after 'o'))
728 }
729
730
731 # ~ handle tokens ~
732
733
734 if ( $_TOKENS_PROC && $inside_tokens_tag == $rl ){
735
736 my $ix = pop @oti2;
737
738 my $aix = $#{$tokens[$ix]};
739
740 $fval2 = ${$tokens[$ix]}[ $aix ]; # from-value
741
742 if( $fval2 > 0 && not exists $ws{ $fval2 - 1 } ){ # ~ whitespace related issue ~
743
Peter Harders41c35622020-07-12 01:16:22 +0200744 # ~ previous node was a text-node ~
Peter Harders6f526a32020-06-29 21:44:41 +0200745
Peter Harders41c35622020-07-12 01:16:22 +0200746 ${$tokens[$ix]}[ $aix ] = $fval2 - 1; # recorrect from-value (see below: Notes on ~ whitespace related issue ~)
Peter Harders6f526a32020-06-29 21:44:41 +0200747 }
748
749 # in case this fails, check input
750 die "ERROR ($0, retr_info()): text_id='$text_id', processing of \@tokens: from-value ($fval2) is 2 or more greater"
751 ." than to-value ($dl) => please check. aborting ...\n"
752 if ( $fval2 - 1 ) > $dl;
753
Peter Harders41c35622020-07-12 01:16:22 +0200754 # TODO: find example for which this case applies
Peter Harders6f526a32020-06-29 21:44:41 +0200755 # maybe this is not necessary anymore, because the above recorrection of the from-value suffices
756 # TODO: check, if it's better to remove this line and change above check to 'if ( $fval2 - 1) >= $dl;
Peter Harders41c35622020-07-12 01:16:22 +0200757 # do testing with bigger corpus excerpt (wikipedia?)
Peter Harders6f526a32020-06-29 21:44:41 +0200758 ${$tokens[$ix]}[ $aix ] = $dl if $fval2 == $dl + 1; # correct from-value (same as ... if $fval-1 == $dl)
759
760 push @{$tokens[$ix]}, $dl, $rl; # to-value and recursion-level
761
762 $inside_tokens_tag = -1; # reset
763 }
764
765 # ~ whitespace related issue ~
Peter Hardersd892a582020-02-12 15:45:22 +0100766 # clean up
Peter Harders6f526a32020-06-29 21:44:41 +0200767 delete $ws{ $fval - 1 } if $fval > 0 && exists $ws{ $fval - 1 };
768 delete $ws{ $fval2 - 1 } if $_TOKENS_PROC && $fval2 > 0 && exists $ws{ $fval2 - 1 };
Peter Hardersd892a582020-02-12 15:45:22 +0100769
770
Peter Harders41c35622020-07-12 01:16:22 +0200771 #~~~~
772 # until here: tag-node (closing)
773 #~~~~
Peter Hardersd892a582020-02-12 15:45:22 +0100774
775
Peter Harders41c35622020-07-12 01:16:22 +0200776 #~~~~~
777 # from here: text- and whitespace-nodes
778 #~~~~~
779
780 # The 3rd form of nodes, besides text- (XML_READER_TYPE_TEXT) and tag-nodes (XML_READER_TYPE_ELEMENT) are nodes of the type
781 # 'XML_READER_TYPE_SIGNIFICANT_WHITESPACE'.
Peter Harders6f526a32020-06-29 21:44:41 +0200782 #
Peter Harders41c35622020-07-12 01:16:22 +0200783 # When modifiying the previous example (see: Notes on how 'XML::CompactTree::XS' works) by inserting an additional blank between
784 # '</node1>' and '<node2>', the output for '$data->[2]->[0]->[5]->[1]->[1]' is a blank (' ') and it's type is '14'
785 # (XML_READER_TYPE_SIGNIFICANT_WHITESPACE, see 'man XML::LibXML::Reader'):
Peter Harders6f526a32020-06-29 21:44:41 +0200786 #
Peter Harders41c35622020-07-12 01:16:22 +0200787 # 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=\x27".$data->[2]->[0]->[5]->[1]->[1]."\x27, type=".$data->[2]->[0]->[5]->[1]->[0]."\n"'
Peter Hardersd892a582020-02-12 15:45:22 +0100788
Peter Harders6f526a32020-06-29 21:44:41 +0200789 } elsif ( $e->[0] == XML_READER_TYPE_TEXT || $e->[0] == XML_READER_TYPE_SIGNIFICANT_WHITESPACE ){
Peter Hardersd892a582020-02-12 15:45:22 +0100790
Peter Harders41c35622020-07-12 01:16:22 +0200791 # Notes on ~ whitespace related issue ~ (referred to the code fragment below)
Peter Harders6f526a32020-06-29 21:44:41 +0200792 #
Peter Harders41c35622020-07-12 01:16:22 +0200793 # Example: '... <head type="main"><s>Campagne in Frankreich</s></head><head type="sub"> <s>1792</s> ...'
Peter Harders6f526a32020-06-29 21:44:41 +0200794 #
795 # Two text-nodes should normally be separated by a blank. In the above example, that would be the 2 text-nodes
Peter Harders41c35622020-07-12 01:16:22 +0200796 # 'Campagne in Frankreich' and '1792', which are separated by the whitespace-node ' ' (see [2]).
Peter Harders6f526a32020-06-29 21:44:41 +0200797 #
Peter Harders41c35622020-07-12 01:16:22 +0200798 # The text-node 'Campagne in Frankreich' leads to the setting of '$add_one' to 1, so that when opening the 2nd 'head'-tag,
799 # it's from-index gets set to the correct start-index of '1792' (and not to the start-index of the whitespace-node ' ').
Peter Harders6f526a32020-06-29 21:44:41 +0200800 #
Peter Harders41c35622020-07-12 01:16:22 +0200801 # The assumption here is, that in most cases there _is_ a whitespace node between 2 text-nodes. The below code fragment
802 # enables a way, to check, if this really _was_ the case for the last 2 'non-tag'-nodes, when closing a tag:
Peter Harders6f526a32020-06-29 21:44:41 +0200803 #
Peter Harders41c35622020-07-12 01:16:22 +0200804 # When a whitespace-node is read, its from-index is stored as a hash-key (in %ws), to state that it belongs to a ws-node.
805 # So when closing a tag, it can be checked, if the previous 'non-tag'-node (text or whitespace), which is the one before
806 # the last read 'non-tag'-node, was a actually _not_ a ws-node, but instead a text-node. In that case, the from-value of
807 # the last read 'non-tag'-node has to be corrected (see [1]),
Peter Harders6f526a32020-06-29 21:44:41 +0200808 #
Peter Harders41c35622020-07-12 01:16:22 +0200809 # For whitespace-nodes $add_one is set to 0, so when opening the next tag (in the above example the 2nd 's'-tag), no
810 # additional 1 is added (because this was already done by the whitespace-node itself when incrementing the variable $dl).
Peter Harders6f526a32020-06-29 21:44:41 +0200811 #
Peter Harders41c35622020-07-12 01:16:22 +0200812 # [1]
813 # Now, what happens, when 2 text-nodes are _not_ seperated by a whitespace-node (e.g.: <w>Augen<c>,</c></w>)?
814 # In this case, the falsely increased from-value has to be decreased again by 1 when closing the enclosing tag
815 # (see above code fragment '... not exists $ws{ $fval - 1 } ...').
Peter Harders6f526a32020-06-29 21:44:41 +0200816 #
Peter Harders41c35622020-07-12 01:16:22 +0200817 # [2]
818 # Comparing the 2 examples '<w>fu</w> <w>bar</w>' and '<w>fu</w><w> </w><w>bar</w>', is ' ' in both cases handled as a
819 # whitespace-node (XML_READER_TYPE_SIGNIFICANT_WHITESPACE).
Peter Harders6f526a32020-06-29 21:44:41 +0200820 #
Peter Harders41c35622020-07-12 01:16:22 +0200821 # The from-index of the 2nd w-tag in the second example refers to 'bar', which may not have been the intention
822 # (even though '<w> </w>' doesn't make a lot of sense). TODO: could this be a bug?
Peter Harders6f526a32020-06-29 21:44:41 +0200823 #
Peter Harders41c35622020-07-12 01:16:22 +0200824 # Empty tags also cling to the next text-token - e.g. in '<w>tok1</w> <w>tok2</w><a><b/></a> <w>tok3</w>' are the from-
825 # and to-indizes for the tags 'a' and 'b' both 12, which is the start-index of the token 'tok3'.
Peter Harders6f526a32020-06-29 21:44:41 +0200826
827 if( $e->[0] == XML_READER_TYPE_SIGNIFICANT_WHITESPACE ){
828
Peter Harders41c35622020-07-12 01:16:22 +0200829 # ~ whitespace-node ~
830
831 # ~ whitespace related issue ~
Peter Harders6f526a32020-06-29 21:44:41 +0200832
833 $add_one = 0;
834
Peter Harders41c35622020-07-12 01:16:22 +0200835 $ws{ $dl }++; # state, that this from-index belongs to a whitespace-node
836 # ('++' doesn't mean a thing here - maybe it could be used for a consistency check)
Peter Harders6f526a32020-06-29 21:44:41 +0200837
838 }else{
839
840 # ~ text-node ~
841
842 $add_one = 1;
843 }
844
845
846 # ~ update $data and $dl ~
847
848 $data .= $e->[1];
849
850 $dl += length( $e->[1] ); # update length of $data
851
852
Peter Harders41c35622020-07-12 01:16:22 +0200853 #~~~~~
854 # until here: text- and whitespace-nodes
855 #~~~~~
856
857
858 #elsif ( $e->[0] == XML_READER_TYPE_ATTRIBUTE ) # attribute-node
Peter Harders6f526a32020-06-29 21:44:41 +0200859 # note: attributes cannot be processed like this ( => use 'XCT_ATTRIBUTE_ARRAY' - see above )
860
861
862 }else{ # not yet handled type
863
864 die "ERROR ($0): Not yet handled type (\$e->[0]=".$e->[0].") ... => Aborting\n";
865 }
866
867 } # end: foreach iteration
868
869} # end: sub retr_info
870
871
Peter Harders41c35622020-07-12 01:16:22 +0200872sub write_structures { # called from main()
Peter Harders6f526a32020-06-29 21:44:41 +0200873
874 # ~ write @structures ~
Peter Hardersd892a582020-02-12 15:45:22 +0100875
876 #print STDERR "$0: write_structures(): ...\n";
877
Peter Harders6f526a32020-06-29 21:44:41 +0200878 if ( $dir eq "" ){
879
880 print STDERR "WARNING ($0): write_structures(): empty textSigle => nothing to do ...\n";
Peter Hardersd892a582020-02-12 15:45:22 +0100881 return;
882 }
883
Peter Harders6f526a32020-06-29 21:44:41 +0200884 $output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-model href=\"span.rng\" type=\"application/xml\""
885 ." schematypens=\"http://relaxng.org/ns/structure/1.0\"?>\n\n<layer docid=\""
886 .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 +0100887
888 $c = 0;
889
Peter Harders6f526a32020-06-29 21:44:41 +0200890 foreach $ref ( @structures ){
Peter Hardersd892a582020-02-12 15:45:22 +0100891
Peter Harders6f526a32020-06-29 21:44:41 +0200892 ( @{$ref} == 4 )?( $idx = 1 ):( $idx = @{$ref}-3 ); # if array '@{$ref}' doesn't contain attributes, then the number of elements in this array is 4
893 # (name, from, to, rec_level), otherwise >4
Peter Hardersd892a582020-02-12 15:45:22 +0100894
Peter Harders6f526a32020-06-29 21:44:41 +0200895 # 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 )
896
897 if( $#structures == $c && ${$ref}[ $idx ] == ${$ref}[ $idx+1 ] + 1 ){
898
899 ${$ref}[$idx] = ${$ref}[ $idx+1 ];
Peter Hardersd892a582020-02-12 15:45:22 +0100900 }
Peter Hardersd892a582020-02-12 15:45:22 +0100901
Peter Harders6f526a32020-06-29 21:44:41 +0200902 # this consistency check is already done in 'retr_info()'
903 #elsif( ${$ref}[$idx] > ${$ref}[$idx+1] ){ # consistency check: abort, if this doesn't hold
904 # die "ERROR ($0: write_structures(): \$text_id=$text_id, \$c=$c, tag-name=${$ref}[0]):"
905 # ." 'from-index=${$ref}[$idx]' > 'to-index=${$ref}[$idx+1]' => please check! aborting ...\n";
906 # die "ERROR ($0: write_structures(): \$text_id=$text_id, \$c=$c, tag-name=${$ref}[0]):"
907 # ." 'from-index=${$ref}[$idx]' > 'to-index=${$ref}[$idx+1]' => please check! aborting ...\n\n$output" }
Peter Hardersd892a582020-02-12 15:45:22 +0100908
Peter Harders6f526a32020-06-29 21:44:41 +0200909 # at least 'POS' should always be there => remove constraint '$_TOKENS_PROC'
910 #if( $_TOKENS_PROC && ${$ref}[0] ne $_TOKENS_TAG )
Peter Hardersd892a582020-02-12 15:45:22 +0100911
Peter Harders6f526a32020-06-29 21:44:41 +0200912 if( ${$ref}[0] ne $_TOKENS_TAG ){ # $_TOKENS_TAG is already written in 'write_tokens'
Peter Hardersd892a582020-02-12 15:45:22 +0100913
Peter Harders6f526a32020-06-29 21:44:41 +0200914 # l (level): insert information about depth of element in XML-tree (top element = level 1)
915 $output .= " <span id=\"s$c\" from=\"${$ref}[ $idx ]\" to=\"${$ref}[ $idx+1 ]\" l=\"${$ref}[ $idx+2 ]\">\n"
916 ." <fs type=\"struct\" xmlns=\"http://www.tei-c.org/ns/1.0\">\n"
917 ." <f name=\"name\">${$ref}[ 0 ]</f>\n";
918
919 if ( $idx > 2 ) # attributes
920 {
921 $output .= " <f name=\"attr\">\n <fs type=\"attr\">\n";
922
923 for ( $att_idx = 1; $att_idx < $idx; $att_idx += 2 ){
924
925 ${$ref}[ $att_idx+1 ] =~ s/(&|<|>)/$ent{$1}/g; # see explanation in func. 'write_tokens'
926
927 # attribute (at index $att_idx) with value (at index $att_idx+1)
928 $output .= " <f name=\"${$ref}[ $att_idx ]\">${$ref}[ $att_idx+1 ]</f>\n";
929 }
930
931 $output .= " </fs>\n </f>\n";
Peter Hardersd892a582020-02-12 15:45:22 +0100932 }
933
Peter Harders6f526a32020-06-29 21:44:41 +0200934 $output .= " </fs>\n </span>\n";
Peter Hardersd892a582020-02-12 15:45:22 +0100935
Peter Harders6f526a32020-06-29 21:44:41 +0200936 } # fi: ... ne $_TOKENS_TAG
Peter Hardersd892a582020-02-12 15:45:22 +0100937
938 $c++;
939
Peter Harders6f526a32020-06-29 21:44:41 +0200940 } # end: foreach
Peter Hardersd892a582020-02-12 15:45:22 +0100941
942 $output .= " </spanList>\n</layer>";
943
Peter Harders6f526a32020-06-29 21:44:41 +0200944 $output = encode_utf8( $output );
Peter Hardersd892a582020-02-12 15:45:22 +0100945
Akron85717512020-07-08 11:19:19 +0200946 $zipper->new_stream("$_root_dir$dir/$_structure_dir/$_structure_file")
947 ->print($output);
Peter Hardersd892a582020-02-12 15:45:22 +0100948
949 #print STDERR "$0: write_structures(): DONE\n";
Peter Harders6f526a32020-06-29 21:44:41 +0200950
Peter Hardersd892a582020-02-12 15:45:22 +0100951} # end: sub write_structures
952
953
Peter Harders41c35622020-07-12 01:16:22 +0200954sub write_tokens { # called from main()
Peter Harders6f526a32020-06-29 21:44:41 +0200955
956 # ~ write @tokens ~
957
958 #print STDERR "$0: write_tokens(): ...\n";
Peter Hardersd892a582020-02-12 15:45:22 +0100959
960 if( $dir eq "" ){
Peter Harders6f526a32020-06-29 21:44:41 +0200961
962 print STDERR "WARNING ($0): write_tokens(): empty textSigle => nothing to do ...\n";
Peter Hardersd892a582020-02-12 15:45:22 +0100963 return;
964 }
965
Peter Harders6f526a32020-06-29 21:44:41 +0200966 $output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-model href=\"span.rng\" type=\"application/xml\""
967 ." schematypens=\"http://relaxng.org/ns/structure/1.0\"?>\n\n<layer docid=\""
968 .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 +0100969
970 $c = 0;
971
Peter Harders6f526a32020-06-29 21:44:41 +0200972 foreach $ref ( @tokens ){
Peter Hardersd892a582020-02-12 15:45:22 +0100973
Peter Harders6f526a32020-06-29 21:44:41 +0200974 # if array '@{$ref}' doesn't contain attributes, then the number of elements in this array is 4 (name, from, to, rec_level), otherwise >4
975 ( @{$ref} == 4 )?( $idx = 1 ):( $idx = @{$ref}-3 );
Peter Hardersd892a582020-02-12 15:45:22 +0100976
Peter Harders6f526a32020-06-29 21:44:41 +0200977 # 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())
978 if ( $#tokens == $c && ${$ref}[ $idx ] == ${$ref}[ $idx+1 ] + 1 ){
979
980 ${$ref}[ $idx ] = ${$ref}[ $idx+1 ]; # TODO: check
Peter Hardersd892a582020-02-12 15:45:22 +0100981 }
Peter Hardersd892a582020-02-12 15:45:22 +0100982
Peter Harders6f526a32020-06-29 21:44:41 +0200983 # l (level): insert information about depth of element in XML-tree (top element = level 1)
984 $output .= " <span id=\"s$c\" from=\"${$ref}[ $idx ]\" to=\"${$ref}[ $idx+1 ]\" l=\"${$ref}[ $idx+2 ]\">\n"
985 ." <fs type=\"lex\" xmlns=\"http://www.tei-c.org/ns/1.0\">\n"
986 ." <f name=\"lex\">\n";
Peter Hardersd892a582020-02-12 15:45:22 +0100987
Peter Harders6f526a32020-06-29 21:44:41 +0200988 if ( $idx > 2 ){ # attributes
989
Peter Hardersd892a582020-02-12 15:45:22 +0100990 $output .= " <fs>\n";
991
Peter Harders6f526a32020-06-29 21:44:41 +0200992 for ( $att_idx = 1; $att_idx < $idx; $att_idx += 2 ){
Peter Hardersd892a582020-02-12 15:45:22 +0100993
Peter Harders6f526a32020-06-29 21:44:41 +0200994 ${$ref}[ $att_idx+1 ] =~ s/(&|<|>)/$ent{$1}/g; # ... <w lemma="&gt;" ana="PUNCTUATION">&gt;</w> ...
995 # the '&gt;' is translated to '>' and hence the result would be '<f name="lemma">></f>'
Peter Hardersd892a582020-02-12 15:45:22 +0100996
Peter Harders6f526a32020-06-29 21:44:41 +0200997 if ( $_INLINE_ANNOT && ${$ref}[ $att_idx ] eq "$_INLINE_ATT_RD" ){
Peter Hardersd892a582020-02-12 15:45:22 +0100998
Peter Harders6f526a32020-06-29 21:44:41 +0200999 ${$ref}[ $att_idx+1 ] =~ /^([^ ]+)(?: (.+))?$/;
1000
1001 die "ERROR (write_tokens()): unexpected format! => Aborting ... (att: ${$ref}[ $att_idx+1 ])\n"
1002 if ( $_INLINE_POS_WR && not defined $1 ) || ( $_INLINE_MSD_WR && not defined $2 );
1003
1004 if ( "$_INLINE_POS_WR" ){
1005
1006 $output .= " <f name=\"$_INLINE_POS_WR\">";
Peter Hardersd892a582020-02-12 15:45:22 +01001007 $output .= "$1" if defined $1;
1008 $output .= "</f>\n";
1009 }
Peter Harders6f526a32020-06-29 21:44:41 +02001010
1011 if ( "$_INLINE_MSD_WR" ){
1012
1013 $output .= " <f name=\"$_INLINE_MSD_WR\">";
Peter Hardersd892a582020-02-12 15:45:22 +01001014 $output .= "$2" if defined $2;
1015 $output .= "</f>\n";
1016 }
1017
Peter Harders6f526a32020-06-29 21:44:41 +02001018 } elsif ( $_INLINE_ANNOT && "$_INLINE_LEM_RD" && ${$ref}[ $att_idx ] eq "$_INLINE_LEM_RD" ){
Peter Hardersd892a582020-02-12 15:45:22 +01001019
Peter Harders6f526a32020-06-29 21:44:41 +02001020 $output .= " <f name=\"$_INLINE_LEM_WR\">${$ref}[ $att_idx+1 ]</f>\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001021
Peter Harders6f526a32020-06-29 21:44:41 +02001022 } else { # all other attributes
Peter Hardersd892a582020-02-12 15:45:22 +01001023
Peter Harders6f526a32020-06-29 21:44:41 +02001024 $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 +01001025 }
1026
Peter Harders6f526a32020-06-29 21:44:41 +02001027 } # end: for
Peter Hardersd892a582020-02-12 15:45:22 +01001028
1029 $output .= " </fs>\n";
Peter Harders6f526a32020-06-29 21:44:41 +02001030
1031 } # fi: attributes
Peter Hardersd892a582020-02-12 15:45:22 +01001032
1033 $output .= " </f>\n </fs>\n </span>\n";
1034
1035 $c++;
1036
Peter Harders6f526a32020-06-29 21:44:41 +02001037 } # end: foreach
Peter Hardersd892a582020-02-12 15:45:22 +01001038
1039 $output .= " </spanList>\n</layer>";
1040
Peter Harders6f526a32020-06-29 21:44:41 +02001041 $output = encode_utf8( $output );
Peter Hardersd892a582020-02-12 15:45:22 +01001042
Akron85717512020-07-08 11:19:19 +02001043 $zipper->new_stream("$_root_dir$dir/$_tokens_dir/$_tokens_file")
1044 ->print($output);
Peter Hardersd892a582020-02-12 15:45:22 +01001045
Peter Harders6f526a32020-06-29 21:44:41 +02001046 #print STDERR "$0: write_tokens(): DONE\n";
Peter Hardersd892a582020-02-12 15:45:22 +01001047
Peter Harders6f526a32020-06-29 21:44:41 +02001048} # end: sub write_tokens
Peter Hardersd892a582020-02-12 15:45:22 +01001049
Peter Hardersd892a582020-02-12 15:45:22 +01001050
Akrond949e182020-02-14 12:23:57 +01001051__END__
1052
1053=pod
1054
1055=encoding utf8
1056
1057=head1 NAME
1058
1059tei2korapxml - Conversion of TEI P5 based formats to KorAP-XML
1060
1061=head1 SYNOPSIS
1062
1063 cat corpus.i5.xml | tei2korapxml > corpus.korapxml.zip
1064
1065=head1 DESCRIPTION
1066
Akronee434b12020-07-08 12:53:01 +02001067C<tei2korapxml> is a script to convert TEI P5 and
1068L<I5|https://www1.ids-mannheim.de/kl/projekte/korpora/textmodell.html>
1069based documents to the
1070L<KorAP-XML format|https://github.com/KorAP/KorAP-XML-Krill#about-korap-xml>.
1071If no specific input is defined, data is
Akrond949e182020-02-14 12:23:57 +01001072read from C<STDIN>. If no specific output is defined, data is written
1073to C<STDOUT>.
Peter Harders6f526a32020-06-29 21:44:41 +02001074
Akrond949e182020-02-14 12:23:57 +01001075This program is usually called from inside another script.
1076
Akronee434b12020-07-08 12:53:01 +02001077=head1 FORMATS
1078
1079=head2 Input restrictions
1080
1081=over 2
1082
1083=item
1084
1085utf8 encoded
1086
1087=item
1088
1089TEI P5 formatted input with certain restrictions:
1090
1091=over 4
1092
1093=item
1094
1095B<mandatory>: text-header with integrated textsigle, text-body
1096
1097=item
1098
1099B<optional>: corp-header with integrated corpsigle,
1100doc-header with integrated docsigle
1101
1102=back
1103
1104=item
1105
1106all tokens inside the primary text (inside $data) may not be
1107newline seperated, because newlines are removed
1108(see code section C<~ inside text body ~>) and a conversion of newlines
1109into blanks between 2 tokens could lead to additional blanks,
1110where there should be none (e.g.: punctuation characters like C<,> or
1111C<.> should not be seperated from their predecessor token).
1112(see also code section C<~ whitespace handling ~>).
1113
1114=back
1115
1116=head2 Notes on the output
1117
1118=over 2
1119
1120=item
1121
1122zip file output (default on C<stdout>) with utf8 encoded entries
1123(which together form the KorAP-XML format)
1124
1125=back
1126
Akrond949e182020-02-14 12:23:57 +01001127=head1 INSTALLATION
1128
1129C<tei2korapxml> requires L<libxml2-dev> bindings to build. When
1130these bindings are available, the preferred way to install the script is
1131to use L<cpanm|App::cpanminus>.
1132
1133 $ cpanm https://github.com/KorAP/KorAP-XML-TEI.git
1134
1135In case everything went well, the C<tei2korapxml> tool will
1136be available on your command line immediately.
Peter Harders6f526a32020-06-29 21:44:41 +02001137
Akrond949e182020-02-14 12:23:57 +01001138Minimum requirement for L<KorAP::XML::TEI> is Perl 5.16.
1139
1140=head1 OPTIONS
1141
1142=over 2
1143
1144=item B<--base|-b>
1145
1146The base directory for output. Defaults to C<.>.
1147
1148=item B<--help|-h>
1149
1150Print help information.
1151
1152=item B<--version|-v>
1153
1154Print version information.
1155
1156=back
1157
1158=head1 COPYRIGHT AND LICENSE
1159
1160Copyright (C) 2020, L<IDS Mannheim|https://www.ids-mannheim.de/>
1161
1162Author: Peter Harders
1163
1164Contributors: Marc Kupietz, Carsten Schnober, Nils Diewald
1165
1166L<KorAP::XML::TEI> is developed as part of the L<KorAP|https://korap.ids-mannheim.de/>
1167Corpus Analysis Platform at the
1168L<Leibniz Institute for the German Language (IDS)|http://ids-mannheim.de/>,
1169member of the
1170L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/>.
1171
1172This program is free software published under the
1173L<BSD-2 License|https://raw.githubusercontent.com/KorAP/KorAP-XML-TEI/master/LICENSE>.
1174
1175=cut