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