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