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 |
Akron | bd3adda | 2017-04-11 15:00:55 +0200 | [diff] [blame^] | 370 | if (make_path($new_out) == 0 && !-d $new_out) { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 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 |
Akron | bd3adda | 2017-04-11 15:00:55 +0200 | [diff] [blame^] | 528 | $glob =~ s![\\\/]!-!g; # Transform paths |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 529 | $glob =~ s/[\*\?]//g; # Remove arbitrary fills |
| 530 | $glob =~ s/[\{\}\[\]]/-/g; # Remove class and multiple brackets |
| 531 | $glob =~ s/\-\-+/-/g; # Remove sequences of binding characters |
| 532 | $glob =~ s/^-//; # Clean beginning |
| 533 | $glob =~ s/-$//; # Clean end |
| 534 | return $glob; |
| 535 | }; |
| 536 | |
| 537 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 538 | # Convert sigle to path construct |
| 539 | s!^\s*([^_]+?)_([^\.]+?)\.(.+?)\s*$!$1/$2/$3! foreach @sigle; |
| 540 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 541 | if ($cmd) { |
| 542 | if ($output && (!-e $output || !-d $output)) { |
| 543 | print "Directory '$output' does not exist.\n\n"; |
| 544 | exit(0); |
| 545 | }; |
| 546 | }; |
| 547 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 548 | |
| 549 | # Glob and prefix files |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 550 | if (@input) { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 551 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 552 | my @new_input = (); |
| 553 | |
| 554 | # Iterate over all inputs |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 555 | foreach my $wild_card (@input) { |
| 556 | |
| 557 | # Prefix with input root |
| 558 | $wild_card = $input_base ? catfile($input_base, $wild_card) : $wild_card; |
| 559 | |
| 560 | push (@new_input, bsd_glob($wild_card)); |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 561 | }; |
| 562 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 563 | # Sort files by length |
| 564 | @input = sort { length($a) <=> length($b) } @new_input; |
| 565 | |
| 566 | print 'Input is ' . join(', ', @input)."\n"; |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 567 | }; |
| 568 | |
| 569 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 570 | # Process a single file |
| 571 | unless ($cmd) { |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 572 | my $input = $input[0]; |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 573 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 574 | BEGIN { |
| 575 | $main::TIME = Benchmark->new; |
| 576 | $main::LAST_STOP = Benchmark->new; |
| 577 | }; |
| 578 | |
| 579 | sub stop_time { |
| 580 | my $new = Benchmark->new; |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 581 | $log->info( |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 582 | 'The code took: '. |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 583 | timestr(timediff($new, $main::LAST_STOP)) . |
| 584 | ' (overall: ' . timestr(timediff($new, $main::TIME)) . ')' |
| 585 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 586 | $main::LAST_STOP = $new; |
| 587 | }; |
| 588 | |
| 589 | # Create and parse new document |
| 590 | $input =~ s{([^/])$}{$1/}; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 591 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 592 | # Process file |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 593 | $batch_file->process($input, $output); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 594 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 595 | # Delete cache file |
| 596 | unlink($cache_file) if $cache_delete; |
| 597 | |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 598 | stop_time; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 599 | exit(1); |
| 600 | }; |
| 601 | |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 602 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 603 | # Extract XML files |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 604 | if ($cmd eq 'extract') { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 605 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 606 | # Create new archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 607 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 608 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 609 | # Check zip capabilities |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 610 | unless ($archive->test_unzip) { |
| 611 | print "Unzip is not installed or incompatible.\n\n"; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 612 | exit(0); |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 613 | }; |
| 614 | |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 615 | # Add further annotation archived |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 616 | $archive->attach($_) foreach @input[1..$#input]; |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 617 | |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 618 | my $prefix = 1; |
| 619 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 620 | # No sigles given |
| 621 | unless (@sigle) { |
| 622 | |
| 623 | # Get files |
| 624 | foreach ($archive->list_texts) { |
| 625 | |
| 626 | # Split path information |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 627 | ($prefix, my ($corpus, $doc, $text)) = $archive->split_path($_); |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 628 | |
| 629 | # TODO: Make this OS independent |
| 630 | push @sigle, join '/', $corpus, $doc, $text; |
| 631 | }; |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | # Check sigle for doc sigles |
| 635 | else { |
| 636 | my @new_sigle; |
| 637 | |
| 638 | my $prefix_check = 0; |
| 639 | |
| 640 | # Iterate over all sigle |
| 641 | foreach (@sigle) { |
| 642 | |
| 643 | # Sigle is a doc sigle |
| 644 | if ($_ =~ m!^(?:\.[/\\])?[^/\\]+?[/\\][^/\\]+?$!) { |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 645 | |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 646 | print "$_ ..."; |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 647 | # Check if a prefix is needed |
| 648 | unless ($prefix_check) { |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 649 | |
| 650 | if ($prefix = $archive->check_prefix) { |
| 651 | print " with prefix ..."; |
| 652 | }; |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 653 | $prefix_check = 1; |
| 654 | }; |
| 655 | |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 656 | print "\n"; |
| 657 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 658 | # TODO: Make this OS independent |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 659 | my $path = ($prefix ? './' : '') . $_; |
| 660 | |
| 661 | print '... ' . ( |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 662 | $archive->extract_doc( |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 663 | $path, $output, $jobs |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 664 | ) ? '' : 'not ' |
| 665 | ); |
| 666 | print "extracted.\n"; |
| 667 | } |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 668 | |
| 669 | # Sigle is a text sigle |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 670 | else { |
| 671 | push @new_sigle, $_; |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 672 | |
| 673 | unless ($prefix_check) { |
| 674 | |
| 675 | if ($prefix = $archive->check_prefix) { |
| 676 | print " with prefix ..."; |
| 677 | }; |
| 678 | $prefix_check = 1; |
| 679 | }; |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 680 | }; |
| 681 | }; |
| 682 | @sigle = @new_sigle; |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 683 | }; |
| 684 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 685 | # Iterate over all given sigles and extract |
| 686 | foreach (@sigle) { |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 687 | |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 688 | print "$_ ...\n"; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 689 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 690 | # TODO: Make this OS independent |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 691 | print '... ' . ( |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 692 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 693 | $archive->extract_text( |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 694 | ($prefix ? './' : '') . $_, $output |
| 695 | ) ? '' : 'not ' |
| 696 | ); |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 697 | print "extracted.\n"; |
| 698 | }; |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 699 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 700 | |
| 701 | # Can't create archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 702 | else { |
| 703 | $log->error('Unable to extract from primary archive ' . $input[0]); |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 704 | exit(1); |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 705 | }; |
| 706 | } |
| 707 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 708 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 709 | # Process an archive |
| 710 | elsif ($cmd eq 'archive') { |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 711 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 712 | my $archive_output; |
| 713 | |
| 714 | # First extract, then archive |
| 715 | if (defined $extract_dir) { |
| 716 | |
| 717 | # Create new archive object |
| 718 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
| 719 | |
| 720 | # Check zip capabilities |
| 721 | unless ($archive->test_unzip) { |
| 722 | print "Unzip is not installed or incompatible.\n\n"; |
| 723 | exit(0); |
| 724 | }; |
| 725 | |
| 726 | # Add further annotation archived |
| 727 | $archive->attach($_) foreach @input[1..$#input]; |
| 728 | |
| 729 | # Create a temporary directory |
| 730 | if ($extract_dir eq ':temp:') { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 731 | $extract_dir = tempdir(CLEANUP => 0); |
| 732 | print "Temporarily extract to $extract_dir\n"; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 733 | }; |
| 734 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 735 | # Add some random extra to avoid clashes with multiple archives |
| 736 | $extract_dir = catdir($extract_dir, random_string('cccccc')); |
| 737 | |
| 738 | # Extract to temprary directory |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 739 | if ($archive->extract_all($extract_dir, $jobs)) { |
| 740 | @input = ($extract_dir); |
| 741 | } |
| 742 | else { |
| 743 | $log->error('Unable to extract from primary archive ' . $input[0] . |
| 744 | ' to ' . $extract_dir); |
| 745 | exit(1); |
| 746 | }; |
| 747 | } |
| 748 | |
| 749 | # Can't create archive object |
| 750 | else { |
| 751 | $log->error('Unable to extract from primary archive ' . $input[0]); |
| 752 | exit(1); |
| 753 | }; |
| 754 | }; |
| 755 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 756 | # TODO: Support sigles |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 757 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 758 | # Zero means: everything runs in the parent process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 759 | my $pool = Parallel::ForkManager->new($jobs); |
| 760 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 761 | my $count = 0; # Texts to process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 762 | my $iter = 1; # Current text in process |
| 763 | |
| 764 | # Report on fork message |
| 765 | $pool->run_on_finish ( |
| 766 | sub { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 767 | my ($pid, $code) = @_; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 768 | my $data = pop; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 769 | |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 770 | print 'Convert ['. ($jobs > 0 ? "\$$pid:" : '') . |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 771 | ($iter++) . "/$count]" . |
| 772 | ($code ? " $code" : '') . |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 773 | ' ' . $data->[0] . "\n"; |
| 774 | $data->[1] = undef if $data->[1]; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 775 | } |
| 776 | ); |
| 777 | |
| 778 | my $t; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 779 | my $temp; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 780 | print "Reading data ...\n"; |
| 781 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 782 | # unless (Cache::FastMmap->new( |
| 783 | # share_file => $cache_file, |
| 784 | # cache_size => $cache_size, |
| 785 | # init_file => $cache_init |
| 786 | # )) { |
| 787 | # print "Unable to intialize cache '$cache_file'\n\n"; |
| 788 | # exit(1); |
| 789 | # }; |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 790 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 791 | # Input is a directory |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 792 | if (-d $input[0]) { |
| 793 | my $it = Directory::Iterator->new($input[0]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 794 | my @dirs; |
| 795 | my $dir; |
| 796 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 797 | # Todo: Make a DO WHILE |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 798 | while (1) { |
| 799 | if (!$it->is_directory && ($dir = $it->get) && $dir =~ s{/data\.xml$}{}) { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 800 | push @dirs, $dir; |
| 801 | $it->prune; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 802 | }; |
| 803 | last unless $it->next; |
| 804 | }; |
| 805 | |
| 806 | print "Start processing ...\n"; |
| 807 | $t = Benchmark->new; |
| 808 | $count = scalar @dirs; |
| 809 | |
| 810 | DIRECTORY_LOOP: |
| 811 | for (my $i = 0; $i < $count; $i++) { |
| 812 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 813 | my $filename = catfile( |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 814 | $output, |
| 815 | get_file_name($dirs[$i]) . '.json' . ($gzip ? '.gz' : '') |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 816 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 817 | |
| 818 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 819 | $pool->start and next DIRECTORY_LOOP; |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 820 | |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 821 | if (my $return = $batch_file->process($dirs[$i] => $filename)) { |
| 822 | $pool->finish( |
| 823 | 0, |
| 824 | ["Processed " . $filename . ($return == -1 ? " - already existing" : '')] |
| 825 | ); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 826 | } |
| 827 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 828 | $pool->finish(1, ["Unable to process " . $dirs[$i]]); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 829 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 830 | }; |
| 831 | } |
| 832 | |
| 833 | # Input is a file |
Akron | 29866ac | 2016-06-24 16:40:47 +0200 | [diff] [blame] | 834 | elsif (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 835 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 836 | unless ($archive->test_unzip) { |
| 837 | print "Unzip is not installed or incompatible.\n\n"; |
| 838 | exit(1); |
| 839 | }; |
| 840 | |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 841 | # Add further annotation archived |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 842 | $archive->attach($_) foreach @input[1..$#input]; |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 843 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 844 | print "Start processing ...\n"; |
| 845 | $t = Benchmark->new; |
| 846 | my @dirs = $archive->list_texts; |
| 847 | $count = scalar @dirs; |
| 848 | |
| 849 | ARCHIVE_LOOP: |
| 850 | for (my $i = 0; $i < $count; $i++) { |
| 851 | |
| 852 | # Split path information |
| 853 | my ($prefix, $corpus, $doc, $text) = $archive->split_path($dirs[$i]); |
| 854 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 855 | my $filename = catfile( |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 856 | $output, |
| 857 | get_file_name( |
| 858 | catfile($corpus, $doc, $text) |
| 859 | . '.json' . ($gzip ? '.gz' : '') |
| 860 | ) |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 861 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 862 | |
| 863 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 864 | $pool->start and next ARCHIVE_LOOP; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 865 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 866 | # Create temporary file |
| 867 | $temp = File::Temp->newdir; |
| 868 | |
Akron | bdf434a | 2016-10-24 17:42:07 +0200 | [diff] [blame] | 869 | # TODO: Check if $filename exist at the beginning, |
| 870 | # because extraction can be horrible slow! |
| 871 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 872 | # Extract from archive |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 873 | if ($archive->extract_text($dirs[$i], $temp)) { |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 874 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 875 | # Create corpus directory |
| 876 | my $input = catdir("$temp", $corpus); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 877 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 878 | # Temporary directory |
| 879 | my $dir = catdir($input, $doc, $text); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 880 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 881 | # Write file |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 882 | if (my $return = $batch_file->process($dir => $filename)) { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 883 | # Delete temporary file |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 884 | $pool->finish( |
| 885 | 0, |
| 886 | ["Processed " . $filename . ($return == -1 ? " - already existing" : ''), $temp] |
| 887 | ); |
| 888 | #$pool->finish(0, ["Processed " . $filename, $temp]); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 889 | } |
| 890 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 891 | # Delete temporary file |
| 892 | $pool->finish(1, ["Unable to process " . $dir, $temp]); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 893 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 894 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 895 | |
| 896 | # Unable to extract |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 897 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 898 | $pool->finish(1, ["Unable to extract " . $dirs[$i], $temp]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 899 | }; |
| 900 | }; |
| 901 | } |
| 902 | |
| 903 | else { |
| 904 | print "Input is neither a directory nor an archive.\n\n"; |
| 905 | }; |
| 906 | |
| 907 | $pool->wait_all_children; |
| 908 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 909 | # Delete cache file |
| 910 | unlink($cache_file) if $cache_delete; |
| 911 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 912 | print timestr(timediff(Benchmark->new, $t))."\n"; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 913 | print "Done.\n"; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 914 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 915 | |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 916 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 917 | # Cleanup temporary extraction directory |
| 918 | if ($extract_dir) { |
| 919 | my $objects = remove_tree($extract_dir, { safe => 1 }); |
| 920 | print "Removed directory $extract_dir with $objects objects.\n"; |
| 921 | }; |
| 922 | |
| 923 | |
| 924 | print "\n"; |
| 925 | |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 926 | __END__ |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 927 | |
| 928 | =pod |
| 929 | |
| 930 | =encoding utf8 |
| 931 | |
| 932 | =head1 NAME |
| 933 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 934 | korapxml2krill - Merge KorapXML data and create Krill documents |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 935 | |
| 936 | |
| 937 | =head1 SYNOPSIS |
| 938 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 939 | korapxml2krill [archive|extract] --input <directory|archive> [options] |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 940 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 941 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 942 | =head1 DESCRIPTION |
| 943 | |
| 944 | L<KorAP::XML::Krill> is a library to convert KorAP-XML documents to files |
| 945 | compatible with the L<Krill|https://github.com/KorAP/Krill> indexer. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 946 | The C<korapxml2krill> command line tool is a simple wrapper to the library. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 947 | |
| 948 | |
| 949 | =head1 INSTALLATION |
| 950 | |
| 951 | The preferred way to install L<KorAP::XML::Krill> is to use L<cpanm|App::cpanminus>. |
| 952 | |
Akron | af38698 | 2016-10-12 00:33:25 +0200 | [diff] [blame] | 953 | $ cpanm https://github.com/KorAP/KorAP-XML-Krill.git |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 954 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 955 | In case everything went well, the C<korapxml2krill> tool will |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 956 | be available on your command line immediately. |
Akron | 7438151 | 2016-10-14 11:56:22 +0200 | [diff] [blame] | 957 | Minimum requirement for L<KorAP::XML::Krill> is Perl 5.14. |
Akron | a93d51b | 2016-10-24 20:27:48 +0200 | [diff] [blame] | 958 | 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] | 959 | |
| 960 | =head1 ARGUMENTS |
| 961 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 962 | $ korapxml2krill -z --input <directory> --output <filename> |
| 963 | |
| 964 | Without arguments, C<korapxml2krill> converts a directory of a single KorAP-XML document. |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 965 | It expects the input to point to the text level folder. |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 966 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 967 | =over 2 |
| 968 | |
| 969 | =item B<archive> |
| 970 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 971 | $ korapxml2krill archive -z --input <directory|archive> --output <directory> |
| 972 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 973 | Converts an archive of KorAP-XML documents. It expects a directory |
| 974 | (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] | 975 | |
| 976 | =item B<extract> |
| 977 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 978 | $ korapxml2krill extract --input <archive> --output <directory> --sigle <SIGLE> |
| 979 | |
| 980 | Extracts KorAP-XML documents from a zip file. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 981 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 982 | =item B<serial> |
| 983 | |
| 984 | $ korapxml2krill serial -i <archive1> -i <archive2> -o <directory> -cfg <config-file> |
| 985 | |
| 986 | Convert archives sequentially. The inputs are not merged but treated |
| 987 | as they are (so they may be premerged or globs). |
| 988 | the C<--out> directory is treated as the base directory where subdirectories |
| 989 | are created based on the archive name. |
| 990 | |
| 991 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 992 | =back |
| 993 | |
| 994 | |
| 995 | =head1 OPTIONS |
| 996 | |
| 997 | =over 2 |
| 998 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 999 | =item B<--input|-i> <directory|zip file> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1000 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1001 | Directory or zip file(s) of documents to convert. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1002 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1003 | Without arguments, C<korapxml2krill> expects a folder of a single KorAP-XML |
Akron | f1a1de9 | 2016-11-02 17:32:12 +0100 | [diff] [blame] | 1004 | document, while C<archive> expects a KorAP-XML corpus folder or a zip |
| 1005 | file to batch process multiple files. |
| 1006 | C<extract> expects zip files only. |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1007 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1008 | C<archive> supports multiple input zip files with the constraint, |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1009 | that the first archive listed contains all primary data files |
| 1010 | and all meta data files. |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1011 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1012 | -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] | 1013 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1014 | Input may also be defined using BSD glob wildcards. |
| 1015 | |
| 1016 | -i 'file/news*.zip' |
| 1017 | |
| 1018 | The extended input array will be sorted in length order, so the shortest |
| 1019 | path needs to contain all primary data files and all meta data files. |
| 1020 | |
Akron | 0c3e375 | 2016-06-28 15:55:53 +0200 | [diff] [blame] | 1021 | (The directory structure follows the base directory format, |
| 1022 | that may include a C<.> root folder. |
| 1023 | In this case further archives lacking a C<.> root folder |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1024 | need to be passed with a hash sign in front of the archive's name. |
| 1025 | This may require to quote the parameter.) |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1026 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1027 | To support zip files, a version of C<unzip> needs to be installed that is |
| 1028 | compatible with the archive file. |
Akron | a93d51b | 2016-10-24 20:27:48 +0200 | [diff] [blame] | 1029 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1030 | B<The root folder switch using the hash sign is experimental and |
| 1031 | may vanish in future versions.> |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 1032 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1033 | =item B<--input-base|-ib> <directory> |
| 1034 | |
| 1035 | The base directory for inputs. |
| 1036 | |
| 1037 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1038 | =item B<--output|-o> <directory|file> |
| 1039 | |
| 1040 | Output folder for archive processing or |
| 1041 | document name for single output (optional), |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1042 | writes to C<STDOUT> by default |
| 1043 | (in case C<output> is not mandatory due to further options). |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1044 | |
| 1045 | =item B<--overwrite|-w> |
| 1046 | |
| 1047 | Overwrite files that already exist. |
| 1048 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1049 | =item B<--token|-t> <foundry>#<file> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1050 | |
| 1051 | Define the default tokenization by specifying |
| 1052 | the name of the foundry and optionally the name |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1053 | of the layer-file. Defaults to C<OpenNLP#tokens>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1054 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1055 | |
| 1056 | =item B<--base-sentences|-bs> <foundry>#<layer> |
| 1057 | |
| 1058 | Define the layer for base sentences. |
| 1059 | If given, this will be used instead of using C<Base#Sentences>. |
| 1060 | Currently C<DeReKo#Structure> is the only additional layer supported. |
| 1061 | |
| 1062 | Defaults to unset. |
| 1063 | |
| 1064 | |
| 1065 | =item B<--base-paragraphs|-bp> <foundry>#<layer> |
| 1066 | |
| 1067 | Define the layer for base paragraphs. |
| 1068 | If given, this will be used instead of using C<Base#Paragraphs>. |
| 1069 | Currently C<DeReKo#Structure> is the only additional layer supported. |
| 1070 | |
| 1071 | Defaults to unset. |
| 1072 | |
| 1073 | |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 1074 | =item B<--base-pagebreaks|-bpb> <foundry>#<layer> |
| 1075 | |
| 1076 | Define the layer for base pagebreaks. |
| 1077 | Currently C<DeReKo#Structure> is the only layer supported. |
| 1078 | |
| 1079 | Defaults to unset. |
| 1080 | |
| 1081 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1082 | =item B<--skip|-s> <foundry>[#<layer>] |
| 1083 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1084 | Skip specific annotations by specifying the foundry |
| 1085 | (and optionally the layer with a C<#>-prefix), |
| 1086 | 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] | 1087 | Can be set multiple times. |
| 1088 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1089 | =item B<--anno|-a> <foundry>#<layer> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1090 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1091 | Convert specific annotations by specifying the foundry |
| 1092 | (and optionally the layer with a C<#>-prefix), |
| 1093 | e.g. C<Mate> or C<Mate#Morpho>. |
| 1094 | Can be set multiple times. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1095 | |
| 1096 | =item B<--primary|-p> |
| 1097 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1098 | Output primary data or not. Defaults to C<true>. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1099 | Can be flagged using C<--no-primary> as well. |
| 1100 | This is I<deprecated>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1101 | |
| 1102 | =item B<--jobs|-j> |
| 1103 | |
| 1104 | Define the number of concurrent jobs in seperated forks |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1105 | for archive processing. |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1106 | Defaults to C<0> (everything runs in a single process). |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 1107 | Pass -1, and the value will be set automatically to 5 |
| 1108 | times the number of available cores. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1109 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1110 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1111 | =item B<--meta|-m> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1112 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1113 | Define the metadata parser to use. Defaults to C<I5>. |
| 1114 | Metadata parsers can be defined in the C<KorAP::XML::Meta> namespace. |
| 1115 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1116 | |
| 1117 | =item B<--pretty|-y> |
| 1118 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1119 | Pretty print JSON output. Defaults to C<false>. |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1120 | This is I<deprecated>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1121 | |
| 1122 | =item B<--gzip|-z> |
| 1123 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1124 | Compress the output. |
| 1125 | Expects a defined C<output> file in single processing. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1126 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1127 | =item B<--cache|-c> |
| 1128 | |
| 1129 | File to mmap a cache (using L<Cache::FastMmap>). |
| 1130 | Defaults to C<korapxml2krill.cache> in the calling directory. |
| 1131 | |
| 1132 | =item B<--cache-size|-cs> |
| 1133 | |
| 1134 | Size of the cache. Defaults to C<50m>. |
| 1135 | |
| 1136 | =item B<--cache-init|-ci> |
| 1137 | |
| 1138 | Initialize cache file. |
| 1139 | Can be flagged using C<--no-cache-init> as well. |
| 1140 | Defaults to C<true>. |
| 1141 | |
| 1142 | =item B<--cache-delete|-cd> |
| 1143 | |
| 1144 | Delete cache file after processing. |
| 1145 | Can be flagged using C<--no-cache-delete> as well. |
| 1146 | Defaults to C<true>. |
| 1147 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1148 | =item B<--config|-cfg> |
| 1149 | |
| 1150 | Configure the parameters of your call in a file |
| 1151 | of key-value pairs with whitespace separator |
| 1152 | |
| 1153 | overwrite 1 |
| 1154 | token DeReKo#Structure |
| 1155 | ... |
| 1156 | |
| 1157 | Supported parameters are: |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1158 | C<overwrite>, C<gzip>, C<jobs>, C<input-base>, |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1159 | 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] | 1160 | C<output>, C<base-sentences>, C<temp-extract>, C<base-paragraphs>, |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1161 | C<base-pagebreaks>, C<skip> (semicolon separated), C<sigle> |
| 1162 | (semicolon separated), C<anno> (semicolon separated). |
| 1163 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1164 | =item B<--temporary-extract|-te> |
| 1165 | |
| 1166 | Only valid for the C<archive> command. |
| 1167 | |
| 1168 | This will first extract all files into a |
| 1169 | directory and then will archive. |
| 1170 | If the directory is given as C<:temp:>, |
| 1171 | a temporary directory is used. |
| 1172 | This is especially useful to avoid |
| 1173 | massive unzipping and potential |
| 1174 | network latency. |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1175 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1176 | =item B<--sigle|-sg> |
| 1177 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1178 | Extract the given texts. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1179 | Can be set multiple times. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1180 | I<Currently only supported on C<extract>.> |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 1181 | Sigles have the structure C<Corpus>/C<Document>/C<Text>. |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1182 | 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] | 1183 | On the document level, the postfix wildcard C<*> is supported. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1184 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1185 | =item B<--log|-l> |
| 1186 | |
| 1187 | The L<Log4perl> log level, defaults to C<ERROR>. |
| 1188 | |
| 1189 | =item B<--help|-h> |
| 1190 | |
| 1191 | Print this document. |
| 1192 | |
| 1193 | =item B<--version|-v> |
| 1194 | |
| 1195 | Print version information. |
| 1196 | |
| 1197 | =back |
| 1198 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1199 | =head1 ANNOTATION SUPPORT |
| 1200 | |
| 1201 | L<KorAP::XML::Krill> has built-in importer for some annotation foundries and layers |
| 1202 | developed in the KorAP project that are part of the KorAP preprocessing pipeline. |
| 1203 | The base foundry with paragraphs, sentences, and the text element are mandatory for |
| 1204 | L<Krill|https://github.com/KorAP/Krill>. |
| 1205 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1206 | Base |
| 1207 | #Paragraphs |
| 1208 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1209 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1210 | Connexor |
| 1211 | #Morpho |
| 1212 | #Phrase |
| 1213 | #Sentences |
| 1214 | #Syntax |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1215 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1216 | CoreNLP |
| 1217 | #Constituency |
| 1218 | #Morpho |
| 1219 | #NamedEntities |
| 1220 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1221 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1222 | DeReKo |
| 1223 | #Structure |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1224 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1225 | DRuKoLa |
| 1226 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1227 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1228 | Glemm |
| 1229 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1230 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1231 | Malt |
| 1232 | #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1233 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1234 | MarMoT |
| 1235 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1236 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1237 | Mate |
| 1238 | #Dependency |
| 1239 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1240 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1241 | MDParser |
| 1242 | #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1243 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1244 | OpenNLP |
| 1245 | #Morpho |
| 1246 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1247 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1248 | Sgbr |
| 1249 | #Lemma |
| 1250 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1251 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1252 | TreeTagger |
| 1253 | #Morpho |
| 1254 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1255 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1256 | XIP |
| 1257 | #Constituency |
| 1258 | #Morpho |
| 1259 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1260 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1261 | |
| 1262 | More importers are in preparation. |
| 1263 | New annotation importers can be defined in the C<KorAP::XML::Annotation> namespace. |
| 1264 | See the built-in annotation importers as examples. |
| 1265 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1266 | =head1 AVAILABILITY |
| 1267 | |
| 1268 | https://github.com/KorAP/KorAP-XML-Krill |
| 1269 | |
| 1270 | |
| 1271 | =head1 COPYRIGHT AND LICENSE |
| 1272 | |
Akron | 3ec0a1c | 2017-01-18 14:41:55 +0100 | [diff] [blame] | 1273 | Copyright (C) 2015-2017, L<IDS Mannheim|http://www.ids-mannheim.de/> |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1274 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1275 | Author: L<Nils Diewald|http://nils-diewald.de/> |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1276 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1277 | Contributor: Eliza Margaretha |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1278 | |
| 1279 | L<KorAP::XML::Krill> is developed as part of the L<KorAP|http://korap.ids-mannheim.de/> |
| 1280 | Corpus Analysis Platform at the |
| 1281 | L<Institute for the German Language (IDS)|http://ids-mannheim.de/>, |
| 1282 | member of the |
| 1283 | L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/en/about-us/leibniz-competition/projekte-2011/2011-funding-line-2/>. |
| 1284 | |
| 1285 | This program is free software published under the |
| 1286 | L<BSD-2 License|https://raw.githubusercontent.com/KorAP/KorAP-XML-Krill/master/LICENSE>. |
| 1287 | |
| 1288 | =cut |