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