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