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