Akron | 9cb1394 | 2020-02-14 07:39:54 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 2 | use strict; |
| 3 | use warnings; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 4 | |
Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame] | 5 | use Log::Any '$log'; |
| 6 | use Log::Any::Adapter; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 7 | use Pod::Usage; |
| 8 | use Getopt::Long qw(GetOptions :config no_auto_abbrev); |
| 9 | |
| 10 | use File::Basename qw(dirname); |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 11 | |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 12 | use Encode qw(decode); |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 13 | |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 14 | use FindBin; |
| 15 | BEGIN { |
| 16 | unshift @INC, "$FindBin::Bin/../lib"; |
| 17 | }; |
| 18 | |
Marc Kupietz | 8a954e5 | 2021-02-16 22:03:07 +0100 | [diff] [blame] | 19 | use KorAP::XML::TEI qw!remove_xml_comments replace_entities!; |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 20 | use KorAP::XML::TEI::Tokenizer::External; |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 21 | use KorAP::XML::TEI::Tokenizer::Conservative; |
| 22 | use KorAP::XML::TEI::Tokenizer::Aggressive; |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 23 | use KorAP::XML::TEI::Zipper; |
Akron | f57ed81 | 2020-07-27 10:37:52 +0200 | [diff] [blame] | 24 | use KorAP::XML::TEI::Header; |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 25 | use KorAP::XML::TEI::Inline; |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 26 | |
Marc Kupietz | 1e882fb | 2020-09-09 00:05:46 +0200 | [diff] [blame] | 27 | eval { |
| 28 | require KorAP::XML::TEI::Tokenizer::KorAP; |
| 29 | 1; |
| 30 | }; |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 31 | |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 32 | our $VERSION = '1.01'; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 33 | |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 34 | our $VERSION_MSG = "\ntei2korapxml - v$VERSION\n"; |
| 35 | |
Akron | 33db4ec | 2021-02-24 12:52:21 +0100 | [diff] [blame] | 36 | use constant { |
| 37 | # Set to 1 for minimal more debug output (no need to be parametrized) |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 38 | DEBUG => $ENV{KORAPXMLTEI_DEBUG} // 0 |
Akron | 33db4ec | 2021-02-24 12:52:21 +0100 | [diff] [blame] | 39 | }; |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 40 | |
Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 41 | if ($ENV{KORAPXMLTEI_INLINE}) { |
| 42 | warn 'KORAPXMLTEI_INLINE is deprecated in favor of --skip-inline-token-annotations'; |
| 43 | }; |
| 44 | |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 45 | # Parse options from the command line |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 46 | GetOptions( |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 47 | 'root|r=s' => \(my $root_dir = '.'), |
| 48 | 'input|i=s' => \(my $input_fname = ''), |
Akron | 75d6314 | 2021-02-23 18:40:56 +0100 | [diff] [blame] | 49 | 'tokenizer-call|tc=s' => \(my $tokenizer_call), |
| 50 | 'tokenizer-korap|tk' => \(my $tokenizer_korap), |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 51 | 'tokenizer-internal|ti' => \(my $tokenizer_intern), |
Akron | 75d6314 | 2021-02-23 18:40:56 +0100 | [diff] [blame] | 52 | 'use-tokenizer-sentence-splits|s' => \(my $use_tokenizer_sentence_splits), |
| 53 | 'inline-tokens=s' => \(my $inline_tokens = 'tokens#morpho'), |
| 54 | 'inline-structures=s' => \(my $inline_structures = 'struct#structure'), |
| 55 | 'skip-inline-tokens' => \(my $skip_inline_tokens = 0), |
Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 56 | 'skip-inline-token-annotations' => \( |
| 57 | my $skip_inline_token_annotations = ($ENV{KORAPXMLTEI_INLINE} ? 0 : 1)), |
Akron | 54c3ff1 | 2021-02-25 11:33:37 +0100 | [diff] [blame] | 58 | 'skip-inline-tags=s' => \(my $skip_inline_tags_str = ''), |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 59 | 'base-foundry=s' => \(my $base_dir = 'base'), |
| 60 | 'data-file=s' => \(my $data_file = 'data'), |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 61 | 'header-file=s' => \(my $header_file = 'header'), |
| 62 | 'tokens-file=s' => \(my $tokens_file = 'tokens'), |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 63 | 'log|l=s' => \(my $log_level = 'notice'), |
Akron | 75d6314 | 2021-02-23 18:40:56 +0100 | [diff] [blame] | 64 | 'help|h' => sub { |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 65 | pod2usage( |
| 66 | -verbose => 99, |
| 67 | -sections => 'NAME|DESCRIPTION|SYNOPSIS|ARGUMENTS|OPTIONS', |
| 68 | -msg => $VERSION_MSG, |
| 69 | -output => '-' |
| 70 | ) |
| 71 | }, |
| 72 | 'version|v' => sub { |
| 73 | pod2usage( |
| 74 | -verbose => 0, |
| 75 | -msg => $VERSION_MSG, |
| 76 | -output => '-' |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 77 | ); |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 78 | } |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 79 | ); |
| 80 | |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 81 | |
Akron | b87c58d | 2021-02-23 17:23:30 +0100 | [diff] [blame] | 82 | # Establish logger |
Akron | 33db4ec | 2021-02-24 12:52:21 +0100 | [diff] [blame] | 83 | binmode(STDERR, ':encoding(UTF-8)'); |
Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame] | 84 | Log::Any::Adapter->set('Stderr', log_level => $log_level); |
Akron | b364947 | 2020-09-29 08:24:46 +0200 | [diff] [blame] | 85 | $log->notice('Debugging is activated') if DEBUG; |
| 86 | |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 87 | |
Akron | 0529e51 | 2021-02-22 09:55:35 +0100 | [diff] [blame] | 88 | # tag (without attributes), which contains the primary text |
| 89 | my $_TEXT_BODY = 'text'; |
Akron | 0c41ab3 | 2020-09-29 07:33:33 +0200 | [diff] [blame] | 90 | # optional |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 91 | |
Akron | 0529e51 | 2021-02-22 09:55:35 +0100 | [diff] [blame] | 92 | # TODO: IDS-specific (and redundant) |
| 93 | my $_HEADER_TAG = 'idsHeader'; |
Akron | 0c41ab3 | 2020-09-29 07:33:33 +0200 | [diff] [blame] | 94 | |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 95 | |
| 96 | # Define tokenizers |
Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 97 | if ($use_tokenizer_sentence_splits && !$tokenizer_korap) { |
Akron | 33db4ec | 2021-02-24 12:52:21 +0100 | [diff] [blame] | 98 | die $log->fatal( |
| 99 | 'Sentence splitting is currently only supported by KorAP tokenizer ' . |
| 100 | '(use -tk to activate it)' |
| 101 | ); |
Akron | b87c58d | 2021-02-23 17:23:30 +0100 | [diff] [blame] | 102 | }; |
Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 103 | |
Akron | 54c3ff1 | 2021-02-25 11:33:37 +0100 | [diff] [blame] | 104 | # Remember to skip certain inline tags |
| 105 | my %skip_inline_tags = (); |
| 106 | if ($skip_inline_tags_str) { |
| 107 | foreach (split /\s*,\s*/, $skip_inline_tags_str) { |
| 108 | $skip_inline_tags{$_} = 1; |
| 109 | }; |
| 110 | }; |
| 111 | |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 112 | # External tokenization |
Akron | 0c41ab3 | 2020-09-29 07:33:33 +0200 | [diff] [blame] | 113 | my $ext_tok; |
| 114 | if ($tokenizer_call) { |
| 115 | $ext_tok = KorAP::XML::TEI::Tokenizer::External->new($tokenizer_call); |
| 116 | } |
Marc Kupietz | 1e882fb | 2020-09-09 00:05:46 +0200 | [diff] [blame] | 117 | |
Akron | 0c41ab3 | 2020-09-29 07:33:33 +0200 | [diff] [blame] | 118 | elsif ($tokenizer_korap) { |
Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 119 | $ext_tok = KorAP::XML::TEI::Tokenizer::KorAP->new($use_tokenizer_sentence_splits); |
Akron | 54c3ff1 | 2021-02-25 11:33:37 +0100 | [diff] [blame] | 120 | if ($use_tokenizer_sentence_splits) { |
| 121 | $skip_inline_tags{s} = 1; |
| 122 | }; |
Akron | 0c41ab3 | 2020-09-29 07:33:33 +0200 | [diff] [blame] | 123 | }; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 124 | |
Akron | 0c41ab3 | 2020-09-29 07:33:33 +0200 | [diff] [blame] | 125 | |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 126 | # Internal tokenization |
Akron | b87c58d | 2021-02-23 17:23:30 +0100 | [diff] [blame] | 127 | my $aggr_tok = KorAP::XML::TEI::Tokenizer::Aggressive->new; |
| 128 | my $cons_tok = KorAP::XML::TEI::Tokenizer::Conservative->new; |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 129 | |
Peter Harders | 41c3562 | 2020-07-12 01:16:22 +0200 | [diff] [blame] | 130 | |
Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 131 | # Name of the directory and the file containing all inline structure informations |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 132 | # except for $_TOKENS_TAG information |
Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 133 | my ($_structure_dir, $_structure_file) = split '#', $inline_structures . '#structure'; |
Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 134 | |
Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 135 | # Name of the directory and the file containing all inline token informations |
| 136 | # i.e. tokens of the $_TOKENS_TAG, if $_TOKENS_PROC is set |
| 137 | my ($_tokens_dir, $_tokens_file) = split '#', $inline_tokens . '#morpho'; |
Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 138 | |
Akron | b87c58d | 2021-02-23 17:23:30 +0100 | [diff] [blame] | 139 | # Initialize zipper |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 140 | my $zipper = KorAP::XML::TEI::Zipper->new($root_dir); |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 141 | |
Akron | bc89919 | 2021-02-24 12:14:47 +0100 | [diff] [blame] | 142 | # text directory (below $root_dir) |
| 143 | my $dir = ''; |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 144 | |
Akron | bc89919 | 2021-02-24 12:14:47 +0100 | [diff] [blame] | 145 | # Escaped version of text id |
| 146 | my $text_id_esc; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 147 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 148 | # Default encoding of the text |
| 149 | my $input_enc = 'UTF-8'; |
| 150 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 151 | # text line (needed for whitespace handling) |
| 152 | my $text_line = 0; |
| 153 | |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 154 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 155 | # Input file handle (default: stdin) |
| 156 | my $input_fh = *STDIN; |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 157 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 158 | if ($input_fname ne '') { |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 159 | unless (open($input_fh, '<', $input_fname)) { |
| 160 | die $log->fatal("File '$input_fname' could not be opened."); |
| 161 | }; |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 162 | }; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 163 | |
Akron | f8088e6 | 2021-02-18 16:18:59 +0100 | [diff] [blame] | 164 | # Prevents segfaulting (see notes on segfault prevention) |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 165 | binmode $input_fh; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 166 | |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 167 | |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 168 | # Create inline parser object |
| 169 | my $inline = KorAP::XML::TEI::Inline->new( |
| 170 | $skip_inline_tokens, |
| 171 | \%skip_inline_tags |
| 172 | ); |
| 173 | |
| 174 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 175 | # Reading input document |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 176 | MAIN: while (<$input_fh>) { |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 177 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 178 | # remove HTML (multi-line) comments (<!--...-->) |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 179 | $_ = remove_xml_comments($input_fh, $_); |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 180 | |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 181 | # Set input encoding |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 182 | if (index($_, '<?xml') == 0 && $_ =~ /\sencoding=(['"])([^\1]+?)\1/) { |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 183 | $input_enc = $2; |
| 184 | next; |
| 185 | }; |
| 186 | |
| 187 | $_ = decode($input_enc, $_); |
Marc Kupietz | 8a954e5 | 2021-02-16 22:03:07 +0100 | [diff] [blame] | 188 | $_ = replace_entities($_); |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 189 | |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 190 | # Start of text body |
| 191 | if (index($_, $_TEXT_BODY) >= 0 && m#^(.*)<${_TEXT_BODY}(?: [^>]*)?>(.*)$#) { |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 192 | my $suffix = $2; |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 193 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 194 | if ($1 !~ /^\s*$/ || $suffix !~ /^\s*$/) { |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 195 | die $log->fatal("input line number $.: " . |
| 196 | "line with opening text-body tag '${_TEXT_BODY}' " . |
| 197 | "contains additional information ... => Aborting (line=$_)"); |
Akron | 0bb7e72 | 2020-09-29 07:48:33 +0200 | [diff] [blame] | 198 | }; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 199 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 200 | # Text body data extracted from input document ($input_fh), |
| 201 | # further processed by XML::LibXML::Reader |
| 202 | my $text_buffer = ''; |
Peter Harders | 9015734 | 2020-07-01 21:05:14 +0200 | [diff] [blame] | 203 | |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 204 | # Iterate over all lines in the text body |
| 205 | while (<$input_fh>) { |
Peter Harders | 9015734 | 2020-07-01 21:05:14 +0200 | [diff] [blame] | 206 | |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 207 | $_ = remove_xml_comments($input_fh, $_); |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 208 | $_ = decode($input_enc, $_); |
Marc Kupietz | 8a954e5 | 2021-02-16 22:03:07 +0100 | [diff] [blame] | 209 | $_ = replace_entities($_); |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 210 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 211 | # End of text body |
Akron | b43b491 | 2021-02-25 10:31:11 +0100 | [diff] [blame] | 212 | if ((my $pos = index($_, '</' . $_TEXT_BODY)) >= 0) { |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 213 | |
Akron | 91705d7 | 2021-02-19 10:59:45 +0100 | [diff] [blame] | 214 | # write data.xml, structure.xml and evtl. morpho.xml and/or tokenization files |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 215 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 216 | if ((substr($_, 0, $pos) . substr($_, length("</$_TEXT_BODY>") + $pos)) !~ /^\s*$/) { |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 217 | die $log->fatal("input line number $.: " . |
| 218 | "line with closing text-body tag '${_TEXT_BODY}'". |
| 219 | " contains additional information ... => Aborting (line=$_)"); |
| 220 | }; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 221 | |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 222 | if ($dir eq '') { |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 223 | $log->warn( |
| 224 | "Maybe empty textSigle => skipping this text ...\n" . |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 225 | 'data=' . substr($inline->data->data, 0, 200) |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 226 | ); |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 227 | next MAIN; |
| 228 | }; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 229 | |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 230 | # Parse inline structure |
| 231 | $inline->parse($text_id_esc, \$text_buffer); |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 232 | |
| 233 | if (DEBUG) { |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 234 | $log->debug("Writing (utf8-formatted) xml file $dir/${data_file}.xml"); |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 235 | }; |
| 236 | |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 237 | my $data = $inline->data; |
| 238 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 239 | # Write data.xml |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 240 | $data->to_zip( |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 241 | $zipper->new_stream("$dir/${data_file}.xml"), |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 242 | $text_id_esc |
| 243 | ); |
| 244 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 245 | # Tokenize with external tokenizer |
Akron | 9df4a24 | 2021-02-19 15:31:16 +0100 | [diff] [blame] | 246 | if ($ext_tok) { |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 247 | |
| 248 | # Tokenize and output |
| 249 | $ext_tok->tokenize($data->data)->to_zip( |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 250 | $zipper->new_stream("$dir/$base_dir/${tokens_file}.xml"), |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 251 | $text_id_esc |
Akron | d20898f | 2021-02-19 15:52:17 +0100 | [diff] [blame] | 252 | ); |
Akron | d53ab4b | 2021-02-24 09:56:12 +0100 | [diff] [blame] | 253 | |
| 254 | if ($use_tokenizer_sentence_splits) { |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 255 | $ext_tok->sentencize_from_previous_input($inline->structures); |
Akron | d53ab4b | 2021-02-24 09:56:12 +0100 | [diff] [blame] | 256 | }; |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 257 | }; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 258 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 259 | # Tokenize with internal tokenizer |
| 260 | if ($tokenizer_intern) { |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 261 | |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 262 | # Tokenize and output |
| 263 | $cons_tok->tokenize($data->data)->to_zip( |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 264 | $zipper->new_stream("$dir/$base_dir/" . $cons_tok->name . '.xml'), |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 265 | $text_id_esc |
Akron | cc27d79 | 2021-02-24 12:32:20 +0100 | [diff] [blame] | 266 | )->reset; |
Akron | 598d1a7 | 2020-08-02 17:33:31 +0200 | [diff] [blame] | 267 | |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 268 | $aggr_tok->tokenize($data->data)->to_zip( |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 269 | $zipper->new_stream("$dir/$base_dir/" . $aggr_tok->name . '.xml'), |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 270 | $text_id_esc |
Akron | cc27d79 | 2021-02-24 12:32:20 +0100 | [diff] [blame] | 271 | )->reset; |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 272 | }; |
Akron | a10ad59 | 2020-08-03 11:20:23 +0200 | [diff] [blame] | 273 | |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 274 | # ~ write structures ~ |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 275 | if (!$inline->structures->empty) { |
| 276 | $inline->structures->to_zip( |
Akron | b87c58d | 2021-02-23 17:23:30 +0100 | [diff] [blame] | 277 | $zipper->new_stream("$dir/$_structure_dir/${_structure_file}.xml"), |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 278 | $text_id_esc, |
| 279 | 2 # = structure serialization |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 280 | ); |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | # ~ write tokens ~ |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 284 | unless ($skip_inline_tokens || $inline->tokens->empty) { |
| 285 | $inline->tokens->to_zip( |
Akron | b87c58d | 2021-02-23 17:23:30 +0100 | [diff] [blame] | 286 | $zipper->new_stream("$dir/$_tokens_dir/${_tokens_file}.xml"), |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 287 | $text_id_esc, |
Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 288 | # Either 0 = tokens without inline or 1 = tokens with inline |
| 289 | !$skip_inline_token_annotations |
Akron | eb12e23 | 2021-02-25 13:49:50 +0100 | [diff] [blame] | 290 | ); |
Akron | dafaa7a | 2021-02-19 15:17:58 +0100 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | # reinit. |
| 294 | $dir = ''; |
| 295 | |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 296 | next MAIN; |
Akron | 598d1a7 | 2020-08-02 17:33:31 +0200 | [diff] [blame] | 297 | }; |
| 298 | |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 299 | |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 300 | # ~ whitespace handling ~ |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 301 | |
Akron | f8088e6 | 2021-02-18 16:18:59 +0100 | [diff] [blame] | 302 | # Fix whitespaces (see notes on whitespace fixing) |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 303 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 304 | # TODO: |
| 305 | # Maybe it's best, to keep the stripping of whitespace and |
| 306 | # to just remove the if-clause and to insert a blank by default |
| 307 | # (with possibly an option on how newlines in primary text should |
| 308 | # be handled (stripped or replaced by a whitespace)). |
Akron | f8088e6 | 2021-02-18 16:18:59 +0100 | [diff] [blame] | 309 | |
| 310 | # Remove consecutive whitespace at beginning and end (mostly one newline) |
| 311 | s/^\s+//; s/\s+$//; |
Akron | f57ed81 | 2020-07-27 10:37:52 +0200 | [diff] [blame] | 312 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 313 | # NOTE: |
| 314 | # this is only relevant, if a text consists of more than one line |
Akron | f57ed81 | 2020-07-27 10:37:52 +0200 | [diff] [blame] | 315 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 316 | # TODO: |
| 317 | # find a better solution, or create a warning, if a text has more |
| 318 | # than one line ($text_line > 1) |
Akron | f57ed81 | 2020-07-27 10:37:52 +0200 | [diff] [blame] | 319 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 320 | # TODO: |
| 321 | # do testing with 2 different corpora |
| 322 | # (one with only one-line texts, the other with several lines per text) |
| 323 | |
| 324 | # line contains at least one tag with at least one character contents |
| 325 | if (m/<[^>]+>[^<]/) { |
| 326 | |
| 327 | # Increment counter for text lines |
| 328 | $text_line++; |
| 329 | |
| 330 | # insert blank before 1st character |
Akron | 6e2b125 | 2021-02-24 12:41:15 +0100 | [diff] [blame] | 331 | # (for 2nd line and consecutive lines) |
| 332 | $_ = ' ' . $_ if $text_line > 1; |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 333 | } |
Akron | f57ed81 | 2020-07-27 10:37:52 +0200 | [diff] [blame] | 334 | |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 335 | # add line to buffer |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 336 | $text_buffer .= $_; |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 337 | }; |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 338 | } |
Akron | f57ed81 | 2020-07-27 10:37:52 +0200 | [diff] [blame] | 339 | |
Akron | d3e1d28 | 2021-02-24 14:51:27 +0100 | [diff] [blame] | 340 | # Start of header section |
| 341 | elsif (m#^(.*)(\<${_HEADER_TAG}[^>]*?type=["'].*)$#) { |
Akron | f57ed81 | 2020-07-27 10:37:52 +0200 | [diff] [blame] | 342 | |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 343 | my $content = "$2\n"; |
Akron | f57ed81 | 2020-07-27 10:37:52 +0200 | [diff] [blame] | 344 | |
Akron | d20898f | 2021-02-19 15:52:17 +0100 | [diff] [blame] | 345 | if ($1 !~ /^\s*$/) { |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 346 | die $log->fatal( |
| 347 | "input line number $.: " . |
| 348 | 'line with opening header tag is not in expected format ... ' . |
| 349 | "=> Aborting (line=$_)"); |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | # Parse header |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 353 | my $header = KorAP::XML::TEI::Header->new($content, $input_enc)->parse($input_fh); |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 354 | |
| 355 | # Header was parseable |
| 356 | if ($header) { |
| 357 | |
| 358 | # Write header to zip |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 359 | my $file = $header->dir . '/' . $header_file . '.xml'; |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 360 | |
Akron | b364947 | 2020-09-29 08:24:46 +0200 | [diff] [blame] | 361 | $log->debug("Writing file $file") if DEBUG; |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 362 | |
| 363 | $header->to_zip($zipper->new_stream($file)); |
| 364 | |
| 365 | # Header is for text level |
| 366 | if ($header->type eq 'text') { |
| 367 | |
| 368 | # Remember dir and sigles |
| 369 | $dir = $header->dir; |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 370 | $text_id_esc = $header->id_esc; |
| 371 | |
| 372 | # log output for seeing progression |
Akron | bc89919 | 2021-02-24 12:14:47 +0100 | [diff] [blame] | 373 | $log->notice("$0: text_id=$text_id_esc"); |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 374 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 375 | # Reset counter for text lines |
| 376 | # (needed for whitespace handling) |
| 377 | $text_line = 0; |
| 378 | }; |
| 379 | }; |
| 380 | }; |
| 381 | }; |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 382 | |
Akron | 347be81 | 2020-09-29 07:52:52 +0200 | [diff] [blame] | 383 | $zipper->close; |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 384 | |
Akron | 9df4a24 | 2021-02-19 15:31:16 +0100 | [diff] [blame] | 385 | $ext_tok->close if $ext_tok; |
Peter Harders | d892a58 | 2020-02-12 15:45:22 +0100 | [diff] [blame] | 386 | |
Akron | d53913c | 2021-02-24 09:50:13 +0100 | [diff] [blame] | 387 | close $input_fh; |
| 388 | |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 389 | |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 390 | __END__ |
| 391 | |
| 392 | =pod |
| 393 | |
| 394 | =encoding utf8 |
| 395 | |
| 396 | =head1 NAME |
| 397 | |
| 398 | tei2korapxml - Conversion of TEI P5 based formats to KorAP-XML |
| 399 | |
| 400 | =head1 SYNOPSIS |
| 401 | |
| 402 | cat corpus.i5.xml | tei2korapxml > corpus.korapxml.zip |
| 403 | |
| 404 | =head1 DESCRIPTION |
| 405 | |
Akron | ee434b1 | 2020-07-08 12:53:01 +0200 | [diff] [blame] | 406 | C<tei2korapxml> is a script to convert TEI P5 and |
| 407 | L<I5|https://www1.ids-mannheim.de/kl/projekte/korpora/textmodell.html> |
| 408 | based documents to the |
| 409 | L<KorAP-XML format|https://github.com/KorAP/KorAP-XML-Krill#about-korap-xml>. |
| 410 | If no specific input is defined, data is |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 411 | read from C<STDIN>. If no specific output is defined, data is written |
| 412 | to C<STDOUT>. |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 413 | |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 414 | This program is usually called from inside another script. |
| 415 | |
Akron | ee434b1 | 2020-07-08 12:53:01 +0200 | [diff] [blame] | 416 | =head1 FORMATS |
| 417 | |
| 418 | =head2 Input restrictions |
| 419 | |
| 420 | =over 2 |
| 421 | |
| 422 | =item |
| 423 | |
Akron | ee434b1 | 2020-07-08 12:53:01 +0200 | [diff] [blame] | 424 | TEI P5 formatted input with certain restrictions: |
| 425 | |
| 426 | =over 4 |
| 427 | |
| 428 | =item |
| 429 | |
| 430 | B<mandatory>: text-header with integrated textsigle, text-body |
| 431 | |
| 432 | =item |
| 433 | |
| 434 | B<optional>: corp-header with integrated corpsigle, |
| 435 | doc-header with integrated docsigle |
| 436 | |
| 437 | =back |
| 438 | |
| 439 | =item |
| 440 | |
Akron | 0c41ab3 | 2020-09-29 07:33:33 +0200 | [diff] [blame] | 441 | All tokens inside the primary text may not be |
Akron | ee434b1 | 2020-07-08 12:53:01 +0200 | [diff] [blame] | 442 | newline seperated, because newlines are removed |
Akron | 0c41ab3 | 2020-09-29 07:33:33 +0200 | [diff] [blame] | 443 | (see L<KorAP::XML::TEI::Data>) and a conversion of newlines |
Akron | ee434b1 | 2020-07-08 12:53:01 +0200 | [diff] [blame] | 444 | into blanks between 2 tokens could lead to additional blanks, |
| 445 | where there should be none (e.g.: punctuation characters like C<,> or |
| 446 | C<.> should not be seperated from their predecessor token). |
| 447 | (see also code section C<~ whitespace handling ~>). |
| 448 | |
| 449 | =back |
| 450 | |
| 451 | =head2 Notes on the output |
| 452 | |
| 453 | =over 2 |
| 454 | |
| 455 | =item |
| 456 | |
| 457 | zip file output (default on C<stdout>) with utf8 encoded entries |
| 458 | (which together form the KorAP-XML format) |
| 459 | |
| 460 | =back |
| 461 | |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 462 | =head1 INSTALLATION |
| 463 | |
| 464 | C<tei2korapxml> requires L<libxml2-dev> bindings to build. When |
| 465 | these bindings are available, the preferred way to install the script is |
| 466 | to use L<cpanm|App::cpanminus>. |
| 467 | |
| 468 | $ cpanm https://github.com/KorAP/KorAP-XML-TEI.git |
| 469 | |
| 470 | In case everything went well, the C<tei2korapxml> tool will |
| 471 | be available on your command line immediately. |
Peter Harders | 6f526a3 | 2020-06-29 21:44:41 +0200 | [diff] [blame] | 472 | |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 473 | Minimum requirement for L<KorAP::XML::TEI> is Perl 5.16. |
| 474 | |
| 475 | =head1 OPTIONS |
| 476 | |
| 477 | =over 2 |
| 478 | |
Akron | 4e603a5 | 2020-07-27 14:23:49 +0200 | [diff] [blame] | 479 | =item B<--root|-r> |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 480 | |
Akron | 4e603a5 | 2020-07-27 14:23:49 +0200 | [diff] [blame] | 481 | The root directory for output. Defaults to C<.>. |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 482 | |
| 483 | =item B<--help|-h> |
| 484 | |
| 485 | Print help information. |
| 486 | |
| 487 | =item B<--version|-v> |
| 488 | |
| 489 | Print version information. |
| 490 | |
Akron | 4e603a5 | 2020-07-27 14:23:49 +0200 | [diff] [blame] | 491 | =item B<--tokenizer-call|-tc> |
| 492 | |
| 493 | Call an external tokenizer process, that will tokenize |
| 494 | a single line from STDIN and outputs one token per line. |
| 495 | |
Marc Kupietz | 1e882fb | 2020-09-09 00:05:46 +0200 | [diff] [blame] | 496 | =item B<--tokenizer-korap|-tk> |
| 497 | |
| 498 | Use the standard KorAP/DeReKo tokenizer. |
| 499 | |
Akron | 6d7b8e4 | 2020-09-29 07:37:41 +0200 | [diff] [blame] | 500 | =item B<--tokenizer-internal|-ti> |
Akron | 4e603a5 | 2020-07-27 14:23:49 +0200 | [diff] [blame] | 501 | |
| 502 | Tokenize the data using two embedded tokenizers, |
| 503 | that will take an I<Aggressive> and a I<conservative> |
| 504 | approach. |
| 505 | |
Akron | 75d6314 | 2021-02-23 18:40:56 +0100 | [diff] [blame] | 506 | =item B<--skip-inline-tokens> |
| 507 | |
| 508 | Boolean flag indicating that inline tokens should not |
| 509 | be processed. Defaults to false (meaning inline tokens will be processed). |
| 510 | |
Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 511 | =item B<--skip-inline-token-annotations> |
| 512 | |
| 513 | Boolean flag indicating that inline token annotations should not |
| 514 | be processed. Defaults to true (meaning inline token annotations |
| 515 | won't be processed). |
| 516 | |
Akron | ca70a1d | 2021-02-25 16:21:31 +0100 | [diff] [blame] | 517 | =item B<--skip-inline-tags> <tags> |
Akron | 54c3ff1 | 2021-02-25 11:33:37 +0100 | [diff] [blame] | 518 | |
| 519 | Expects a comma-separated list of tags to be ignored when the structure |
| 520 | is parsed. Content of these tags however will be processed. |
| 521 | |
Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 522 | =item B<--inline-tokens> <foundry>#[<file>] |
| 523 | |
| 524 | Define the foundry and file (without extension) |
| 525 | to store inline token information in. |
| 526 | If L</KORAPXMLTEI_INLINE> is set, this will contain |
| 527 | annotations as well. |
| 528 | Defaults to C<tokens> and C<morpho>. |
| 529 | |
Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 530 | =item B<--inline-structures> <foundry>#[<file>] |
| 531 | |
| 532 | Define the foundry and file (without extension) |
| 533 | to store inline structure information in. |
| 534 | Defaults to C<struct> and C<structures>. |
| 535 | |
Akron | 26a7152 | 2021-02-19 10:27:37 +0100 | [diff] [blame] | 536 | =item B<--base-foundry> <foundry> |
| 537 | |
| 538 | Define the base foundry to store newly generated |
| 539 | token information in. |
| 540 | Defaults to C<base>. |
| 541 | |
| 542 | =item B<--data-file> <file> |
| 543 | |
| 544 | Define the file (without extension) |
| 545 | to store primary data information in. |
| 546 | Defaults to C<data>. |
| 547 | |
| 548 | =item B<--header-file> <file> |
| 549 | |
| 550 | Define the file name (without extension) |
| 551 | to store header information on |
| 552 | the corpus, document, and text level in. |
| 553 | Defaults to C<header>. |
| 554 | |
Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 555 | =item B<--use-tokenizer-sentence-splits|-s> |
| 556 | |
| 557 | Replace existing with, or add new, sentence boundary information |
| 558 | provided by the KorAP tokenizer (currently supported only). |
| 559 | |
Akron | 91705d7 | 2021-02-19 10:59:45 +0100 | [diff] [blame] | 560 | =item B<--tokens-file> <file> |
| 561 | |
| 562 | Define the file (without extension) |
| 563 | to store generated token information in |
| 564 | (either from the KorAP tokenizer or an externally called tokenizer). |
| 565 | Defaults to C<tokens>. |
| 566 | |
Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame] | 567 | =item B<--log|-l> |
| 568 | |
| 569 | Loglevel for I<Log::Any>. Defaults to C<notice>. |
| 570 | |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 571 | =back |
| 572 | |
Akron | b364947 | 2020-09-29 08:24:46 +0200 | [diff] [blame] | 573 | =head1 ENVIRONMENT VARIABLES |
| 574 | |
| 575 | =over 2 |
| 576 | |
| 577 | =item B<KORAPXMLTEI_DEBUG> |
| 578 | |
| 579 | Activate minimal debugging. |
| 580 | Defaults to C<false>. |
| 581 | |
Akron | b364947 | 2020-09-29 08:24:46 +0200 | [diff] [blame] | 582 | =back |
| 583 | |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 584 | =head1 COPYRIGHT AND LICENSE |
| 585 | |
Marc Kupietz | e955ecc | 2021-02-17 17:42:01 +0100 | [diff] [blame] | 586 | Copyright (C) 2021, L<IDS Mannheim|https://www.ids-mannheim.de/> |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 587 | |
| 588 | Author: Peter Harders |
| 589 | |
Akron | aabd095 | 2020-09-29 07:35:08 +0200 | [diff] [blame] | 590 | Contributors: Nils Diewald, Marc Kupietz, Carsten Schnober |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 591 | |
| 592 | L<KorAP::XML::TEI> is developed as part of the L<KorAP|https://korap.ids-mannheim.de/> |
| 593 | Corpus Analysis Platform at the |
| 594 | L<Leibniz Institute for the German Language (IDS)|http://ids-mannheim.de/>, |
| 595 | member of the |
| 596 | L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/>. |
| 597 | |
| 598 | This program is free software published under the |
Marc Kupietz | e955ecc | 2021-02-17 17:42:01 +0100 | [diff] [blame] | 599 | L<BSD-2 License|https://opensource.org/licenses/BSD-2-Clause>. |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 600 | |
| 601 | =cut |
Akron | f8088e6 | 2021-02-18 16:18:59 +0100 | [diff] [blame] | 602 | |
| 603 | # NOTES |
| 604 | |
Akron | f8088e6 | 2021-02-18 16:18:59 +0100 | [diff] [blame] | 605 | ## Notes on segfault prevention |
| 606 | |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 607 | binmode on the input handler prevents segfaulting of 'XML::LibXML::Reader' inside the main loop |
Akron | f8088e6 | 2021-02-18 16:18:59 +0100 | [diff] [blame] | 608 | (see notes on 'PerlIO layers' in 'man XML::LibXML'), |
| 609 | removing 'use open qw(:std :utf8)' would fix this problem too, but using binmode on input is more granular |
| 610 | see in perluniintro: You can switch encodings on an already opened stream by using "binmode() |
| 611 | see in perlfunc: If LAYER is omitted or specified as ":raw" the filehandle is made suitable for passing binary data. |