Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 4 | use v5.10; |
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 | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 16 | use Directory::Iterator; |
Akron | 41127e3 | 2020-08-07 12:46:19 +0200 | [diff] [blame] | 17 | use KorAP::XML::Krill qw!get_file_name get_file_name_from_glob!; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 18 | use KorAP::XML::Archive; |
Akron | eb370a0 | 2022-02-24 13:33:40 +0100 | [diff] [blame] | 19 | use KorAP::XML::TarBuilder; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 20 | use KorAP::XML::Tokenizer; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 21 | use KorAP::XML::Batch::File; |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 22 | use Config::Simple; |
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 | c0ac4ff | 2024-04-15 18:03:15 +0200 | [diff] [blame] | 181 | our $LAST_CHANGE = '2024/04/15'; |
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 | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 463 | # CMC |
| 464 | push(@layers, ['CMC', 'Morpho']); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 465 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 466 | # DeReKo |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 467 | my @dereko_attr = (); |
| 468 | if ($base_sentences eq 'dereko#structure') { |
| 469 | push @dereko_attr, 'sentences'; |
| 470 | }; |
| 471 | if ($base_paragraphs eq 'dereko#structure') { |
| 472 | push @dereko_attr, 'paragraphs'; |
| 473 | }; |
Akron | 636bd9c | 2017-02-09 17:13:00 +0100 | [diff] [blame] | 474 | |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 475 | if ($base_pagebreaks eq 'dereko#structure') { |
| 476 | push @dereko_attr, 'pagebreaks'; |
| 477 | }; |
| 478 | |
| 479 | if ($dereko_attr[0]) { |
| 480 | push(@layers, ['DeReKo', 'Structure', 'base-' . join('-', @dereko_attr)]); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 481 | } |
| 482 | else { |
| 483 | push(@layers, ['DeReKo', 'Structure']); |
| 484 | }; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 485 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 486 | # DGD |
| 487 | push(@layers, ['DGD', 'Morpho']); |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 488 | if ($base_sentences eq 'dgd#structure') { |
| 489 | push(@layers, ['DGD', 'Structure', 'base-sentence']); |
| 490 | } |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 491 | |
| 492 | # DRuKoLa |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 493 | push(@layers, |
| 494 | ['DRuKoLa', 'Morpho']); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 495 | |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 496 | # Gingko |
| 497 | push(@layers, |
| 498 | ['Gingko', 'Morpho']); |
| 499 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 500 | # Glemm |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 501 | push(@layers, |
| 502 | ['Glemm', 'Morpho']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 503 | |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 504 | # HNC |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 505 | push(@layers, |
| 506 | ['HNC', 'Morpho']); |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 507 | |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 508 | # LWC |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 509 | push(@layers, |
| 510 | ['LWC', 'Dependency']); |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 511 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 512 | # Malt |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 513 | push(@layers, |
| 514 | ['Malt', 'Dependency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 515 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 516 | # Marmot |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 517 | push(@layers, |
| 518 | ['MarMoT', 'Morpho']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 519 | |
| 520 | # Mate |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 521 | push(@layers, |
| 522 | ['Mate', 'Morpho'], |
| 523 | ['Mate', 'Dependency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 524 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 525 | # MDParser |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 526 | push(@layers, |
| 527 | ['MDParser', 'Dependency']); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 528 | |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 529 | # NKJP |
| 530 | push(@layers, |
Akron | a65cd68 | 2022-07-21 15:40:40 +0200 | [diff] [blame] | 531 | ['NKJP', 'Morpho'], |
| 532 | ['NKJP', 'NamedEntities']); |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 533 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 534 | # OpenNLP |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 535 | push(@layers, |
| 536 | ['OpenNLP', 'Morpho'], |
| 537 | ['OpenNLP', 'Sentences']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 538 | |
Akron | 07e2477 | 2020-04-23 14:00:54 +0200 | [diff] [blame] | 539 | # Redewiedergabe |
| 540 | push(@layers, ['RWK', 'Morpho']); |
| 541 | if ($base_sentences eq 'rwk#structure') { |
| 542 | push(@layers, ['RWK', 'Structure']); |
| 543 | }; |
| 544 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 545 | # Schreibgebrauch |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 546 | push(@layers, |
| 547 | ['Sgbr', 'Lemma'], |
| 548 | ['Sgbr', 'Morpho']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 549 | |
Marc Kupietz | b8c5382 | 2024-03-16 18:54:08 +0100 | [diff] [blame] | 550 | # Spacy |
| 551 | push(@layers, |
| 552 | ['Spacy', 'Morpho']); |
| 553 | |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 554 | # Talismane |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 555 | push(@layers, |
| 556 | ['Talismane', 'Dependency'], |
| 557 | ['Talismane', 'Morpho']); |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 558 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 559 | # TreeTagger |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 560 | push(@layers, |
| 561 | ['TreeTagger', 'Morpho'], |
| 562 | ['TreeTagger', 'Sentences']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 563 | |
Marc Kupietz | 400590b | 2022-12-23 16:02:36 +0100 | [diff] [blame] | 564 | # UDPipe |
| 565 | push(@layers, |
| 566 | ['UDPipe', 'Morpho'], |
| 567 | ['UDPipe', 'Dependency']); |
| 568 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 569 | # XIP |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 570 | push(@layers, |
| 571 | ['XIP', 'Morpho'], |
| 572 | ['XIP', 'Constituency'], |
| 573 | ['XIP', 'Sentences'], |
| 574 | ['XIP', 'Dependency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 575 | |
Akron | 4fa37c3 | 2017-01-20 14:43:10 +0100 | [diff] [blame] | 576 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 577 | # Check filters |
| 578 | my @filtered_anno; |
| 579 | if ($skip{'#all'}) { |
| 580 | foreach (@anno) { |
| 581 | push @filtered_anno, [ split('#', $_) ]; |
| 582 | }; |
| 583 | } |
| 584 | |
| 585 | # Add all annotations that are not skipped |
| 586 | else { |
| 587 | # Add to index file - respect skipping |
| 588 | foreach my $info (@layers) { |
| 589 | # Skip if Foundry or Foundry#Layer should be skipped |
| 590 | unless ($skip{lc($info->[0])} || $skip{lc($info->[0]) . '#' . lc($info->[1])}) { |
| 591 | push @filtered_anno, $info; |
| 592 | }; |
| 593 | }; |
| 594 | }; |
| 595 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 596 | |
| 597 | # TODO: This should not be initialized for batch |
| 598 | my $cache = Cache::FastMmap->new( |
| 599 | share_file => $cache_file, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 600 | cache_size => ($cfg{cache_size} // '50m'), |
Akron | c0ac4ff | 2024-04-15 18:03:15 +0200 | [diff] [blame] | 601 | init_file => ($cfg{cache_init} // 1), |
| 602 | unlink_on_exit => $cache_delete |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 603 | ); |
| 604 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 605 | # Create batch object |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 606 | my $batch_file = KorAP::XML::Batch::File->new( |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 607 | cache => $cache, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 608 | meta_type => $cfg{meta}, |
| 609 | overwrite => $cfg{overwrite}, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 610 | foundry => $token_base_foundry, |
| 611 | layer => $token_base_layer, |
| 612 | gzip => $gzip, |
| 613 | log => $log, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 614 | koral => ($cfg{koral} // $KORAL_VERSION), |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 615 | anno => \@filtered_anno, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 616 | non_word_tokens => ($cfg{non_word_tokens} // 0), |
Akron | 64f7fae | 2022-07-27 12:45:33 +0200 | [diff] [blame] | 617 | non_verbal_tokens => ($cfg{non_verbal_tokens} // 0), |
| 618 | lang => $cfg{lang}, |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 619 | ); |
| 620 | |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 621 | # Auto adjust jobs |
| 622 | if ($jobs eq '-1') { |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame^] | 623 | ($jobs, my $msg) = count_jobs(); |
| 624 | print $msg . "\n" unless $q; |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 625 | }; |
| 626 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 627 | # Glob and prefix files |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 628 | if (@input > 0) { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 629 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 630 | my @new_input = (); |
| 631 | |
| 632 | # Iterate over all inputs |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 633 | foreach my $wild_card (@input) { |
| 634 | |
| 635 | # Prefix with input root |
| 636 | $wild_card = $input_base ? catfile($input_base, $wild_card) : $wild_card; |
| 637 | |
| 638 | push (@new_input, bsd_glob($wild_card)); |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 639 | }; |
| 640 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 641 | # Sort files by length |
| 642 | @input = sort { length($a) <=> length($b) } @new_input; |
| 643 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 644 | print 'Input is ' . join(', ', @input)."\n" unless $q; |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 645 | }; |
| 646 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 647 | # Process a single file |
| 648 | unless ($cmd) { |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 649 | my $input = $input[0]; |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 650 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 651 | BEGIN { |
| 652 | $main::TIME = Benchmark->new; |
| 653 | $main::LAST_STOP = Benchmark->new; |
| 654 | }; |
| 655 | |
| 656 | sub stop_time { |
| 657 | my $new = Benchmark->new; |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 658 | $log->info( |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 659 | 'The code took: '. |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 660 | timestr(timediff($new, $main::LAST_STOP)) . |
| 661 | ' (overall: ' . timestr(timediff($new, $main::TIME)) . ')' |
| 662 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 663 | $main::LAST_STOP = $new; |
| 664 | }; |
| 665 | |
| 666 | # Create and parse new document |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 667 | $input =~ s{([^/])$}{$1/}o; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 668 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 669 | # Process file |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 670 | $batch_file->process($input, $output); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 671 | |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 672 | stop_time; |
Akron | c0ac4ff | 2024-04-15 18:03:15 +0200 | [diff] [blame] | 673 | |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 674 | exit; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 675 | }; |
| 676 | |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 677 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 678 | # Extract XML files |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 679 | if ($cmd eq 'extract') { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 680 | |
Akron | d5643ad | 2017-07-04 20:27:13 +0200 | [diff] [blame] | 681 | # Output is required |
| 682 | pod2usage(%ERROR_HASH) unless $output; |
| 683 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 684 | # Create new archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 685 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 686 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 687 | # Check zip capabilities |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 688 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 689 | $log->error("Unzip is not installed or incompatible."); |
| 690 | exit 1; |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 691 | }; |
| 692 | |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 693 | # Add further annotation archived |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 694 | $archive->attach($_) foreach @input[1..$#input]; |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 695 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 696 | # Will set @sigle |
| 697 | my $prefix = set_sigle($archive); |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 698 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 699 | # Iterate over all given sigles and extract |
| 700 | foreach (@sigle) { |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 701 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 702 | unless ($q) { |
| 703 | print "$_ ...\n"; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 704 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 705 | # TODO: Make this OS independent |
| 706 | print '... ' . ( |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 707 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 708 | # TODO: |
| 709 | # - prefix??? |
| 710 | $archive->extract_sigle(0, [$_], $output, $jobs) |
| 711 | ? '' : 'not ' |
| 712 | ); |
| 713 | print "extracted.\n"; |
| 714 | } else { |
| 715 | $archive->extract_sigle(1, [$_], $output, $jobs); |
| 716 | } |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 717 | }; |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 718 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 719 | |
| 720 | # Can't create archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 721 | else { |
| 722 | $log->error('Unable to extract from primary archive ' . $input[0]); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 723 | exit 1; |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 724 | }; |
| 725 | } |
| 726 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 727 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 728 | # Process an archive |
| 729 | elsif ($cmd eq 'archive') { |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 730 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 731 | my $archive_output; |
| 732 | |
| 733 | # First extract, then archive |
Akron | 63d03ee | 2019-02-13 18:49:38 +0100 | [diff] [blame] | 734 | if (defined $extract_dir && !-d $input[0]) { |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 735 | |
| 736 | # Create new archive object |
| 737 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
| 738 | |
| 739 | # Check zip capabilities |
| 740 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 741 | $log->error("Unzip is not installed or incompatible."); |
| 742 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 743 | }; |
| 744 | |
| 745 | # Add further annotation archived |
| 746 | $archive->attach($_) foreach @input[1..$#input]; |
| 747 | |
| 748 | # Create a temporary directory |
| 749 | if ($extract_dir eq ':temp:') { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 750 | $extract_dir = tempdir(CLEANUP => 0); |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 751 | print "Temporarily extract to $extract_dir\n" unless $q; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 752 | }; |
| 753 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 754 | # Add some random extra to avoid clashes with multiple archives |
| 755 | $extract_dir = catdir($extract_dir, random_string('cccccc')); |
| 756 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 757 | # Extract to temporary directory |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 758 | if ($archive->extract_all($q, $extract_dir, $sequential_extraction ? 1: $jobs)) { |
| 759 | print "Extract sequentially to $extract_dir\n" unless $q; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 760 | @input = ($extract_dir); |
| 761 | } |
| 762 | else { |
| 763 | $log->error('Unable to extract from primary archive ' . $input[0] . |
| 764 | ' to ' . $extract_dir); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 765 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 766 | }; |
| 767 | } |
| 768 | |
| 769 | # Can't create archive object |
| 770 | else { |
| 771 | $log->error('Unable to extract from primary archive ' . $input[0]); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 772 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 773 | }; |
| 774 | }; |
| 775 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 776 | # Zero means: everything runs in the parent process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 777 | my $pool = Parallel::ForkManager->new($jobs); |
| 778 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 779 | my $count = 0; # Texts to process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 780 | my $iter = 1; # Current text in process |
| 781 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 782 | my $tar_archive; |
| 783 | my $output_dir = $output; |
| 784 | my $tar_fh; |
| 785 | |
| 786 | # Initialize tar archive |
| 787 | if ($to_tar) { |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 788 | |
| 789 | # Set output name |
| 790 | my $tar_file = $output; |
| 791 | unless ($tar_file =~ /\.tar$/) { |
| 792 | $tar_file .= '.tar'; |
| 793 | }; |
| 794 | |
| 795 | # Initiate the tar file |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 796 | print "Writing to file $tar_file\n" unless $q; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 797 | $tar_fh = IO::File->new($tar_file, 'w'); |
| 798 | $tar_fh->binmode(1); |
| 799 | |
Akron | eb370a0 | 2022-02-24 13:33:40 +0100 | [diff] [blame] | 800 | # Use tar builder for archiving |
| 801 | if (eval("use Archive::Tar::Builder; 1;")) { |
| 802 | $tar_archive = Archive::Tar::Builder->new( |
| 803 | ignore_errors => 1 |
| 804 | ); |
| 805 | |
| 806 | # Set handle |
| 807 | $tar_archive->set_handle($tar_fh); |
| 808 | } |
| 809 | |
| 810 | # Fallback solution |
| 811 | else { |
| 812 | $tar_archive = KorAP::XML::TarBuilder->new( |
| 813 | $tar_fh |
| 814 | ); |
| 815 | }; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 816 | |
| 817 | # Output to temporary directory |
| 818 | $output_dir = File::Temp->newdir; |
| 819 | }; |
| 820 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 821 | # Report on fork message |
| 822 | $pool->run_on_finish ( |
| 823 | sub { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 824 | my ($pid, $code) = @_; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 825 | my $data = pop; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 826 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 827 | unless ($q) { |
| 828 | print 'Convert ['. ($jobs > 0 ? "\$$pid:" : '') . |
| 829 | $iter . "/$count]" . |
| 830 | ($code ? " $code" : '') . |
| 831 | ' ' . $data->[0] . "\n"; |
| 832 | }; |
| 833 | $iter++; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 834 | |
| 835 | if (!$code && $to_tar && $data->[2]) { |
| 836 | my $filename = $data->[2]; |
| 837 | |
| 838 | # Lock filehandle |
| 839 | if (flock($tar_fh, LOCK_EX)) { |
| 840 | |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 841 | my $clean_file = fileparse($filename); |
| 842 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 843 | # Archive and remove file |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 844 | $tar_archive->archive_as($filename => $clean_file); |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 845 | unlink $filename; |
| 846 | |
| 847 | # Unlock filehandle |
| 848 | flock($tar_fh, LOCK_UN); |
| 849 | } |
| 850 | else { |
| 851 | $log->warn("Unable to add $filename to archive"); |
| 852 | }; |
| 853 | }; |
| 854 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 855 | $data->[1] = undef if $data->[1]; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 856 | } |
| 857 | ); |
| 858 | |
| 859 | my $t; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 860 | my $temp; |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 861 | print "Reading data ...\n" unless $q; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 862 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 863 | # unless (Cache::FastMmap->new( |
| 864 | # share_file => $cache_file, |
| 865 | # cache_size => $cache_size, |
| 866 | # init_file => $cache_init |
| 867 | # )) { |
| 868 | # print "Unable to intialize cache '$cache_file'\n\n"; |
| 869 | # exit(1); |
| 870 | # }; |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 871 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 872 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 873 | # Input is a directory |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 874 | if (-d $input[0]) { |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 875 | # TODO: |
| 876 | # Replace with Mojo::File |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 877 | my $it = Directory::Iterator->new($input[0]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 878 | my @dirs; |
| 879 | my $dir; |
| 880 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 881 | # Todo: Make a DO WHILE |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 882 | while (1) { |
| 883 | if (!$it->is_directory && ($dir = $it->get) && $dir =~ s{/data\.xml$}{}) { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 884 | push @dirs, $dir; |
| 885 | $it->prune; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 886 | }; |
| 887 | last unless $it->next; |
| 888 | }; |
| 889 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 890 | print "Start processing ...\n" unless $q; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 891 | $t = Benchmark->new; |
| 892 | $count = scalar @dirs; |
| 893 | |
| 894 | DIRECTORY_LOOP: |
| 895 | for (my $i = 0; $i < $count; $i++) { |
| 896 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 897 | my $filename = catfile( |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 898 | $output_dir, |
Akron | 41127e3 | 2020-08-07 12:46:19 +0200 | [diff] [blame] | 899 | get_file_name($input[0], $dirs[$i]) . '.json' . ($gzip ? '.gz' : '') |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 900 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 901 | |
| 902 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 903 | $pool->start and next DIRECTORY_LOOP; |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 904 | |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 905 | if (my $return = $batch_file->process($dirs[$i] => $filename)) { |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 906 | $pool->finish( |
| 907 | 0, |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 908 | [ |
| 909 | "Processed " . $filename . ($return == -1 ? " - already existing" : ''), |
| 910 | undef, |
| 911 | $filename |
| 912 | ] |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 913 | ); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 914 | } |
| 915 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 916 | $pool->finish(1, ["Unable to process " . $dirs[$i]]); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 917 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 918 | }; |
| 919 | } |
| 920 | |
| 921 | # Input is a file |
Akron | 29866ac | 2016-06-24 16:40:47 +0200 | [diff] [blame] | 922 | elsif (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 923 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 924 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 925 | $log->error("Unzip is not installed or incompatible."); |
| 926 | exit 1; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 927 | }; |
| 928 | |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 929 | # Add further annotation archived |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 930 | $archive->attach($_) foreach @input[1..$#input]; |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 931 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 932 | # Get sigles to extract |
| 933 | my $prefix = set_sigle($archive); |
| 934 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 935 | print "Start processing ...\n" unless $q; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 936 | $t = Benchmark->new; |
| 937 | my @dirs = $archive->list_texts; |
| 938 | $count = scalar @dirs; |
| 939 | |
| 940 | ARCHIVE_LOOP: |
| 941 | for (my $i = 0; $i < $count; $i++) { |
| 942 | |
| 943 | # Split path information |
| 944 | my ($prefix, $corpus, $doc, $text) = $archive->split_path($dirs[$i]); |
| 945 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 946 | my $filename = catfile( |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 947 | $output_dir, |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 948 | get_file_name( |
Akron | 41127e3 | 2020-08-07 12:46:19 +0200 | [diff] [blame] | 949 | $input[0], |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 950 | catfile($corpus, $doc, $text) |
| 951 | . '.json' . ($gzip ? '.gz' : '') |
| 952 | ) |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 953 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 954 | |
| 955 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 956 | $pool->start and next ARCHIVE_LOOP; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 957 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 958 | # Create temporary file |
| 959 | $temp = File::Temp->newdir; |
| 960 | |
Akron | bdf434a | 2016-10-24 17:42:07 +0200 | [diff] [blame] | 961 | # TODO: Check if $filename exist at the beginning, |
| 962 | # because extraction can be horrible slow! |
| 963 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 964 | # Extract from archive |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 965 | 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] | 966 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 967 | # Create corpus directory |
| 968 | my $input = catdir("$temp", $corpus); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 969 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 970 | # Temporary directory |
| 971 | my $dir = catdir($input, $doc, $text); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 972 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 973 | # Write file |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 974 | if (my $return = $batch_file->process($dir => $filename)) { |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 975 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 976 | # Delete temporary file |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 977 | $pool->finish( |
| 978 | 0, |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 979 | [ |
| 980 | "Processed " . $filename . ($return == -1 ? " - already existing" : ''), |
| 981 | $temp, |
| 982 | $filename |
| 983 | ] |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 984 | ); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 985 | } |
| 986 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 987 | # Delete temporary file |
| 988 | $pool->finish(1, ["Unable to process " . $dir, $temp]); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 989 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 990 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 991 | |
| 992 | # Unable to extract |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 993 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 994 | $pool->finish(1, ["Unable to extract " . $dirs[$i], $temp]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 995 | }; |
| 996 | }; |
| 997 | } |
| 998 | |
| 999 | else { |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1000 | print "Input is neither a directory nor an archive.\n\n" unless $q; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1001 | }; |
| 1002 | |
| 1003 | $pool->wait_all_children; |
| 1004 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 1005 | # Close tar filehandle |
| 1006 | if ($to_tar && $tar_fh) { |
| 1007 | $tar_archive->finish; |
| 1008 | $tar_fh->close; |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1009 | print "Wrote to tar archive.\n" unless $q; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 1010 | }; |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1011 | unless ($q) { |
| 1012 | print timestr(timediff(Benchmark->new, $t))."\n"; |
| 1013 | print "Done.\n"; |
| 1014 | }; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1015 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1016 | |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 1017 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1018 | # For an archive, this will create the list |
| 1019 | # of all sigles to process |
| 1020 | sub set_sigle { |
| 1021 | my $archive = shift; |
| 1022 | |
| 1023 | my $prefix = 1; |
| 1024 | my @dirs = (); |
| 1025 | |
| 1026 | # No sigles given |
| 1027 | unless (@sigle) { |
| 1028 | |
| 1029 | # Get files |
| 1030 | foreach ($archive->list_texts) { |
| 1031 | |
| 1032 | push @dirs, $_; |
| 1033 | |
| 1034 | # Split path information |
| 1035 | ($prefix, my ($corpus, $doc, $text)) = $archive->split_path($_); |
| 1036 | |
| 1037 | # TODO: Make this OS independent |
| 1038 | push @sigle, join '/', $corpus, $doc, $text; |
| 1039 | }; |
| 1040 | } |
| 1041 | |
| 1042 | # Check sigle for doc sigles |
| 1043 | else { |
| 1044 | my @new_sigle; |
| 1045 | |
| 1046 | my $prefix_check = 0; |
| 1047 | |
| 1048 | # Iterate over all sigle |
| 1049 | foreach (@sigle) { |
| 1050 | |
| 1051 | # Sigle is a doc sigle |
| 1052 | if ($_ =~ m!^(?:\.[/\\])?[^/\\]+?[/\\][^/\\]+?$!) { |
| 1053 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1054 | print "$_ ..." unless $q; |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1055 | # Check if a prefix is needed |
| 1056 | unless ($prefix_check) { |
| 1057 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1058 | if ($prefix = $archive->check_prefix && !$q) { |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1059 | print " with prefix ..."; |
| 1060 | }; |
| 1061 | $prefix_check = 1; |
| 1062 | }; |
| 1063 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1064 | unless ($q) { |
| 1065 | print "\n"; |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1066 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1067 | print '... ' . ( |
| 1068 | $archive->extract_sigle($q, [$_], $output, $sequential_extraction ? 1 : $jobs) |
Akron | 955b75b | 2019-02-21 14:28:41 +0100 | [diff] [blame] | 1069 | ? '' : 'not ' |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1070 | ); |
| 1071 | print "extracted.\n"; |
| 1072 | } |
| 1073 | else { |
| 1074 | $archive->extract_sigle($q, [$_], $output, $sequential_extraction ? 1 : $jobs) |
| 1075 | }; |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | # Sigle is a text sigle |
| 1079 | else { |
| 1080 | push @new_sigle, $_; |
| 1081 | |
| 1082 | unless ($prefix_check) { |
| 1083 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1084 | if ($prefix = $archive->check_prefix && !$q) { |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1085 | print " with prefix ..."; |
| 1086 | }; |
| 1087 | $prefix_check = 1; |
| 1088 | }; |
| 1089 | }; |
| 1090 | }; |
| 1091 | @sigle = @new_sigle; |
| 1092 | }; |
| 1093 | |
| 1094 | return $prefix; |
| 1095 | }; |
| 1096 | |
| 1097 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1098 | # Cleanup temporary extraction directory |
| 1099 | if ($extract_dir) { |
| 1100 | my $objects = remove_tree($extract_dir, { safe => 1 }); |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 1101 | $log->info("Removed directory $extract_dir with $objects objects"); |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1102 | }; |
| 1103 | |
| 1104 | |
| 1105 | print "\n"; |
| 1106 | |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 1107 | __END__ |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1108 | |
| 1109 | =pod |
| 1110 | |
| 1111 | =encoding utf8 |
| 1112 | |
| 1113 | =head1 NAME |
| 1114 | |
Akron | 42f48c1 | 2020-02-14 13:08:13 +0100 | [diff] [blame] | 1115 | korapxml2krill - Merge KorAP-XML data and create Krill documents |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1116 | |
| 1117 | |
| 1118 | =head1 SYNOPSIS |
| 1119 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1120 | $ korapxml2krill [archive|extract] --input <directory|archive> [options] |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1121 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1122 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1123 | =head1 DESCRIPTION |
| 1124 | |
| 1125 | L<KorAP::XML::Krill> is a library to convert KorAP-XML documents to files |
| 1126 | compatible with the L<Krill|https://github.com/KorAP/Krill> indexer. |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1127 | The C<korapxml2krill> command line tool is a simple wrapper of this library. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1128 | |
| 1129 | |
| 1130 | =head1 INSTALLATION |
| 1131 | |
| 1132 | The preferred way to install L<KorAP::XML::Krill> is to use L<cpanm|App::cpanminus>. |
| 1133 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1134 | $ cpanm https://github.com/KorAP/KorAP-XML-Krill.git |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1135 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1136 | In case everything went well, the C<korapxml2krill> tool will |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1137 | be available on your command line immediately. |
Akron | 8ce23f7 | 2023-12-13 15:48:49 +0100 | [diff] [blame] | 1138 | Minimum requirement for L<KorAP::XML::Krill> is Perl 5.32. |
Akron | eb370a0 | 2022-02-24 13:33:40 +0100 | [diff] [blame] | 1139 | Optionally installing L<Archive::Tar::Builder> speeds up archive building. |
| 1140 | Optional support for L<Sys::Info> to calculate available cores is available. |
Akron | a93d51b | 2016-10-24 20:27:48 +0200 | [diff] [blame] | 1141 | 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] | 1142 | |
| 1143 | =head1 ARGUMENTS |
| 1144 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1145 | $ korapxml2krill -z --input <directory> --output <filename> |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1146 | |
| 1147 | Without arguments, C<korapxml2krill> converts a directory of a single KorAP-XML document. |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1148 | It expects the input to point to the text level folder. |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1149 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1150 | =over 2 |
| 1151 | |
| 1152 | =item B<archive> |
| 1153 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1154 | $ korapxml2krill archive -z --input <directory|archive> --output <directory|tar> |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1155 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1156 | Converts an archive of KorAP-XML documents. It expects a directory |
| 1157 | (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] | 1158 | |
| 1159 | =item B<extract> |
| 1160 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1161 | $ korapxml2krill extract --input <archive> --output <directory> --sigle <SIGLE> |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1162 | |
| 1163 | Extracts KorAP-XML documents from a zip file. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1164 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1165 | =item B<serial> |
| 1166 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1167 | $ korapxml2krill serial -i <archive1> -i <archive2> -o <directory> -cfg <config-file> |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1168 | |
| 1169 | Convert archives sequentially. The inputs are not merged but treated |
| 1170 | as they are (so they may be premerged or globs). |
| 1171 | the C<--out> directory is treated as the base directory where subdirectories |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 1172 | are created based on the archive name. In case the C<--to-tar> flag is given, |
| 1173 | the output will be a tar file. |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1174 | |
| 1175 | |
Akron | 84b53ad | 2022-01-14 12:39:15 +0100 | [diff] [blame] | 1176 | =item B<slimlog> |
| 1177 | |
Akron | 9cb8c98 | 2024-03-22 10:46:56 +0100 | [diff] [blame] | 1178 | $ korapxml2krill slimlog <logfile> > <logfile-slim> |
Akron | 84b53ad | 2022-01-14 12:39:15 +0100 | [diff] [blame] | 1179 | |
| 1180 | Filters out all useless aka succesfull information from logs, to simplify |
| 1181 | log checks. Expects no further options. |
| 1182 | |
| 1183 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1184 | =back |
| 1185 | |
| 1186 | |
| 1187 | =head1 OPTIONS |
| 1188 | |
| 1189 | =over 2 |
| 1190 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1191 | =item B<--input|-i> <directory|zip file> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1192 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1193 | Directory or zip file(s) of documents to convert. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1194 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1195 | Without arguments, C<korapxml2krill> expects a folder of a single KorAP-XML |
Akron | f1a1de9 | 2016-11-02 17:32:12 +0100 | [diff] [blame] | 1196 | document, while C<archive> expects a KorAP-XML corpus folder or a zip |
| 1197 | file to batch process multiple files. |
| 1198 | C<extract> expects zip files only. |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1199 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1200 | C<archive> supports multiple input zip files with the constraint, |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1201 | that the first archive listed contains all primary data files |
| 1202 | and all meta data files. |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1203 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1204 | -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] | 1205 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1206 | Input may also be defined using BSD glob wildcards. |
| 1207 | |
| 1208 | -i 'file/news*.zip' |
| 1209 | |
| 1210 | The extended input array will be sorted in length order, so the shortest |
| 1211 | path needs to contain all primary data files and all meta data files. |
| 1212 | |
Akron | 0c3e375 | 2016-06-28 15:55:53 +0200 | [diff] [blame] | 1213 | (The directory structure follows the base directory format, |
| 1214 | that may include a C<.> root folder. |
| 1215 | In this case further archives lacking a C<.> root folder |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1216 | need to be passed with a hash sign in front of the archive's name. |
| 1217 | This may require to quote the parameter.) |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1218 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1219 | To support zip files, a version of C<unzip> needs to be installed that is |
| 1220 | compatible with the archive file. |
Akron | a93d51b | 2016-10-24 20:27:48 +0200 | [diff] [blame] | 1221 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1222 | B<The root folder switch using the hash sign is experimental and |
| 1223 | may vanish in future versions.> |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 1224 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1225 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1226 | =item B<--input-base|-ib> <directory> |
| 1227 | |
| 1228 | The base directory for inputs. |
| 1229 | |
| 1230 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1231 | =item B<--output|-o> <directory|file> |
| 1232 | |
| 1233 | Output folder for archive processing or |
| 1234 | document name for single output (optional), |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1235 | writes to C<STDOUT> by default |
| 1236 | (in case C<output> is not mandatory due to further options). |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1237 | |
| 1238 | =item B<--overwrite|-w> |
| 1239 | |
| 1240 | Overwrite files that already exist. |
| 1241 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1242 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1243 | =item B<--token|-t> <foundry>#<file> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1244 | |
| 1245 | Define the default tokenization by specifying |
| 1246 | the name of the foundry and optionally the name |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1247 | of the layer-file. Defaults to C<OpenNLP#tokens>. |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 1248 | This will directly take the file instead of running |
| 1249 | the layer implementation! |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1250 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1251 | |
| 1252 | =item B<--base-sentences|-bs> <foundry>#<layer> |
| 1253 | |
| 1254 | Define the layer for base sentences. |
| 1255 | If given, this will be used instead of using C<Base#Sentences>. |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 1256 | Currently C<DeReKo#Structure> and C<DGD#Structure> are the only additional |
| 1257 | layers supported. |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1258 | |
| 1259 | Defaults to unset. |
| 1260 | |
| 1261 | |
| 1262 | =item B<--base-paragraphs|-bp> <foundry>#<layer> |
| 1263 | |
| 1264 | Define the layer for base paragraphs. |
| 1265 | If given, this will be used instead of using C<Base#Paragraphs>. |
Akron | 0ffbd52 | 2021-02-16 12:01:19 +0100 | [diff] [blame] | 1266 | Currently C<DeReKo#Structure> and C<DGD#Structure> are the only additional |
| 1267 | layer supported. |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1268 | |
| 1269 | Defaults to unset. |
| 1270 | |
| 1271 | |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 1272 | =item B<--base-pagebreaks|-bpb> <foundry>#<layer> |
| 1273 | |
| 1274 | Define the layer for base pagebreaks. |
| 1275 | Currently C<DeReKo#Structure> is the only layer supported. |
| 1276 | |
| 1277 | Defaults to unset. |
| 1278 | |
| 1279 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1280 | =item B<--skip|-s> <foundry>[#<layer>] |
| 1281 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1282 | Skip specific annotations by specifying the foundry |
| 1283 | (and optionally the layer with a C<#>-prefix), |
| 1284 | 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] | 1285 | Can be set multiple times. |
| 1286 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1287 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1288 | =item B<--anno|-a> <foundry>#<layer> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1289 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1290 | Convert specific annotations by specifying the foundry |
| 1291 | (and optionally the layer with a C<#>-prefix), |
| 1292 | e.g. C<Mate> or C<Mate#Morpho>. |
| 1293 | Can be set multiple times. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1294 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1295 | |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 1296 | =item B<--non-word-tokens|-nwt> |
| 1297 | |
| 1298 | Tokenize non-word tokens like word tokens (defined as matching |
| 1299 | C</[\d\w]/>). Useful to treat punctuations as tokens. |
| 1300 | |
| 1301 | Defaults to unset. |
| 1302 | |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 1303 | |
| 1304 | =item B<--non-verbal-tokens|-nvt> |
| 1305 | |
| 1306 | Tokenize non-verbal tokens marked as in the primary data as |
| 1307 | the unicode symbol 'Black Vertical Rectangle' aka \x25ae. |
| 1308 | |
| 1309 | Defaults to unset. |
| 1310 | |
| 1311 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1312 | =item B<--jobs|-j> |
| 1313 | |
Akron | 2912826 | 2024-04-17 15:50:36 +0200 | [diff] [blame] | 1314 | Define the number of spawned forks for concurrent jobs |
| 1315 | of archive processing. |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1316 | Defaults to C<0> (everything runs in a single process). |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1317 | |
Akron | a472a24 | 2023-02-13 13:46:30 +0100 | [diff] [blame] | 1318 | If C<sequential-extraction> is not set to true, this will |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1319 | also apply to extraction. |
| 1320 | |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame^] | 1321 | Pass C<-1>, and the value will be set automatically to 5 |
Akron | 0b04b31 | 2020-10-30 17:39:18 +0100 | [diff] [blame] | 1322 | times the number of available cores, in case L<Sys::Info> |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame^] | 1323 | is available and can read CPU count (see C<--job-count>). |
| 1324 | Be aware, that the report of available cores |
Akron | 2912826 | 2024-04-17 15:50:36 +0200 | [diff] [blame] | 1325 | may not work in certain conditions. Benchmarking the processing |
| 1326 | speed based on the number of jobs may be valuable. |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame^] | 1327 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1328 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1329 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1330 | |
Akron | ebbac2e | 2024-03-22 10:31:23 +0100 | [diff] [blame^] | 1331 | =item B<--job-count|-jc> |
| 1332 | |
| 1333 | Print job and core information that would be used if |
| 1334 | C<-1> was passed to C<--jobs>. |
| 1335 | |
| 1336 | |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 1337 | =item B<--koral|-k> |
| 1338 | |
| 1339 | Version of the output format. Supported versions are: |
| 1340 | C<0> for legacy serialization, C<0.03> for serialization |
| 1341 | with metadata fields as key-values on the root object, |
| 1342 | C<0.4> for serialization with metadata fields as a list |
| 1343 | of C<"@type":"koral:field"> objects. |
| 1344 | |
| 1345 | Currently defaults to C<0.03>. |
| 1346 | |
| 1347 | |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1348 | =item B<--sequential-extraction|-se> |
| 1349 | |
| 1350 | Flag to indicate, if the C<jobs> value also applies to extraction. |
| 1351 | Some systems may have problems with extracting multiple archives |
| 1352 | to the same folder at the same time. |
| 1353 | Can be flagged using C<--no-sequential-extraction> as well. |
| 1354 | Defaults to C<false>. |
| 1355 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1356 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1357 | =item B<--meta|-m> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1358 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1359 | Define the metadata parser to use. Defaults to C<I5>. |
| 1360 | Metadata parsers can be defined in the C<KorAP::XML::Meta> namespace. |
| 1361 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1362 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1363 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1364 | =item B<--gzip|-z> |
| 1365 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1366 | Compress the output. |
| 1367 | Expects a defined C<output> file in single processing. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1368 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1369 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1370 | =item B<--cache|-c> |
| 1371 | |
| 1372 | File to mmap a cache (using L<Cache::FastMmap>). |
| 1373 | Defaults to C<korapxml2krill.cache> in the calling directory. |
| 1374 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1375 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1376 | =item B<--cache-size|-cs> |
| 1377 | |
| 1378 | Size of the cache. Defaults to C<50m>. |
| 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-init|-ci> |
| 1382 | |
| 1383 | Initialize cache file. |
| 1384 | Can be flagged using C<--no-cache-init> as well. |
| 1385 | Defaults to C<true>. |
| 1386 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1387 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1388 | =item B<--cache-delete|-cd> |
| 1389 | |
| 1390 | Delete cache file after processing. |
| 1391 | Can be flagged using C<--no-cache-delete> as well. |
| 1392 | Defaults to C<true>. |
| 1393 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1394 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1395 | =item B<--config|-cfg> |
| 1396 | |
| 1397 | Configure the parameters of your call in a file |
| 1398 | of key-value pairs with whitespace separator |
| 1399 | |
| 1400 | overwrite 1 |
| 1401 | token DeReKo#Structure |
| 1402 | ... |
| 1403 | |
| 1404 | Supported parameters are: |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1405 | C<overwrite>, C<gzip>, C<jobs>, C<input-base>, |
Akron | c0ac4ff | 2024-04-15 18:03:15 +0200 | [diff] [blame] | 1406 | C<token>, C<log>, |
| 1407 | C<cache>, C<cache-size>, C<cache-init>, C<cache-delete>, C<meta>, |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1408 | C<output>, C<koral>, |
Akron | eb370a0 | 2022-02-24 13:33:40 +0100 | [diff] [blame] | 1409 | C<temporary-extract>, C<sequential-extraction>, |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1410 | C<base-sentences>, C<base-paragraphs>, |
| 1411 | C<base-pagebreaks>, |
| 1412 | C<skip> (semicolon separated), C<sigle> |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1413 | (semicolon separated), C<anno> (semicolon separated). |
| 1414 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1415 | Configuration parameters will always be overwritten by |
| 1416 | passed parameters. |
| 1417 | |
| 1418 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1419 | =item B<--temporary-extract|-te> |
| 1420 | |
Akron | a472a24 | 2023-02-13 13:46:30 +0100 | [diff] [blame] | 1421 | Only valid for the C<archive> and C<serial> |
| 1422 | commands. |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1423 | |
| 1424 | This will first extract all files into a |
| 1425 | directory and then will archive. |
| 1426 | If the directory is given as C<:temp:>, |
| 1427 | a temporary directory is used. |
| 1428 | This is especially useful to avoid |
| 1429 | massive unzipping and potential |
| 1430 | network latency. |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1431 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1432 | |
Akron | c93a080 | 2019-07-11 15:48:34 +0200 | [diff] [blame] | 1433 | =item B<--to-tar> |
| 1434 | |
| 1435 | Only valid for the C<archive> command. |
| 1436 | |
| 1437 | Writes the output into a tar archive. |
| 1438 | |
| 1439 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1440 | =item B<--sigle|-sg> |
| 1441 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1442 | Extract the given texts. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1443 | Can be set multiple times. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1444 | I<Currently only supported on C<extract>.> |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 1445 | Sigles have the structure C<Corpus>/C<Document>/C<Text>. |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1446 | 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] | 1447 | On the document level, the postfix wildcard C<*> is supported. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1448 | |
Akron | 64f7fae | 2022-07-27 12:45:33 +0200 | [diff] [blame] | 1449 | =item B<--lang> |
| 1450 | |
| 1451 | Preferred language for metadata fields. In case multiple titles are |
| 1452 | given (on any level) with different C<xml:lang> attributes, |
| 1453 | the language given is preferred. |
| 1454 | Because titles may have different sources and different priorities, |
| 1455 | non-specific language titles may still be preferred in case the title |
| 1456 | source has a higher priority. |
| 1457 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1458 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1459 | =item B<--log|-l> |
| 1460 | |
Akron | b9c3381 | 2020-10-21 16:19:35 +0200 | [diff] [blame] | 1461 | The L<Log::Any> log level, defaults to C<ERROR>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1462 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1463 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1464 | =item B<--quiet> |
| 1465 | |
| 1466 | Silence all information (non-log) outputs. |
| 1467 | |
| 1468 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1469 | =item B<--help|-h> |
| 1470 | |
Akron | 42f48c1 | 2020-02-14 13:08:13 +0100 | [diff] [blame] | 1471 | Print help information. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1472 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1473 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1474 | =item B<--version|-v> |
| 1475 | |
| 1476 | Print version information. |
| 1477 | |
| 1478 | =back |
| 1479 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1480 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1481 | =head1 ANNOTATION SUPPORT |
| 1482 | |
| 1483 | L<KorAP::XML::Krill> has built-in importer for some annotation foundries and layers |
| 1484 | developed in the KorAP project that are part of the KorAP preprocessing pipeline. |
| 1485 | The base foundry with paragraphs, sentences, and the text element are mandatory for |
| 1486 | L<Krill|https://github.com/KorAP/Krill>. |
| 1487 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1488 | Base |
| 1489 | #Paragraphs |
| 1490 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1491 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1492 | Connexor |
| 1493 | #Morpho |
| 1494 | #Phrase |
| 1495 | #Sentences |
| 1496 | #Syntax |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1497 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1498 | CoreNLP |
| 1499 | #Constituency |
| 1500 | #Morpho |
| 1501 | #NamedEntities |
| 1502 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1503 | |
Akron | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 1504 | CMC |
| 1505 | #Morpho |
| 1506 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1507 | DeReKo |
| 1508 | #Structure |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1509 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 1510 | DGD |
| 1511 | #Morpho |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 1512 | #Structure |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 1513 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1514 | DRuKoLa |
| 1515 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1516 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1517 | Glemm |
| 1518 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1519 | |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 1520 | Gingko |
| 1521 | #Morpho |
| 1522 | |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 1523 | HNC |
| 1524 | #Morpho |
| 1525 | |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 1526 | LWC |
| 1527 | #Dependency |
| 1528 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1529 | Malt |
| 1530 | #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1531 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1532 | MarMoT |
| 1533 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1534 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1535 | Mate |
| 1536 | #Dependency |
| 1537 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1538 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1539 | MDParser |
| 1540 | #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1541 | |
Akron | e85a776 | 2022-07-22 08:05:03 +0200 | [diff] [blame] | 1542 | NKJP |
| 1543 | #Morpho |
| 1544 | #NamedEntities |
| 1545 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1546 | OpenNLP |
| 1547 | #Morpho |
| 1548 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1549 | |
Akron | 07e2477 | 2020-04-23 14:00:54 +0200 | [diff] [blame] | 1550 | RWK |
| 1551 | #Morpho |
| 1552 | #Structure |
| 1553 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1554 | Sgbr |
| 1555 | #Lemma |
| 1556 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1557 | |
Marc Kupietz | b8c5382 | 2024-03-16 18:54:08 +0100 | [diff] [blame] | 1558 | Spacy |
| 1559 | #Morpho |
| 1560 | |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 1561 | Talismane |
| 1562 | #Dependency |
| 1563 | #Morpho |
| 1564 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1565 | TreeTagger |
| 1566 | #Morpho |
| 1567 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1568 | |
Akron | 83aedd3 | 2023-02-07 10:57:41 +0100 | [diff] [blame] | 1569 | UDPipe |
| 1570 | #Dependency |
| 1571 | #Morpho |
| 1572 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1573 | XIP |
| 1574 | #Constituency |
| 1575 | #Morpho |
| 1576 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1577 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1578 | |
| 1579 | More importers are in preparation. |
| 1580 | New annotation importers can be defined in the C<KorAP::XML::Annotation> namespace. |
| 1581 | See the built-in annotation importers as examples. |
| 1582 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1583 | |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 1584 | =head1 METADATA SUPPORT |
| 1585 | |
| 1586 | L<KorAP::XML::Krill> has built-in importer for some meta data variants |
| 1587 | developed in the KorAP project that are part of the KorAP preprocessing pipeline. |
| 1588 | |
| 1589 | =over 2 |
| 1590 | |
| 1591 | =item I5 - Meta data for all I5 files |
| 1592 | |
| 1593 | =item Sgbr - Meta data from the Schreibgebrauch project |
| 1594 | |
| 1595 | =item Gingko - Meta data from the Gingko project in addition to I5 |
| 1596 | |
Akron | 2532f1b | 2023-05-15 13:41:24 +0200 | [diff] [blame] | 1597 | =item ICC - Meta data for the ICC in addition to I5 |
| 1598 | |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 1599 | =back |
| 1600 | |
| 1601 | More importers are in preparation. |
| 1602 | New meta data importers can be defined in the C<KorAP::XML::Meta> namespace. |
| 1603 | See the built-in meta data importers as examples. |
| 1604 | |
| 1605 | |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1606 | =head1 About KorAP-XML |
| 1607 | |
| 1608 | KorAP-XML (Bański et al. 2012) is an implementation of the KorAP |
| 1609 | data model (Bański et al. 2013), where text data are stored physically |
| 1610 | separated from their interpretations (i.e. annotations). |
| 1611 | A text document in KorAP-XML therefore consists of several files |
| 1612 | containing primary data, metadata and annotations. |
| 1613 | |
| 1614 | The structure of a single KorAP-XML document can be as follows: |
| 1615 | |
| 1616 | - data.xml |
| 1617 | - header.xml |
| 1618 | + base |
| 1619 | - tokens.xml |
| 1620 | - ... |
| 1621 | + struct |
| 1622 | - structure.xml |
| 1623 | - ... |
| 1624 | + corenlp |
| 1625 | - morpho.xml |
| 1626 | - constituency.xml |
| 1627 | - ... |
| 1628 | + tree_tagger |
| 1629 | - morpho.xml |
| 1630 | - ... |
| 1631 | - ... |
| 1632 | |
| 1633 | The C<data.xml> contains the primary data, the C<header.xml> contains |
| 1634 | the metadata, and the annotation layers are stored in subfolders |
| 1635 | like C<base>, C<struct> or C<corenlp> |
| 1636 | (so-called "foundries"; Bański et al. 2013). |
| 1637 | |
| 1638 | Metadata is available in the TEI-P5 variant I5 |
Akron | d4c5c10 | 2020-02-11 11:47:59 +0100 | [diff] [blame] | 1639 | (Lüngen and Sperberg-McQueen 2012). See the documentation in |
| 1640 | L<KorAP::XML::Meta::I5> for translatable fields. |
| 1641 | |
| 1642 | Annotations correspond to a variant of the TEI-P5 feature structures |
| 1643 | (TEI Consortium; Lee et al. 2004). |
Akron | 72bc522 | 2020-02-06 16:00:13 +0100 | [diff] [blame] | 1644 | Annotation feature structures refer to character sequences of the primary text |
| 1645 | inside the C<text> element of the C<data.xml>. |
| 1646 | A single annotation containing the lemma of a token can have the following structure: |
| 1647 | |
| 1648 | <span from="0" to="3"> |
| 1649 | <fs type="lex" xmlns="http://www.tei-c.org/ns/1.0"> |
| 1650 | <f name="lex"> |
| 1651 | <fs> |
| 1652 | <f name="lemma">zum</f> |
| 1653 | </fs> |
| 1654 | </f> |
| 1655 | </fs> |
| 1656 | </span> |
| 1657 | |
| 1658 | The C<from> and C<to> attributes are refering to the character span |
| 1659 | in the primary text. |
| 1660 | Depending on the kind of annotation (e.g. token-based, span-based, relation-based), |
| 1661 | the structure may vary. See L<KorAP::XML::Annotation::*> for various |
| 1662 | annotation preprocessors. |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1663 | |
| 1664 | Multiple KorAP-XML documents are organized on three levels following |
| 1665 | the "IDS Textmodell" (Lüngen and Sperberg-McQueen 2012): |
| 1666 | corpus E<gt> document E<gt> text. On each level metadata information |
| 1667 | can be stored, that C<korapxml2krill> will merge to a single metadata |
| 1668 | object per text. A corpus is therefore structured as follows: |
| 1669 | |
| 1670 | + <corpus> |
| 1671 | - header.xml |
| 1672 | + <document> |
| 1673 | - header.xml |
| 1674 | + <text> |
| 1675 | - data.xml |
| 1676 | - header.xml |
| 1677 | - ... |
| 1678 | - ... |
| 1679 | |
| 1680 | A single text can be identified by the concatenation of |
| 1681 | the corpus identifier, the document identifier and the text identifier. |
| 1682 | This identifier is called the text sigle |
| 1683 | (e.g. a text with the identifier C<18486> in the document C<060> in the |
| 1684 | corpus C<WPD17> has the text sigle C<WPD17/060/18486>, see C<--sigle>). |
| 1685 | |
| 1686 | These corpora are often stored in zip files, with which C<korapxml2krill> |
| 1687 | can deal with. Corpora may also be split in multiple zip archives |
| 1688 | (e.g. one zip file per foundry), which is also supported (see C<--input>). |
| 1689 | |
| 1690 | Examples for KorAP-XML files are included in L<KorAP::XML::Krill> |
| 1691 | in form of a test suite. |
| 1692 | The resulting JSON format merges all annotation layers |
| 1693 | based on a single token stream. |
| 1694 | |
| 1695 | =head2 References |
| 1696 | |
| 1697 | Piotr Bański, Cyril Belica, Helge Krause, Marc Kupietz, Carsten Schnober, Oliver Schonefeld, and Andreas Witt (2011): |
| 1698 | KorAP data model: first approximation, December. |
| 1699 | |
| 1700 | Piotr Bański, Peter M. Fischer, Elena Frick, Erik Ketzan, Marc Kupietz, Carsten Schnober, Oliver Schonefeld and Andreas Witt (2012): |
| 1701 | "The New IDS Corpus Analysis Platform: Challenges and Prospects", |
| 1702 | Proceedings of the Eighth International Conference on Language Resources and Evaluation (LREC 2012). |
| 1703 | L<PDF|http://www.lrec-conf.org/proceedings/lrec2012/pdf/789_Paper.pdf> |
| 1704 | |
| 1705 | Piotr Bański, Elena Frick, Michael Hanl, Marc Kupietz, Carsten Schnober and Andreas Witt (2013): |
| 1706 | "Robust corpus architecture: a new look at virtual collections and data access", |
| 1707 | Corpus Linguistics 2013. Abstract Book. Lancaster: UCREL, pp. 23-25. |
| 1708 | L<PDF|https://ids-pub.bsz-bw.de/frontdoor/deliver/index/docId/4485/file/Ba%c5%84ski_Frick_Hanl_Robust_corpus_architecture_2013.pdf> |
| 1709 | |
| 1710 | Kiyong Lee, Lou Burnard, Laurent Romary, Eric de la Clergerie, Thierry Declerck, |
| 1711 | Syd Bauman, Harry Bunt, Lionel Clément, Tomaz Erjavec, Azim Roussanaly and Claude Roux (2004): |
| 1712 | "Towards an international standard on featurestructure representation", |
| 1713 | Proceedings of the fourth International Conference on Language Resources and Evaluation (LREC 2004), |
| 1714 | pp. 373-376. |
| 1715 | L<PDF|http://www.lrec-conf.org/proceedings/lrec2004/pdf/687.pdf> |
| 1716 | |
| 1717 | Harald Lüngen and C. M. Sperberg-McQueen (2012): |
| 1718 | "A TEI P5 Document Grammar for the IDS Text Model", |
| 1719 | Journal of the Text Encoding Initiative, Issue 3 | November 2012. |
| 1720 | L<PDF|https://journals.openedition.org/jtei/pdf/508> |
| 1721 | |
| 1722 | TEI Consortium, eds: |
| 1723 | "Feature Structures", |
| 1724 | Guidelines for Electronic Text Encoding and Interchange. |
| 1725 | L<html|https://www.tei-c.org/release/doc/tei-p5-doc/en/html/FS.html> |
| 1726 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1727 | =head1 AVAILABILITY |
| 1728 | |
| 1729 | https://github.com/KorAP/KorAP-XML-Krill |
| 1730 | |
| 1731 | |
| 1732 | =head1 COPYRIGHT AND LICENSE |
| 1733 | |
Akron | a351837 | 2024-01-22 23:29:00 +0100 | [diff] [blame] | 1734 | Copyright (C) 2015-2024, L<IDS Mannheim|https://www.ids-mannheim.de/> |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1735 | |
Akron | 6882d7d | 2021-02-08 09:43:57 +0100 | [diff] [blame] | 1736 | Author: L<Nils Diewald|https://www.nils-diewald.de/> |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1737 | |
Akron | 2912826 | 2024-04-17 15:50:36 +0200 | [diff] [blame] | 1738 | Contributor: Eliza Margaretha, Marc Kupietz |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1739 | |
Akron | 6882d7d | 2021-02-08 09:43:57 +0100 | [diff] [blame] | 1740 | 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] | 1741 | Corpus Analysis Platform at the |
Akron | 6882d7d | 2021-02-08 09:43:57 +0100 | [diff] [blame] | 1742 | L<Leibniz Institute for the German Language (IDS)|https://www.ids-mannheim.de/>, |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1743 | member of the |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 1744 | L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1745 | |
| 1746 | This program is free software published under the |
Akron | 6882d7d | 2021-02-08 09:43:57 +0100 | [diff] [blame] | 1747 | L<BSD-2 License|https://opensource.org/licenses/BSD-2-Clause>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1748 | |
| 1749 | =cut |