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