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