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