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