Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 4 | use FindBin; |
| 5 | BEGIN { unshift @INC, "$FindBin::Bin/../lib" }; |
| 6 | use File::Spec::Functions qw/catfile catdir/; |
| 7 | use Getopt::Long qw/GetOptions :config no_auto_abbrev/; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 8 | use Benchmark qw/:hireswallclock/; |
| 9 | use IO::Compress::Gzip qw/$GzipError/; |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 10 | use POSIX qw/ceil/; |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 11 | use Log::Log4perl; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 12 | use Pod::Usage; |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 13 | use Cache::FastMmap; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 14 | use Directory::Iterator; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 15 | use KorAP::XML::Krill; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 16 | use KorAP::XML::Archive; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 17 | use KorAP::XML::Tokenizer; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 18 | use KorAP::XML::Batch::File; |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 19 | use Config::Simple; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 20 | use Parallel::ForkManager; |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 21 | use v5.10; |
| 22 | use Sys::Info; |
| 23 | use Sys::Info::Constants qw( :device_cpu ); |
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; |
| 31 | use Archive::Tar::Builder; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 32 | use Fcntl qw(:flock SEEK_END); |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 33 | |
| 34 | # use KorAP::XML::ForkPool; |
Akron | 75ba57d | 2016-03-07 23:36:27 +0100 | [diff] [blame] | 35 | # TODO: use Parallel::Loops |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 36 | # TODO: make output files |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 37 | |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 38 | # TODO: Use KorAP::XML::ForkPool! |
| 39 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 40 | # CHANGES: |
| 41 | # ---------------------------------------------------------- |
| 42 | # 2013/11/25 |
| 43 | # - Initial release |
| 44 | # |
| 45 | # 2014/10/29 |
| 46 | # - Merges foundry data to create indexer friendly documents |
| 47 | # |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 48 | # 2016/02/04 |
| 49 | # - renamed to korapxml2krill |
| 50 | # - added Schreibgebrauch support |
Akron | 069bd71 | 2016-02-12 19:09:06 +0100 | [diff] [blame] | 51 | # |
| 52 | # 2016/02/12 |
| 53 | # - fixed foundry skipping |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 54 | # - Support overwrite in archive processing |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 55 | # |
| 56 | # 2016/02/14 |
| 57 | # - Added version information |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 58 | # - Added support for archive files |
| 59 | # |
| 60 | # 2016/02/15 |
| 61 | # - Fixed temporary directory bug |
| 62 | # - Improved skipping before unzipping |
| 63 | # - Added EXPERIMENTAL concurrency support |
| 64 | # |
| 65 | # 2016/02/23 |
| 66 | # - Merge korapxml2krill and korapxml2krill_dir |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 67 | # |
| 68 | # 2016/02/27 |
| 69 | # - Added extract function |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 70 | # |
| 71 | # 2016/03/17 |
| 72 | # - Added meta switch |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 73 | # |
| 74 | # 2016/03/18 |
| 75 | # - Added meta data caching |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 76 | # |
Akron | f3f0c94 | 2016-06-27 13:27:14 +0200 | [diff] [blame] | 77 | # 2016/06/27 |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 78 | # - Added multi archive support |
| 79 | # - Added prefix negation support |
Akron | f3f0c94 | 2016-06-27 13:27:14 +0200 | [diff] [blame] | 80 | # - Added Malt#Dependency support |
Akron | 8b99052 | 2016-07-06 16:45:57 +0200 | [diff] [blame] | 81 | # |
| 82 | # 2016/07/06 |
| 83 | # - Added MDParser#Dependency |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 84 | # |
| 85 | # 2016/10/15 |
Nils Diewald | 0e48977 | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 86 | # - Fixed temporary path issue in script |
| 87 | # |
| 88 | # 2016/10/24 |
| 89 | # - Improved Windows support |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 90 | # |
Akron | b4bbec7 | 2016-10-26 20:21:02 +0200 | [diff] [blame] | 91 | # 2016/10/24 |
| 92 | # - Added support for document extraction |
| 93 | # |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 94 | # 2016/10/27 |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 95 | # - Added wildcard support for document extraction |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 96 | # |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 97 | # 2016/12/21 |
| 98 | # - added support for base-sentences and base-tokenizations |
| 99 | # |
Akron | 4fa37c3 | 2017-01-20 14:43:10 +0100 | [diff] [blame] | 100 | # 2017/01/20 |
| 101 | # - added support for DRuKoLa annotations |
| 102 | # |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 103 | # 2017/02/08 |
| 104 | # - added support for pagebreak annotations |
| 105 | # |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 106 | # 2017/04/06 |
| 107 | # - added support for wildcards in input |
| 108 | # |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 109 | # 2017/04/07 |
| 110 | # - support configuration option |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 111 | # - support for temporary extraction |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 112 | # |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 113 | # 2017/04/12 |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 114 | # - support serial processing |
| 115 | # - support input root |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 116 | # - introduced --sequential-extraction flag |
Akron | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 117 | # |
| 118 | # 2017/06/19 |
| 119 | # - added support for DCK |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 120 | # |
| 121 | # 2017/06/29 |
| 122 | # - Fixed exit codes |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 123 | # |
| 124 | # 2017/07/04 |
| 125 | # - Fixed tar building process |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 126 | # |
| 127 | # 2018/01/16 |
| 128 | # - Added LWC support |
Akron | 5fdc7e1 | 2018-07-19 12:37:48 +0200 | [diff] [blame] | 129 | # |
| 130 | # 2018/07/19 |
| 131 | # - Preliminary support for HNC. |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 132 | # |
| 133 | # 2019/01/22 |
| 134 | # - Support for non-word tokens. |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 135 | # |
| 136 | # 2019/02/07 |
| 137 | # - Support for 'koral:field' array. |
| 138 | # - Support for Koral versioning. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 139 | # ---------------------------------------------------------- |
Akron | 069bd71 | 2016-02-12 19:09:06 +0100 | [diff] [blame] | 140 | |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 141 | our $LAST_CHANGE = '2019/02/07'; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 142 | our $LOCAL = $FindBin::Bin; |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 143 | our $KORAL_VERSION = 0.03; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 144 | our $VERSION_MSG = <<"VERSION"; |
| 145 | Version $KorAP::XML::Krill::VERSION - diewald\@ids-mannheim.de - $LAST_CHANGE |
| 146 | VERSION |
| 147 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 148 | # Prototypes |
| 149 | sub get_file_name_from_glob($); |
| 150 | sub get_file_name($); |
| 151 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 152 | # Parse comand |
| 153 | my $cmd; |
| 154 | our @ARGV; |
| 155 | if ($ARGV[0] && index($ARGV[0], '-') != 0) { |
| 156 | $cmd = shift @ARGV; |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 157 | }; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 158 | my @keep_argv = @ARGV; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 159 | |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 160 | my (@skip, @sigle, @anno, @input); |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 161 | my $text; |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 162 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 163 | # Parse options from the command line |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 164 | GetOptions( |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 165 | 'input|i=s' => \@input, |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 166 | 'input-base|ib=s' => \(my $input_base), |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 167 | 'output|o=s' => \(my $output), |
| 168 | 'overwrite|w' => \(my $overwrite), |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 169 | 'meta|m=s' => \(my $meta), |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 170 | 'token|t=s' => \(my $token_base), |
| 171 | 'base-sentences|bs=s' => \(my $base_sentences), |
| 172 | 'base-paragraphs|bp=s' => \(my $base_paragraphs), |
| 173 | 'base-pagebreaks|bpb=s' => \(my $base_pagebreaks), |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 174 | 'gzip|z' => \(my $gzip), |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 175 | 'temporary-extract|te=s' => \(my $extract_dir), |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 176 | 'skip|s=s' => \@skip, |
| 177 | 'sigle|sg=s' => \@sigle, |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 178 | 'cache|c=s' => \(my $cache_file), |
| 179 | 'config|cfg=s' => \(my $cfg_file), |
| 180 | 'log|l=s' => \(my $log_level), |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 181 | 'anno|a=s' => \@anno, |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 182 | 'primary|p!' => \(my $primary), |
| 183 | 'pretty|y' => \(my $pretty), |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 184 | 'jobs|j=i' => \(my $jobs), |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 185 | 'koral|k=f' => \(my $koral), |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 186 | 'to-tar' => \(my $to_tar), |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 187 | 'non-word-tokens|nwt' => \(my $non_word_tokens), |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 188 | 'sequential-extraction|se' => \(my $sequential_extraction), |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 189 | 'cache-size|cs=s' => \(my $cache_size), |
| 190 | 'cache-delete|cd!' => \(my $cache_delete), |
| 191 | 'cache-init|ci!' => \(my $cache_init), |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 192 | 'help|h' => sub { |
| 193 | pod2usage( |
| 194 | -sections => 'NAME|SYNOPSIS|ARGUMENTS|OPTIONS', |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 195 | -verbose => 99, |
| 196 | -msg => $VERSION_MSG, |
| 197 | -output => '-' |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 198 | ); |
| 199 | }, |
| 200 | 'version|v' => sub { |
| 201 | pod2usage( |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 202 | -verbose => 0, |
| 203 | -msg => $VERSION_MSG, |
| 204 | -output => '-' |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 205 | ) |
| 206 | } |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 207 | ); |
| 208 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 209 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 210 | # Load from configuration |
| 211 | if ($cfg_file && -e $cfg_file) { |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 212 | my %config; |
| 213 | |
| 214 | Config::Simple->import_from($cfg_file, \%config); |
| 215 | |
| 216 | # Overwrite |
| 217 | if (!defined($overwrite) && defined $config{overwrite}) { |
| 218 | $overwrite = $config{overwrite}; |
| 219 | }; |
| 220 | |
| 221 | # Gzip |
| 222 | if (!defined($gzip) && defined $config{gzip}) { |
| 223 | $gzip = $config{gzip}; |
| 224 | }; |
| 225 | |
| 226 | # Jobs |
| 227 | if (!defined($jobs) && defined $config{jobs}) { |
| 228 | $jobs = $config{jobs}; |
| 229 | }; |
| 230 | |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 231 | # Koral version |
| 232 | if (!defined($koral) && defined $config{koral}) { |
| 233 | $koral = $config{koral}; |
| 234 | }; |
| 235 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 236 | # Input root base directory |
| 237 | if (!defined($input_base) && defined $config{'input-base'}) { |
| 238 | $input_base = $config{'input-base'}; |
| 239 | }; |
| 240 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 241 | # temporary-extract |
| 242 | if (!defined($extract_dir) && defined $config{'temporary-extract'}) { |
| 243 | $extract_dir = $config{'temporary-extract'}; |
| 244 | }; |
| 245 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 246 | # Token base |
| 247 | if (!defined($token_base) && defined $config{token}) { |
| 248 | $token_base = $config{token}; |
| 249 | }; |
| 250 | |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 251 | # temporary-extract |
| 252 | if (!defined($non_word_tokens) && defined $config{'non-word-tokens'}) { |
| 253 | $non_word_tokens = $config{'non-word-tokens'}; |
| 254 | }; |
| 255 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 256 | # Cache file |
| 257 | if (!defined($cache_file) && defined $config{cache}) { |
| 258 | $cache_file = $config{cache}; |
| 259 | }; |
| 260 | |
| 261 | # Cache size |
| 262 | if (!defined($cache_size) && defined $config{'cache-size'}) { |
| 263 | $cache_size = $config{'cache-size'}; |
| 264 | }; |
| 265 | |
| 266 | # Cache delete |
| 267 | if (!defined($cache_delete) && defined $config{'cache-delete'}) { |
| 268 | $cache_delete = $config{'cache-delete'} ; |
| 269 | }; |
| 270 | |
| 271 | # Cache init |
| 272 | if (!(defined $cache_init) && defined $config{'cache-init'}) { |
| 273 | $cache_init = $config{'cache-init'} ; |
| 274 | }; |
| 275 | |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 276 | # Jobs for extraction |
| 277 | if (!(defined $sequential_extraction) && defined $config{'sequential-extraction'}) { |
| 278 | $sequential_extraction = $config{'sequential-extraction'} ; |
| 279 | }; |
| 280 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 281 | # Meta |
| 282 | if (!(defined $meta) && defined $config{'meta'}) { |
| 283 | $meta = $config{'meta'} ; |
| 284 | }; |
| 285 | |
| 286 | # Output |
| 287 | if (!(defined $output) && defined $config{'output'}) { |
| 288 | $output = $config{'output'} ; |
| 289 | }; |
| 290 | |
| 291 | # Base-sentences |
| 292 | if (!(defined $base_sentences) && defined $config{'base-sentences'}) { |
| 293 | $base_sentences = $config{'base-sentences'} ; |
| 294 | }; |
| 295 | |
| 296 | # Base-paragraphs |
| 297 | if (!(defined $base_paragraphs) && defined $config{'base-paragraphs'}) { |
| 298 | $base_paragraphs = $config{'base-paragraphs'} ; |
| 299 | }; |
| 300 | |
| 301 | # Base-pagebreaks |
| 302 | if (!(defined $base_pagebreaks) && defined $config{'base-pagebreaks'}) { |
| 303 | $base_pagebreaks = $config{'base-pagebreaks'} ; |
| 304 | }; |
| 305 | |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 306 | # Write to tar |
| 307 | if (!(defined $to_tar) && defined $config{'to-tar'}) { |
| 308 | $to_tar = $config{'to-tar'} ; |
| 309 | }; |
| 310 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 311 | # Log |
| 312 | if (!(defined $log_level) && defined $config{'log'}) { |
| 313 | $log_level = $config{'log'} ; |
| 314 | }; |
| 315 | |
| 316 | # Skip |
| 317 | if (!scalar(@skip) && defined $config{'skip'}) { |
| 318 | @skip = split /\s*;\s*/, $config{'skip'} ; |
| 319 | }; |
| 320 | |
| 321 | # Sigle |
| 322 | if (!scalar(@sigle) && defined $config{'sigle'}) { |
| 323 | @sigle = split /\s*;\s*/, $config{'sigle'} ; |
| 324 | }; |
| 325 | |
| 326 | # Anno |
| 327 | if (!scalar(@anno) && defined $config{'anno'}) { |
| 328 | @anno = split /\s*;\s*/, $config{'anno'} ; |
| 329 | }; |
| 330 | }; |
| 331 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 332 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 333 | # Set default token base |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 334 | $token_base //= 'OpenNLP#tokens'; |
| 335 | $cache_file //= 'korapxml2krill.cache'; |
| 336 | $cache_size //= '50m'; |
| 337 | $jobs //= 0; |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 338 | $koral //= $KORAL_VERSION; |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 339 | $cache_delete //= 1; |
| 340 | $cache_init //= 1; |
| 341 | $sequential_extraction //= 0; |
| 342 | $log_level //= 'ERROR'; |
| 343 | $base_sentences //= ''; |
| 344 | $base_paragraphs //= ''; |
| 345 | $base_pagebreaks //= ''; |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 346 | $non_word_tokens //= 0; |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 347 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 348 | $base_sentences = lc $base_sentences; |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 349 | $base_paragraphs = lc $base_paragraphs; |
Akron | 636bd9c | 2017-02-09 17:13:00 +0100 | [diff] [blame] | 350 | $base_pagebreaks = lc $base_pagebreaks; |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 351 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 352 | |
| 353 | # Initialize log4perl object |
| 354 | Log::Log4perl->init({ |
| 355 | 'log4perl.rootLogger' => uc($log_level) . ', STDERR', |
| 356 | 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels', |
| 357 | 'log4perl.appender.STDERR.layout' => 'PatternLayout', |
| 358 | 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n' |
| 359 | }); |
| 360 | |
| 361 | my $log = Log::Log4perl->get_logger('main'); |
| 362 | |
| 363 | |
| 364 | print "Reading config from $cfg_file\n" if $cfg_file; |
| 365 | |
| 366 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 367 | my %ERROR_HASH = ( |
| 368 | -sections => 'NAME|SYNOPSIS|ARGUMENTS|OPTIONS', |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 369 | -verbose => 99, |
| 370 | -msg => $VERSION_MSG, |
| 371 | -output => '-', |
| 372 | -exit => 1 |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 373 | ); |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 374 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 375 | # Input has to be defined |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 376 | pod2usage(%ERROR_HASH) unless @input; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 377 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 378 | # Gzip has no effect, if no output is given |
| 379 | pod2usage(%ERROR_HASH) if $gzip && !$output; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 380 | |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 381 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 382 | if ($jobs eq '-1') { |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 383 | state $cores = Sys::Info->new->device('CPU')->count; |
| 384 | $jobs = ceil(5 * $cores); |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 385 | $log->info("Run using $jobs jobs on $cores cores"); |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 386 | }; |
| 387 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 388 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 389 | # Start serial processing |
Akron | 28c4e54 | 2017-07-04 20:30:33 +0200 | [diff] [blame] | 390 | if ($cmd && $cmd eq 'serial') { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 391 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 392 | if ($output && (!defined($to_tar)) && (!-e $output || !-d $output)) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 393 | $log->error("Directory '$output' does not exist."); |
| 394 | exit 1; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 395 | }; |
| 396 | |
| 397 | # Remove all inputs |
| 398 | my $remove_next = 0; |
| 399 | @keep_argv = @{c(@keep_argv)->grep( |
| 400 | sub { |
| 401 | # Input flag |
| 402 | if ($_ eq '-i' || $_ eq '--input' || $_ eq '--output' || $_ eq '-o') { |
| 403 | $remove_next = 1; |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | # input value |
| 408 | elsif ($remove_next) { |
| 409 | $remove_next = 0; |
| 410 | return 0; |
| 411 | }; |
| 412 | |
| 413 | # Pass parameter |
| 414 | return 1; |
| 415 | } |
| 416 | )->to_array}; |
| 417 | |
| 418 | |
| 419 | # Iterate over all inputs |
| 420 | foreach (@input) { |
| 421 | |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 422 | # This will create a directory |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 423 | my $new_out = catdir($output, get_file_name_from_glob($_)); |
| 424 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 425 | # Create new path, in case the output is not meant to be tarred |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 426 | unless ($to_tar) { |
| 427 | if (make_path($new_out) == 0 && !-d $new_out) { |
| 428 | $log->error("Can\'t create path $new_out"); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 429 | exit 1; |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 430 | }; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 431 | }; |
| 432 | |
| 433 | # Create archive command |
| 434 | my @archive_cmd = ($^X, $0, 'archive', @keep_argv, '-i', $_, '-o', $new_out); |
| 435 | print "Start serial processing of $_ to $new_out\n"; |
| 436 | |
| 437 | # Start archiving |
| 438 | system @archive_cmd; |
| 439 | }; |
| 440 | |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 441 | exit; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 442 | }; |
| 443 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 444 | my %skip; |
| 445 | $skip{lc($_)} = 1 foreach @skip; |
| 446 | |
| 447 | my @layers; |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 448 | push(@layers, ['Base', 'Sentences']) unless $base_sentences; |
| 449 | push(@layers, ['Base', 'Paragraphs']) unless $base_paragraphs; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 450 | |
| 451 | # Connexor |
| 452 | push(@layers, ['Connexor', 'Morpho']); |
| 453 | push(@layers, ['Connexor', 'Syntax']); |
| 454 | push(@layers, ['Connexor', 'Phrase']); |
| 455 | push(@layers, ['Connexor', 'Sentences']); |
| 456 | |
| 457 | # CoreNLP |
| 458 | push(@layers, ['CoreNLP', 'NamedEntities']); |
| 459 | push(@layers, ['CoreNLP', 'Sentences']); |
| 460 | push(@layers, ['CoreNLP', 'Morpho']); |
| 461 | push(@layers, ['CoreNLP', 'Constituency']); |
| 462 | |
Akron | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 463 | # CMC |
| 464 | push(@layers, ['CMC', 'Morpho']); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 465 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 466 | # DeReKo |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 467 | my @dereko_attr = (); |
| 468 | if ($base_sentences eq 'dereko#structure') { |
| 469 | push @dereko_attr, 'sentences'; |
| 470 | }; |
| 471 | if ($base_paragraphs eq 'dereko#structure') { |
| 472 | push @dereko_attr, 'paragraphs'; |
| 473 | }; |
Akron | 636bd9c | 2017-02-09 17:13:00 +0100 | [diff] [blame] | 474 | |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 475 | if ($base_pagebreaks eq 'dereko#structure') { |
| 476 | push @dereko_attr, 'pagebreaks'; |
| 477 | }; |
| 478 | |
| 479 | if ($dereko_attr[0]) { |
| 480 | push(@layers, ['DeReKo', 'Structure', 'base-' . join('-', @dereko_attr)]); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 481 | } |
| 482 | else { |
| 483 | push(@layers, ['DeReKo', 'Structure']); |
| 484 | }; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 485 | |
| 486 | # Glemm |
| 487 | push(@layers, ['Glemm', 'Morpho']); |
| 488 | |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 489 | # HNC |
| 490 | push(@layers, ['HNC', 'Morpho']); |
| 491 | |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 492 | # LWC |
| 493 | push(@layers, ['LWC', 'Dependency']); |
| 494 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 495 | # Malt |
| 496 | push(@layers, ['Malt', 'Dependency']); |
| 497 | |
| 498 | # MDParser |
| 499 | push(@layers, ['MDParser', 'Dependency']); |
| 500 | |
| 501 | # Mate |
| 502 | push(@layers, ['Mate', 'Morpho']); |
| 503 | push(@layers, ['Mate', 'Dependency']); |
| 504 | |
| 505 | # OpenNLP |
| 506 | push(@layers, ['OpenNLP', 'Morpho']); |
| 507 | push(@layers, ['OpenNLP', 'Sentences']); |
| 508 | |
| 509 | # Schreibgebrauch |
| 510 | push(@layers, ['Sgbr', 'Lemma']); |
| 511 | push(@layers, ['Sgbr', 'Morpho']); |
| 512 | |
| 513 | # TreeTagger |
| 514 | push(@layers, ['TreeTagger', 'Morpho']); |
| 515 | push(@layers, ['TreeTagger', 'Sentences']); |
| 516 | |
| 517 | # XIP |
| 518 | push(@layers, ['XIP', 'Morpho']); |
| 519 | push(@layers, ['XIP', 'Constituency']); |
| 520 | push(@layers, ['XIP', 'Sentences']); |
| 521 | push(@layers, ['XIP', 'Dependency']); |
| 522 | |
Akron | 4fa37c3 | 2017-01-20 14:43:10 +0100 | [diff] [blame] | 523 | # DRuKoLa |
| 524 | push(@layers, ['DRuKoLa', 'Morpho']); |
| 525 | |
Akron | 3bd942f | 2017-02-20 20:09:14 +0100 | [diff] [blame] | 526 | # Marmot |
| 527 | push(@layers, ['MarMoT', 'Morpho']); |
| 528 | |
Akron | 4fa37c3 | 2017-01-20 14:43:10 +0100 | [diff] [blame] | 529 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 530 | # Check filters |
| 531 | my @filtered_anno; |
| 532 | if ($skip{'#all'}) { |
| 533 | foreach (@anno) { |
| 534 | push @filtered_anno, [ split('#', $_) ]; |
| 535 | }; |
| 536 | } |
| 537 | |
| 538 | # Add all annotations that are not skipped |
| 539 | else { |
| 540 | # Add to index file - respect skipping |
| 541 | foreach my $info (@layers) { |
| 542 | # Skip if Foundry or Foundry#Layer should be skipped |
| 543 | unless ($skip{lc($info->[0])} || $skip{lc($info->[0]) . '#' . lc($info->[1])}) { |
| 544 | push @filtered_anno, $info; |
| 545 | }; |
| 546 | }; |
| 547 | }; |
| 548 | |
| 549 | # Get tokenization basis |
Akron | 3c56f50 | 2017-10-24 15:37:27 +0200 | [diff] [blame] | 550 | my ($token_base_foundry, $token_base_layer) = split(/#/, $token_base) if $token_base; |
| 551 | |
| 552 | # Remove file extension |
| 553 | $token_base_layer =~ s/\.xml$//i; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 554 | |
| 555 | # TODO: This should not be initialized for batch |
| 556 | my $cache = Cache::FastMmap->new( |
| 557 | share_file => $cache_file, |
| 558 | cache_size => $cache_size, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 559 | init_file => $cache_init |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 560 | ); |
| 561 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 562 | # Create batch object |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 563 | my $batch_file = KorAP::XML::Batch::File->new( |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 564 | cache => $cache, |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 565 | meta_type => $meta, |
| 566 | overwrite => $overwrite, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 567 | foundry => $token_base_foundry, |
| 568 | layer => $token_base_layer, |
| 569 | gzip => $gzip, |
| 570 | log => $log, |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 571 | koral => $koral, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 572 | primary => $primary, |
| 573 | pretty => $pretty, |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 574 | anno => \@filtered_anno, |
| 575 | non_word_tokens => $non_word_tokens |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 576 | ); |
| 577 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 578 | # Get file name based on path information |
| 579 | sub get_file_name ($) { |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 580 | my $i = $input[0]; |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 581 | if (-d $i) { |
| 582 | $i =~ s![^\/]+$!!; |
| 583 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 584 | my $file = shift; |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 585 | |
| 586 | # Remove temp dir fragments |
Akron | 6255760 | 2016-06-27 14:10:13 +0200 | [diff] [blame] | 587 | $file =~ s!^/?tmp/[^/]+!!; |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 588 | $file =~ s/^?\/?$i//; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 589 | $file =~ tr/\//-/; |
| 590 | $file =~ s{^-+}{}; |
Akron | b4bbec7 | 2016-10-26 20:21:02 +0200 | [diff] [blame] | 591 | $file =~ s/^.*?-(.+?-.+?-.+?)$/$1/; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 592 | return $file; |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 593 | }; |
| 594 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 595 | |
| 596 | sub get_file_name_from_glob ($) { |
| 597 | my $glob = shift; |
Akron | bd3adda | 2017-04-11 15:00:55 +0200 | [diff] [blame] | 598 | $glob =~ s![\\\/]!-!g; # Transform paths |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 599 | $glob =~ s/[\*\?]//g; # Remove arbitrary fills |
| 600 | $glob =~ s/[\{\}\[\]]/-/g; # Remove class and multiple brackets |
| 601 | $glob =~ s/\-\-+/-/g; # Remove sequences of binding characters |
| 602 | $glob =~ s/^-//; # Clean beginning |
| 603 | $glob =~ s/-$//; # Clean end |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 604 | $glob =~ s/\.zip$//; # Remove file extension |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 605 | return $glob; |
| 606 | }; |
| 607 | |
| 608 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 609 | # Convert sigle to path construct |
| 610 | s!^\s*([^_]+?)_([^\.]+?)\.(.+?)\s*$!$1/$2/$3! foreach @sigle; |
| 611 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 612 | if ($cmd) { |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 613 | if ($output && (!defined($to_tar)) && (!-e $output || !-d $output)) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 614 | $log->error("Directory '$output' does not exist."); |
| 615 | exit 1; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 616 | }; |
| 617 | }; |
| 618 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 619 | |
| 620 | # Glob and prefix files |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 621 | if (@input) { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 622 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 623 | my @new_input = (); |
| 624 | |
| 625 | # Iterate over all inputs |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 626 | foreach my $wild_card (@input) { |
| 627 | |
| 628 | # Prefix with input root |
| 629 | $wild_card = $input_base ? catfile($input_base, $wild_card) : $wild_card; |
| 630 | |
| 631 | push (@new_input, bsd_glob($wild_card)); |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 632 | }; |
| 633 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 634 | # Sort files by length |
| 635 | @input = sort { length($a) <=> length($b) } @new_input; |
| 636 | |
| 637 | print 'Input is ' . join(', ', @input)."\n"; |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 638 | }; |
| 639 | |
| 640 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 641 | # Process a single file |
| 642 | unless ($cmd) { |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 643 | my $input = $input[0]; |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 644 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 645 | BEGIN { |
| 646 | $main::TIME = Benchmark->new; |
| 647 | $main::LAST_STOP = Benchmark->new; |
| 648 | }; |
| 649 | |
| 650 | sub stop_time { |
| 651 | my $new = Benchmark->new; |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 652 | $log->info( |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 653 | 'The code took: '. |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 654 | timestr(timediff($new, $main::LAST_STOP)) . |
| 655 | ' (overall: ' . timestr(timediff($new, $main::TIME)) . ')' |
| 656 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 657 | $main::LAST_STOP = $new; |
| 658 | }; |
| 659 | |
| 660 | # Create and parse new document |
| 661 | $input =~ s{([^/])$}{$1/}; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 662 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 663 | # Process file |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 664 | $batch_file->process($input, $output); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 665 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 666 | # Delete cache file |
| 667 | unlink($cache_file) if $cache_delete; |
| 668 | |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 669 | stop_time; |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 670 | exit; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 671 | }; |
| 672 | |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 673 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 674 | # Extract XML files |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 675 | if ($cmd eq 'extract') { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 676 | |
Akron | d5643ad | 2017-07-04 20:27:13 +0200 | [diff] [blame] | 677 | # Output is required |
| 678 | pod2usage(%ERROR_HASH) unless $output; |
| 679 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 680 | # Create new archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 681 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 682 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 683 | # Check zip capabilities |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 684 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 685 | $log->error("Unzip is not installed or incompatible."); |
| 686 | exit 1; |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 687 | }; |
| 688 | |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 689 | # Add further annotation archived |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 690 | $archive->attach($_) foreach @input[1..$#input]; |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 691 | |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 692 | my $prefix = 1; |
| 693 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 694 | # No sigles given |
| 695 | unless (@sigle) { |
| 696 | |
| 697 | # Get files |
| 698 | foreach ($archive->list_texts) { |
| 699 | |
| 700 | # Split path information |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 701 | ($prefix, my ($corpus, $doc, $text)) = $archive->split_path($_); |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 702 | |
| 703 | # TODO: Make this OS independent |
| 704 | push @sigle, join '/', $corpus, $doc, $text; |
| 705 | }; |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | # Check sigle for doc sigles |
| 709 | else { |
| 710 | my @new_sigle; |
| 711 | |
| 712 | my $prefix_check = 0; |
| 713 | |
| 714 | # Iterate over all sigle |
| 715 | foreach (@sigle) { |
| 716 | |
| 717 | # Sigle is a doc sigle |
| 718 | if ($_ =~ m!^(?:\.[/\\])?[^/\\]+?[/\\][^/\\]+?$!) { |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 719 | |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 720 | print "$_ ..."; |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 721 | # Check if a prefix is needed |
| 722 | unless ($prefix_check) { |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 723 | |
| 724 | if ($prefix = $archive->check_prefix) { |
| 725 | print " with prefix ..."; |
| 726 | }; |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 727 | $prefix_check = 1; |
| 728 | }; |
| 729 | |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 730 | print "\n"; |
| 731 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 732 | # TODO: Make this OS independent |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 733 | my $path = ($prefix ? './' : '') . $_; |
| 734 | |
| 735 | print '... ' . ( |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 736 | $archive->extract_doc( |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 737 | $path, $output, $sequential_extraction ? 1 : $jobs |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 738 | ) ? '' : 'not ' |
| 739 | ); |
| 740 | print "extracted.\n"; |
| 741 | } |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 742 | |
| 743 | # Sigle is a text sigle |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 744 | else { |
| 745 | push @new_sigle, $_; |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 746 | |
| 747 | unless ($prefix_check) { |
| 748 | |
| 749 | if ($prefix = $archive->check_prefix) { |
| 750 | print " with prefix ..."; |
| 751 | }; |
| 752 | $prefix_check = 1; |
| 753 | }; |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 754 | }; |
| 755 | }; |
| 756 | @sigle = @new_sigle; |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 757 | }; |
| 758 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 759 | # Iterate over all given sigles and extract |
| 760 | foreach (@sigle) { |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 761 | |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 762 | print "$_ ...\n"; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 763 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 764 | # TODO: Make this OS independent |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 765 | print '... ' . ( |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 766 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 767 | $archive->extract_text( |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 768 | ($prefix ? './' : '') . $_, $output |
| 769 | ) ? '' : 'not ' |
| 770 | ); |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 771 | print "extracted.\n"; |
| 772 | }; |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 773 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 774 | |
| 775 | # Can't create archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 776 | else { |
| 777 | $log->error('Unable to extract from primary archive ' . $input[0]); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 778 | exit 1; |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 779 | }; |
| 780 | } |
| 781 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 782 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 783 | # Process an archive |
| 784 | elsif ($cmd eq 'archive') { |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 785 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 786 | my $archive_output; |
| 787 | |
| 788 | # First extract, then archive |
| 789 | if (defined $extract_dir) { |
| 790 | |
| 791 | # Create new archive object |
| 792 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
| 793 | |
| 794 | # Check zip capabilities |
| 795 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 796 | $log->error("Unzip is not installed or incompatible."); |
| 797 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 798 | }; |
| 799 | |
| 800 | # Add further annotation archived |
| 801 | $archive->attach($_) foreach @input[1..$#input]; |
| 802 | |
| 803 | # Create a temporary directory |
| 804 | if ($extract_dir eq ':temp:') { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 805 | $extract_dir = tempdir(CLEANUP => 0); |
| 806 | print "Temporarily extract to $extract_dir\n"; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 807 | }; |
| 808 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 809 | # Add some random extra to avoid clashes with multiple archives |
| 810 | $extract_dir = catdir($extract_dir, random_string('cccccc')); |
| 811 | |
| 812 | # Extract to temprary directory |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 813 | if ($archive->extract_all($extract_dir, $sequential_extraction ? 1: $jobs)) { |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 814 | @input = ($extract_dir); |
| 815 | } |
| 816 | else { |
| 817 | $log->error('Unable to extract from primary archive ' . $input[0] . |
| 818 | ' to ' . $extract_dir); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 819 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 820 | }; |
| 821 | } |
| 822 | |
| 823 | # Can't create archive object |
| 824 | else { |
| 825 | $log->error('Unable to extract from primary archive ' . $input[0]); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 826 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 827 | }; |
| 828 | }; |
| 829 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 830 | # TODO: Support sigles |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 831 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 832 | # Zero means: everything runs in the parent process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 833 | my $pool = Parallel::ForkManager->new($jobs); |
| 834 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 835 | my $count = 0; # Texts to process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 836 | my $iter = 1; # Current text in process |
| 837 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 838 | my $tar_archive; |
| 839 | my $output_dir = $output; |
| 840 | my $tar_fh; |
| 841 | |
| 842 | # Initialize tar archive |
| 843 | if ($to_tar) { |
| 844 | $tar_archive = Archive::Tar::Builder->new( |
| 845 | ignore_errors => 1 |
| 846 | ); |
| 847 | |
| 848 | # Set output name |
| 849 | my $tar_file = $output; |
| 850 | unless ($tar_file =~ /\.tar$/) { |
| 851 | $tar_file .= '.tar'; |
| 852 | }; |
| 853 | |
| 854 | # Initiate the tar file |
| 855 | print "Writing to file $tar_file\n"; |
| 856 | $tar_fh = IO::File->new($tar_file, 'w'); |
| 857 | $tar_fh->binmode(1); |
| 858 | |
| 859 | # Set handle |
| 860 | $tar_archive->set_handle($tar_fh); |
| 861 | |
| 862 | # Output to temporary directory |
| 863 | $output_dir = File::Temp->newdir; |
| 864 | }; |
| 865 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 866 | # Report on fork message |
| 867 | $pool->run_on_finish ( |
| 868 | sub { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 869 | my ($pid, $code) = @_; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 870 | my $data = pop; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 871 | |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 872 | print 'Convert ['. ($jobs > 0 ? "\$$pid:" : '') . |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 873 | ($iter++) . "/$count]" . |
| 874 | ($code ? " $code" : '') . |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 875 | ' ' . $data->[0] . "\n"; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 876 | |
| 877 | if (!$code && $to_tar && $data->[2]) { |
| 878 | my $filename = $data->[2]; |
| 879 | |
| 880 | # Lock filehandle |
| 881 | if (flock($tar_fh, LOCK_EX)) { |
| 882 | |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 883 | my $clean_file = fileparse($filename); |
| 884 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 885 | # Archive and remove file |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 886 | $tar_archive->archive_as($filename => $clean_file); |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 887 | unlink $filename; |
| 888 | |
| 889 | # Unlock filehandle |
| 890 | flock($tar_fh, LOCK_UN); |
| 891 | } |
| 892 | else { |
| 893 | $log->warn("Unable to add $filename to archive"); |
| 894 | }; |
| 895 | }; |
| 896 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 897 | $data->[1] = undef if $data->[1]; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 898 | } |
| 899 | ); |
| 900 | |
| 901 | my $t; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 902 | my $temp; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 903 | print "Reading data ...\n"; |
| 904 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 905 | # unless (Cache::FastMmap->new( |
| 906 | # share_file => $cache_file, |
| 907 | # cache_size => $cache_size, |
| 908 | # init_file => $cache_init |
| 909 | # )) { |
| 910 | # print "Unable to intialize cache '$cache_file'\n\n"; |
| 911 | # exit(1); |
| 912 | # }; |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 913 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 914 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 915 | # Input is a directory |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 916 | if (-d $input[0]) { |
| 917 | my $it = Directory::Iterator->new($input[0]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 918 | my @dirs; |
| 919 | my $dir; |
| 920 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 921 | # Todo: Make a DO WHILE |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 922 | while (1) { |
| 923 | if (!$it->is_directory && ($dir = $it->get) && $dir =~ s{/data\.xml$}{}) { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 924 | push @dirs, $dir; |
| 925 | $it->prune; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 926 | }; |
| 927 | last unless $it->next; |
| 928 | }; |
| 929 | |
| 930 | print "Start processing ...\n"; |
| 931 | $t = Benchmark->new; |
| 932 | $count = scalar @dirs; |
| 933 | |
| 934 | DIRECTORY_LOOP: |
| 935 | for (my $i = 0; $i < $count; $i++) { |
| 936 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 937 | my $filename = catfile( |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 938 | $output_dir, |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 939 | get_file_name($dirs[$i]) . '.json' . ($gzip ? '.gz' : '') |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 940 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 941 | |
| 942 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 943 | $pool->start and next DIRECTORY_LOOP; |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 944 | |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 945 | if (my $return = $batch_file->process($dirs[$i] => $filename)) { |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 946 | $pool->finish( |
| 947 | 0, |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 948 | [ |
| 949 | "Processed " . $filename . ($return == -1 ? " - already existing" : ''), |
| 950 | undef, |
| 951 | $filename |
| 952 | ] |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 953 | ); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 954 | } |
| 955 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 956 | $pool->finish(1, ["Unable to process " . $dirs[$i]]); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 957 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 958 | }; |
| 959 | } |
| 960 | |
| 961 | # Input is a file |
Akron | 29866ac | 2016-06-24 16:40:47 +0200 | [diff] [blame] | 962 | elsif (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 963 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 964 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 965 | $log->error("Unzip is not installed or incompatible."); |
| 966 | exit 1; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 967 | }; |
| 968 | |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 969 | # Add further annotation archived |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 970 | $archive->attach($_) foreach @input[1..$#input]; |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 971 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 972 | print "Start processing ...\n"; |
| 973 | $t = Benchmark->new; |
| 974 | my @dirs = $archive->list_texts; |
| 975 | $count = scalar @dirs; |
| 976 | |
| 977 | ARCHIVE_LOOP: |
| 978 | for (my $i = 0; $i < $count; $i++) { |
| 979 | |
| 980 | # Split path information |
| 981 | my ($prefix, $corpus, $doc, $text) = $archive->split_path($dirs[$i]); |
| 982 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 983 | my $filename = catfile( |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 984 | $output_dir, |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 985 | get_file_name( |
| 986 | catfile($corpus, $doc, $text) |
| 987 | . '.json' . ($gzip ? '.gz' : '') |
| 988 | ) |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 989 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 990 | |
| 991 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 992 | $pool->start and next ARCHIVE_LOOP; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 993 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 994 | # Create temporary file |
| 995 | $temp = File::Temp->newdir; |
| 996 | |
Akron | bdf434a | 2016-10-24 17:42:07 +0200 | [diff] [blame] | 997 | # TODO: Check if $filename exist at the beginning, |
| 998 | # because extraction can be horrible slow! |
| 999 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1000 | # Extract from archive |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1001 | if ($archive->extract_text($dirs[$i], $temp)) { |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1002 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 1003 | # Create corpus directory |
| 1004 | my $input = catdir("$temp", $corpus); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1005 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 1006 | # Temporary directory |
| 1007 | my $dir = catdir($input, $doc, $text); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1008 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 1009 | # Write file |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 1010 | if (my $return = $batch_file->process($dir => $filename)) { |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 1011 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 1012 | # Delete temporary file |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 1013 | $pool->finish( |
| 1014 | 0, |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 1015 | [ |
| 1016 | "Processed " . $filename . ($return == -1 ? " - already existing" : ''), |
| 1017 | $temp, |
| 1018 | $filename |
| 1019 | ] |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 1020 | ); |
| 1021 | #$pool->finish(0, ["Processed " . $filename, $temp]); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 1022 | } |
| 1023 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 1024 | # Delete temporary file |
| 1025 | $pool->finish(1, ["Unable to process " . $dir, $temp]); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 1026 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1027 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 1028 | |
| 1029 | # Unable to extract |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1030 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 1031 | $pool->finish(1, ["Unable to extract " . $dirs[$i], $temp]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1032 | }; |
| 1033 | }; |
| 1034 | } |
| 1035 | |
| 1036 | else { |
| 1037 | print "Input is neither a directory nor an archive.\n\n"; |
| 1038 | }; |
| 1039 | |
| 1040 | $pool->wait_all_children; |
| 1041 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1042 | # Delete cache file |
| 1043 | unlink($cache_file) if $cache_delete; |
| 1044 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 1045 | # Close tar filehandle |
| 1046 | if ($to_tar && $tar_fh) { |
| 1047 | $tar_archive->finish; |
| 1048 | $tar_fh->close; |
| 1049 | print "Wrote to tar archive.\n"; |
| 1050 | }; |
| 1051 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1052 | print timestr(timediff(Benchmark->new, $t))."\n"; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1053 | print "Done.\n"; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1054 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1055 | |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 1056 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1057 | # Cleanup temporary extraction directory |
| 1058 | if ($extract_dir) { |
| 1059 | my $objects = remove_tree($extract_dir, { safe => 1 }); |
| 1060 | print "Removed directory $extract_dir with $objects objects.\n"; |
| 1061 | }; |
| 1062 | |
| 1063 | |
| 1064 | print "\n"; |
| 1065 | |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 1066 | __END__ |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1067 | |
| 1068 | =pod |
| 1069 | |
| 1070 | =encoding utf8 |
| 1071 | |
| 1072 | =head1 NAME |
| 1073 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1074 | korapxml2krill - Merge KorapXML data and create Krill documents |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1075 | |
| 1076 | |
| 1077 | =head1 SYNOPSIS |
| 1078 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1079 | korapxml2krill [archive|extract] --input <directory|archive> [options] |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1080 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1081 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1082 | =head1 DESCRIPTION |
| 1083 | |
| 1084 | L<KorAP::XML::Krill> is a library to convert KorAP-XML documents to files |
| 1085 | compatible with the L<Krill|https://github.com/KorAP/Krill> indexer. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1086 | The C<korapxml2krill> command line tool is a simple wrapper to the library. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1087 | |
| 1088 | |
| 1089 | =head1 INSTALLATION |
| 1090 | |
| 1091 | The preferred way to install L<KorAP::XML::Krill> is to use L<cpanm|App::cpanminus>. |
| 1092 | |
Akron | af38698 | 2016-10-12 00:33:25 +0200 | [diff] [blame] | 1093 | $ cpanm https://github.com/KorAP/KorAP-XML-Krill.git |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1094 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1095 | In case everything went well, the C<korapxml2krill> tool will |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1096 | be available on your command line immediately. |
Akron | 6eff23b | 2018-09-24 10:31:20 +0200 | [diff] [blame] | 1097 | Minimum requirement for L<KorAP::XML::Krill> is Perl 5.16. |
Akron | a93d51b | 2016-10-24 20:27:48 +0200 | [diff] [blame] | 1098 | 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] | 1099 | |
| 1100 | =head1 ARGUMENTS |
| 1101 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1102 | $ korapxml2krill -z --input <directory> --output <filename> |
| 1103 | |
| 1104 | Without arguments, C<korapxml2krill> converts a directory of a single KorAP-XML document. |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1105 | It expects the input to point to the text level folder. |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1106 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1107 | =over 2 |
| 1108 | |
| 1109 | =item B<archive> |
| 1110 | |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 1111 | $ korapxml2krill archive -z --input <directory|archive> --output <directory|tar> |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1112 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1113 | Converts an archive of KorAP-XML documents. It expects a directory |
| 1114 | (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] | 1115 | |
| 1116 | =item B<extract> |
| 1117 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1118 | $ korapxml2krill extract --input <archive> --output <directory> --sigle <SIGLE> |
| 1119 | |
| 1120 | Extracts KorAP-XML documents from a zip file. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1121 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1122 | =item B<serial> |
| 1123 | |
| 1124 | $ korapxml2krill serial -i <archive1> -i <archive2> -o <directory> -cfg <config-file> |
| 1125 | |
| 1126 | Convert archives sequentially. The inputs are not merged but treated |
| 1127 | as they are (so they may be premerged or globs). |
| 1128 | the C<--out> directory is treated as the base directory where subdirectories |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 1129 | are created based on the archive name. In case the C<--to-tar> flag is given, |
| 1130 | the output will be a tar file. |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1131 | |
| 1132 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1133 | =back |
| 1134 | |
| 1135 | |
| 1136 | =head1 OPTIONS |
| 1137 | |
| 1138 | =over 2 |
| 1139 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1140 | =item B<--input|-i> <directory|zip file> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1141 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1142 | Directory or zip file(s) of documents to convert. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1143 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1144 | Without arguments, C<korapxml2krill> expects a folder of a single KorAP-XML |
Akron | f1a1de9 | 2016-11-02 17:32:12 +0100 | [diff] [blame] | 1145 | document, while C<archive> expects a KorAP-XML corpus folder or a zip |
| 1146 | file to batch process multiple files. |
| 1147 | C<extract> expects zip files only. |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1148 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1149 | C<archive> supports multiple input zip files with the constraint, |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1150 | that the first archive listed contains all primary data files |
| 1151 | and all meta data files. |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1152 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1153 | -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] | 1154 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1155 | Input may also be defined using BSD glob wildcards. |
| 1156 | |
| 1157 | -i 'file/news*.zip' |
| 1158 | |
| 1159 | The extended input array will be sorted in length order, so the shortest |
| 1160 | path needs to contain all primary data files and all meta data files. |
| 1161 | |
Akron | 0c3e375 | 2016-06-28 15:55:53 +0200 | [diff] [blame] | 1162 | (The directory structure follows the base directory format, |
| 1163 | that may include a C<.> root folder. |
| 1164 | In this case further archives lacking a C<.> root folder |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1165 | need to be passed with a hash sign in front of the archive's name. |
| 1166 | This may require to quote the parameter.) |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1167 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1168 | To support zip files, a version of C<unzip> needs to be installed that is |
| 1169 | compatible with the archive file. |
Akron | a93d51b | 2016-10-24 20:27:48 +0200 | [diff] [blame] | 1170 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1171 | B<The root folder switch using the hash sign is experimental and |
| 1172 | may vanish in future versions.> |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 1173 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1174 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1175 | =item B<--input-base|-ib> <directory> |
| 1176 | |
| 1177 | The base directory for inputs. |
| 1178 | |
| 1179 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1180 | =item B<--output|-o> <directory|file> |
| 1181 | |
| 1182 | Output folder for archive processing or |
| 1183 | document name for single output (optional), |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1184 | writes to C<STDOUT> by default |
| 1185 | (in case C<output> is not mandatory due to further options). |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1186 | |
| 1187 | =item B<--overwrite|-w> |
| 1188 | |
| 1189 | Overwrite files that already exist. |
| 1190 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1191 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1192 | =item B<--token|-t> <foundry>#<file> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1193 | |
| 1194 | Define the default tokenization by specifying |
| 1195 | the name of the foundry and optionally the name |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1196 | of the layer-file. Defaults to C<OpenNLP#tokens>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1197 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1198 | |
| 1199 | =item B<--base-sentences|-bs> <foundry>#<layer> |
| 1200 | |
| 1201 | Define the layer for base sentences. |
| 1202 | If given, this will be used instead of using C<Base#Sentences>. |
| 1203 | Currently C<DeReKo#Structure> is the only additional layer supported. |
| 1204 | |
| 1205 | Defaults to unset. |
| 1206 | |
| 1207 | |
| 1208 | =item B<--base-paragraphs|-bp> <foundry>#<layer> |
| 1209 | |
| 1210 | Define the layer for base paragraphs. |
| 1211 | If given, this will be used instead of using C<Base#Paragraphs>. |
| 1212 | Currently C<DeReKo#Structure> is the only additional layer supported. |
| 1213 | |
| 1214 | Defaults to unset. |
| 1215 | |
| 1216 | |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 1217 | =item B<--base-pagebreaks|-bpb> <foundry>#<layer> |
| 1218 | |
| 1219 | Define the layer for base pagebreaks. |
| 1220 | Currently C<DeReKo#Structure> is the only layer supported. |
| 1221 | |
| 1222 | Defaults to unset. |
| 1223 | |
| 1224 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1225 | =item B<--skip|-s> <foundry>[#<layer>] |
| 1226 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1227 | Skip specific annotations by specifying the foundry |
| 1228 | (and optionally the layer with a C<#>-prefix), |
| 1229 | 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] | 1230 | Can be set multiple times. |
| 1231 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1232 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1233 | =item B<--anno|-a> <foundry>#<layer> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1234 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1235 | Convert specific annotations by specifying the foundry |
| 1236 | (and optionally the layer with a C<#>-prefix), |
| 1237 | e.g. C<Mate> or C<Mate#Morpho>. |
| 1238 | Can be set multiple times. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1239 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1240 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1241 | =item B<--primary|-p> |
| 1242 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1243 | Output primary data or not. Defaults to C<true>. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1244 | Can be flagged using C<--no-primary> as well. |
| 1245 | This is I<deprecated>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1246 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1247 | |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 1248 | =item B<--non-word-tokens|-nwt> |
| 1249 | |
| 1250 | Tokenize non-word tokens like word tokens (defined as matching |
| 1251 | C</[\d\w]/>). Useful to treat punctuations as tokens. |
| 1252 | |
| 1253 | Defaults to unset. |
| 1254 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1255 | =item B<--jobs|-j> |
| 1256 | |
| 1257 | Define the number of concurrent jobs in seperated forks |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1258 | for archive processing. |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1259 | Defaults to C<0> (everything runs in a single process). |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1260 | |
| 1261 | If C<sequential-extraction> is not set to false, this will |
| 1262 | also apply to extraction. |
| 1263 | |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 1264 | Pass -1, and the value will be set automatically to 5 |
| 1265 | times the number of available cores. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1266 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1267 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1268 | |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 1269 | =item B<--koral|-k> |
| 1270 | |
| 1271 | Version of the output format. Supported versions are: |
| 1272 | C<0> for legacy serialization, C<0.03> for serialization |
| 1273 | with metadata fields as key-values on the root object, |
| 1274 | C<0.4> for serialization with metadata fields as a list |
| 1275 | of C<"@type":"koral:field"> objects. |
| 1276 | |
| 1277 | Currently defaults to C<0.03>. |
| 1278 | |
| 1279 | |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1280 | =item B<--sequential-extraction|-se> |
| 1281 | |
| 1282 | Flag to indicate, if the C<jobs> value also applies to extraction. |
| 1283 | Some systems may have problems with extracting multiple archives |
| 1284 | to the same folder at the same time. |
| 1285 | Can be flagged using C<--no-sequential-extraction> as well. |
| 1286 | Defaults to C<false>. |
| 1287 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1288 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1289 | =item B<--meta|-m> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1290 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1291 | Define the metadata parser to use. Defaults to C<I5>. |
| 1292 | Metadata parsers can be defined in the C<KorAP::XML::Meta> namespace. |
| 1293 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1294 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1295 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1296 | =item B<--pretty|-y> |
| 1297 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1298 | Pretty print JSON output. Defaults to C<false>. |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1299 | This is I<deprecated>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1300 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1301 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1302 | =item B<--gzip|-z> |
| 1303 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1304 | Compress the output. |
| 1305 | Expects a defined C<output> file in single processing. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1306 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1307 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1308 | =item B<--cache|-c> |
| 1309 | |
| 1310 | File to mmap a cache (using L<Cache::FastMmap>). |
| 1311 | Defaults to C<korapxml2krill.cache> in the calling directory. |
| 1312 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1313 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1314 | =item B<--cache-size|-cs> |
| 1315 | |
| 1316 | Size of the cache. Defaults to C<50m>. |
| 1317 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1318 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1319 | =item B<--cache-init|-ci> |
| 1320 | |
| 1321 | Initialize cache file. |
| 1322 | Can be flagged using C<--no-cache-init> as well. |
| 1323 | Defaults to C<true>. |
| 1324 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1325 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1326 | =item B<--cache-delete|-cd> |
| 1327 | |
| 1328 | Delete cache file after processing. |
| 1329 | Can be flagged using C<--no-cache-delete> as well. |
| 1330 | Defaults to C<true>. |
| 1331 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1332 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1333 | =item B<--config|-cfg> |
| 1334 | |
| 1335 | Configure the parameters of your call in a file |
| 1336 | of key-value pairs with whitespace separator |
| 1337 | |
| 1338 | overwrite 1 |
| 1339 | token DeReKo#Structure |
| 1340 | ... |
| 1341 | |
| 1342 | Supported parameters are: |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1343 | C<overwrite>, C<gzip>, C<jobs>, C<input-base>, |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1344 | C<token>, C<log>, C<cache>, C<cache-size>, C<cache-delete>, C<meta>, |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1345 | C<output>, |
| 1346 | C<temp-extract>, C<sequential-extraction>, |
| 1347 | C<base-sentences>, C<base-paragraphs>, |
| 1348 | C<base-pagebreaks>, |
| 1349 | C<skip> (semicolon separated), C<sigle> |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1350 | (semicolon separated), C<anno> (semicolon separated). |
| 1351 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1352 | Configuration parameters will always be overwritten by |
| 1353 | passed parameters. |
| 1354 | |
| 1355 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1356 | =item B<--temporary-extract|-te> |
| 1357 | |
| 1358 | Only valid for the C<archive> command. |
| 1359 | |
| 1360 | This will first extract all files into a |
| 1361 | directory and then will archive. |
| 1362 | If the directory is given as C<:temp:>, |
| 1363 | a temporary directory is used. |
| 1364 | This is especially useful to avoid |
| 1365 | massive unzipping and potential |
| 1366 | network latency. |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1367 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1368 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1369 | =item B<--sigle|-sg> |
| 1370 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1371 | Extract the given texts. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1372 | Can be set multiple times. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1373 | I<Currently only supported on C<extract>.> |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 1374 | Sigles have the structure C<Corpus>/C<Document>/C<Text>. |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1375 | 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] | 1376 | On the document level, the postfix wildcard C<*> is supported. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1377 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1378 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1379 | =item B<--log|-l> |
| 1380 | |
| 1381 | The L<Log4perl> log level, defaults to C<ERROR>. |
| 1382 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1383 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1384 | =item B<--help|-h> |
| 1385 | |
| 1386 | Print this document. |
| 1387 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1388 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1389 | =item B<--version|-v> |
| 1390 | |
| 1391 | Print version information. |
| 1392 | |
| 1393 | =back |
| 1394 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1395 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1396 | =head1 ANNOTATION SUPPORT |
| 1397 | |
| 1398 | L<KorAP::XML::Krill> has built-in importer for some annotation foundries and layers |
| 1399 | developed in the KorAP project that are part of the KorAP preprocessing pipeline. |
| 1400 | The base foundry with paragraphs, sentences, and the text element are mandatory for |
| 1401 | L<Krill|https://github.com/KorAP/Krill>. |
| 1402 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1403 | Base |
| 1404 | #Paragraphs |
| 1405 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1406 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1407 | Connexor |
| 1408 | #Morpho |
| 1409 | #Phrase |
| 1410 | #Sentences |
| 1411 | #Syntax |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1412 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1413 | CoreNLP |
| 1414 | #Constituency |
| 1415 | #Morpho |
| 1416 | #NamedEntities |
| 1417 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1418 | |
Akron | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 1419 | CMC |
| 1420 | #Morpho |
| 1421 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1422 | DeReKo |
| 1423 | #Structure |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1424 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1425 | DRuKoLa |
| 1426 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1427 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1428 | Glemm |
| 1429 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1430 | |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 1431 | HNC |
| 1432 | #Morpho |
| 1433 | |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 1434 | LWC |
| 1435 | #Dependency |
| 1436 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1437 | Malt |
| 1438 | #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1439 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1440 | MarMoT |
| 1441 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1442 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1443 | Mate |
| 1444 | #Dependency |
| 1445 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1446 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1447 | MDParser |
| 1448 | #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1449 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1450 | OpenNLP |
| 1451 | #Morpho |
| 1452 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1453 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1454 | Sgbr |
| 1455 | #Lemma |
| 1456 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1457 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1458 | TreeTagger |
| 1459 | #Morpho |
| 1460 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1461 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1462 | XIP |
| 1463 | #Constituency |
| 1464 | #Morpho |
| 1465 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1466 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1467 | |
| 1468 | More importers are in preparation. |
| 1469 | New annotation importers can be defined in the C<KorAP::XML::Annotation> namespace. |
| 1470 | See the built-in annotation importers as examples. |
| 1471 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1472 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1473 | =head1 AVAILABILITY |
| 1474 | |
| 1475 | https://github.com/KorAP/KorAP-XML-Krill |
| 1476 | |
| 1477 | |
| 1478 | =head1 COPYRIGHT AND LICENSE |
| 1479 | |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 1480 | Copyright (C) 2015-2019, L<IDS Mannheim|http://www.ids-mannheim.de/> |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1481 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1482 | Author: L<Nils Diewald|http://nils-diewald.de/> |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1483 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1484 | Contributor: Eliza Margaretha |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1485 | |
| 1486 | L<KorAP::XML::Krill> is developed as part of the L<KorAP|http://korap.ids-mannheim.de/> |
| 1487 | Corpus Analysis Platform at the |
| 1488 | L<Institute for the German Language (IDS)|http://ids-mannheim.de/>, |
| 1489 | member of the |
| 1490 | L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/en/about-us/leibniz-competition/projekte-2011/2011-funding-line-2/>. |
| 1491 | |
| 1492 | This program is free software published under the |
| 1493 | L<BSD-2 License|https://raw.githubusercontent.com/KorAP/KorAP-XML-Krill/master/LICENSE>. |
| 1494 | |
| 1495 | =cut |