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