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