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