Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
Akron | 7d4d2d7 | 2024-09-05 11:05:35 +0200 | [diff] [blame] | 4 | use v5.32; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 5 | use FindBin; |
| 6 | BEGIN { unshift @INC, "$FindBin::Bin/../lib" }; |
| 7 | use File::Spec::Functions qw/catfile catdir/; |
| 8 | use Getopt::Long qw/GetOptions :config no_auto_abbrev/; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 9 | use Benchmark qw/:hireswallclock/; |
| 10 | use IO::Compress::Gzip qw/$GzipError/; |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 11 | use POSIX qw/ceil/; |
Akron | b9c3381 | 2020-10-21 16:19:35 +0200 | [diff] [blame] | 12 | use Log::Any qw($log); |
| 13 | use Log::Any::Adapter; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 14 | use Pod::Usage; |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 15 | use Cache::FastMmap; |
Akron | 41127e3 | 2020-08-07 12:46:19 +0200 | [diff] [blame] | 16 | use KorAP::XML::Krill qw!get_file_name get_file_name_from_glob!; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 17 | use KorAP::XML::Archive; |
Akron | eb370a0 | 2022-02-24 13:33:40 +0100 | [diff] [blame] | 18 | use KorAP::XML::TarBuilder; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 19 | use KorAP::XML::Tokenizer; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 20 | use KorAP::XML::Batch::File; |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 21 | use Config::Simple; |
Akron | 0a0d1f9 | 2024-11-14 14:31:42 +0100 | [diff] [blame^] | 22 | use Path::Iterator::Rule; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 23 | use Parallel::ForkManager; |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 24 | use File::Glob ':bsd_glob'; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 25 | use File::Temp qw/tempdir/; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 26 | use File::Path qw(remove_tree make_path); |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 27 | use File::Basename; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 28 | use Mojo::Collection 'c'; |
| 29 | use String::Random qw(random_string); |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 30 | use IO::File; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 31 | use Fcntl qw(:flock SEEK_END); |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 32 | |
| 33 | # use KorAP::XML::ForkPool; |
Akron | 75ba57d | 2016-03-07 23:36:27 +0100 | [diff] [blame] | 34 | # TODO: use Parallel::Loops |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 35 | # TODO: make output files |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 36 | |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 37 | # TODO: Use KorAP::XML::ForkPool! |
| 38 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 39 | # CHANGES: |
| 40 | # ---------------------------------------------------------- |
| 41 | # 2013/11/25 |
| 42 | # - Initial release |
| 43 | # |
| 44 | # 2014/10/29 |
| 45 | # - Merges foundry data to create indexer friendly documents |
| 46 | # |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 47 | # 2016/02/04 |
| 48 | # - renamed to korapxml2krill |
| 49 | # - added Schreibgebrauch support |
Akron | 069bd71 | 2016-02-12 19:09:06 +0100 | [diff] [blame] | 50 | # |
| 51 | # 2016/02/12 |
| 52 | # - fixed foundry skipping |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 53 | # - Support overwrite in archive processing |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 54 | # |
| 55 | # 2016/02/14 |
| 56 | # - Added version information |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 57 | # - Added support for archive files |
| 58 | # |
| 59 | # 2016/02/15 |
| 60 | # - Fixed temporary directory bug |
| 61 | # - Improved skipping before unzipping |
| 62 | # - Added EXPERIMENTAL concurrency support |
| 63 | # |
| 64 | # 2016/02/23 |
| 65 | # - Merge korapxml2krill and korapxml2krill_dir |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 66 | # |
| 67 | # 2016/02/27 |
| 68 | # - Added extract function |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 69 | # |
| 70 | # 2016/03/17 |
| 71 | # - Added meta switch |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 72 | # |
| 73 | # 2016/03/18 |
| 74 | # - Added meta data caching |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 75 | # |
Akron | f3f0c94 | 2016-06-27 13:27:14 +0200 | [diff] [blame] | 76 | # 2016/06/27 |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 77 | # - Added multi archive support |
| 78 | # - Added prefix negation support |
Akron | f3f0c94 | 2016-06-27 13:27:14 +0200 | [diff] [blame] | 79 | # - Added Malt#Dependency support |
Akron | 8b99052 | 2016-07-06 16:45:57 +0200 | [diff] [blame] | 80 | # |
| 81 | # 2016/07/06 |
| 82 | # - Added MDParser#Dependency |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 83 | # |
| 84 | # 2016/10/15 |
Nils Diewald | 0e48977 | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 85 | # - Fixed temporary path issue in script |
| 86 | # |
| 87 | # 2016/10/24 |
| 88 | # - Improved Windows support |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 89 | # |
Akron | b4bbec7 | 2016-10-26 20:21:02 +0200 | [diff] [blame] | 90 | # 2016/10/24 |
| 91 | # - Added support for document extraction |
| 92 | # |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 93 | # 2016/10/27 |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 94 | # - Added wildcard support for document extraction |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 95 | # |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 96 | # 2016/12/21 |
| 97 | # - added support for base-sentences and base-tokenizations |
| 98 | # |
Akron | 4fa37c3 | 2017-01-20 14:43:10 +0100 | [diff] [blame] | 99 | # 2017/01/20 |
| 100 | # - added support for DRuKoLa annotations |
| 101 | # |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 102 | # 2017/02/08 |
| 103 | # - added support for pagebreak annotations |
| 104 | # |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 105 | # 2017/04/06 |
| 106 | # - added support for wildcards in input |
| 107 | # |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 108 | # 2017/04/07 |
| 109 | # - support configuration option |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 110 | # - support for temporary extraction |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 111 | # |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 112 | # 2017/04/12 |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 113 | # - support serial processing |
| 114 | # - support input root |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 115 | # - introduced --sequential-extraction flag |
Akron | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 116 | # |
| 117 | # 2017/06/19 |
| 118 | # - added support for DCK |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 119 | # |
| 120 | # 2017/06/29 |
| 121 | # - Fixed exit codes |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 122 | # |
| 123 | # 2017/07/04 |
| 124 | # - Fixed tar building process |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 125 | # |
| 126 | # 2018/01/16 |
| 127 | # - Added LWC support |
Akron | 5fdc7e1 | 2018-07-19 12:37:48 +0200 | [diff] [blame] | 128 | # |
| 129 | # 2018/07/19 |
| 130 | # - Preliminary support for HNC. |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 131 | # |
| 132 | # 2019/01/22 |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 133 | # - Preliminary support for DGD. |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 134 | # - Support for non-word tokens. |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 135 | # |
Akron | 63d03ee | 2019-02-13 18:49:38 +0100 | [diff] [blame] | 136 | # 2019/02/13 |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 137 | # - Support for 'koral:field' array. |
| 138 | # - Support for Koral versioning. |
Akron | 63d03ee | 2019-02-13 18:49:38 +0100 | [diff] [blame] | 139 | # - Ignore temporary extract parameter on |
| 140 | # directory archiving. |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 141 | # |
| 142 | # 2019/08/08 |
| 143 | # - Support for Talismane. |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 144 | # |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 145 | # 2019/12/17 |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 146 | # - Added support for DGD pseudo-sentences |
| 147 | # based on anchor milestones. |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 148 | # - Support for non-verbal annotations. |
Akron | 07e2477 | 2020-04-23 14:00:54 +0200 | [diff] [blame] | 149 | # |
| 150 | # 2020/04/23 |
| 151 | # - Added support for Redewiedergabe-Korpus structure |
| 152 | # annotations, based on sentence and paragraph milestones |
| 153 | # - Added support for Redewiedergabe-Korpus morphology |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 154 | # |
| 155 | # 2021/10/11 |
| 156 | # - Introduced support for Gingko |
Akron | 9a2545e | 2022-01-16 15:15:50 +0100 | [diff] [blame] | 157 | # |
| 158 | # 2022/01/17 |
| 159 | # - Support for temporary extraction in config |
Akron | 84b53ad | 2022-01-14 12:39:15 +0100 | [diff] [blame] | 160 | # - Introduced support for Gingko |
Akron | a65cd68 | 2022-07-21 15:40:40 +0200 | [diff] [blame] | 161 | # |
| 162 | # 2022/07/21 |
| 163 | # - Support for NKJP |
Akron | 64f7fae | 2022-07-27 12:45:33 +0200 | [diff] [blame] | 164 | # |
| 165 | # 2022/07/27 |
| 166 | # - Support for preferred language transformation |
Akron | 83aedd3 | 2023-02-07 10:57:41 +0100 | [diff] [blame] | 167 | # |
| 168 | # 2023/02/05 |
| 169 | # - Support for UD |
Akron | a472a24 | 2023-02-13 13:46:30 +0100 | [diff] [blame] | 170 | # |
| 171 | # 2023/02/13 |
| 172 | # - Fix temporary-extract handling from configuration file. |
| 173 | # |
Marc Kupietz | b8c5382 | 2024-03-16 18:54:08 +0100 | [diff] [blame] | 174 | # 2024/03/20 |
| 175 | # - Added Spacy support. |
| 176 | # |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame] | 177 | # 2024/03/22 |
| 178 | # - Improve core count logging. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 179 | # ---------------------------------------------------------- |
Akron | 069bd71 | 2016-02-12 19:09:06 +0100 | [diff] [blame] | 180 | |
Akron | 0a0d1f9 | 2024-11-14 14:31:42 +0100 | [diff] [blame^] | 181 | our $LAST_CHANGE = '2024/11/14'; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 182 | our $LOCAL = $FindBin::Bin; |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 183 | our $KORAL_VERSION = 0.03; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 184 | our $VERSION_MSG = <<"VERSION"; |
| 185 | Version $KorAP::XML::Krill::VERSION - diewald\@ids-mannheim.de - $LAST_CHANGE |
| 186 | VERSION |
| 187 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 188 | # Parse comand |
| 189 | my $cmd; |
| 190 | our @ARGV; |
| 191 | if ($ARGV[0] && index($ARGV[0], '-') != 0) { |
| 192 | $cmd = shift @ARGV; |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 193 | }; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 194 | my @keep_argv = @ARGV; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 195 | |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 196 | my (@skip, @sigle, @anno, @input); |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 197 | |
| 198 | # Configuration hash |
| 199 | my %cfg = (); |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 200 | |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame] | 201 | # Count jobs/cores if not set |
| 202 | sub count_jobs { |
| 203 | my ($cores, $jobs); |
| 204 | my $msg = 'Unable to determine number of cores - set to 1'; |
| 205 | if (eval("use Sys::Info; 1;") && eval("use Sys::Info::Constants qw( :device_cpu ); 1;")) { |
| 206 | $cores = Sys::Info->new->device('CPU')->count; |
| 207 | if ($cores <= 0) { |
| 208 | $log->error($msg); |
| 209 | $cores = 1; |
| 210 | } |
| 211 | } |
| 212 | else { |
| 213 | $log->error($msg); |
| 214 | $cores = 1; |
| 215 | }; |
| 216 | |
| 217 | $jobs = ceil(5 * $cores); |
| 218 | return $jobs, "Run using $jobs jobs on $cores cores"; |
| 219 | } |
| 220 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 221 | # Parse options from the command line |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 222 | GetOptions( |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 223 | 'input|i=s' => \@input, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 224 | 'input-base|ib=s' => \($cfg{input_base}), |
| 225 | 'output|o=s' => \($cfg{output}), |
| 226 | 'overwrite|w' => \($cfg{overwrite}), |
| 227 | 'meta|m=s' => \($cfg{meta}), |
| 228 | 'token|t=s' => \($cfg{token}), |
| 229 | 'base-sentences|bs=s' => \($cfg{base_sentences}), |
| 230 | 'base-paragraphs|bp=s' => \($cfg{base_paragraphs}), |
| 231 | 'base-pagebreaks|bpb=s' => \($cfg{base_pagebreaks}), |
| 232 | 'gzip|z' => \($cfg{gzip}), |
Akron | a472a24 | 2023-02-13 13:46:30 +0100 | [diff] [blame] | 233 | 'temporary-extract|te=s' => \($cfg{temporary_extract}), |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 234 | 'skip|s=s' => \@skip, |
| 235 | 'sigle|sg=s' => \@sigle, |
Akron | c0ac4ff | 2024-04-15 18:03:15 +0200 | [diff] [blame] | 236 | 'cache|c=s' => \($cfg{cache}), |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 237 | 'config|cfg=s' => \(my $cfg_file), |
Akron | 64f7fae | 2022-07-27 12:45:33 +0200 | [diff] [blame] | 238 | 'lang=s' => \($cfg{lang}), |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 239 | 'log|l=s' => \($cfg{log}), |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 240 | 'anno|a=s' => \@anno, |
Akron | 11daf96 | 2020-08-07 16:29:22 +0200 | [diff] [blame] | 241 | 'primary|p!' => sub { |
| 242 | warn 'Primary flag no longer supported!'; |
| 243 | }, |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 244 | 'quiet' => \($cfg{quiet}), |
Akron | 6aed056 | 2020-08-07 16:46:00 +0200 | [diff] [blame] | 245 | 'pretty|y' => sub { |
| 246 | warn 'Pretty flag no longer supported!'; |
| 247 | }, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 248 | 'jobs|j=i' => \($cfg{jobs}), |
| 249 | 'koral|k=f' => \($cfg{koral}), |
| 250 | 'to-tar' => \($cfg{to_tar}), |
| 251 | 'non-word-tokens|nwt' => \($cfg{non_word_tokens}), |
| 252 | 'non-verbal-tokens|nvt' => \($cfg{non_verbal_tokens}), |
| 253 | 'sequential-extraction|se' => \($cfg{sequential_extraction}), |
| 254 | 'cache-size|cs=s' => \($cfg{cache_size}), |
| 255 | 'cache-delete|cd!' => \($cfg{cache_delete}), |
| 256 | 'cache-init|ci!' => \($cfg{cache_init}), |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 257 | 'help|h' => sub { |
| 258 | pod2usage( |
| 259 | -sections => 'NAME|SYNOPSIS|ARGUMENTS|OPTIONS', |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 260 | -verbose => 99, |
| 261 | -msg => $VERSION_MSG, |
| 262 | -output => '-' |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 263 | ); |
| 264 | }, |
| 265 | 'version|v' => sub { |
| 266 | pod2usage( |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 267 | -verbose => 0, |
| 268 | -msg => $VERSION_MSG, |
| 269 | -output => '-' |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame] | 270 | ), |
| 271 | }, |
| 272 | 'job-count|jc' => sub { |
| 273 | my ($j, $msg) = count_jobs(); |
| 274 | pod2usage( |
| 275 | -verbose => 0, |
| 276 | -msg => $msg, |
| 277 | -output => '-' |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 278 | ) |
| 279 | } |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 280 | ); |
| 281 | |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 282 | my %ERROR_HASH = ( |
| 283 | -sections => 'NAME|SYNOPSIS|ARGUMENTS|OPTIONS', |
| 284 | -verbose => 99, |
| 285 | -msg => $VERSION_MSG, |
| 286 | -output => '-', |
| 287 | -exit => 1 |
| 288 | ); |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 289 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 290 | # Load from configuration and fill non-given data |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 291 | if ($cfg_file && -e $cfg_file) { |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 292 | my %config; |
| 293 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 294 | print "Reading config from $cfg_file\n"; |
| 295 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 296 | Config::Simple->import_from($cfg_file, \%config); |
| 297 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 298 | foreach (qw!output cache-size input-base token overwrite |
| 299 | meta base-sentences base-paragraphs base-pagebreaks |
Akron | 64f7fae | 2022-07-27 12:45:33 +0200 | [diff] [blame] | 300 | gzip to-tar log lang cache non-word-tokens |
Akron | 9a2545e | 2022-01-16 15:15:50 +0100 | [diff] [blame] | 301 | non-verbal-tokens sequential-extraction |
Akron | c0ac4ff | 2024-04-15 18:03:15 +0200 | [diff] [blame] | 302 | temporary-extract cache-init cache-delete |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 303 | koral extract-dir jobs quiet!) { |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 304 | my $underlined = $_ =~ tr/-/_/r; |
| 305 | if (!defined($cfg{$underlined}) && defined $config{$_}) { |
| 306 | $cfg{$underlined} = $config{$_}; |
| 307 | }; |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | # Skip |
| 311 | if (!scalar(@skip) && defined $config{'skip'}) { |
| 312 | @skip = split /\s*;\s*/, $config{'skip'} ; |
| 313 | }; |
| 314 | |
| 315 | # Sigle |
| 316 | if (!scalar(@sigle) && defined $config{'sigle'}) { |
| 317 | @sigle = split /\s*;\s*/, $config{'sigle'} ; |
| 318 | }; |
| 319 | |
| 320 | # Anno |
| 321 | if (!scalar(@anno) && defined $config{'anno'}) { |
| 322 | @anno = split /\s*;\s*/, $config{'anno'} ; |
| 323 | }; |
| 324 | }; |
| 325 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 326 | # Init variables and set default values |
| 327 | my $output = $cfg{output}; |
| 328 | my $input_base = $cfg{input_base}; |
| 329 | my $gzip = $cfg{gzip}; |
| 330 | my $to_tar = $cfg{to_tar}; |
Akron | a472a24 | 2023-02-13 13:46:30 +0100 | [diff] [blame] | 331 | my $extract_dir = $cfg{temporary_extract}; |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 332 | my $token_base = $cfg{token} // 'OpenNLP#tokens'; |
| 333 | my $cache_file = $cfg{cache} // 'korapxml2krill.cache'; |
| 334 | my $jobs = $cfg{jobs} // 0; |
| 335 | my $cache_delete = $cfg{cache_delete} // 1; |
| 336 | my $base_sentences = lc($cfg{base_sentences} // ''); |
| 337 | my $base_paragraphs = lc($cfg{base_paragraphs} // ''); |
| 338 | my $base_pagebreaks = lc($cfg{base_pagebreaks} // ''); |
| 339 | my $sequential_extraction = $cfg{sequential_extraction} // 0; |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 340 | my $q = !!($cfg{quiet}) // 0; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 341 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 342 | # Get tokenization basis |
| 343 | my ($token_base_foundry, $token_base_layer) = split(/#/, $token_base) if $token_base; |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 344 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 345 | # Remove file extension |
| 346 | $token_base_layer =~ s/\.xml$//i; |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 347 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 348 | # Convert sigle to path construct |
| 349 | s!^\s*([^_]+?)_([^\.]+?)\.(.+?)\s*$!$1/$2/$3! foreach @sigle; |
| 350 | |
| 351 | my %skip; |
| 352 | $skip{lc($_)} = 1 foreach @skip; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 353 | |
Akron | b9c3381 | 2020-10-21 16:19:35 +0200 | [diff] [blame] | 354 | Log::Any::Adapter->set( |
| 355 | 'Stderr', log_level => uc($cfg{log} // 'ERROR') |
| 356 | ); |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 357 | |
Akron | 84b53ad | 2022-01-14 12:39:15 +0100 | [diff] [blame] | 358 | # Start log slimming |
| 359 | if ($cmd && $cmd eq 'slimlog') { |
| 360 | require KorAP::XML::Log::Slim; |
| 361 | |
| 362 | my $log_file = shift @ARGV; |
| 363 | |
| 364 | if (-e $log_file) { |
| 365 | |
| 366 | my $slimmer = KorAP::XML::Log::Slim->new($log_file); |
| 367 | |
| 368 | # Run log filter |
| 369 | $slimmer->slim_to; |
| 370 | } |
| 371 | |
| 372 | else { |
| 373 | warn "Log file can't be found"; |
| 374 | exit(1); |
| 375 | }; |
| 376 | |
| 377 | exit; |
| 378 | }; |
| 379 | |
| 380 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 381 | if ($cmd && $output && (!defined($to_tar)) && (!-e $output || !-d $output)) { |
| 382 | $log->error("Directory '$output' does not exist."); |
| 383 | exit 1; |
| 384 | }; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 385 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 386 | # Input has to be defined |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 387 | pod2usage(%ERROR_HASH) unless @input; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 388 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 389 | # Gzip has no effect, if no output is given |
| 390 | pod2usage(%ERROR_HASH) if $gzip && !$output; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 391 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 392 | # Start serial processing |
Akron | 28c4e54 | 2017-07-04 20:30:33 +0200 | [diff] [blame] | 393 | if ($cmd && $cmd eq 'serial') { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 394 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 395 | # Remove all inputs |
| 396 | my $remove_next = 0; |
| 397 | @keep_argv = @{c(@keep_argv)->grep( |
| 398 | sub { |
| 399 | # Input flag |
| 400 | if ($_ eq '-i' || $_ eq '--input' || $_ eq '--output' || $_ eq '-o') { |
| 401 | $remove_next = 1; |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | # input value |
| 406 | elsif ($remove_next) { |
| 407 | $remove_next = 0; |
| 408 | return 0; |
| 409 | }; |
| 410 | |
| 411 | # Pass parameter |
| 412 | return 1; |
| 413 | } |
| 414 | )->to_array}; |
| 415 | |
| 416 | |
| 417 | # Iterate over all inputs |
| 418 | foreach (@input) { |
| 419 | |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 420 | # This will create a directory |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 421 | my $new_out = catdir($output, get_file_name_from_glob($_)); |
| 422 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 423 | # Create new path, in case the output is not meant to be tarred |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 424 | unless ($to_tar) { |
| 425 | if (make_path($new_out) == 0 && !-d $new_out) { |
| 426 | $log->error("Can\'t create path $new_out"); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 427 | exit 1; |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 428 | }; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 429 | }; |
| 430 | |
| 431 | # Create archive command |
| 432 | my @archive_cmd = ($^X, $0, 'archive', @keep_argv, '-i', $_, '-o', $new_out); |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 433 | unless ($q) { |
| 434 | print "Start serial processing of $_ to $new_out\n"; |
| 435 | print 'Command: ', join(' ', @archive_cmd), "\n"; |
| 436 | }; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 437 | |
| 438 | # Start archiving |
| 439 | system @archive_cmd; |
| 440 | }; |
| 441 | |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 442 | exit; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 443 | }; |
| 444 | |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 445 | # Define supported (and preinstalled) transformation modules |
| 446 | my @layers = (); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 447 | push(@layers, ['Base', 'Sentences']) unless $base_sentences; |
| 448 | push(@layers, ['Base', 'Paragraphs']) unless $base_paragraphs; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 449 | |
| 450 | # Connexor |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 451 | push(@layers, ['Connexor', 'Morpho'], |
| 452 | ['Connexor', 'Syntax'], |
| 453 | ['Connexor', 'Phrase'], |
| 454 | ['Connexor', 'Sentences']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 455 | |
| 456 | # CoreNLP |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 457 | push(@layers, |
| 458 | ['CoreNLP', 'NamedEntities'], |
| 459 | ['CoreNLP', 'Sentences'], |
| 460 | ['CoreNLP', 'Morpho'], |
| 461 | ['CoreNLP', 'Constituency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 462 | |
Akron | 5530a55 | 2022-02-17 17:53:15 +0100 | [diff] [blame] | 463 | # CorpusExplorer |
| 464 | push(@layers, |
| 465 | ['CorpusExplorer', 'Morpho']); |
| 466 | |
Akron | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 467 | # CMC |
| 468 | push(@layers, ['CMC', 'Morpho']); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 469 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 470 | # DeReKo |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 471 | my @dereko_attr = (); |
| 472 | if ($base_sentences eq 'dereko#structure') { |
| 473 | push @dereko_attr, 'sentences'; |
| 474 | }; |
| 475 | if ($base_paragraphs eq 'dereko#structure') { |
| 476 | push @dereko_attr, 'paragraphs'; |
| 477 | }; |
Akron | 636bd9c | 2017-02-09 17:13:00 +0100 | [diff] [blame] | 478 | |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 479 | if ($base_pagebreaks eq 'dereko#structure') { |
| 480 | push @dereko_attr, 'pagebreaks'; |
| 481 | }; |
| 482 | |
| 483 | if ($dereko_attr[0]) { |
| 484 | push(@layers, ['DeReKo', 'Structure', 'base-' . join('-', @dereko_attr)]); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 485 | } |
| 486 | else { |
| 487 | push(@layers, ['DeReKo', 'Structure']); |
| 488 | }; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 489 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 490 | # DGD |
| 491 | push(@layers, ['DGD', 'Morpho']); |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 492 | if ($base_sentences eq 'dgd#structure') { |
| 493 | push(@layers, ['DGD', 'Structure', 'base-sentence']); |
| 494 | } |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 495 | |
| 496 | # DRuKoLa |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 497 | push(@layers, |
| 498 | ['DRuKoLa', 'Morpho']); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 499 | |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 500 | # Gingko |
| 501 | push(@layers, |
| 502 | ['Gingko', 'Morpho']); |
| 503 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 504 | # Glemm |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 505 | push(@layers, |
| 506 | ['Glemm', 'Morpho']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 507 | |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 508 | # HNC |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 509 | push(@layers, |
| 510 | ['HNC', 'Morpho']); |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 511 | |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 512 | # LWC |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 513 | push(@layers, |
| 514 | ['LWC', 'Dependency']); |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 515 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 516 | # Malt |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 517 | push(@layers, |
| 518 | ['Malt', 'Dependency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 519 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 520 | # Marmot |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 521 | push(@layers, |
| 522 | ['MarMoT', 'Morpho']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 523 | |
| 524 | # Mate |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 525 | push(@layers, |
| 526 | ['Mate', 'Morpho'], |
| 527 | ['Mate', 'Dependency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 528 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 529 | # MDParser |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 530 | push(@layers, |
| 531 | ['MDParser', 'Dependency']); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 532 | |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 533 | # NKJP |
| 534 | push(@layers, |
Akron | a65cd68 | 2022-07-21 15:40:40 +0200 | [diff] [blame] | 535 | ['NKJP', 'Morpho'], |
| 536 | ['NKJP', 'NamedEntities']); |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 537 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 538 | # OpenNLP |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 539 | push(@layers, |
| 540 | ['OpenNLP', 'Morpho'], |
| 541 | ['OpenNLP', 'Sentences']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 542 | |
Akron | 07e2477 | 2020-04-23 14:00:54 +0200 | [diff] [blame] | 543 | # Redewiedergabe |
| 544 | push(@layers, ['RWK', 'Morpho']); |
| 545 | if ($base_sentences eq 'rwk#structure') { |
| 546 | push(@layers, ['RWK', 'Structure']); |
| 547 | }; |
| 548 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 549 | # Schreibgebrauch |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 550 | push(@layers, |
| 551 | ['Sgbr', 'Lemma'], |
| 552 | ['Sgbr', 'Morpho']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 553 | |
Marc Kupietz | b8c5382 | 2024-03-16 18:54:08 +0100 | [diff] [blame] | 554 | # Spacy |
| 555 | push(@layers, |
| 556 | ['Spacy', 'Morpho']); |
| 557 | |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 558 | # Talismane |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 559 | push(@layers, |
| 560 | ['Talismane', 'Dependency'], |
| 561 | ['Talismane', 'Morpho']); |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 562 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 563 | # TreeTagger |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 564 | push(@layers, |
| 565 | ['TreeTagger', 'Morpho'], |
| 566 | ['TreeTagger', 'Sentences']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 567 | |
Marc Kupietz | 400590b | 2022-12-23 16:02:36 +0100 | [diff] [blame] | 568 | # UDPipe |
| 569 | push(@layers, |
| 570 | ['UDPipe', 'Morpho'], |
| 571 | ['UDPipe', 'Dependency']); |
| 572 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 573 | # XIP |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 574 | push(@layers, |
| 575 | ['XIP', 'Morpho'], |
| 576 | ['XIP', 'Constituency'], |
| 577 | ['XIP', 'Sentences'], |
| 578 | ['XIP', 'Dependency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 579 | |
Akron | 4fa37c3 | 2017-01-20 14:43:10 +0100 | [diff] [blame] | 580 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 581 | # Check filters |
| 582 | my @filtered_anno; |
| 583 | if ($skip{'#all'}) { |
| 584 | foreach (@anno) { |
| 585 | push @filtered_anno, [ split('#', $_) ]; |
| 586 | }; |
| 587 | } |
| 588 | |
| 589 | # Add all annotations that are not skipped |
| 590 | else { |
| 591 | # Add to index file - respect skipping |
| 592 | foreach my $info (@layers) { |
| 593 | # Skip if Foundry or Foundry#Layer should be skipped |
| 594 | unless ($skip{lc($info->[0])} || $skip{lc($info->[0]) . '#' . lc($info->[1])}) { |
| 595 | push @filtered_anno, $info; |
| 596 | }; |
| 597 | }; |
| 598 | }; |
| 599 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 600 | |
| 601 | # TODO: This should not be initialized for batch |
| 602 | my $cache = Cache::FastMmap->new( |
| 603 | share_file => $cache_file, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 604 | cache_size => ($cfg{cache_size} // '50m'), |
Akron | c0ac4ff | 2024-04-15 18:03:15 +0200 | [diff] [blame] | 605 | init_file => ($cfg{cache_init} // 1), |
| 606 | unlink_on_exit => $cache_delete |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 607 | ); |
| 608 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 609 | # Create batch object |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 610 | my $batch_file = KorAP::XML::Batch::File->new( |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 611 | cache => $cache, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 612 | meta_type => $cfg{meta}, |
| 613 | overwrite => $cfg{overwrite}, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 614 | foundry => $token_base_foundry, |
| 615 | layer => $token_base_layer, |
| 616 | gzip => $gzip, |
| 617 | log => $log, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 618 | koral => ($cfg{koral} // $KORAL_VERSION), |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 619 | anno => \@filtered_anno, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 620 | non_word_tokens => ($cfg{non_word_tokens} // 0), |
Akron | 64f7fae | 2022-07-27 12:45:33 +0200 | [diff] [blame] | 621 | non_verbal_tokens => ($cfg{non_verbal_tokens} // 0), |
| 622 | lang => $cfg{lang}, |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 623 | ); |
| 624 | |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 625 | # Auto adjust jobs |
| 626 | if ($jobs eq '-1') { |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame] | 627 | ($jobs, my $msg) = count_jobs(); |
| 628 | print $msg . "\n" unless $q; |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 629 | }; |
| 630 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 631 | # Glob and prefix files |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 632 | if (@input > 0) { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 633 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 634 | my @new_input = (); |
| 635 | |
| 636 | # Iterate over all inputs |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 637 | foreach my $wild_card (@input) { |
| 638 | |
| 639 | # Prefix with input root |
| 640 | $wild_card = $input_base ? catfile($input_base, $wild_card) : $wild_card; |
| 641 | |
| 642 | push (@new_input, bsd_glob($wild_card)); |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 643 | }; |
| 644 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 645 | # Sort files by length |
| 646 | @input = sort { length($a) <=> length($b) } @new_input; |
| 647 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 648 | print 'Input is ' . join(', ', @input)."\n" unless $q; |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 649 | }; |
| 650 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 651 | # Process a single file |
| 652 | unless ($cmd) { |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 653 | my $input = $input[0]; |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 654 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 655 | BEGIN { |
| 656 | $main::TIME = Benchmark->new; |
| 657 | $main::LAST_STOP = Benchmark->new; |
| 658 | }; |
| 659 | |
| 660 | sub stop_time { |
| 661 | my $new = Benchmark->new; |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 662 | $log->info( |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 663 | 'The code took: '. |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 664 | timestr(timediff($new, $main::LAST_STOP)) . |
| 665 | ' (overall: ' . timestr(timediff($new, $main::TIME)) . ')' |
| 666 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 667 | $main::LAST_STOP = $new; |
| 668 | }; |
| 669 | |
| 670 | # Create and parse new document |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 671 | $input =~ s{([^/])$}{$1/}o; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 672 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 673 | # Process file |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 674 | $batch_file->process($input, $output); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 675 | |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 676 | stop_time; |
Akron | c0ac4ff | 2024-04-15 18:03:15 +0200 | [diff] [blame] | 677 | |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 678 | exit; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 679 | }; |
| 680 | |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 681 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 682 | # Extract XML files |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 683 | if ($cmd eq 'extract') { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 684 | |
Akron | d5643ad | 2017-07-04 20:27:13 +0200 | [diff] [blame] | 685 | # Output is required |
| 686 | pod2usage(%ERROR_HASH) unless $output; |
| 687 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 688 | # Create new archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 689 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 690 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 691 | # Check zip capabilities |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 692 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 693 | $log->error("Unzip is not installed or incompatible."); |
| 694 | exit 1; |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 695 | }; |
| 696 | |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 697 | # Add further annotation archived |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 698 | $archive->attach($_) foreach @input[1..$#input]; |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 699 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 700 | # Will set @sigle |
| 701 | my $prefix = set_sigle($archive); |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 702 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 703 | # Iterate over all given sigles and extract |
| 704 | foreach (@sigle) { |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 705 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 706 | unless ($q) { |
| 707 | print "$_ ...\n"; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 708 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 709 | # TODO: Make this OS independent |
| 710 | print '... ' . ( |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 711 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 712 | # TODO: |
| 713 | # - prefix??? |
| 714 | $archive->extract_sigle(0, [$_], $output, $jobs) |
| 715 | ? '' : 'not ' |
| 716 | ); |
| 717 | print "extracted.\n"; |
| 718 | } else { |
| 719 | $archive->extract_sigle(1, [$_], $output, $jobs); |
| 720 | } |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 721 | }; |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 722 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 723 | |
| 724 | # Can't create archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 725 | else { |
| 726 | $log->error('Unable to extract from primary archive ' . $input[0]); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 727 | exit 1; |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 728 | }; |
| 729 | } |
| 730 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 731 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 732 | # Process an archive |
| 733 | elsif ($cmd eq 'archive') { |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 734 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 735 | my $archive_output; |
| 736 | |
| 737 | # First extract, then archive |
Akron | 63d03ee | 2019-02-13 18:49:38 +0100 | [diff] [blame] | 738 | if (defined $extract_dir && !-d $input[0]) { |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 739 | |
| 740 | # Create new archive object |
| 741 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
| 742 | |
| 743 | # Check zip capabilities |
| 744 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 745 | $log->error("Unzip is not installed or incompatible."); |
| 746 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 747 | }; |
| 748 | |
| 749 | # Add further annotation archived |
| 750 | $archive->attach($_) foreach @input[1..$#input]; |
| 751 | |
| 752 | # Create a temporary directory |
| 753 | if ($extract_dir eq ':temp:') { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 754 | $extract_dir = tempdir(CLEANUP => 0); |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 755 | print "Temporarily extract to $extract_dir\n" unless $q; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 756 | }; |
| 757 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 758 | # Add some random extra to avoid clashes with multiple archives |
| 759 | $extract_dir = catdir($extract_dir, random_string('cccccc')); |
| 760 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 761 | # Extract to temporary directory |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 762 | if ($archive->extract_all($q, $extract_dir, $sequential_extraction ? 1: $jobs)) { |
| 763 | print "Extract sequentially to $extract_dir\n" unless $q; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 764 | @input = ($extract_dir); |
| 765 | } |
| 766 | else { |
| 767 | $log->error('Unable to extract from primary archive ' . $input[0] . |
| 768 | ' to ' . $extract_dir); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 769 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 770 | }; |
| 771 | } |
| 772 | |
| 773 | # Can't create archive object |
| 774 | else { |
| 775 | $log->error('Unable to extract from primary archive ' . $input[0]); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 776 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 777 | }; |
| 778 | }; |
| 779 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 780 | # Zero means: everything runs in the parent process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 781 | my $pool = Parallel::ForkManager->new($jobs); |
| 782 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 783 | my $count = 0; # Texts to process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 784 | my $iter = 1; # Current text in process |
| 785 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 786 | my $tar_archive; |
| 787 | my $output_dir = $output; |
| 788 | my $tar_fh; |
| 789 | |
| 790 | # Initialize tar archive |
| 791 | if ($to_tar) { |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 792 | |
| 793 | # Set output name |
| 794 | my $tar_file = $output; |
| 795 | unless ($tar_file =~ /\.tar$/) { |
| 796 | $tar_file .= '.tar'; |
| 797 | }; |
| 798 | |
| 799 | # Initiate the tar file |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 800 | print "Writing to file $tar_file\n" unless $q; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 801 | $tar_fh = IO::File->new($tar_file, 'w'); |
| 802 | $tar_fh->binmode(1); |
| 803 | |
Akron | eb370a0 | 2022-02-24 13:33:40 +0100 | [diff] [blame] | 804 | # Use tar builder for archiving |
| 805 | if (eval("use Archive::Tar::Builder; 1;")) { |
| 806 | $tar_archive = Archive::Tar::Builder->new( |
| 807 | ignore_errors => 1 |
| 808 | ); |
| 809 | |
| 810 | # Set handle |
| 811 | $tar_archive->set_handle($tar_fh); |
| 812 | } |
| 813 | |
| 814 | # Fallback solution |
| 815 | else { |
| 816 | $tar_archive = KorAP::XML::TarBuilder->new( |
| 817 | $tar_fh |
| 818 | ); |
| 819 | }; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 820 | |
| 821 | # Output to temporary directory |
| 822 | $output_dir = File::Temp->newdir; |
| 823 | }; |
| 824 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 825 | # Report on fork message |
| 826 | $pool->run_on_finish ( |
| 827 | sub { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 828 | my ($pid, $code) = @_; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 829 | my $data = pop; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 830 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 831 | unless ($q) { |
| 832 | print 'Convert ['. ($jobs > 0 ? "\$$pid:" : '') . |
| 833 | $iter . "/$count]" . |
| 834 | ($code ? " $code" : '') . |
| 835 | ' ' . $data->[0] . "\n"; |
| 836 | }; |
| 837 | $iter++; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 838 | |
| 839 | if (!$code && $to_tar && $data->[2]) { |
| 840 | my $filename = $data->[2]; |
| 841 | |
| 842 | # Lock filehandle |
| 843 | if (flock($tar_fh, LOCK_EX)) { |
| 844 | |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 845 | my $clean_file = fileparse($filename); |
| 846 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 847 | # Archive and remove file |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 848 | $tar_archive->archive_as($filename => $clean_file); |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 849 | unlink $filename; |
| 850 | |
| 851 | # Unlock filehandle |
| 852 | flock($tar_fh, LOCK_UN); |
| 853 | } |
| 854 | else { |
| 855 | $log->warn("Unable to add $filename to archive"); |
| 856 | }; |
| 857 | }; |
| 858 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 859 | $data->[1] = undef if $data->[1]; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 860 | } |
| 861 | ); |
| 862 | |
| 863 | my $t; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 864 | my $temp; |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 865 | print "Reading data ...\n" unless $q; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 866 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 867 | # unless (Cache::FastMmap->new( |
| 868 | # share_file => $cache_file, |
| 869 | # cache_size => $cache_size, |
| 870 | # init_file => $cache_init |
| 871 | # )) { |
| 872 | # print "Unable to intialize cache '$cache_file'\n\n"; |
| 873 | # exit(1); |
| 874 | # }; |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 875 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 876 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 877 | # Input is a directory |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 878 | if (-d $input[0]) { |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 879 | |
Akron | ce03350 | 2024-09-11 10:51:49 +0200 | [diff] [blame] | 880 | my @dirs; |
| 881 | |
Akron | 0a0d1f9 | 2024-11-14 14:31:42 +0100 | [diff] [blame^] | 882 | my $rule = Path::Iterator::Rule->new; |
| 883 | $rule->name('data.xml')->file; |
| 884 | my $next = $rule->iter( |
| 885 | $input[0] => { |
| 886 | sorted => 0, |
| 887 | depthfirst => -1, |
| 888 | error_handler => undef |
| 889 | }); |
| 890 | while (defined(my $file = $next->())) { |
| 891 | $file =~ s/\/data\.xml$//; |
| 892 | push @dirs, $file; |
| 893 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 894 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 895 | print "Start processing ...\n" unless $q; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 896 | $t = Benchmark->new; |
| 897 | $count = scalar @dirs; |
| 898 | |
| 899 | DIRECTORY_LOOP: |
| 900 | for (my $i = 0; $i < $count; $i++) { |
| 901 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 902 | my $filename = catfile( |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 903 | $output_dir, |
Akron | 41127e3 | 2020-08-07 12:46:19 +0200 | [diff] [blame] | 904 | get_file_name($input[0], $dirs[$i]) . '.json' . ($gzip ? '.gz' : '') |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 905 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 906 | |
| 907 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 908 | $pool->start and next DIRECTORY_LOOP; |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 909 | |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 910 | if (my $return = $batch_file->process($dirs[$i] => $filename)) { |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 911 | $pool->finish( |
| 912 | 0, |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 913 | [ |
| 914 | "Processed " . $filename . ($return == -1 ? " - already existing" : ''), |
| 915 | undef, |
| 916 | $filename |
| 917 | ] |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 918 | ); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 919 | } |
| 920 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 921 | $pool->finish(1, ["Unable to process " . $dirs[$i]]); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 922 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 923 | }; |
| 924 | } |
| 925 | |
| 926 | # Input is a file |
Akron | 29866ac | 2016-06-24 16:40:47 +0200 | [diff] [blame] | 927 | elsif (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 928 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 929 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 930 | $log->error("Unzip is not installed or incompatible."); |
| 931 | exit 1; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 932 | }; |
| 933 | |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 934 | # Add further annotation archived |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 935 | $archive->attach($_) foreach @input[1..$#input]; |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 936 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 937 | # Get sigles to extract |
| 938 | my $prefix = set_sigle($archive); |
| 939 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 940 | print "Start processing ...\n" unless $q; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 941 | $t = Benchmark->new; |
| 942 | my @dirs = $archive->list_texts; |
| 943 | $count = scalar @dirs; |
| 944 | |
| 945 | ARCHIVE_LOOP: |
| 946 | for (my $i = 0; $i < $count; $i++) { |
| 947 | |
| 948 | # Split path information |
| 949 | my ($prefix, $corpus, $doc, $text) = $archive->split_path($dirs[$i]); |
| 950 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 951 | my $filename = catfile( |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 952 | $output_dir, |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 953 | get_file_name( |
Akron | 41127e3 | 2020-08-07 12:46:19 +0200 | [diff] [blame] | 954 | $input[0], |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 955 | catfile($corpus, $doc, $text) |
| 956 | . '.json' . ($gzip ? '.gz' : '') |
| 957 | ) |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 958 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 959 | |
| 960 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 961 | $pool->start and next ARCHIVE_LOOP; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 962 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 963 | # Create temporary file |
| 964 | $temp = File::Temp->newdir; |
| 965 | |
Akron | bdf434a | 2016-10-24 17:42:07 +0200 | [diff] [blame] | 966 | # TODO: Check if $filename exist at the beginning, |
| 967 | # because extraction can be horrible slow! |
| 968 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 969 | # Extract from archive |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 970 | if ($archive->extract_sigle($q, [join('/', $corpus, $doc, $text)], $temp, $sequential_extraction ? 1 : $jobs)) { |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 971 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 972 | # Create corpus directory |
| 973 | my $input = catdir("$temp", $corpus); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 974 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 975 | # Temporary directory |
| 976 | my $dir = catdir($input, $doc, $text); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 977 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 978 | # Write file |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 979 | if (my $return = $batch_file->process($dir => $filename)) { |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 980 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 981 | # Delete temporary file |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 982 | $pool->finish( |
| 983 | 0, |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 984 | [ |
| 985 | "Processed " . $filename . ($return == -1 ? " - already existing" : ''), |
| 986 | $temp, |
| 987 | $filename |
| 988 | ] |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 989 | ); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 990 | } |
| 991 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 992 | # Delete temporary file |
| 993 | $pool->finish(1, ["Unable to process " . $dir, $temp]); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 994 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 995 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 996 | |
| 997 | # Unable to extract |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 998 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 999 | $pool->finish(1, ["Unable to extract " . $dirs[$i], $temp]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1000 | }; |
| 1001 | }; |
| 1002 | } |
| 1003 | |
| 1004 | else { |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1005 | print "Input is neither a directory nor an archive.\n\n" unless $q; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1006 | }; |
| 1007 | |
| 1008 | $pool->wait_all_children; |
| 1009 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 1010 | # Close tar filehandle |
| 1011 | if ($to_tar && $tar_fh) { |
| 1012 | $tar_archive->finish; |
| 1013 | $tar_fh->close; |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1014 | print "Wrote to tar archive.\n" unless $q; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 1015 | }; |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1016 | unless ($q) { |
| 1017 | print timestr(timediff(Benchmark->new, $t))."\n"; |
| 1018 | print "Done.\n"; |
| 1019 | }; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1020 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1021 | |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 1022 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1023 | # For an archive, this will create the list |
| 1024 | # of all sigles to process |
| 1025 | sub set_sigle { |
| 1026 | my $archive = shift; |
| 1027 | |
| 1028 | my $prefix = 1; |
| 1029 | my @dirs = (); |
| 1030 | |
| 1031 | # No sigles given |
| 1032 | unless (@sigle) { |
| 1033 | |
| 1034 | # Get files |
| 1035 | foreach ($archive->list_texts) { |
| 1036 | |
| 1037 | push @dirs, $_; |
| 1038 | |
| 1039 | # Split path information |
| 1040 | ($prefix, my ($corpus, $doc, $text)) = $archive->split_path($_); |
| 1041 | |
| 1042 | # TODO: Make this OS independent |
| 1043 | push @sigle, join '/', $corpus, $doc, $text; |
| 1044 | }; |
| 1045 | } |
| 1046 | |
| 1047 | # Check sigle for doc sigles |
| 1048 | else { |
| 1049 | my @new_sigle; |
| 1050 | |
| 1051 | my $prefix_check = 0; |
| 1052 | |
| 1053 | # Iterate over all sigle |
| 1054 | foreach (@sigle) { |
| 1055 | |
| 1056 | # Sigle is a doc sigle |
| 1057 | if ($_ =~ m!^(?:\.[/\\])?[^/\\]+?[/\\][^/\\]+?$!) { |
| 1058 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1059 | print "$_ ..." unless $q; |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1060 | # Check if a prefix is needed |
| 1061 | unless ($prefix_check) { |
| 1062 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1063 | if ($prefix = $archive->check_prefix && !$q) { |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1064 | print " with prefix ..."; |
| 1065 | }; |
| 1066 | $prefix_check = 1; |
| 1067 | }; |
| 1068 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1069 | unless ($q) { |
| 1070 | print "\n"; |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1071 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1072 | print '... ' . ( |
| 1073 | $archive->extract_sigle($q, [$_], $output, $sequential_extraction ? 1 : $jobs) |
Akron | 955b75b | 2019-02-21 14:28:41 +0100 | [diff] [blame] | 1074 | ? '' : 'not ' |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1075 | ); |
| 1076 | print "extracted.\n"; |
| 1077 | } |
| 1078 | else { |
| 1079 | $archive->extract_sigle($q, [$_], $output, $sequential_extraction ? 1 : $jobs) |
| 1080 | }; |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | # Sigle is a text sigle |
| 1084 | else { |
| 1085 | push @new_sigle, $_; |
| 1086 | |
| 1087 | unless ($prefix_check) { |
| 1088 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1089 | if ($prefix = $archive->check_prefix && !$q) { |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1090 | print " with prefix ..."; |
| 1091 | }; |
| 1092 | $prefix_check = 1; |
| 1093 | }; |
| 1094 | }; |
| 1095 | }; |
| 1096 | @sigle = @new_sigle; |
| 1097 | }; |
| 1098 | |
| 1099 | return $prefix; |
| 1100 | }; |
| 1101 | |
| 1102 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1103 | # Cleanup temporary extraction directory |
| 1104 | if ($extract_dir) { |
| 1105 | my $objects = remove_tree($extract_dir, { safe => 1 }); |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 1106 | $log->info("Removed directory $extract_dir with $objects objects"); |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1107 | }; |
| 1108 | |
| 1109 | |
| 1110 | print "\n"; |
| 1111 | |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 1112 | __END__ |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1113 | |
| 1114 | =pod |
| 1115 | |
| 1116 | =encoding utf8 |
| 1117 | |
| 1118 | =head1 NAME |
| 1119 | |
Akron | 42f48c1 | 2020-02-14 13:08:13 +0100 | [diff] [blame] | 1120 | korapxml2krill - Merge KorAP-XML data and create Krill documents |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1121 | |
| 1122 | |
| 1123 | =head1 SYNOPSIS |
| 1124 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1125 | $ korapxml2krill [archive|extract] --input <directory|archive> [options] |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1126 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1127 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1128 | =head1 DESCRIPTION |
| 1129 | |
| 1130 | L<KorAP::XML::Krill> is a library to convert KorAP-XML documents to files |
| 1131 | compatible with the L<Krill|https://github.com/KorAP/Krill> indexer. |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1132 | The C<korapxml2krill> command line tool is a simple wrapper of this library. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1133 | |
| 1134 | |
| 1135 | =head1 INSTALLATION |
| 1136 | |
| 1137 | The preferred way to install L<KorAP::XML::Krill> is to use L<cpanm|App::cpanminus>. |
| 1138 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1139 | $ cpanm https://github.com/KorAP/KorAP-XML-Krill.git |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1140 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1141 | In case everything went well, the C<korapxml2krill> tool will |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1142 | be available on your command line immediately. |
Akron | 8ce23f7 | 2023-12-13 15:48:49 +0100 | [diff] [blame] | 1143 | Minimum requirement for L<KorAP::XML::Krill> is Perl 5.32. |
Akron | eb370a0 | 2022-02-24 13:33:40 +0100 | [diff] [blame] | 1144 | Optionally installing L<Archive::Tar::Builder> speeds up archive building. |
| 1145 | Optional support for L<Sys::Info> to calculate available cores is available. |
Akron | a93d51b | 2016-10-24 20:27:48 +0200 | [diff] [blame] | 1146 | In addition to work with zip archives, the C<unzip> tool needs to be present. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1147 | |
| 1148 | =head1 ARGUMENTS |
| 1149 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1150 | $ korapxml2krill -z --input <directory> --output <filename> |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1151 | |
| 1152 | Without arguments, C<korapxml2krill> converts a directory of a single KorAP-XML document. |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1153 | It expects the input to point to the text level folder. |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1154 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1155 | =over 2 |
| 1156 | |
| 1157 | =item B<archive> |
| 1158 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1159 | $ korapxml2krill archive -z --input <directory|archive> --output <directory|tar> |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1160 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1161 | Converts an archive of KorAP-XML documents. It expects a directory |
| 1162 | (pointing to the corpus level folder) or one or more zip files as input. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1163 | |
| 1164 | =item B<extract> |
| 1165 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1166 | $ korapxml2krill extract --input <archive> --output <directory> --sigle <SIGLE> |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1167 | |
| 1168 | Extracts KorAP-XML documents from a zip file. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1169 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1170 | =item B<serial> |
| 1171 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1172 | $ korapxml2krill serial -i <archive1> -i <archive2> -o <directory> -cfg <config-file> |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1173 | |
Akron | ce03350 | 2024-09-11 10:51:49 +0200 | [diff] [blame] | 1174 | Convert archives in serial. The inputs are not merged but treated |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1175 | as they are (so they may be premerged or globs). |
| 1176 | the C<--out> directory is treated as the base directory where subdirectories |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 1177 | are created based on the archive name. In case the C<--to-tar> flag is given, |
| 1178 | the output will be a tar file. |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1179 | |
| 1180 | |
Akron | 84b53ad | 2022-01-14 12:39:15 +0100 | [diff] [blame] | 1181 | =item B<slimlog> |
| 1182 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1183 | $ korapxml2krill slimlog <logfile> > <logfile-slim> |
Akron | 84b53ad | 2022-01-14 12:39:15 +0100 | [diff] [blame] | 1184 | |
| 1185 | Filters out all useless aka succesfull information from logs, to simplify |
| 1186 | log checks. Expects no further options. |
| 1187 | |
| 1188 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1189 | =back |
| 1190 | |
| 1191 | |
| 1192 | =head1 OPTIONS |
| 1193 | |
| 1194 | =over 2 |
| 1195 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1196 | =item B<--input|-i> <directory|zip file> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1197 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1198 | Directory or zip file(s) of documents to convert. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1199 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1200 | Without arguments, C<korapxml2krill> expects a folder of a single KorAP-XML |
Akron | f1a1de9 | 2016-11-02 17:32:12 +0100 | [diff] [blame] | 1201 | document, while C<archive> expects a KorAP-XML corpus folder or a zip |
| 1202 | file to batch process multiple files. |
| 1203 | C<extract> expects zip files only. |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1204 | |
Akron | dee3cf6 | 2024-06-14 18:14:48 +0200 | [diff] [blame] | 1205 | C<archive> supports multiple input zip files with the constraint |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1206 | that the first archive listed contains all primary data files |
| 1207 | and all meta data files. |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1208 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1209 | -i file/news.zip -i file/news.malt.zip -i "#file/news.tt.zip" |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1210 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1211 | Input may also be defined using BSD glob wildcards. |
| 1212 | |
| 1213 | -i 'file/news*.zip' |
| 1214 | |
| 1215 | The extended input array will be sorted in length order, so the shortest |
| 1216 | path needs to contain all primary data files and all meta data files. |
| 1217 | |
Akron | dee3cf6 | 2024-06-14 18:14:48 +0200 | [diff] [blame] | 1218 | (The directory structure follows the base directory format |
Akron | 0c3e375 | 2016-06-28 15:55:53 +0200 | [diff] [blame] | 1219 | that may include a C<.> root folder. |
| 1220 | In this case further archives lacking a C<.> root folder |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1221 | need to be passed with a hash sign in front of the archive's name. |
| 1222 | This may require to quote the parameter.) |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1223 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1224 | To support zip files, a version of C<unzip> needs to be installed that is |
| 1225 | compatible with the archive file. |
Akron | a93d51b | 2016-10-24 20:27:48 +0200 | [diff] [blame] | 1226 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1227 | B<The root folder switch using the hash sign is experimental and |
| 1228 | may vanish in future versions.> |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 1229 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1230 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1231 | =item B<--input-base|-ib> <directory> |
| 1232 | |
| 1233 | The base directory for inputs. |
| 1234 | |
| 1235 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1236 | =item B<--output|-o> <directory|file> |
| 1237 | |
| 1238 | Output folder for archive processing or |
| 1239 | document name for single output (optional), |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1240 | writes to C<STDOUT> by default |
| 1241 | (in case C<output> is not mandatory due to further options). |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1242 | |
| 1243 | =item B<--overwrite|-w> |
| 1244 | |
| 1245 | Overwrite files that already exist. |
| 1246 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1247 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1248 | =item B<--token|-t> <foundry>#<file> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1249 | |
| 1250 | Define the default tokenization by specifying |
| 1251 | the name of the foundry and optionally the name |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1252 | of the layer-file. Defaults to C<OpenNLP#tokens>. |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 1253 | This will directly take the file instead of running |
| 1254 | the layer implementation! |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1255 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1256 | |
| 1257 | =item B<--base-sentences|-bs> <foundry>#<layer> |
| 1258 | |
| 1259 | Define the layer for base sentences. |
| 1260 | If given, this will be used instead of using C<Base#Sentences>. |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 1261 | Currently C<DeReKo#Structure> and C<DGD#Structure> are the only additional |
| 1262 | layers supported. |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1263 | |
| 1264 | Defaults to unset. |
| 1265 | |
| 1266 | |
| 1267 | =item B<--base-paragraphs|-bp> <foundry>#<layer> |
| 1268 | |
| 1269 | Define the layer for base paragraphs. |
| 1270 | If given, this will be used instead of using C<Base#Paragraphs>. |
Akron | 0ffbd52 | 2021-02-16 12:01:19 +0100 | [diff] [blame] | 1271 | Currently C<DeReKo#Structure> and C<DGD#Structure> are the only additional |
| 1272 | layer supported. |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1273 | |
| 1274 | Defaults to unset. |
| 1275 | |
| 1276 | |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 1277 | =item B<--base-pagebreaks|-bpb> <foundry>#<layer> |
| 1278 | |
| 1279 | Define the layer for base pagebreaks. |
| 1280 | Currently C<DeReKo#Structure> is the only layer supported. |
| 1281 | |
| 1282 | Defaults to unset. |
| 1283 | |
| 1284 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1285 | =item B<--skip|-s> <foundry>[#<layer>] |
| 1286 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1287 | Skip specific annotations by specifying the foundry |
| 1288 | (and optionally the layer with a C<#>-prefix), |
| 1289 | e.g. C<Mate> or C<Mate#Morpho>. Alternatively you can skip C<#ALL>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1290 | Can be set multiple times. |
| 1291 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1292 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1293 | =item B<--anno|-a> <foundry>#<layer> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1294 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1295 | Convert specific annotations by specifying the foundry |
| 1296 | (and optionally the layer with a C<#>-prefix), |
| 1297 | e.g. C<Mate> or C<Mate#Morpho>. |
| 1298 | Can be set multiple times. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1299 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1300 | |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 1301 | =item B<--non-word-tokens|-nwt> |
| 1302 | |
| 1303 | Tokenize non-word tokens like word tokens (defined as matching |
| 1304 | C</[\d\w]/>). Useful to treat punctuations as tokens. |
| 1305 | |
| 1306 | Defaults to unset. |
| 1307 | |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 1308 | |
| 1309 | =item B<--non-verbal-tokens|-nvt> |
| 1310 | |
| 1311 | Tokenize non-verbal tokens marked as in the primary data as |
| 1312 | the unicode symbol 'Black Vertical Rectangle' aka \x25ae. |
| 1313 | |
| 1314 | Defaults to unset. |
| 1315 | |
| 1316 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1317 | =item B<--jobs|-j> |
| 1318 | |
Akron | 2912826 | 2024-04-17 15:50:36 +0200 | [diff] [blame] | 1319 | Define the number of spawned forks for concurrent jobs |
| 1320 | of archive processing. |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1321 | Defaults to C<0> (everything runs in a single process). |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1322 | |
Akron | a472a24 | 2023-02-13 13:46:30 +0100 | [diff] [blame] | 1323 | If C<sequential-extraction> is not set to true, this will |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1324 | also apply to extraction. |
| 1325 | |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame] | 1326 | Pass C<-1>, and the value will be set automatically to 5 |
Akron | 0b04b31 | 2020-10-30 17:39:18 +0100 | [diff] [blame] | 1327 | times the number of available cores, in case L<Sys::Info> |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame] | 1328 | is available and can read CPU count (see C<--job-count>). |
| 1329 | Be aware, that the report of available cores |
Akron | 2912826 | 2024-04-17 15:50:36 +0200 | [diff] [blame] | 1330 | may not work in certain conditions. Benchmarking the processing |
| 1331 | speed based on the number of jobs may be valuable. |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame] | 1332 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1333 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1334 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1335 | |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame] | 1336 | =item B<--job-count|-jc> |
| 1337 | |
| 1338 | Print job and core information that would be used if |
| 1339 | C<-1> was passed to C<--jobs>. |
| 1340 | |
| 1341 | |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 1342 | =item B<--koral|-k> |
| 1343 | |
| 1344 | Version of the output format. Supported versions are: |
| 1345 | C<0> for legacy serialization, C<0.03> for serialization |
| 1346 | with metadata fields as key-values on the root object, |
| 1347 | C<0.4> for serialization with metadata fields as a list |
| 1348 | of C<"@type":"koral:field"> objects. |
| 1349 | |
| 1350 | Currently defaults to C<0.03>. |
| 1351 | |
| 1352 | |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1353 | =item B<--sequential-extraction|-se> |
| 1354 | |
| 1355 | Flag to indicate, if the C<jobs> value also applies to extraction. |
| 1356 | Some systems may have problems with extracting multiple archives |
| 1357 | to the same folder at the same time. |
| 1358 | Can be flagged using C<--no-sequential-extraction> as well. |
| 1359 | Defaults to C<false>. |
| 1360 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1361 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1362 | =item B<--meta|-m> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1363 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1364 | Define the metadata parser to use. Defaults to C<I5>. |
| 1365 | Metadata parsers can be defined in the C<KorAP::XML::Meta> namespace. |
| 1366 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1367 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1368 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1369 | =item B<--gzip|-z> |
| 1370 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1371 | Compress the output. |
| 1372 | Expects a defined C<output> file in single processing. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1373 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1374 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1375 | =item B<--cache|-c> |
| 1376 | |
| 1377 | File to mmap a cache (using L<Cache::FastMmap>). |
| 1378 | Defaults to C<korapxml2krill.cache> in the calling directory. |
| 1379 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1380 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1381 | =item B<--cache-size|-cs> |
| 1382 | |
| 1383 | Size of the cache. Defaults to C<50m>. |
| 1384 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1385 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1386 | =item B<--cache-init|-ci> |
| 1387 | |
| 1388 | Initialize cache file. |
| 1389 | Can be flagged using C<--no-cache-init> as well. |
| 1390 | Defaults to C<true>. |
| 1391 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1392 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1393 | =item B<--cache-delete|-cd> |
| 1394 | |
| 1395 | Delete cache file after processing. |
| 1396 | Can be flagged using C<--no-cache-delete> as well. |
| 1397 | Defaults to C<true>. |
| 1398 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1399 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1400 | =item B<--config|-cfg> |
| 1401 | |
| 1402 | Configure the parameters of your call in a file |
| 1403 | of key-value pairs with whitespace separator |
| 1404 | |
| 1405 | overwrite 1 |
| 1406 | token DeReKo#Structure |
| 1407 | ... |
| 1408 | |
| 1409 | Supported parameters are: |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1410 | C<overwrite>, C<gzip>, C<jobs>, C<input-base>, |
Akron | c0ac4ff | 2024-04-15 18:03:15 +0200 | [diff] [blame] | 1411 | C<token>, C<log>, |
| 1412 | C<cache>, C<cache-size>, C<cache-init>, C<cache-delete>, C<meta>, |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1413 | C<output>, C<koral>, |
Akron | eb370a0 | 2022-02-24 13:33:40 +0100 | [diff] [blame] | 1414 | C<temporary-extract>, C<sequential-extraction>, |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1415 | C<base-sentences>, C<base-paragraphs>, |
| 1416 | C<base-pagebreaks>, |
| 1417 | C<skip> (semicolon separated), C<sigle> |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1418 | (semicolon separated), C<anno> (semicolon separated). |
| 1419 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1420 | Configuration parameters will always be overwritten by |
| 1421 | passed parameters. |
| 1422 | |
| 1423 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1424 | =item B<--temporary-extract|-te> |
| 1425 | |
Akron | a472a24 | 2023-02-13 13:46:30 +0100 | [diff] [blame] | 1426 | Only valid for the C<archive> and C<serial> |
| 1427 | commands. |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1428 | |
| 1429 | This will first extract all files into a |
| 1430 | directory and then will archive. |
| 1431 | If the directory is given as C<:temp:>, |
| 1432 | a temporary directory is used. |
| 1433 | This is especially useful to avoid |
| 1434 | massive unzipping and potential |
| 1435 | network latency. |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1436 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1437 | |
Akron | c93a080 | 2019-07-11 15:48:34 +0200 | [diff] [blame] | 1438 | =item B<--to-tar> |
| 1439 | |
| 1440 | Only valid for the C<archive> command. |
| 1441 | |
| 1442 | Writes the output into a tar archive. |
| 1443 | |
| 1444 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1445 | =item B<--sigle|-sg> |
| 1446 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1447 | Extract the given texts. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1448 | Can be set multiple times. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1449 | I<Currently only supported on C<extract>.> |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 1450 | Sigles have the structure C<Corpus>/C<Document>/C<Text>. |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1451 | In case the C<Text> path is omitted, the whole document will be extracted. |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1452 | On the document level, the postfix wildcard C<*> is supported. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1453 | |
Akron | 64f7fae | 2022-07-27 12:45:33 +0200 | [diff] [blame] | 1454 | =item B<--lang> |
| 1455 | |
| 1456 | Preferred language for metadata fields. In case multiple titles are |
| 1457 | given (on any level) with different C<xml:lang> attributes, |
| 1458 | the language given is preferred. |
| 1459 | Because titles may have different sources and different priorities, |
| 1460 | non-specific language titles may still be preferred in case the title |
| 1461 | source has a higher priority. |
| 1462 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1463 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1464 | =item B<--log|-l> |
| 1465 | |
Akron | b9c3381 | 2020-10-21 16:19:35 +0200 | [diff] [blame] | 1466 | The L<Log::Any> log level, defaults to C<ERROR>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1467 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1468 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1469 | =item B<--quiet> |
| 1470 | |
| 1471 | Silence all information (non-log) outputs. |
| 1472 | |
| 1473 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1474 | =item B<--help|-h> |
| 1475 | |
Akron | 42f48c1 | 2020-02-14 13:08:13 +0100 | [diff] [blame] | 1476 | Print help information. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1477 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1478 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1479 | =item B<--version|-v> |
| 1480 | |
| 1481 | Print version information. |
| 1482 | |
| 1483 | =back |
| 1484 | |
Akron | 311e29b | 2024-09-11 11:46:09 +0200 | [diff] [blame] | 1485 | =head1 PERFORMANCE |
| 1486 | |
| 1487 | There are some ways to improve performance for large tasks: |
| 1488 | |
| 1489 | =item First unpack |
| 1490 | |
| 1491 | Using the archive or serial command on one or multiple zip files |
| 1492 | can be very slow, as it needs to unpack small portions every time. |
| 1493 | It's better to use C<--temporary-extract> to unpack the whole archive |
| 1494 | first into a temprary directory and then read the extracted files. |
| 1495 | This is especially important for remote archives |
| 1496 | |
| 1497 | =item Limit annotations |
| 1498 | |
| 1499 | Per default, all supported annotation layers are sought. This can be limited |
| 1500 | by adding C<--skip '#ALL'> and only listing the expected annotations with C<--anno>. |
| 1501 | |
| 1502 | =item Checking the parallel job count |
| 1503 | |
| 1504 | By providing the number of parallel jobs using C<--jobs>, the execution can be tailored to specific |
| 1505 | hardware environments. |
| 1506 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1507 | =head1 ANNOTATION SUPPORT |
| 1508 | |
| 1509 | L<KorAP::XML::Krill> has built-in importer for some annotation foundries and layers |
| 1510 | developed in the KorAP project that are part of the KorAP preprocessing pipeline. |
| 1511 | The base foundry with paragraphs, sentences, and the text element are mandatory for |
| 1512 | L<Krill|https://github.com/KorAP/Krill>. |
| 1513 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1514 | Base |
| 1515 | #Paragraphs |
| 1516 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1517 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1518 | Connexor |
| 1519 | #Morpho |
| 1520 | #Phrase |
| 1521 | #Sentences |
| 1522 | #Syntax |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1523 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1524 | CoreNLP |
| 1525 | #Constituency |
| 1526 | #Morpho |
| 1527 | #NamedEntities |
| 1528 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1529 | |
Akron | 5530a55 | 2022-02-17 17:53:15 +0100 | [diff] [blame] | 1530 | CorpusExplorer |
| 1531 | #Morpho |
| 1532 | |
Akron | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 1533 | CMC |
| 1534 | #Morpho |
| 1535 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1536 | DeReKo |
| 1537 | #Structure |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1538 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 1539 | DGD |
| 1540 | #Morpho |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 1541 | #Structure |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 1542 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1543 | DRuKoLa |
| 1544 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1545 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1546 | Glemm |
| 1547 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1548 | |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 1549 | Gingko |
| 1550 | #Morpho |
| 1551 | |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 1552 | HNC |
| 1553 | #Morpho |
| 1554 | |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 1555 | LWC |
| 1556 | #Dependency |
| 1557 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1558 | Malt |
| 1559 | #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1560 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1561 | MarMoT |
| 1562 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1563 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1564 | Mate |
| 1565 | #Dependency |
| 1566 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1567 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1568 | MDParser |
| 1569 | #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1570 | |
Akron | e85a776 | 2022-07-22 08:05:03 +0200 | [diff] [blame] | 1571 | NKJP |
| 1572 | #Morpho |
| 1573 | #NamedEntities |
| 1574 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1575 | OpenNLP |
| 1576 | #Morpho |
| 1577 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1578 | |
Akron | 07e2477 | 2020-04-23 14:00:54 +0200 | [diff] [blame] | 1579 | RWK |
| 1580 | #Morpho |
| 1581 | #Structure |
| 1582 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1583 | Sgbr |
| 1584 | #Lemma |
| 1585 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1586 | |
Marc Kupietz | b8c5382 | 2024-03-16 18:54:08 +0100 | [diff] [blame] | 1587 | Spacy |
| 1588 | #Morpho |
| 1589 | |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 1590 | Talismane |
| 1591 | #Dependency |
| 1592 | #Morpho |
| 1593 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1594 | TreeTagger |
| 1595 | #Morpho |
| 1596 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1597 | |
Akron | 83aedd3 | 2023-02-07 10:57:41 +0100 | [diff] [blame] | 1598 | UDPipe |
| 1599 | #Dependency |
| 1600 | #Morpho |
| 1601 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1602 | XIP |
| 1603 | #Constituency |
| 1604 | #Morpho |
| 1605 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1606 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1607 | |
| 1608 | More importers are in preparation. |
| 1609 | New annotation importers can be defined in the C<KorAP::XML::Annotation> namespace. |
| 1610 | See the built-in annotation importers as examples. |
| 1611 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1612 | |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 1613 | =head1 METADATA SUPPORT |
| 1614 | |
| 1615 | L<KorAP::XML::Krill> has built-in importer for some meta data variants |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1616 | that are part of the KorAP preprocessing pipeline. |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 1617 | |
| 1618 | =over 2 |
| 1619 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1620 | =item B<I5> |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 1621 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1622 | Meta data for all I5 files |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 1623 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1624 | =item B<Sgbr> |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 1625 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1626 | Meta data from the Schreibgebrauch project |
Akron | 2532f1b | 2023-05-15 13:41:24 +0200 | [diff] [blame] | 1627 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1628 | =item B<Gingko> |
| 1629 | |
| 1630 | Meta data from the Gingko project in addition to I5 |
| 1631 | |
| 1632 | =item B<ICC> |
| 1633 | |
| 1634 | Meta data for the ICC in addition to I5 |
| 1635 | |
| 1636 | =item B<NKJP> |
| 1637 | |
| 1638 | Meta data for the NKJP corpora |
Akron | 24ad3c0 | 2024-06-03 12:38:20 +0200 | [diff] [blame] | 1639 | |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 1640 | =back |
| 1641 | |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 1642 | New meta data importers can be defined in the C<KorAP::XML::Meta> namespace. |
| 1643 | See the built-in meta data importers as examples. |
| 1644 | |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1645 | The I5 metadata definition is based on TEI-P5 and supports C<E<lt>xenoDataE<gt>> |
Akron | 82064bb | 2024-06-17 12:53:23 +0200 | [diff] [blame] | 1646 | with C<E<lt>metaE<gt>> elements like |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1647 | |
| 1648 | <meta type="..." name="..." project="..." desc="...">...</meta> |
| 1649 | |
| 1650 | that are directly translated to Krill objects. The supported values are: |
| 1651 | |
| 1652 | =over 2 |
| 1653 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1654 | =item C<type> |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1655 | |
| 1656 | =over 4 |
| 1657 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1658 | =item C<string> |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1659 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1660 | String meta data value |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1661 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1662 | =item C<keyword> |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1663 | |
Akron | dee3cf6 | 2024-06-14 18:14:48 +0200 | [diff] [blame] | 1664 | String meta data value that can be given multiple times |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1665 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1666 | =item C<text> |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1667 | |
Akron | dee3cf6 | 2024-06-14 18:14:48 +0200 | [diff] [blame] | 1668 | String meta data value that is tokenized and can be searched as token sequences |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1669 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1670 | =item C<date> |
| 1671 | |
| 1672 | Date meta data value (as "yyyy/mm/dd" with optional granularity) |
| 1673 | |
| 1674 | =item C<integer> |
| 1675 | |
| 1676 | Numerical meta data value |
| 1677 | |
Akron | dee3cf6 | 2024-06-14 18:14:48 +0200 | [diff] [blame] | 1678 | =item C<attachment> |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1679 | |
| 1680 | Non-indexed meta data value (only retrievable) |
| 1681 | |
| 1682 | =item C<uri> |
| 1683 | |
| 1684 | Non-indexed attached URI, takes the desc as the title for links |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1685 | |
| 1686 | =back |
| 1687 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1688 | =item C<name> |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1689 | |
Akron | dee3cf6 | 2024-06-14 18:14:48 +0200 | [diff] [blame] | 1690 | The key of the meta object that may be prefixed by C<corpus> or C<doc>, in case the |
Akron | 693f588 | 2024-06-06 12:52:39 +0200 | [diff] [blame] | 1691 | C<E<lt>xenoDataE<gt>> information is located on these levels. The text level introduces |
| 1692 | no prefixes. |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1693 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1694 | =item C<project> (optional) |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1695 | |
Akron | 1d10149 | 2024-06-06 12:47:35 +0200 | [diff] [blame] | 1696 | A prefixed namespace of the key |
| 1697 | |
| 1698 | =item C<desc> (optional) |
| 1699 | |
| 1700 | A description of the key |
| 1701 | |
| 1702 | =item text content |
| 1703 | |
| 1704 | The value of the meta object |
Akron | 4b001ce | 2024-06-06 12:32:11 +0200 | [diff] [blame] | 1705 | |
| 1706 | =back |
| 1707 | |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 1708 | |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1709 | =head1 About KorAP-XML |
| 1710 | |
| 1711 | KorAP-XML (Bański et al. 2012) is an implementation of the KorAP |
| 1712 | data model (Bański et al. 2013), where text data are stored physically |
| 1713 | separated from their interpretations (i.e. annotations). |
| 1714 | A text document in KorAP-XML therefore consists of several files |
| 1715 | containing primary data, metadata and annotations. |
| 1716 | |
| 1717 | The structure of a single KorAP-XML document can be as follows: |
| 1718 | |
| 1719 | - data.xml |
| 1720 | - header.xml |
| 1721 | + base |
| 1722 | - tokens.xml |
| 1723 | - ... |
| 1724 | + struct |
| 1725 | - structure.xml |
| 1726 | - ... |
| 1727 | + corenlp |
| 1728 | - morpho.xml |
| 1729 | - constituency.xml |
| 1730 | - ... |
| 1731 | + tree_tagger |
| 1732 | - morpho.xml |
| 1733 | - ... |
| 1734 | - ... |
| 1735 | |
| 1736 | The C<data.xml> contains the primary data, the C<header.xml> contains |
| 1737 | the metadata, and the annotation layers are stored in subfolders |
| 1738 | like C<base>, C<struct> or C<corenlp> |
| 1739 | (so-called "foundries"; Bański et al. 2013). |
| 1740 | |
| 1741 | Metadata is available in the TEI-P5 variant I5 |
Akron | d4c5c10 | 2020-02-11 11:47:59 +0100 | [diff] [blame] | 1742 | (Lüngen and Sperberg-McQueen 2012). See the documentation in |
| 1743 | L<KorAP::XML::Meta::I5> for translatable fields. |
| 1744 | |
| 1745 | Annotations correspond to a variant of the TEI-P5 feature structures |
| 1746 | (TEI Consortium; Lee et al. 2004). |
Akron | 72bc522 | 2020-02-06 16:00:13 +0100 | [diff] [blame] | 1747 | Annotation feature structures refer to character sequences of the primary text |
| 1748 | inside the C<text> element of the C<data.xml>. |
| 1749 | A single annotation containing the lemma of a token can have the following structure: |
| 1750 | |
| 1751 | <span from="0" to="3"> |
| 1752 | <fs type="lex" xmlns="http://www.tei-c.org/ns/1.0"> |
| 1753 | <f name="lex"> |
| 1754 | <fs> |
| 1755 | <f name="lemma">zum</f> |
| 1756 | </fs> |
| 1757 | </f> |
| 1758 | </fs> |
| 1759 | </span> |
| 1760 | |
| 1761 | The C<from> and C<to> attributes are refering to the character span |
| 1762 | in the primary text. |
| 1763 | Depending on the kind of annotation (e.g. token-based, span-based, relation-based), |
| 1764 | the structure may vary. See L<KorAP::XML::Annotation::*> for various |
| 1765 | annotation preprocessors. |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1766 | |
| 1767 | Multiple KorAP-XML documents are organized on three levels following |
| 1768 | the "IDS Textmodell" (Lüngen and Sperberg-McQueen 2012): |
| 1769 | corpus E<gt> document E<gt> text. On each level metadata information |
| 1770 | can be stored, that C<korapxml2krill> will merge to a single metadata |
| 1771 | object per text. A corpus is therefore structured as follows: |
| 1772 | |
| 1773 | + <corpus> |
| 1774 | - header.xml |
| 1775 | + <document> |
| 1776 | - header.xml |
| 1777 | + <text> |
| 1778 | - data.xml |
| 1779 | - header.xml |
| 1780 | - ... |
| 1781 | - ... |
| 1782 | |
| 1783 | A single text can be identified by the concatenation of |
| 1784 | the corpus identifier, the document identifier and the text identifier. |
| 1785 | This identifier is called the text sigle |
| 1786 | (e.g. a text with the identifier C<18486> in the document C<060> in the |
| 1787 | corpus C<WPD17> has the text sigle C<WPD17/060/18486>, see C<--sigle>). |
| 1788 | |
| 1789 | These corpora are often stored in zip files, with which C<korapxml2krill> |
| 1790 | can deal with. Corpora may also be split in multiple zip archives |
| 1791 | (e.g. one zip file per foundry), which is also supported (see C<--input>). |
| 1792 | |
| 1793 | Examples for KorAP-XML files are included in L<KorAP::XML::Krill> |
| 1794 | in form of a test suite. |
| 1795 | The resulting JSON format merges all annotation layers |
| 1796 | based on a single token stream. |
| 1797 | |
| 1798 | =head2 References |
| 1799 | |
| 1800 | Piotr Bański, Cyril Belica, Helge Krause, Marc Kupietz, Carsten Schnober, Oliver Schonefeld, and Andreas Witt (2011): |
| 1801 | KorAP data model: first approximation, December. |
| 1802 | |
| 1803 | Piotr Bański, Peter M. Fischer, Elena Frick, Erik Ketzan, Marc Kupietz, Carsten Schnober, Oliver Schonefeld and Andreas Witt (2012): |
| 1804 | "The New IDS Corpus Analysis Platform: Challenges and Prospects", |
| 1805 | Proceedings of the Eighth International Conference on Language Resources and Evaluation (LREC 2012). |
| 1806 | L<PDF|http://www.lrec-conf.org/proceedings/lrec2012/pdf/789_Paper.pdf> |
| 1807 | |
| 1808 | Piotr Bański, Elena Frick, Michael Hanl, Marc Kupietz, Carsten Schnober and Andreas Witt (2013): |
| 1809 | "Robust corpus architecture: a new look at virtual collections and data access", |
| 1810 | Corpus Linguistics 2013. Abstract Book. Lancaster: UCREL, pp. 23-25. |
| 1811 | L<PDF|https://ids-pub.bsz-bw.de/frontdoor/deliver/index/docId/4485/file/Ba%c5%84ski_Frick_Hanl_Robust_corpus_architecture_2013.pdf> |
| 1812 | |
| 1813 | Kiyong Lee, Lou Burnard, Laurent Romary, Eric de la Clergerie, Thierry Declerck, |
| 1814 | Syd Bauman, Harry Bunt, Lionel Clément, Tomaz Erjavec, Azim Roussanaly and Claude Roux (2004): |
| 1815 | "Towards an international standard on featurestructure representation", |
| 1816 | Proceedings of the fourth International Conference on Language Resources and Evaluation (LREC 2004), |
| 1817 | pp. 373-376. |
| 1818 | L<PDF|http://www.lrec-conf.org/proceedings/lrec2004/pdf/687.pdf> |
| 1819 | |
| 1820 | Harald Lüngen and C. M. Sperberg-McQueen (2012): |
| 1821 | "A TEI P5 Document Grammar for the IDS Text Model", |
| 1822 | Journal of the Text Encoding Initiative, Issue 3 | November 2012. |
| 1823 | L<PDF|https://journals.openedition.org/jtei/pdf/508> |
| 1824 | |
| 1825 | TEI Consortium, eds: |
| 1826 | "Feature Structures", |
| 1827 | Guidelines for Electronic Text Encoding and Interchange. |
| 1828 | L<html|https://www.tei-c.org/release/doc/tei-p5-doc/en/html/FS.html> |
| 1829 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1830 | =head1 AVAILABILITY |
| 1831 | |
| 1832 | https://github.com/KorAP/KorAP-XML-Krill |
| 1833 | |
| 1834 | |
| 1835 | =head1 COPYRIGHT AND LICENSE |
| 1836 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1837 | Copyright (C) 2015-2024, L<IDS Mannheim|https://www.ids-mannheim.de/> |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1838 | |
Akron | 6882d7d | 2021-02-08 09:43:57 +0100 | [diff] [blame] | 1839 | Author: L<Nils Diewald|https://www.nils-diewald.de/> |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1840 | |
Akron | 2912826 | 2024-04-17 15:50:36 +0200 | [diff] [blame] | 1841 | Contributor: Eliza Margaretha, Marc Kupietz |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1842 | |
Akron | 6882d7d | 2021-02-08 09:43:57 +0100 | [diff] [blame] | 1843 | L<KorAP::XML::Krill> is developed as part of the L<KorAP|https://korap.ids-mannheim.de/> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1844 | Corpus Analysis Platform at the |
Akron | 6882d7d | 2021-02-08 09:43:57 +0100 | [diff] [blame] | 1845 | L<Leibniz Institute for the German Language (IDS)|https://www.ids-mannheim.de/>, |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1846 | member of the |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 1847 | L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1848 | |
| 1849 | This program is free software published under the |
Akron | 6882d7d | 2021-02-08 09:43:57 +0100 | [diff] [blame] | 1850 | L<BSD-2 License|https://opensource.org/licenses/BSD-2-Clause>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1851 | |
| 1852 | =cut |