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/; |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 10 | use Log::Log4perl; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 11 | use Pod::Usage; |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 12 | use Cache::FastMmap; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 13 | use Directory::Iterator; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 14 | use KorAP::XML::Krill; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 15 | use KorAP::XML::Archive; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 16 | use KorAP::XML::Tokenizer; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 17 | use KorAP::XML::Batch::File; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 18 | use Parallel::ForkManager; |
Akron | 75ba57d | 2016-03-07 23:36:27 +0100 | [diff] [blame] | 19 | # TODO: use Parallel::Loops |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 20 | # TODO: make output files |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 21 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 22 | # CHANGES: |
| 23 | # ---------------------------------------------------------- |
| 24 | # 2013/11/25 |
| 25 | # - Initial release |
| 26 | # |
| 27 | # 2014/10/29 |
| 28 | # - Merges foundry data to create indexer friendly documents |
| 29 | # |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 30 | # 2016/02/04 |
| 31 | # - renamed to korapxml2krill |
| 32 | # - added Schreibgebrauch support |
Akron | 069bd71 | 2016-02-12 19:09:06 +0100 | [diff] [blame] | 33 | # |
| 34 | # 2016/02/12 |
| 35 | # - fixed foundry skipping |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 36 | # - Support overwrite in archive processing |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 37 | # |
| 38 | # 2016/02/14 |
| 39 | # - Added version information |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 40 | # - Added support for archive files |
| 41 | # |
| 42 | # 2016/02/15 |
| 43 | # - Fixed temporary directory bug |
| 44 | # - Improved skipping before unzipping |
| 45 | # - Added EXPERIMENTAL concurrency support |
| 46 | # |
| 47 | # 2016/02/23 |
| 48 | # - Merge korapxml2krill and korapxml2krill_dir |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 49 | # |
| 50 | # 2016/02/27 |
| 51 | # - Added extract function |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 52 | # |
| 53 | # 2016/03/17 |
| 54 | # - Added meta switch |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 55 | # |
| 56 | # 2016/03/18 |
| 57 | # - Added meta data caching |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 58 | # |
Akron | f3f0c94 | 2016-06-27 13:27:14 +0200 | [diff] [blame] | 59 | # 2016/06/27 |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 60 | # - Added multi archive support |
| 61 | # - Added prefix negation support |
Akron | f3f0c94 | 2016-06-27 13:27:14 +0200 | [diff] [blame] | 62 | # - Added Malt#Dependency support |
Akron | 8b99052 | 2016-07-06 16:45:57 +0200 | [diff] [blame] | 63 | # |
| 64 | # 2016/07/06 |
| 65 | # - Added MDParser#Dependency |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 66 | # |
| 67 | # 2016/10/15 |
Nils Diewald | 0e48977 | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 68 | # - Fixed temporary path issue in script |
| 69 | # |
| 70 | # 2016/10/24 |
| 71 | # - Improved Windows support |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 72 | # |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 73 | # ---------------------------------------------------------- |
Akron | 069bd71 | 2016-02-12 19:09:06 +0100 | [diff] [blame] | 74 | |
Nils Diewald | 0e48977 | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 75 | our $LAST_CHANGE = '2016/10/24'; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 76 | our $LOCAL = $FindBin::Bin; |
| 77 | our $VERSION_MSG = <<"VERSION"; |
| 78 | Version $KorAP::XML::Krill::VERSION - diewald\@ids-mannheim.de - $LAST_CHANGE |
| 79 | VERSION |
| 80 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 81 | # Parse comand |
| 82 | my $cmd; |
| 83 | our @ARGV; |
| 84 | if ($ARGV[0] && index($ARGV[0], '-') != 0) { |
| 85 | $cmd = shift @ARGV; |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 86 | }; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 87 | |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 88 | my (@skip, @sigle, @anno, @input); |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 89 | my $text; |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 90 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 91 | # Parse options from the command line |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 92 | GetOptions( |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 93 | 'input|i=s' => \@input, |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 94 | 'output|o=s' => \(my $output), |
| 95 | 'overwrite|w' => \(my $overwrite), |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 96 | 'meta|m=s' => \(my $meta), |
Akron | af38698 | 2016-10-12 00:33:25 +0200 | [diff] [blame] | 97 | 'token|t=s' => \(my $token_base = 'OpenNLP#tokens'), |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 98 | 'gzip|z' => \(my $gzip), |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 99 | 'skip|s=s' => \@skip, |
| 100 | 'sigle|sg=s' => \@sigle, |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 101 | 'cache|c=s' => \(my $cache_file = 'korapxml2krill.cache'), |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 102 | 'log|l=s' => \(my $log_level = 'ERROR'), |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 103 | 'anno|a=s' => \@anno, |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 104 | 'primary|p!' => \(my $primary), |
| 105 | 'pretty|y' => \(my $pretty), |
| 106 | 'jobs|j=i' => \(my $jobs = 0), |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 107 | 'cache-size|cs=s' => \(my $cache_size = '50m'), |
| 108 | 'cache-delete|cd!' => \(my $cache_delete = 1), |
| 109 | 'cache-init|ci!' => \(my $cache_init = 1), |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 110 | 'help|h' => sub { |
| 111 | pod2usage( |
| 112 | -sections => 'NAME|SYNOPSIS|ARGUMENTS|OPTIONS', |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 113 | -verbose => 99, |
| 114 | -msg => $VERSION_MSG, |
| 115 | -output => '-' |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 116 | ); |
| 117 | }, |
| 118 | 'version|v' => sub { |
| 119 | pod2usage( |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 120 | -verbose => 0, |
| 121 | -msg => $VERSION_MSG, |
| 122 | -output => '-' |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 123 | ) |
| 124 | } |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 125 | ); |
| 126 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 127 | my %ERROR_HASH = ( |
| 128 | -sections => 'NAME|SYNOPSIS|ARGUMENTS|OPTIONS', |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 129 | -verbose => 99, |
| 130 | -msg => $VERSION_MSG, |
| 131 | -output => '-', |
| 132 | -exit => 1 |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 133 | ); |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 134 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 135 | # Input has to be defined |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 136 | pod2usage(%ERROR_HASH) unless @input; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 137 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 138 | # Gzip has no effect, if no output is given |
| 139 | pod2usage(%ERROR_HASH) if $gzip && !$output; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 140 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 141 | # Initialize log4perl object |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 142 | Log::Log4perl->init({ |
| 143 | 'log4perl.rootLogger' => uc($log_level) . ', STDERR', |
| 144 | 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels', |
| 145 | 'log4perl.appender.STDERR.layout' => 'PatternLayout', |
| 146 | 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n' |
| 147 | }); |
| 148 | |
| 149 | my $log = Log::Log4perl->get_logger('main'); |
| 150 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 151 | my %skip; |
| 152 | $skip{lc($_)} = 1 foreach @skip; |
| 153 | |
| 154 | my @layers; |
| 155 | push(@layers, ['Base', 'Sentences']); |
| 156 | push(@layers, ['Base', 'Paragraphs']); |
| 157 | |
| 158 | # Connexor |
| 159 | push(@layers, ['Connexor', 'Morpho']); |
| 160 | push(@layers, ['Connexor', 'Syntax']); |
| 161 | push(@layers, ['Connexor', 'Phrase']); |
| 162 | push(@layers, ['Connexor', 'Sentences']); |
| 163 | |
| 164 | # CoreNLP |
| 165 | push(@layers, ['CoreNLP', 'NamedEntities']); |
| 166 | push(@layers, ['CoreNLP', 'Sentences']); |
| 167 | push(@layers, ['CoreNLP', 'Morpho']); |
| 168 | push(@layers, ['CoreNLP', 'Constituency']); |
| 169 | |
| 170 | # DeReKo |
| 171 | push(@layers, ['DeReKo', 'Structure']); |
| 172 | |
| 173 | # Glemm |
| 174 | push(@layers, ['Glemm', 'Morpho']); |
| 175 | |
| 176 | # Malt |
| 177 | push(@layers, ['Malt', 'Dependency']); |
| 178 | |
| 179 | # MDParser |
| 180 | push(@layers, ['MDParser', 'Dependency']); |
| 181 | |
| 182 | # Mate |
| 183 | push(@layers, ['Mate', 'Morpho']); |
| 184 | push(@layers, ['Mate', 'Dependency']); |
| 185 | |
| 186 | # OpenNLP |
| 187 | push(@layers, ['OpenNLP', 'Morpho']); |
| 188 | push(@layers, ['OpenNLP', 'Sentences']); |
| 189 | |
| 190 | # Schreibgebrauch |
| 191 | push(@layers, ['Sgbr', 'Lemma']); |
| 192 | push(@layers, ['Sgbr', 'Morpho']); |
| 193 | |
| 194 | # TreeTagger |
| 195 | push(@layers, ['TreeTagger', 'Morpho']); |
| 196 | push(@layers, ['TreeTagger', 'Sentences']); |
| 197 | |
| 198 | # XIP |
| 199 | push(@layers, ['XIP', 'Morpho']); |
| 200 | push(@layers, ['XIP', 'Constituency']); |
| 201 | push(@layers, ['XIP', 'Sentences']); |
| 202 | push(@layers, ['XIP', 'Dependency']); |
| 203 | |
| 204 | # Check filters |
| 205 | my @filtered_anno; |
| 206 | if ($skip{'#all'}) { |
| 207 | foreach (@anno) { |
| 208 | push @filtered_anno, [ split('#', $_) ]; |
| 209 | }; |
| 210 | } |
| 211 | |
| 212 | # Add all annotations that are not skipped |
| 213 | else { |
| 214 | # Add to index file - respect skipping |
| 215 | foreach my $info (@layers) { |
| 216 | # Skip if Foundry or Foundry#Layer should be skipped |
| 217 | unless ($skip{lc($info->[0])} || $skip{lc($info->[0]) . '#' . lc($info->[1])}) { |
| 218 | push @filtered_anno, $info; |
| 219 | }; |
| 220 | }; |
| 221 | }; |
| 222 | |
| 223 | # Get tokenization basis |
| 224 | my ($token_base_foundry, $token_base_layer) = split(/#/, $token_base) if ($token_base); |
| 225 | |
| 226 | # TODO: This should not be initialized for batch |
| 227 | my $cache = Cache::FastMmap->new( |
| 228 | share_file => $cache_file, |
| 229 | cache_size => $cache_size, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 230 | init_file => $cache_init |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 231 | ); |
| 232 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 233 | # Create batch object |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 234 | my $batch_file = KorAP::XML::Batch::File->new( |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 235 | cache => $cache, |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 236 | meta_type => $meta, |
| 237 | overwrite => $overwrite, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 238 | foundry => $token_base_foundry, |
| 239 | layer => $token_base_layer, |
| 240 | gzip => $gzip, |
| 241 | log => $log, |
| 242 | primary => $primary, |
| 243 | pretty => $pretty, |
| 244 | anno => \@filtered_anno |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 245 | ); |
| 246 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 247 | |
| 248 | # Get file name based on path information |
| 249 | sub get_file_name ($) { |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 250 | my $i = $input[0]; |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 251 | if (-d $i) { |
| 252 | $i =~ s![^\/]+$!!; |
| 253 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 254 | my $file = shift; |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 255 | |
| 256 | # Remove temp dir fragments |
Akron | 6255760 | 2016-06-27 14:10:13 +0200 | [diff] [blame] | 257 | $file =~ s!^/?tmp/[^/]+!!; |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 258 | $file =~ s/^?\/?$i//; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 259 | $file =~ tr/\//-/; |
| 260 | $file =~ s{^-+}{}; |
| 261 | return $file; |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 262 | }; |
| 263 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 264 | # Convert sigle to path construct |
| 265 | s!^\s*([^_]+?)_([^\.]+?)\.(.+?)\s*$!$1/$2/$3! foreach @sigle; |
| 266 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 267 | if ($cmd) { |
| 268 | if ($output && (!-e $output || !-d $output)) { |
| 269 | print "Directory '$output' does not exist.\n\n"; |
| 270 | exit(0); |
| 271 | }; |
| 272 | }; |
| 273 | |
| 274 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 275 | # Process a single file |
| 276 | unless ($cmd) { |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 277 | my $input = $input[0]; |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 278 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 279 | BEGIN { |
| 280 | $main::TIME = Benchmark->new; |
| 281 | $main::LAST_STOP = Benchmark->new; |
| 282 | }; |
| 283 | |
| 284 | sub stop_time { |
| 285 | my $new = Benchmark->new; |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 286 | $log->info( |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 287 | 'The code took: '. |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 288 | timestr(timediff($new, $main::LAST_STOP)) . |
| 289 | ' (overall: ' . timestr(timediff($new, $main::TIME)) . ')' |
| 290 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 291 | $main::LAST_STOP = $new; |
| 292 | }; |
| 293 | |
| 294 | # Create and parse new document |
| 295 | $input =~ s{([^/])$}{$1/}; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 296 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 297 | # Process file |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 298 | $batch_file->process($input, $output); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 299 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 300 | # Delete cache file |
| 301 | unlink($cache_file) if $cache_delete; |
| 302 | |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 303 | stop_time; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 304 | } |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 305 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 306 | # Extract XML files |
| 307 | elsif ($cmd eq 'extract') { |
| 308 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 309 | # Create new archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 310 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 311 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 312 | # Check zip capabilities |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 313 | unless ($archive->test_unzip) { |
| 314 | print "Unzip is not installed or incompatible.\n\n"; |
| 315 | exit(1); |
| 316 | }; |
| 317 | |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 318 | # Add further annotation archived |
| 319 | $archive->attach($_) foreach @input; |
| 320 | |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 321 | my $prefix = 1; |
| 322 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 323 | # No sigles given |
| 324 | unless (@sigle) { |
| 325 | |
| 326 | # Get files |
| 327 | foreach ($archive->list_texts) { |
| 328 | |
| 329 | # Split path information |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 330 | ($prefix, my ($corpus, $doc, $text)) = $archive->split_path($_); |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 331 | |
| 332 | # TODO: Make this OS independent |
| 333 | push @sigle, join '/', $corpus, $doc, $text; |
| 334 | }; |
| 335 | }; |
| 336 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 337 | # Iterate over all given sigles and extract |
| 338 | foreach (@sigle) { |
| 339 | print "$_ "; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 340 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 341 | # TODO: Make this OS independent |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 342 | print '' . ( |
| 343 | $archive->extract( |
| 344 | ($prefix ? './' : '') . $_, $output |
| 345 | ) ? '' : 'not ' |
| 346 | ); |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 347 | print "extracted.\n"; |
| 348 | }; |
| 349 | |
| 350 | print "\n"; |
| 351 | exit(1); |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 352 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 353 | |
| 354 | # Can't create archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 355 | else { |
| 356 | $log->error('Unable to extract from primary archive ' . $input[0]); |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 357 | }; |
| 358 | } |
| 359 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 360 | # Process an archive |
| 361 | elsif ($cmd eq 'archive') { |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 362 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 363 | # TODO: Support sigles |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 364 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 365 | # Zero means: everything runs in the parent process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 366 | my $pool = Parallel::ForkManager->new($jobs); |
| 367 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 368 | my $count = 0; # Texts to process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 369 | my $iter = 1; # Current text in process |
| 370 | |
| 371 | # Report on fork message |
| 372 | $pool->run_on_finish ( |
| 373 | sub { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 374 | my ($pid, $code) = @_; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 375 | my $data = pop; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 376 | |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 377 | print 'Convert ['. ($jobs > 0 ? "\$$pid:" : '') . |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 378 | ($iter++) . "/$count]" . |
| 379 | ($code ? " $code" : '') . |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 380 | ' ' . $data->[0] . "\n"; |
| 381 | $data->[1] = undef if $data->[1]; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 382 | } |
| 383 | ); |
| 384 | |
| 385 | my $t; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 386 | my $temp; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 387 | print "Reading data ...\n"; |
| 388 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 389 | # unless (Cache::FastMmap->new( |
| 390 | # share_file => $cache_file, |
| 391 | # cache_size => $cache_size, |
| 392 | # init_file => $cache_init |
| 393 | # )) { |
| 394 | # print "Unable to intialize cache '$cache_file'\n\n"; |
| 395 | # exit(1); |
| 396 | # }; |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 397 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 398 | # Input is a directory |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 399 | if (-d $input[0]) { |
| 400 | my $it = Directory::Iterator->new($input[0]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 401 | my @dirs; |
| 402 | my $dir; |
| 403 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 404 | # Todo: Make a DO WHILE |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 405 | while (1) { |
| 406 | if (!$it->is_directory && ($dir = $it->get) && $dir =~ s{/data\.xml$}{}) { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 407 | push @dirs, $dir; |
| 408 | $it->prune; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 409 | }; |
| 410 | last unless $it->next; |
| 411 | }; |
| 412 | |
| 413 | print "Start processing ...\n"; |
| 414 | $t = Benchmark->new; |
| 415 | $count = scalar @dirs; |
| 416 | |
| 417 | DIRECTORY_LOOP: |
| 418 | for (my $i = 0; $i < $count; $i++) { |
| 419 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 420 | my $filename = catfile( |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 421 | $output, |
| 422 | get_file_name($dirs[$i]) . '.json' . ($gzip ? '.gz' : '') |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 423 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 424 | |
| 425 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 426 | $pool->start and next DIRECTORY_LOOP; |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 427 | |
| 428 | if ($batch_file->process($dirs[$i] => $filename)) { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 429 | $pool->finish(0, ["Processed " . $filename]); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 430 | } |
| 431 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 432 | $pool->finish(1, ["Unable to process " . $dirs[$i]]); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 433 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 434 | }; |
| 435 | } |
| 436 | |
| 437 | # Input is a file |
Akron | 29866ac | 2016-06-24 16:40:47 +0200 | [diff] [blame] | 438 | elsif (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 439 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 440 | unless ($archive->test_unzip) { |
| 441 | print "Unzip is not installed or incompatible.\n\n"; |
| 442 | exit(1); |
| 443 | }; |
| 444 | |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 445 | # Add further annotation archived |
Akron | 29866ac | 2016-06-24 16:40:47 +0200 | [diff] [blame] | 446 | $archive->attach($_) foreach @input; |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 447 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 448 | print "Start processing ...\n"; |
| 449 | $t = Benchmark->new; |
| 450 | my @dirs = $archive->list_texts; |
| 451 | $count = scalar @dirs; |
| 452 | |
| 453 | ARCHIVE_LOOP: |
| 454 | for (my $i = 0; $i < $count; $i++) { |
| 455 | |
| 456 | # Split path information |
| 457 | my ($prefix, $corpus, $doc, $text) = $archive->split_path($dirs[$i]); |
| 458 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 459 | my $filename = catfile( |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 460 | $output, |
| 461 | get_file_name( |
| 462 | catfile($corpus, $doc, $text) |
| 463 | . '.json' . ($gzip ? '.gz' : '') |
| 464 | ) |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 465 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 466 | |
| 467 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 468 | $pool->start and next ARCHIVE_LOOP; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 469 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 470 | # Create temporary file |
| 471 | $temp = File::Temp->newdir; |
| 472 | |
Akron | bdf434a | 2016-10-24 17:42:07 +0200 | [diff] [blame] | 473 | # TODO: Check if $filename exist at the beginning, |
| 474 | # because extraction can be horrible slow! |
| 475 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 476 | # Extract from archive |
| 477 | if ($archive->extract($dirs[$i], $temp)) { |
| 478 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 479 | # Create corpus directory |
| 480 | my $input = catdir("$temp", $corpus); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 481 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 482 | # Temporary directory |
| 483 | my $dir = catdir($input, $doc, $text); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 484 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 485 | # Write file |
| 486 | if ($batch_file->process($dir => $filename)) { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 487 | # Delete temporary file |
| 488 | $pool->finish(0, ["Processed " . $filename, $temp]); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 489 | } |
| 490 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 491 | # Delete temporary file |
| 492 | $pool->finish(1, ["Unable to process " . $dir, $temp]); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 493 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 494 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 495 | |
| 496 | # Unable to extract |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 497 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 498 | $pool->finish(1, ["Unable to extract " . $dirs[$i], $temp]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 499 | }; |
| 500 | }; |
| 501 | } |
| 502 | |
| 503 | else { |
| 504 | print "Input is neither a directory nor an archive.\n\n"; |
| 505 | }; |
| 506 | |
| 507 | $pool->wait_all_children; |
| 508 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 509 | # Delete cache file |
| 510 | unlink($cache_file) if $cache_delete; |
| 511 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 512 | print "Done.\n"; |
| 513 | print timestr(timediff(Benchmark->new, $t))."\n\n"; |
| 514 | } |
| 515 | |
| 516 | # Unknown command |
| 517 | else { |
| 518 | warn "Unknown command '$cmd'.\n\n"; |
| 519 | pod2usage(%ERROR_HASH); |
| 520 | } |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 521 | |
| 522 | __END__ |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 523 | |
| 524 | =pod |
| 525 | |
| 526 | =encoding utf8 |
| 527 | |
| 528 | =head1 NAME |
| 529 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 530 | korapxml2krill - Merge KorapXML data and create Krill documents |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 531 | |
| 532 | |
| 533 | =head1 SYNOPSIS |
| 534 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 535 | $ korapxml2krill -z --input <directory> --output <filename> |
| 536 | $ korapxml2krill archive -z --input <directory> --output <directory> |
| 537 | $ korapxml2krill extract --input <directory> --output <filename> --sigle <SIGLE> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 538 | |
| 539 | |
| 540 | =head1 DESCRIPTION |
| 541 | |
| 542 | L<KorAP::XML::Krill> is a library to convert KorAP-XML documents to files |
| 543 | compatible with the L<Krill|https://github.com/KorAP/Krill> indexer. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 544 | The C<korapxml2krill> command line tool is a simple wrapper to the library. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 545 | |
| 546 | |
| 547 | =head1 INSTALLATION |
| 548 | |
| 549 | The preferred way to install L<KorAP::XML::Krill> is to use L<cpanm|App::cpanminus>. |
| 550 | |
Akron | af38698 | 2016-10-12 00:33:25 +0200 | [diff] [blame] | 551 | $ cpanm https://github.com/KorAP/KorAP-XML-Krill.git |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 552 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 553 | In case everything went well, the C<korapxml2krill> tool will |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 554 | be available on your command line immediately. |
Akron | 7438151 | 2016-10-14 11:56:22 +0200 | [diff] [blame] | 555 | Minimum requirement for L<KorAP::XML::Krill> is Perl 5.14. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 556 | |
| 557 | =head1 ARGUMENTS |
| 558 | |
| 559 | =over 2 |
| 560 | |
| 561 | =item B<archive> |
| 562 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 563 | Process an archive as a Zip-file or a folder of KorAP-XML documents. |
| 564 | |
| 565 | =item B<extract> |
| 566 | |
| 567 | Extract KorAP-XML files from a Zip-file. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 568 | |
| 569 | =back |
| 570 | |
| 571 | |
| 572 | =head1 OPTIONS |
| 573 | |
| 574 | =over 2 |
| 575 | |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 576 | =item B<--input|-i> <directory|file|files> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 577 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 578 | Directory or archive file of documents to convert. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 579 | |
Akron | 0c3e375 | 2016-06-28 15:55:53 +0200 | [diff] [blame] | 580 | Archiving supports multiple input archives with the constraint, |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 581 | that the first archive listed contains all primary data files |
| 582 | and all meta data files. |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 583 | |
| 584 | -i file/news.zip -i file/news.malt.zip -i #file/news.tt.zip |
| 585 | |
Akron | 0c3e375 | 2016-06-28 15:55:53 +0200 | [diff] [blame] | 586 | (The directory structure follows the base directory format, |
| 587 | that may include a C<.> root folder. |
| 588 | In this case further archives lacking a C<.> root folder |
| 589 | need to be passed with a hash sign in front of the archive's name.) |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 590 | |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 591 | B<The root folder switch is experimental and may vanish in future versions.> |
| 592 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 593 | =item B<--output|-o> <directory|file> |
| 594 | |
| 595 | Output folder for archive processing or |
| 596 | document name for single output (optional), |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 597 | writes to C<STDOUT> by default |
| 598 | (in case C<output> is not mandatory due to further options). |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 599 | |
| 600 | =item B<--overwrite|-w> |
| 601 | |
| 602 | Overwrite files that already exist. |
| 603 | |
| 604 | =item B<--token|-t> <foundry>[#<file>] |
| 605 | |
| 606 | Define the default tokenization by specifying |
| 607 | the name of the foundry and optionally the name |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 608 | of the layer-file. Defaults to C<OpenNLP#tokens>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 609 | |
| 610 | =item B<--skip|-s> <foundry>[#<layer>] |
| 611 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 612 | Skip specific annotations by specifying the foundry |
| 613 | (and optionally the layer with a C<#>-prefix), |
| 614 | 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] | 615 | Can be set multiple times. |
| 616 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 617 | =item B<--anno|-a> <foundry>#<layer> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 618 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 619 | Convert specific annotations by specifying the foundry |
| 620 | (and optionally the layer with a C<#>-prefix), |
| 621 | e.g. C<Mate> or C<Mate#Morpho>. |
| 622 | Can be set multiple times. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 623 | |
| 624 | =item B<--primary|-p> |
| 625 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 626 | Output primary data or not. Defaults to C<true>. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 627 | Can be flagged using C<--no-primary> as well. |
| 628 | This is I<deprecated>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 629 | |
| 630 | =item B<--jobs|-j> |
| 631 | |
| 632 | Define the number of concurrent jobs in seperated forks |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 633 | for archive processing. |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 634 | Defaults to C<0> (everything runs in a single process). |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 635 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 636 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 637 | =item B<--meta|-m> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 638 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 639 | Define the metadata parser to use. Defaults to C<I5>. |
| 640 | Metadata parsers can be defined in the C<KorAP::XML::Meta> namespace. |
| 641 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 642 | |
| 643 | =item B<--pretty|-y> |
| 644 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 645 | Pretty print JSON output. Defaults to C<false>. |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 646 | This is I<deprecated>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 647 | |
| 648 | =item B<--gzip|-z> |
| 649 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 650 | Compress the output. |
| 651 | Expects a defined C<output> file in single processing. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 652 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 653 | =item B<--cache|-c> |
| 654 | |
| 655 | File to mmap a cache (using L<Cache::FastMmap>). |
| 656 | Defaults to C<korapxml2krill.cache> in the calling directory. |
| 657 | |
| 658 | =item B<--cache-size|-cs> |
| 659 | |
| 660 | Size of the cache. Defaults to C<50m>. |
| 661 | |
| 662 | =item B<--cache-init|-ci> |
| 663 | |
| 664 | Initialize cache file. |
| 665 | Can be flagged using C<--no-cache-init> as well. |
| 666 | Defaults to C<true>. |
| 667 | |
| 668 | =item B<--cache-delete|-cd> |
| 669 | |
| 670 | Delete cache file after processing. |
| 671 | Can be flagged using C<--no-cache-delete> as well. |
| 672 | Defaults to C<true>. |
| 673 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 674 | =item B<--sigle|-sg> |
| 675 | |
| 676 | Extract the given text sigles. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 677 | Can be set multiple times. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 678 | I<Currently only supported on C<extract>.> |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 679 | Sigles have the structure C<Corpus>/C<Document>/C<Text>. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 680 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 681 | =item B<--log|-l> |
| 682 | |
| 683 | The L<Log4perl> log level, defaults to C<ERROR>. |
| 684 | |
| 685 | =item B<--help|-h> |
| 686 | |
| 687 | Print this document. |
| 688 | |
| 689 | =item B<--version|-v> |
| 690 | |
| 691 | Print version information. |
| 692 | |
| 693 | =back |
| 694 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 695 | =head1 ANNOTATION SUPPORT |
| 696 | |
| 697 | L<KorAP::XML::Krill> has built-in importer for some annotation foundries and layers |
| 698 | developed in the KorAP project that are part of the KorAP preprocessing pipeline. |
| 699 | The base foundry with paragraphs, sentences, and the text element are mandatory for |
| 700 | L<Krill|https://github.com/KorAP/Krill>. |
| 701 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 702 | =over 2 |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 703 | |
| 704 | =item B<Base> |
| 705 | |
| 706 | =over 4 |
| 707 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 708 | =item #Paragraphs |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 709 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 710 | =item #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 711 | |
| 712 | =back |
| 713 | |
| 714 | =item B<Connexor> |
| 715 | |
| 716 | =over 4 |
| 717 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 718 | =item #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 719 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 720 | =item #Phrase |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 721 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 722 | =item #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 723 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 724 | =item #Syntax |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 725 | |
| 726 | =back |
| 727 | |
| 728 | =item B<CoreNLP> |
| 729 | |
| 730 | =over 4 |
| 731 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 732 | =item #Constituency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 733 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 734 | =item #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 735 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 736 | =item #NamedEntities |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 737 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 738 | =item #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 739 | |
| 740 | =back |
| 741 | |
| 742 | =item B<DeReKo> |
| 743 | |
| 744 | =over 4 |
| 745 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 746 | =item #Structure |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 747 | |
| 748 | =back |
| 749 | |
| 750 | =item B<Glemm> |
| 751 | |
| 752 | =over 4 |
| 753 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 754 | =item #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 755 | |
| 756 | =back |
| 757 | |
| 758 | =item B<Mate> |
| 759 | |
| 760 | =over 4 |
| 761 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 762 | =item #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 763 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 764 | =item #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 765 | |
| 766 | =back |
| 767 | |
| 768 | =item B<OpenNLP> |
| 769 | |
| 770 | =over 4 |
| 771 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 772 | =item #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 773 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 774 | =item #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 775 | |
| 776 | =back |
| 777 | |
| 778 | =item B<Sgbr> |
| 779 | |
| 780 | =over 4 |
| 781 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 782 | =item #Lemma |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 783 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 784 | =item #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 785 | |
| 786 | =back |
| 787 | |
| 788 | =item B<TreeTagger> |
| 789 | |
| 790 | =over 4 |
| 791 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 792 | =item #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 793 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 794 | =item #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 795 | |
| 796 | =back |
| 797 | |
| 798 | =item B<XIP> |
| 799 | |
| 800 | =over 4 |
| 801 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 802 | =item #Constituency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 803 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 804 | =item #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 805 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 806 | =item #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 807 | |
| 808 | =back |
| 809 | |
| 810 | =back |
| 811 | |
| 812 | More importers are in preparation. |
| 813 | New annotation importers can be defined in the C<KorAP::XML::Annotation> namespace. |
| 814 | See the built-in annotation importers as examples. |
| 815 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 816 | =head1 AVAILABILITY |
| 817 | |
| 818 | https://github.com/KorAP/KorAP-XML-Krill |
| 819 | |
| 820 | |
| 821 | =head1 COPYRIGHT AND LICENSE |
| 822 | |
| 823 | Copyright (C) 2015-2016, L<IDS Mannheim|http://www.ids-mannheim.de/> |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 824 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 825 | Author: L<Nils Diewald|http://nils-diewald.de/> |
| 826 | |
| 827 | L<KorAP::XML::Krill> is developed as part of the L<KorAP|http://korap.ids-mannheim.de/> |
| 828 | Corpus Analysis Platform at the |
| 829 | L<Institute for the German Language (IDS)|http://ids-mannheim.de/>, |
| 830 | member of the |
| 831 | L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/en/about-us/leibniz-competition/projekte-2011/2011-funding-line-2/>. |
| 832 | |
| 833 | This program is free software published under the |
| 834 | L<BSD-2 License|https://raw.githubusercontent.com/KorAP/KorAP-XML-Krill/master/LICENSE>. |
| 835 | |
| 836 | =cut |