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