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