Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 4 | use v5.10; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 5 | use FindBin; |
| 6 | BEGIN { unshift @INC, "$FindBin::Bin/../lib" }; |
| 7 | use File::Spec::Functions qw/catfile catdir/; |
| 8 | use Getopt::Long qw/GetOptions :config no_auto_abbrev/; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 9 | use Benchmark qw/:hireswallclock/; |
| 10 | use IO::Compress::Gzip qw/$GzipError/; |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 11 | use POSIX qw/ceil/; |
Akron | b9c3381 | 2020-10-21 16:19:35 +0200 | [diff] [blame] | 12 | use Log::Any qw($log); |
| 13 | use Log::Any::Adapter; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 14 | use Pod::Usage; |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 15 | use Cache::FastMmap; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 16 | use Directory::Iterator; |
Akron | 41127e3 | 2020-08-07 12:46:19 +0200 | [diff] [blame] | 17 | use KorAP::XML::Krill qw!get_file_name get_file_name_from_glob!; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 18 | use KorAP::XML::Archive; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 19 | use KorAP::XML::Tokenizer; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 20 | use KorAP::XML::Batch::File; |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 21 | use Config::Simple; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 22 | use Parallel::ForkManager; |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 23 | use File::Glob ':bsd_glob'; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 24 | use File::Temp qw/tempdir/; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 25 | use File::Path qw(remove_tree make_path); |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 26 | use File::Basename; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 27 | use Mojo::Collection 'c'; |
| 28 | use String::Random qw(random_string); |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 29 | use IO::File; |
| 30 | use Archive::Tar::Builder; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 31 | use Fcntl qw(:flock SEEK_END); |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 32 | |
| 33 | # use KorAP::XML::ForkPool; |
Akron | 75ba57d | 2016-03-07 23:36:27 +0100 | [diff] [blame] | 34 | # TODO: use Parallel::Loops |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 35 | # TODO: make output files |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 36 | |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 37 | # TODO: Use KorAP::XML::ForkPool! |
| 38 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 39 | # CHANGES: |
| 40 | # ---------------------------------------------------------- |
| 41 | # 2013/11/25 |
| 42 | # - Initial release |
| 43 | # |
| 44 | # 2014/10/29 |
| 45 | # - Merges foundry data to create indexer friendly documents |
| 46 | # |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 47 | # 2016/02/04 |
| 48 | # - renamed to korapxml2krill |
| 49 | # - added Schreibgebrauch support |
Akron | 069bd71 | 2016-02-12 19:09:06 +0100 | [diff] [blame] | 50 | # |
| 51 | # 2016/02/12 |
| 52 | # - fixed foundry skipping |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 53 | # - Support overwrite in archive processing |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 54 | # |
| 55 | # 2016/02/14 |
| 56 | # - Added version information |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 57 | # - Added support for archive files |
| 58 | # |
| 59 | # 2016/02/15 |
| 60 | # - Fixed temporary directory bug |
| 61 | # - Improved skipping before unzipping |
| 62 | # - Added EXPERIMENTAL concurrency support |
| 63 | # |
| 64 | # 2016/02/23 |
| 65 | # - Merge korapxml2krill and korapxml2krill_dir |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 66 | # |
| 67 | # 2016/02/27 |
| 68 | # - Added extract function |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 69 | # |
| 70 | # 2016/03/17 |
| 71 | # - Added meta switch |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 72 | # |
| 73 | # 2016/03/18 |
| 74 | # - Added meta data caching |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 75 | # |
Akron | f3f0c94 | 2016-06-27 13:27:14 +0200 | [diff] [blame] | 76 | # 2016/06/27 |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 77 | # - Added multi archive support |
| 78 | # - Added prefix negation support |
Akron | f3f0c94 | 2016-06-27 13:27:14 +0200 | [diff] [blame] | 79 | # - Added Malt#Dependency support |
Akron | 8b99052 | 2016-07-06 16:45:57 +0200 | [diff] [blame] | 80 | # |
| 81 | # 2016/07/06 |
| 82 | # - Added MDParser#Dependency |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 83 | # |
| 84 | # 2016/10/15 |
Nils Diewald | 0e48977 | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 85 | # - Fixed temporary path issue in script |
| 86 | # |
| 87 | # 2016/10/24 |
| 88 | # - Improved Windows support |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 89 | # |
Akron | b4bbec7 | 2016-10-26 20:21:02 +0200 | [diff] [blame] | 90 | # 2016/10/24 |
| 91 | # - Added support for document extraction |
| 92 | # |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 93 | # 2016/10/27 |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 94 | # - Added wildcard support for document extraction |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 95 | # |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 96 | # 2016/12/21 |
| 97 | # - added support for base-sentences and base-tokenizations |
| 98 | # |
Akron | 4fa37c3 | 2017-01-20 14:43:10 +0100 | [diff] [blame] | 99 | # 2017/01/20 |
| 100 | # - added support for DRuKoLa annotations |
| 101 | # |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 102 | # 2017/02/08 |
| 103 | # - added support for pagebreak annotations |
| 104 | # |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 105 | # 2017/04/06 |
| 106 | # - added support for wildcards in input |
| 107 | # |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 108 | # 2017/04/07 |
| 109 | # - support configuration option |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 110 | # - support for temporary extraction |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 111 | # |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 112 | # 2017/04/12 |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 113 | # - support serial processing |
| 114 | # - support input root |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 115 | # - introduced --sequential-extraction flag |
Akron | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 116 | # |
| 117 | # 2017/06/19 |
| 118 | # - added support for DCK |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 119 | # |
| 120 | # 2017/06/29 |
| 121 | # - Fixed exit codes |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 122 | # |
| 123 | # 2017/07/04 |
| 124 | # - Fixed tar building process |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 125 | # |
| 126 | # 2018/01/16 |
| 127 | # - Added LWC support |
Akron | 5fdc7e1 | 2018-07-19 12:37:48 +0200 | [diff] [blame] | 128 | # |
| 129 | # 2018/07/19 |
| 130 | # - Preliminary support for HNC. |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 131 | # |
| 132 | # 2019/01/22 |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 133 | # - Preliminary support for DGD. |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 134 | # - Support for non-word tokens. |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 135 | # |
Akron | 63d03ee | 2019-02-13 18:49:38 +0100 | [diff] [blame] | 136 | # 2019/02/13 |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 137 | # - Support for 'koral:field' array. |
| 138 | # - Support for Koral versioning. |
Akron | 63d03ee | 2019-02-13 18:49:38 +0100 | [diff] [blame] | 139 | # - Ignore temporary extract parameter on |
| 140 | # directory archiving. |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 141 | # |
| 142 | # 2019/08/08 |
| 143 | # - Support for Talismane. |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 144 | # |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 145 | # 2019/12/17 |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 146 | # - Added support for DGD pseudo-sentences |
| 147 | # based on anchor milestones. |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 148 | # - Support for non-verbal annotations. |
Akron | 07e2477 | 2020-04-23 14:00:54 +0200 | [diff] [blame] | 149 | # |
| 150 | # 2020/04/23 |
| 151 | # - Added support for Redewiedergabe-Korpus structure |
| 152 | # annotations, based on sentence and paragraph milestones |
| 153 | # - Added support for Redewiedergabe-Korpus morphology |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 154 | # ---------------------------------------------------------- |
Akron | 069bd71 | 2016-02-12 19:09:06 +0100 | [diff] [blame] | 155 | |
Akron | b9c3381 | 2020-10-21 16:19:35 +0200 | [diff] [blame] | 156 | our $LAST_CHANGE = '2020/10/21'; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 157 | our $LOCAL = $FindBin::Bin; |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 158 | our $KORAL_VERSION = 0.03; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 159 | our $VERSION_MSG = <<"VERSION"; |
| 160 | Version $KorAP::XML::Krill::VERSION - diewald\@ids-mannheim.de - $LAST_CHANGE |
| 161 | VERSION |
| 162 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 163 | # Parse comand |
| 164 | my $cmd; |
| 165 | our @ARGV; |
| 166 | if ($ARGV[0] && index($ARGV[0], '-') != 0) { |
| 167 | $cmd = shift @ARGV; |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 168 | }; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 169 | my @keep_argv = @ARGV; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame] | 170 | |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 171 | my (@skip, @sigle, @anno, @input); |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 172 | |
| 173 | # Configuration hash |
| 174 | my %cfg = (); |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 175 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 176 | # Parse options from the command line |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 177 | GetOptions( |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 178 | 'input|i=s' => \@input, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 179 | 'input-base|ib=s' => \($cfg{input_base}), |
| 180 | 'output|o=s' => \($cfg{output}), |
| 181 | 'overwrite|w' => \($cfg{overwrite}), |
| 182 | 'meta|m=s' => \($cfg{meta}), |
| 183 | 'token|t=s' => \($cfg{token}), |
| 184 | 'base-sentences|bs=s' => \($cfg{base_sentences}), |
| 185 | 'base-paragraphs|bp=s' => \($cfg{base_paragraphs}), |
| 186 | 'base-pagebreaks|bpb=s' => \($cfg{base_pagebreaks}), |
| 187 | 'gzip|z' => \($cfg{gzip}), |
| 188 | 'temporary-extract|te=s' => \($cfg{extract_dir}), |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 189 | 'skip|s=s' => \@skip, |
| 190 | 'sigle|sg=s' => \@sigle, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 191 | 'cache|c=s' => \($cfg{cache_file}), |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 192 | 'config|cfg=s' => \(my $cfg_file), |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 193 | 'log|l=s' => \($cfg{log}), |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 194 | 'anno|a=s' => \@anno, |
Akron | 11daf96 | 2020-08-07 16:29:22 +0200 | [diff] [blame] | 195 | 'primary|p!' => sub { |
| 196 | warn 'Primary flag no longer supported!'; |
| 197 | }, |
Akron | 6aed056 | 2020-08-07 16:46:00 +0200 | [diff] [blame] | 198 | 'pretty|y' => sub { |
| 199 | warn 'Pretty flag no longer supported!'; |
| 200 | }, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 201 | 'jobs|j=i' => \($cfg{jobs}), |
| 202 | 'koral|k=f' => \($cfg{koral}), |
| 203 | 'to-tar' => \($cfg{to_tar}), |
| 204 | 'non-word-tokens|nwt' => \($cfg{non_word_tokens}), |
| 205 | 'non-verbal-tokens|nvt' => \($cfg{non_verbal_tokens}), |
| 206 | 'sequential-extraction|se' => \($cfg{sequential_extraction}), |
| 207 | 'cache-size|cs=s' => \($cfg{cache_size}), |
| 208 | 'cache-delete|cd!' => \($cfg{cache_delete}), |
| 209 | 'cache-init|ci!' => \($cfg{cache_init}), |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 210 | 'help|h' => sub { |
| 211 | pod2usage( |
| 212 | -sections => 'NAME|SYNOPSIS|ARGUMENTS|OPTIONS', |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 213 | -verbose => 99, |
| 214 | -msg => $VERSION_MSG, |
| 215 | -output => '-' |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 216 | ); |
| 217 | }, |
| 218 | 'version|v' => sub { |
| 219 | pod2usage( |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 220 | -verbose => 0, |
| 221 | -msg => $VERSION_MSG, |
| 222 | -output => '-' |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 223 | ) |
| 224 | } |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 225 | ); |
| 226 | |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 227 | my %ERROR_HASH = ( |
| 228 | -sections => 'NAME|SYNOPSIS|ARGUMENTS|OPTIONS', |
| 229 | -verbose => 99, |
| 230 | -msg => $VERSION_MSG, |
| 231 | -output => '-', |
| 232 | -exit => 1 |
| 233 | ); |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 234 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 235 | # Load from configuration and fill non-given data |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 236 | if ($cfg_file && -e $cfg_file) { |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 237 | my %config; |
| 238 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 239 | print "Reading config from $cfg_file\n"; |
| 240 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 241 | Config::Simple->import_from($cfg_file, \%config); |
| 242 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 243 | foreach (qw!output cache-size input-base token overwrite |
| 244 | meta base-sentences base-paragraphs base-pagebreaks |
| 245 | gzip to-tar log cache non-word-tokens |
| 246 | non-verbal-tokens sequential-extraction cache-init |
| 247 | koral extract-dir jobs!) { |
| 248 | my $underlined = $_ =~ tr/-/_/r; |
| 249 | if (!defined($cfg{$underlined}) && defined $config{$_}) { |
| 250 | $cfg{$underlined} = $config{$_}; |
| 251 | }; |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 252 | }; |
| 253 | |
| 254 | # Skip |
| 255 | if (!scalar(@skip) && defined $config{'skip'}) { |
| 256 | @skip = split /\s*;\s*/, $config{'skip'} ; |
| 257 | }; |
| 258 | |
| 259 | # Sigle |
| 260 | if (!scalar(@sigle) && defined $config{'sigle'}) { |
| 261 | @sigle = split /\s*;\s*/, $config{'sigle'} ; |
| 262 | }; |
| 263 | |
| 264 | # Anno |
| 265 | if (!scalar(@anno) && defined $config{'anno'}) { |
| 266 | @anno = split /\s*;\s*/, $config{'anno'} ; |
| 267 | }; |
| 268 | }; |
| 269 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 270 | # Init variables and set default values |
| 271 | my $output = $cfg{output}; |
| 272 | my $input_base = $cfg{input_base}; |
| 273 | my $gzip = $cfg{gzip}; |
| 274 | my $to_tar = $cfg{to_tar}; |
| 275 | my $extract_dir = $cfg{extract_dir}; |
| 276 | my $token_base = $cfg{token} // 'OpenNLP#tokens'; |
| 277 | my $cache_file = $cfg{cache} // 'korapxml2krill.cache'; |
| 278 | my $jobs = $cfg{jobs} // 0; |
| 279 | my $cache_delete = $cfg{cache_delete} // 1; |
| 280 | my $base_sentences = lc($cfg{base_sentences} // ''); |
| 281 | my $base_paragraphs = lc($cfg{base_paragraphs} // ''); |
| 282 | my $base_pagebreaks = lc($cfg{base_pagebreaks} // ''); |
| 283 | my $sequential_extraction = $cfg{sequential_extraction} // 0; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 284 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 285 | # Get tokenization basis |
| 286 | my ($token_base_foundry, $token_base_layer) = split(/#/, $token_base) if $token_base; |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 287 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 288 | # Remove file extension |
| 289 | $token_base_layer =~ s/\.xml$//i; |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 290 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 291 | # Convert sigle to path construct |
| 292 | s!^\s*([^_]+?)_([^\.]+?)\.(.+?)\s*$!$1/$2/$3! foreach @sigle; |
| 293 | |
| 294 | my %skip; |
| 295 | $skip{lc($_)} = 1 foreach @skip; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 296 | |
Akron | b9c3381 | 2020-10-21 16:19:35 +0200 | [diff] [blame] | 297 | Log::Any::Adapter->set( |
| 298 | 'Stderr', log_level => uc($cfg{log} // 'ERROR') |
| 299 | ); |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 300 | |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 301 | if ($cmd && $output && (!defined($to_tar)) && (!-e $output || !-d $output)) { |
| 302 | $log->error("Directory '$output' does not exist."); |
| 303 | exit 1; |
| 304 | }; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 305 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 306 | # Input has to be defined |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 307 | pod2usage(%ERROR_HASH) unless @input; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 308 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 309 | # Gzip has no effect, if no output is given |
| 310 | pod2usage(%ERROR_HASH) if $gzip && !$output; |
Nils Diewald | 7364d1f | 2013-11-05 19:26:35 +0000 | [diff] [blame] | 311 | |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 312 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 313 | # Start serial processing |
Akron | 28c4e54 | 2017-07-04 20:30:33 +0200 | [diff] [blame] | 314 | if ($cmd && $cmd eq 'serial') { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 315 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 316 | # Remove all inputs |
| 317 | my $remove_next = 0; |
| 318 | @keep_argv = @{c(@keep_argv)->grep( |
| 319 | sub { |
| 320 | # Input flag |
| 321 | if ($_ eq '-i' || $_ eq '--input' || $_ eq '--output' || $_ eq '-o') { |
| 322 | $remove_next = 1; |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | # input value |
| 327 | elsif ($remove_next) { |
| 328 | $remove_next = 0; |
| 329 | return 0; |
| 330 | }; |
| 331 | |
| 332 | # Pass parameter |
| 333 | return 1; |
| 334 | } |
| 335 | )->to_array}; |
| 336 | |
| 337 | |
| 338 | # Iterate over all inputs |
| 339 | foreach (@input) { |
| 340 | |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 341 | # This will create a directory |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 342 | my $new_out = catdir($output, get_file_name_from_glob($_)); |
| 343 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 344 | # Create new path, in case the output is not meant to be tarred |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 345 | unless ($to_tar) { |
| 346 | if (make_path($new_out) == 0 && !-d $new_out) { |
| 347 | $log->error("Can\'t create path $new_out"); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 348 | exit 1; |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 349 | }; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | # Create archive command |
| 353 | my @archive_cmd = ($^X, $0, 'archive', @keep_argv, '-i', $_, '-o', $new_out); |
| 354 | print "Start serial processing of $_ to $new_out\n"; |
| 355 | |
| 356 | # Start archiving |
| 357 | system @archive_cmd; |
| 358 | }; |
| 359 | |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 360 | exit; |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 361 | }; |
| 362 | |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 363 | # Define supported (and preinstalled) transformation modules |
| 364 | my @layers = (); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 365 | push(@layers, ['Base', 'Sentences']) unless $base_sentences; |
| 366 | push(@layers, ['Base', 'Paragraphs']) unless $base_paragraphs; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 367 | |
| 368 | # Connexor |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 369 | push(@layers, ['Connexor', 'Morpho'], |
| 370 | ['Connexor', 'Syntax'], |
| 371 | ['Connexor', 'Phrase'], |
| 372 | ['Connexor', 'Sentences']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 373 | |
| 374 | # CoreNLP |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 375 | push(@layers, |
| 376 | ['CoreNLP', 'NamedEntities'], |
| 377 | ['CoreNLP', 'Sentences'], |
| 378 | ['CoreNLP', 'Morpho'], |
| 379 | ['CoreNLP', 'Constituency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 380 | |
Akron | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 381 | # CMC |
| 382 | push(@layers, ['CMC', 'Morpho']); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 383 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 384 | # DeReKo |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 385 | my @dereko_attr = (); |
| 386 | if ($base_sentences eq 'dereko#structure') { |
| 387 | push @dereko_attr, 'sentences'; |
| 388 | }; |
| 389 | if ($base_paragraphs eq 'dereko#structure') { |
| 390 | push @dereko_attr, 'paragraphs'; |
| 391 | }; |
Akron | 636bd9c | 2017-02-09 17:13:00 +0100 | [diff] [blame] | 392 | |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 393 | if ($base_pagebreaks eq 'dereko#structure') { |
| 394 | push @dereko_attr, 'pagebreaks'; |
| 395 | }; |
| 396 | |
| 397 | if ($dereko_attr[0]) { |
| 398 | push(@layers, ['DeReKo', 'Structure', 'base-' . join('-', @dereko_attr)]); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 399 | } |
| 400 | else { |
| 401 | push(@layers, ['DeReKo', 'Structure']); |
| 402 | }; |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 403 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 404 | # DGD |
| 405 | push(@layers, ['DGD', 'Morpho']); |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 406 | if ($base_sentences eq 'dgd#structure') { |
| 407 | push(@layers, ['DGD', 'Structure', 'base-sentence']); |
| 408 | } |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 409 | |
| 410 | # DRuKoLa |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 411 | push(@layers, |
| 412 | ['DRuKoLa', 'Morpho']); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 413 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 414 | # Glemm |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 415 | push(@layers, |
| 416 | ['Glemm', 'Morpho']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 417 | |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 418 | # HNC |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 419 | push(@layers, |
| 420 | ['HNC', 'Morpho']); |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 421 | |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 422 | # LWC |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 423 | push(@layers, |
| 424 | ['LWC', 'Dependency']); |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 425 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 426 | # Malt |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 427 | push(@layers, |
| 428 | ['Malt', 'Dependency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 429 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 430 | # Marmot |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 431 | push(@layers, |
| 432 | ['MarMoT', 'Morpho']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 433 | |
| 434 | # Mate |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 435 | push(@layers, |
| 436 | ['Mate', 'Morpho'], |
| 437 | ['Mate', 'Dependency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 438 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 439 | # MDParser |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 440 | push(@layers, |
| 441 | ['MDParser', 'Dependency']); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 442 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 443 | # OpenNLP |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 444 | push(@layers, |
| 445 | ['OpenNLP', 'Morpho'], |
| 446 | ['OpenNLP', 'Sentences']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 447 | |
Akron | 07e2477 | 2020-04-23 14:00:54 +0200 | [diff] [blame] | 448 | # Redewiedergabe |
| 449 | push(@layers, ['RWK', 'Morpho']); |
| 450 | if ($base_sentences eq 'rwk#structure') { |
| 451 | push(@layers, ['RWK', 'Structure']); |
| 452 | }; |
| 453 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 454 | # Schreibgebrauch |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 455 | push(@layers, |
| 456 | ['Sgbr', 'Lemma'], |
| 457 | ['Sgbr', 'Morpho']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 458 | |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 459 | # Talismane |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 460 | push(@layers, |
| 461 | ['Talismane', 'Dependency'], |
| 462 | ['Talismane', 'Morpho']); |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 463 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 464 | # TreeTagger |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 465 | push(@layers, |
| 466 | ['TreeTagger', 'Morpho'], |
| 467 | ['TreeTagger', 'Sentences']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 468 | |
| 469 | # XIP |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 470 | push(@layers, |
| 471 | ['XIP', 'Morpho'], |
| 472 | ['XIP', 'Constituency'], |
| 473 | ['XIP', 'Sentences'], |
| 474 | ['XIP', 'Dependency']); |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 475 | |
Akron | 4fa37c3 | 2017-01-20 14:43:10 +0100 | [diff] [blame] | 476 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 477 | # Check filters |
| 478 | my @filtered_anno; |
| 479 | if ($skip{'#all'}) { |
| 480 | foreach (@anno) { |
| 481 | push @filtered_anno, [ split('#', $_) ]; |
| 482 | }; |
| 483 | } |
| 484 | |
| 485 | # Add all annotations that are not skipped |
| 486 | else { |
| 487 | # Add to index file - respect skipping |
| 488 | foreach my $info (@layers) { |
| 489 | # Skip if Foundry or Foundry#Layer should be skipped |
| 490 | unless ($skip{lc($info->[0])} || $skip{lc($info->[0]) . '#' . lc($info->[1])}) { |
| 491 | push @filtered_anno, $info; |
| 492 | }; |
| 493 | }; |
| 494 | }; |
| 495 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 496 | |
| 497 | # TODO: This should not be initialized for batch |
| 498 | my $cache = Cache::FastMmap->new( |
| 499 | share_file => $cache_file, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 500 | cache_size => ($cfg{cache_size} // '50m'), |
| 501 | init_file => ($cfg{cache_init} // 1) |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 502 | ); |
| 503 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 504 | # Create batch object |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 505 | my $batch_file = KorAP::XML::Batch::File->new( |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 506 | cache => $cache, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 507 | meta_type => $cfg{meta}, |
| 508 | overwrite => $cfg{overwrite}, |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 509 | foundry => $token_base_foundry, |
| 510 | layer => $token_base_layer, |
| 511 | gzip => $gzip, |
| 512 | log => $log, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 513 | koral => ($cfg{koral} // $KORAL_VERSION), |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 514 | anno => \@filtered_anno, |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 515 | non_word_tokens => ($cfg{non_word_tokens} // 0), |
| 516 | non_verbal_tokens => ($cfg{non_verbal_tokens} // 0) |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 517 | ); |
| 518 | |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 519 | |
| 520 | # Auto adjust jobs |
| 521 | if ($jobs eq '-1') { |
Akron | 0b04b31 | 2020-10-30 17:39:18 +0100 | [diff] [blame] | 522 | my $cores = 1; |
| 523 | if (eval("use Sys::Info; 1;") && eval("use Sys::Info::Constants qw( :device_cpu ); 1;")) { |
| 524 | $cores = Sys::Info->new->device('CPU')->count; |
| 525 | } |
| 526 | else { |
| 527 | $log->warn("Unable to determine number of cores"); |
| 528 | }; |
| 529 | |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 530 | $jobs = ceil(5 * $cores); |
| 531 | $log->info("Run using $jobs jobs on $cores cores"); |
| 532 | }; |
| 533 | |
| 534 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 535 | # Glob and prefix files |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 536 | if (@input > 0) { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 537 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 538 | my @new_input = (); |
| 539 | |
| 540 | # Iterate over all inputs |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 541 | foreach my $wild_card (@input) { |
| 542 | |
| 543 | # Prefix with input root |
| 544 | $wild_card = $input_base ? catfile($input_base, $wild_card) : $wild_card; |
| 545 | |
| 546 | push (@new_input, bsd_glob($wild_card)); |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 547 | }; |
| 548 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 549 | # Sort files by length |
| 550 | @input = sort { length($a) <=> length($b) } @new_input; |
| 551 | |
| 552 | print 'Input is ' . join(', ', @input)."\n"; |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 553 | }; |
| 554 | |
| 555 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 556 | # Process a single file |
| 557 | unless ($cmd) { |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 558 | my $input = $input[0]; |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 559 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 560 | BEGIN { |
| 561 | $main::TIME = Benchmark->new; |
| 562 | $main::LAST_STOP = Benchmark->new; |
| 563 | }; |
| 564 | |
| 565 | sub stop_time { |
| 566 | my $new = Benchmark->new; |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 567 | $log->info( |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 568 | 'The code took: '. |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 569 | timestr(timediff($new, $main::LAST_STOP)) . |
| 570 | ' (overall: ' . timestr(timediff($new, $main::TIME)) . ')' |
| 571 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 572 | $main::LAST_STOP = $new; |
| 573 | }; |
| 574 | |
| 575 | # Create and parse new document |
Akron | e512b7c | 2020-08-07 16:16:12 +0200 | [diff] [blame] | 576 | $input =~ s{([^/])$}{$1/}o; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 577 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 578 | # Process file |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 579 | $batch_file->process($input, $output); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 580 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 581 | # Delete cache file |
| 582 | unlink($cache_file) if $cache_delete; |
| 583 | |
Akron | 5f51d42 | 2016-08-16 16:26:43 +0200 | [diff] [blame] | 584 | stop_time; |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 585 | exit; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 586 | }; |
| 587 | |
Nils Diewald | 59094f2 | 2014-11-05 18:20:50 +0000 | [diff] [blame] | 588 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 589 | # Extract XML files |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 590 | if ($cmd eq 'extract') { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 591 | |
Akron | d5643ad | 2017-07-04 20:27:13 +0200 | [diff] [blame] | 592 | # Output is required |
| 593 | pod2usage(%ERROR_HASH) unless $output; |
| 594 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 595 | # Create new archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 596 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 597 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 598 | # Check zip capabilities |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 599 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 600 | $log->error("Unzip is not installed or incompatible."); |
| 601 | exit 1; |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 602 | }; |
| 603 | |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 604 | # Add further annotation archived |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 605 | $archive->attach($_) foreach @input[1..$#input]; |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 606 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 607 | # Will set @sigle |
| 608 | my $prefix = set_sigle($archive); |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 609 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 610 | # Iterate over all given sigles and extract |
| 611 | foreach (@sigle) { |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 612 | |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 613 | print "$_ ...\n"; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 614 | |
Akron | 03b24db | 2016-08-16 20:54:32 +0200 | [diff] [blame] | 615 | # TODO: Make this OS independent |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 616 | print '... ' . ( |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 617 | |
Akron | 955b75b | 2019-02-21 14:28:41 +0100 | [diff] [blame] | 618 | # TODO: |
| 619 | # - prefix??? |
| 620 | $archive->extract_sigle([$_], $output, $jobs) |
| 621 | ? '' : 'not ' |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 622 | ); |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 623 | print "extracted.\n"; |
| 624 | }; |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 625 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 626 | |
| 627 | # Can't create archive object |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 628 | else { |
| 629 | $log->error('Unable to extract from primary archive ' . $input[0]); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 630 | exit 1; |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 631 | }; |
| 632 | } |
| 633 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 634 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 635 | # Process an archive |
| 636 | elsif ($cmd eq 'archive') { |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 637 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 638 | my $archive_output; |
| 639 | |
| 640 | # First extract, then archive |
Akron | 63d03ee | 2019-02-13 18:49:38 +0100 | [diff] [blame] | 641 | if (defined $extract_dir && !-d $input[0]) { |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 642 | |
| 643 | # Create new archive object |
| 644 | if (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
| 645 | |
| 646 | # Check zip capabilities |
| 647 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 648 | $log->error("Unzip is not installed or incompatible."); |
| 649 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 650 | }; |
| 651 | |
| 652 | # Add further annotation archived |
| 653 | $archive->attach($_) foreach @input[1..$#input]; |
| 654 | |
| 655 | # Create a temporary directory |
| 656 | if ($extract_dir eq ':temp:') { |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 657 | $extract_dir = tempdir(CLEANUP => 0); |
| 658 | print "Temporarily extract to $extract_dir\n"; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 659 | }; |
| 660 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 661 | # Add some random extra to avoid clashes with multiple archives |
| 662 | $extract_dir = catdir($extract_dir, random_string('cccccc')); |
| 663 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 664 | # Extract to temporary directory |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 665 | if ($archive->extract_all($extract_dir, $sequential_extraction ? 1: $jobs)) { |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 666 | @input = ($extract_dir); |
| 667 | } |
| 668 | else { |
| 669 | $log->error('Unable to extract from primary archive ' . $input[0] . |
| 670 | ' to ' . $extract_dir); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 671 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 672 | }; |
| 673 | } |
| 674 | |
| 675 | # Can't create archive object |
| 676 | else { |
| 677 | $log->error('Unable to extract from primary archive ' . $input[0]); |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 678 | exit 1; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 679 | }; |
| 680 | }; |
| 681 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 682 | # Zero means: everything runs in the parent process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 683 | my $pool = Parallel::ForkManager->new($jobs); |
| 684 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 685 | my $count = 0; # Texts to process |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 686 | my $iter = 1; # Current text in process |
| 687 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 688 | my $tar_archive; |
| 689 | my $output_dir = $output; |
| 690 | my $tar_fh; |
| 691 | |
| 692 | # Initialize tar archive |
| 693 | if ($to_tar) { |
| 694 | $tar_archive = Archive::Tar::Builder->new( |
| 695 | ignore_errors => 1 |
| 696 | ); |
| 697 | |
| 698 | # Set output name |
| 699 | my $tar_file = $output; |
| 700 | unless ($tar_file =~ /\.tar$/) { |
| 701 | $tar_file .= '.tar'; |
| 702 | }; |
| 703 | |
| 704 | # Initiate the tar file |
| 705 | print "Writing to file $tar_file\n"; |
| 706 | $tar_fh = IO::File->new($tar_file, 'w'); |
| 707 | $tar_fh->binmode(1); |
| 708 | |
| 709 | # Set handle |
| 710 | $tar_archive->set_handle($tar_fh); |
| 711 | |
| 712 | # Output to temporary directory |
| 713 | $output_dir = File::Temp->newdir; |
| 714 | }; |
| 715 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 716 | # Report on fork message |
| 717 | $pool->run_on_finish ( |
| 718 | sub { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 719 | my ($pid, $code) = @_; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 720 | my $data = pop; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 721 | |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 722 | print 'Convert ['. ($jobs > 0 ? "\$$pid:" : '') . |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 723 | ($iter++) . "/$count]" . |
| 724 | ($code ? " $code" : '') . |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 725 | ' ' . $data->[0] . "\n"; |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 726 | |
| 727 | if (!$code && $to_tar && $data->[2]) { |
| 728 | my $filename = $data->[2]; |
| 729 | |
| 730 | # Lock filehandle |
| 731 | if (flock($tar_fh, LOCK_EX)) { |
| 732 | |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 733 | my $clean_file = fileparse($filename); |
| 734 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 735 | # Archive and remove file |
Akron | 9a062ce | 2017-07-04 19:12:05 +0200 | [diff] [blame] | 736 | $tar_archive->archive_as($filename => $clean_file); |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 737 | unlink $filename; |
| 738 | |
| 739 | # Unlock filehandle |
| 740 | flock($tar_fh, LOCK_UN); |
| 741 | } |
| 742 | else { |
| 743 | $log->warn("Unable to add $filename to archive"); |
| 744 | }; |
| 745 | }; |
| 746 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 747 | $data->[1] = undef if $data->[1]; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 748 | } |
| 749 | ); |
| 750 | |
| 751 | my $t; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 752 | my $temp; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 753 | print "Reading data ...\n"; |
| 754 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 755 | # unless (Cache::FastMmap->new( |
| 756 | # share_file => $cache_file, |
| 757 | # cache_size => $cache_size, |
| 758 | # init_file => $cache_init |
| 759 | # )) { |
| 760 | # print "Unable to intialize cache '$cache_file'\n\n"; |
| 761 | # exit(1); |
| 762 | # }; |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 763 | |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 764 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 765 | # Input is a directory |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 766 | if (-d $input[0]) { |
Akron | 5c602cb | 2020-08-07 17:00:52 +0200 | [diff] [blame] | 767 | # TODO: |
| 768 | # Replace with Mojo::File |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 769 | my $it = Directory::Iterator->new($input[0]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 770 | my @dirs; |
| 771 | my $dir; |
| 772 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 773 | # Todo: Make a DO WHILE |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 774 | while (1) { |
| 775 | if (!$it->is_directory && ($dir = $it->get) && $dir =~ s{/data\.xml$}{}) { |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 776 | push @dirs, $dir; |
| 777 | $it->prune; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 778 | }; |
| 779 | last unless $it->next; |
| 780 | }; |
| 781 | |
| 782 | print "Start processing ...\n"; |
| 783 | $t = Benchmark->new; |
| 784 | $count = scalar @dirs; |
| 785 | |
| 786 | DIRECTORY_LOOP: |
| 787 | for (my $i = 0; $i < $count; $i++) { |
| 788 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 789 | my $filename = catfile( |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 790 | $output_dir, |
Akron | 41127e3 | 2020-08-07 12:46:19 +0200 | [diff] [blame] | 791 | get_file_name($input[0], $dirs[$i]) . '.json' . ($gzip ? '.gz' : '') |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 792 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 793 | |
| 794 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 795 | $pool->start and next DIRECTORY_LOOP; |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 796 | |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 797 | if (my $return = $batch_file->process($dirs[$i] => $filename)) { |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 798 | $pool->finish( |
| 799 | 0, |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 800 | [ |
| 801 | "Processed " . $filename . ($return == -1 ? " - already existing" : ''), |
| 802 | undef, |
| 803 | $filename |
| 804 | ] |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 805 | ); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 806 | } |
| 807 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 808 | $pool->finish(1, ["Unable to process " . $dirs[$i]]); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 809 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 810 | }; |
| 811 | } |
| 812 | |
| 813 | # Input is a file |
Akron | 29866ac | 2016-06-24 16:40:47 +0200 | [diff] [blame] | 814 | elsif (-f($input[0]) && (my $archive = KorAP::XML::Archive->new($input[0]))) { |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 815 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 816 | unless ($archive->test_unzip) { |
Akron | 3abc03e | 2017-06-29 16:23:35 +0200 | [diff] [blame] | 817 | $log->error("Unzip is not installed or incompatible."); |
| 818 | exit 1; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 819 | }; |
| 820 | |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 821 | # Add further annotation archived |
Akron | 2812ba2 | 2016-10-28 21:55:59 +0200 | [diff] [blame] | 822 | $archive->attach($_) foreach @input[1..$#input]; |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 823 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 824 | # Get sigles to extract |
| 825 | my $prefix = set_sigle($archive); |
| 826 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 827 | print "Start processing ...\n"; |
| 828 | $t = Benchmark->new; |
| 829 | my @dirs = $archive->list_texts; |
| 830 | $count = scalar @dirs; |
| 831 | |
| 832 | ARCHIVE_LOOP: |
| 833 | for (my $i = 0; $i < $count; $i++) { |
| 834 | |
| 835 | # Split path information |
| 836 | my ($prefix, $corpus, $doc, $text) = $archive->split_path($dirs[$i]); |
| 837 | |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 838 | my $filename = catfile( |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 839 | $output_dir, |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 840 | get_file_name( |
Akron | 41127e3 | 2020-08-07 12:46:19 +0200 | [diff] [blame] | 841 | $input[0], |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 842 | catfile($corpus, $doc, $text) |
| 843 | . '.json' . ($gzip ? '.gz' : '') |
| 844 | ) |
Akron | e1dbc38 | 2016-07-08 22:24:52 +0200 | [diff] [blame] | 845 | ); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 846 | |
| 847 | # Get the next fork |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 848 | $pool->start and next ARCHIVE_LOOP; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 849 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 850 | # Create temporary file |
| 851 | $temp = File::Temp->newdir; |
| 852 | |
Akron | bdf434a | 2016-10-24 17:42:07 +0200 | [diff] [blame] | 853 | # TODO: Check if $filename exist at the beginning, |
| 854 | # because extraction can be horrible slow! |
| 855 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 856 | # Extract from archive |
Akron | 955b75b | 2019-02-21 14:28:41 +0100 | [diff] [blame] | 857 | if ($archive->extract_sigle([join('/', $corpus, $doc, $text)], $temp, $sequential_extraction ? 1 : $jobs)) { |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 858 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 859 | # Create corpus directory |
| 860 | my $input = catdir("$temp", $corpus); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 861 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 862 | # Temporary directory |
| 863 | my $dir = catdir($input, $doc, $text); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 864 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 865 | # Write file |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 866 | if (my $return = $batch_file->process($dir => $filename)) { |
Akron | 486f9ab | 2017-04-22 23:25:19 +0200 | [diff] [blame] | 867 | |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 868 | # Delete temporary file |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 869 | $pool->finish( |
| 870 | 0, |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 871 | [ |
| 872 | "Processed " . $filename . ($return == -1 ? " - already existing" : ''), |
| 873 | $temp, |
| 874 | $filename |
| 875 | ] |
Akron | 13d5662 | 2016-10-31 14:54:49 +0100 | [diff] [blame] | 876 | ); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 877 | } |
| 878 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 879 | # Delete temporary file |
| 880 | $pool->finish(1, ["Unable to process " . $dir, $temp]); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 881 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 882 | } |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 883 | |
| 884 | # Unable to extract |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 885 | else { |
Akron | 4c0cf31 | 2016-10-15 16:42:09 +0200 | [diff] [blame] | 886 | $pool->finish(1, ["Unable to extract " . $dirs[$i], $temp]); |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 887 | }; |
| 888 | }; |
| 889 | } |
| 890 | |
| 891 | else { |
| 892 | print "Input is neither a directory nor an archive.\n\n"; |
| 893 | }; |
| 894 | |
| 895 | $pool->wait_all_children; |
| 896 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 897 | # Delete cache file |
| 898 | unlink($cache_file) if $cache_delete; |
| 899 | |
Akron | da3097e | 2017-04-23 19:53:57 +0200 | [diff] [blame] | 900 | # Close tar filehandle |
| 901 | if ($to_tar && $tar_fh) { |
| 902 | $tar_archive->finish; |
| 903 | $tar_fh->close; |
| 904 | print "Wrote to tar archive.\n"; |
| 905 | }; |
| 906 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 907 | print timestr(timediff(Benchmark->new, $t))."\n"; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 908 | print "Done.\n"; |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 909 | }; |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 910 | |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 911 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 912 | # For an archive, this will create the list |
| 913 | # of all sigles to process |
| 914 | sub set_sigle { |
| 915 | my $archive = shift; |
| 916 | |
| 917 | my $prefix = 1; |
| 918 | my @dirs = (); |
| 919 | |
| 920 | # No sigles given |
| 921 | unless (@sigle) { |
| 922 | |
| 923 | # Get files |
| 924 | foreach ($archive->list_texts) { |
| 925 | |
| 926 | push @dirs, $_; |
| 927 | |
| 928 | # Split path information |
| 929 | ($prefix, my ($corpus, $doc, $text)) = $archive->split_path($_); |
| 930 | |
| 931 | # TODO: Make this OS independent |
| 932 | push @sigle, join '/', $corpus, $doc, $text; |
| 933 | }; |
| 934 | } |
| 935 | |
| 936 | # Check sigle for doc sigles |
| 937 | else { |
| 938 | my @new_sigle; |
| 939 | |
| 940 | my $prefix_check = 0; |
| 941 | |
| 942 | # Iterate over all sigle |
| 943 | foreach (@sigle) { |
| 944 | |
| 945 | # Sigle is a doc sigle |
| 946 | if ($_ =~ m!^(?:\.[/\\])?[^/\\]+?[/\\][^/\\]+?$!) { |
| 947 | |
| 948 | print "$_ ..."; |
| 949 | # Check if a prefix is needed |
| 950 | unless ($prefix_check) { |
| 951 | |
| 952 | if ($prefix = $archive->check_prefix) { |
| 953 | print " with prefix ..."; |
| 954 | }; |
| 955 | $prefix_check = 1; |
| 956 | }; |
| 957 | |
| 958 | print "\n"; |
| 959 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 960 | print '... ' . ( |
Akron | 955b75b | 2019-02-21 14:28:41 +0100 | [diff] [blame] | 961 | $archive->extract_sigle([$_], $output, $sequential_extraction ? 1 : $jobs) |
| 962 | ? '' : 'not ' |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 963 | ); |
| 964 | print "extracted.\n"; |
| 965 | } |
| 966 | |
| 967 | # Sigle is a text sigle |
| 968 | else { |
| 969 | push @new_sigle, $_; |
| 970 | |
| 971 | unless ($prefix_check) { |
| 972 | |
| 973 | if ($prefix = $archive->check_prefix) { |
| 974 | print " with prefix ..."; |
| 975 | }; |
| 976 | $prefix_check = 1; |
| 977 | }; |
| 978 | }; |
| 979 | }; |
| 980 | @sigle = @new_sigle; |
| 981 | }; |
| 982 | |
| 983 | return $prefix; |
| 984 | }; |
| 985 | |
| 986 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 987 | # Cleanup temporary extraction directory |
| 988 | if ($extract_dir) { |
| 989 | my $objects = remove_tree($extract_dir, { safe => 1 }); |
Akron | f8df216 | 2020-08-07 15:03:39 +0200 | [diff] [blame] | 990 | $log->info("Removed directory $extract_dir with $objects objects"); |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 991 | }; |
| 992 | |
| 993 | |
| 994 | print "\n"; |
| 995 | |
Nils Diewald | 2db9ad0 | 2013-10-29 19:26:43 +0000 | [diff] [blame] | 996 | __END__ |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 997 | |
| 998 | =pod |
| 999 | |
| 1000 | =encoding utf8 |
| 1001 | |
| 1002 | =head1 NAME |
| 1003 | |
Akron | 42f48c1 | 2020-02-14 13:08:13 +0100 | [diff] [blame] | 1004 | korapxml2krill - Merge KorAP-XML data and create Krill documents |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1005 | |
| 1006 | |
| 1007 | =head1 SYNOPSIS |
| 1008 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1009 | korapxml2krill [archive|extract] --input <directory|archive> [options] |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1010 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1011 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1012 | =head1 DESCRIPTION |
| 1013 | |
| 1014 | L<KorAP::XML::Krill> is a library to convert KorAP-XML documents to files |
| 1015 | compatible with the L<Krill|https://github.com/KorAP/Krill> indexer. |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1016 | The C<korapxml2krill> command line tool is a simple wrapper of this library. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1017 | |
| 1018 | |
| 1019 | =head1 INSTALLATION |
| 1020 | |
| 1021 | The preferred way to install L<KorAP::XML::Krill> is to use L<cpanm|App::cpanminus>. |
| 1022 | |
Akron | af38698 | 2016-10-12 00:33:25 +0200 | [diff] [blame] | 1023 | $ cpanm https://github.com/KorAP/KorAP-XML-Krill.git |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1024 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1025 | In case everything went well, the C<korapxml2krill> tool will |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1026 | be available on your command line immediately. |
Akron | 6eff23b | 2018-09-24 10:31:20 +0200 | [diff] [blame] | 1027 | Minimum requirement for L<KorAP::XML::Krill> is Perl 5.16. |
Akron | 0b04b31 | 2020-10-30 17:39:18 +0100 | [diff] [blame] | 1028 | Optional support for L<Sys::Info> to calculate available cores. |
Akron | a93d51b | 2016-10-24 20:27:48 +0200 | [diff] [blame] | 1029 | 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] | 1030 | |
| 1031 | =head1 ARGUMENTS |
| 1032 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1033 | $ korapxml2krill -z --input <directory> --output <filename> |
| 1034 | |
| 1035 | Without arguments, C<korapxml2krill> converts a directory of a single KorAP-XML document. |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1036 | It expects the input to point to the text level folder. |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1037 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1038 | =over 2 |
| 1039 | |
| 1040 | =item B<archive> |
| 1041 | |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 1042 | $ korapxml2krill archive -z --input <directory|archive> --output <directory|tar> |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1043 | |
Akron | 2fd402b | 2016-10-27 21:26:48 +0200 | [diff] [blame] | 1044 | Converts an archive of KorAP-XML documents. It expects a directory |
| 1045 | (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] | 1046 | |
| 1047 | =item B<extract> |
| 1048 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1049 | $ korapxml2krill extract --input <archive> --output <directory> --sigle <SIGLE> |
| 1050 | |
| 1051 | Extracts KorAP-XML documents from a zip file. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1052 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1053 | =item B<serial> |
| 1054 | |
| 1055 | $ korapxml2krill serial -i <archive1> -i <archive2> -o <directory> -cfg <config-file> |
| 1056 | |
| 1057 | Convert archives sequentially. The inputs are not merged but treated |
| 1058 | as they are (so they may be premerged or globs). |
| 1059 | the C<--out> directory is treated as the base directory where subdirectories |
Akron | 081639e | 2017-04-21 19:01:39 +0200 | [diff] [blame] | 1060 | are created based on the archive name. In case the C<--to-tar> flag is given, |
| 1061 | the output will be a tar file. |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1062 | |
| 1063 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1064 | =back |
| 1065 | |
| 1066 | |
| 1067 | =head1 OPTIONS |
| 1068 | |
| 1069 | =over 2 |
| 1070 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1071 | =item B<--input|-i> <directory|zip file> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1072 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1073 | Directory or zip file(s) of documents to convert. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1074 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1075 | Without arguments, C<korapxml2krill> expects a folder of a single KorAP-XML |
Akron | f1a1de9 | 2016-11-02 17:32:12 +0100 | [diff] [blame] | 1076 | document, while C<archive> expects a KorAP-XML corpus folder or a zip |
| 1077 | file to batch process multiple files. |
| 1078 | C<extract> expects zip files only. |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1079 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1080 | C<archive> supports multiple input zip files with the constraint, |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1081 | that the first archive listed contains all primary data files |
| 1082 | and all meta data files. |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1083 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1084 | -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] | 1085 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1086 | Input may also be defined using BSD glob wildcards. |
| 1087 | |
| 1088 | -i 'file/news*.zip' |
| 1089 | |
| 1090 | The extended input array will be sorted in length order, so the shortest |
| 1091 | path needs to contain all primary data files and all meta data files. |
| 1092 | |
Akron | 0c3e375 | 2016-06-28 15:55:53 +0200 | [diff] [blame] | 1093 | (The directory structure follows the base directory format, |
| 1094 | that may include a C<.> root folder. |
| 1095 | In this case further archives lacking a C<.> root folder |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1096 | need to be passed with a hash sign in front of the archive's name. |
| 1097 | This may require to quote the parameter.) |
Akron | 2cfe809 | 2016-06-24 17:48:49 +0200 | [diff] [blame] | 1098 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1099 | To support zip files, a version of C<unzip> needs to be installed that is |
| 1100 | compatible with the archive file. |
Akron | a93d51b | 2016-10-24 20:27:48 +0200 | [diff] [blame] | 1101 | |
Akron | 7606afa | 2016-10-25 16:23:49 +0200 | [diff] [blame] | 1102 | B<The root folder switch using the hash sign is experimental and |
| 1103 | may vanish in future versions.> |
Akron | 651cb8d | 2016-08-16 21:44:49 +0200 | [diff] [blame] | 1104 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1105 | |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1106 | =item B<--input-base|-ib> <directory> |
| 1107 | |
| 1108 | The base directory for inputs. |
| 1109 | |
| 1110 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1111 | =item B<--output|-o> <directory|file> |
| 1112 | |
| 1113 | Output folder for archive processing or |
| 1114 | document name for single output (optional), |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1115 | writes to C<STDOUT> by default |
| 1116 | (in case C<output> is not mandatory due to further options). |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1117 | |
| 1118 | =item B<--overwrite|-w> |
| 1119 | |
| 1120 | Overwrite files that already exist. |
| 1121 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1122 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1123 | =item B<--token|-t> <foundry>#<file> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1124 | |
| 1125 | Define the default tokenization by specifying |
| 1126 | the name of the foundry and optionally the name |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1127 | of the layer-file. Defaults to C<OpenNLP#tokens>. |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 1128 | This will directly take the file instead of running |
| 1129 | the layer implementation! |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1130 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1131 | |
| 1132 | =item B<--base-sentences|-bs> <foundry>#<layer> |
| 1133 | |
| 1134 | Define the layer for base sentences. |
| 1135 | If given, this will be used instead of using C<Base#Sentences>. |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 1136 | Currently C<DeReKo#Structure> and C<DGD#Structure> are the only additional |
| 1137 | layers supported. |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 1138 | |
| 1139 | Defaults to unset. |
| 1140 | |
| 1141 | |
| 1142 | =item B<--base-paragraphs|-bp> <foundry>#<layer> |
| 1143 | |
| 1144 | Define the layer for base paragraphs. |
| 1145 | If given, this will be used instead of using C<Base#Paragraphs>. |
| 1146 | Currently C<DeReKo#Structure> is the only additional layer supported. |
| 1147 | |
| 1148 | Defaults to unset. |
| 1149 | |
| 1150 | |
Akron | 41ac10b | 2017-02-08 22:47:25 +0100 | [diff] [blame] | 1151 | =item B<--base-pagebreaks|-bpb> <foundry>#<layer> |
| 1152 | |
| 1153 | Define the layer for base pagebreaks. |
| 1154 | Currently C<DeReKo#Structure> is the only layer supported. |
| 1155 | |
| 1156 | Defaults to unset. |
| 1157 | |
| 1158 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1159 | =item B<--skip|-s> <foundry>[#<layer>] |
| 1160 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1161 | Skip specific annotations by specifying the foundry |
| 1162 | (and optionally the layer with a C<#>-prefix), |
| 1163 | 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] | 1164 | Can be set multiple times. |
| 1165 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1166 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1167 | =item B<--anno|-a> <foundry>#<layer> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1168 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1169 | Convert specific annotations by specifying the foundry |
| 1170 | (and optionally the layer with a C<#>-prefix), |
| 1171 | e.g. C<Mate> or C<Mate#Morpho>. |
| 1172 | Can be set multiple times. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1173 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1174 | |
Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame] | 1175 | =item B<--non-word-tokens|-nwt> |
| 1176 | |
| 1177 | Tokenize non-word tokens like word tokens (defined as matching |
| 1178 | C</[\d\w]/>). Useful to treat punctuations as tokens. |
| 1179 | |
| 1180 | Defaults to unset. |
| 1181 | |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 1182 | |
| 1183 | =item B<--non-verbal-tokens|-nvt> |
| 1184 | |
| 1185 | Tokenize non-verbal tokens marked as in the primary data as |
| 1186 | the unicode symbol 'Black Vertical Rectangle' aka \x25ae. |
| 1187 | |
| 1188 | Defaults to unset. |
| 1189 | |
| 1190 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1191 | =item B<--jobs|-j> |
| 1192 | |
| 1193 | Define the number of concurrent jobs in seperated forks |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1194 | for archive processing. |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1195 | Defaults to C<0> (everything runs in a single process). |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1196 | |
| 1197 | If C<sequential-extraction> is not set to false, this will |
| 1198 | also apply to extraction. |
| 1199 | |
Akron | c11f798 | 2017-02-21 21:20:14 +0100 | [diff] [blame] | 1200 | Pass -1, and the value will be set automatically to 5 |
Akron | 0b04b31 | 2020-10-30 17:39:18 +0100 | [diff] [blame] | 1201 | times the number of available cores, in case L<Sys::Info> |
| 1202 | is available. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1203 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1204 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1205 | |
Akron | 263274c | 2019-02-07 09:48:30 +0100 | [diff] [blame] | 1206 | =item B<--koral|-k> |
| 1207 | |
| 1208 | Version of the output format. Supported versions are: |
| 1209 | C<0> for legacy serialization, C<0.03> for serialization |
| 1210 | with metadata fields as key-values on the root object, |
| 1211 | C<0.4> for serialization with metadata fields as a list |
| 1212 | of C<"@type":"koral:field"> objects. |
| 1213 | |
| 1214 | Currently defaults to C<0.03>. |
| 1215 | |
| 1216 | |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1217 | =item B<--sequential-extraction|-se> |
| 1218 | |
| 1219 | Flag to indicate, if the C<jobs> value also applies to extraction. |
| 1220 | Some systems may have problems with extracting multiple archives |
| 1221 | to the same folder at the same time. |
| 1222 | Can be flagged using C<--no-sequential-extraction> as well. |
| 1223 | Defaults to C<false>. |
| 1224 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1225 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1226 | =item B<--meta|-m> |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1227 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 1228 | Define the metadata parser to use. Defaults to C<I5>. |
| 1229 | Metadata parsers can be defined in the C<KorAP::XML::Meta> namespace. |
| 1230 | This is I<experimental>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1231 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1232 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1233 | =item B<--gzip|-z> |
| 1234 | |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1235 | Compress the output. |
| 1236 | Expects a defined C<output> file in single processing. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1237 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1238 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1239 | =item B<--cache|-c> |
| 1240 | |
| 1241 | File to mmap a cache (using L<Cache::FastMmap>). |
| 1242 | Defaults to C<korapxml2krill.cache> in the calling directory. |
| 1243 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1244 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1245 | =item B<--cache-size|-cs> |
| 1246 | |
| 1247 | Size of the cache. Defaults to C<50m>. |
| 1248 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1249 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1250 | =item B<--cache-init|-ci> |
| 1251 | |
| 1252 | Initialize cache file. |
| 1253 | Can be flagged using C<--no-cache-init> as well. |
| 1254 | Defaults to C<true>. |
| 1255 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1256 | |
Akron | 11c8030 | 2016-03-18 19:44:43 +0100 | [diff] [blame] | 1257 | =item B<--cache-delete|-cd> |
| 1258 | |
| 1259 | Delete cache file after processing. |
| 1260 | Can be flagged using C<--no-cache-delete> as well. |
| 1261 | Defaults to C<true>. |
| 1262 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1263 | |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1264 | =item B<--config|-cfg> |
| 1265 | |
| 1266 | Configure the parameters of your call in a file |
| 1267 | of key-value pairs with whitespace separator |
| 1268 | |
| 1269 | overwrite 1 |
| 1270 | token DeReKo#Structure |
| 1271 | ... |
| 1272 | |
| 1273 | Supported parameters are: |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 1274 | C<overwrite>, C<gzip>, C<jobs>, C<input-base>, |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1275 | C<token>, C<log>, C<cache>, C<cache-size>, C<cache-delete>, C<meta>, |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 1276 | C<output>, C<koral>, |
| 1277 | C<tempary-extract>, C<sequential-extraction>, |
Akron | 9ec8887 | 2017-04-12 16:29:06 +0200 | [diff] [blame] | 1278 | C<base-sentences>, C<base-paragraphs>, |
| 1279 | C<base-pagebreaks>, |
| 1280 | C<skip> (semicolon separated), C<sigle> |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1281 | (semicolon separated), C<anno> (semicolon separated). |
| 1282 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1283 | Configuration parameters will always be overwritten by |
| 1284 | passed parameters. |
| 1285 | |
| 1286 | |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1287 | =item B<--temporary-extract|-te> |
| 1288 | |
| 1289 | Only valid for the C<archive> command. |
| 1290 | |
| 1291 | This will first extract all files into a |
| 1292 | directory and then will archive. |
| 1293 | If the directory is given as C<:temp:>, |
| 1294 | a temporary directory is used. |
| 1295 | This is especially useful to avoid |
| 1296 | massive unzipping and potential |
| 1297 | network latency. |
Akron | 636aa11 | 2017-04-07 18:48:56 +0200 | [diff] [blame] | 1298 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1299 | |
Akron | c93a080 | 2019-07-11 15:48:34 +0200 | [diff] [blame] | 1300 | =item B<--to-tar> |
| 1301 | |
| 1302 | Only valid for the C<archive> command. |
| 1303 | |
| 1304 | Writes the output into a tar archive. |
| 1305 | |
| 1306 | |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1307 | =item B<--sigle|-sg> |
| 1308 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1309 | Extract the given texts. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1310 | Can be set multiple times. |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1311 | I<Currently only supported on C<extract>.> |
Akron | b0c88db | 2016-06-29 16:33:18 +0200 | [diff] [blame] | 1312 | Sigles have the structure C<Corpus>/C<Document>/C<Text>. |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 1313 | 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] | 1314 | On the document level, the postfix wildcard C<*> is supported. |
Akron | e10ad32 | 2016-02-27 10:54:26 +0100 | [diff] [blame] | 1315 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1316 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1317 | =item B<--log|-l> |
| 1318 | |
Akron | b9c3381 | 2020-10-21 16:19:35 +0200 | [diff] [blame] | 1319 | The L<Log::Any> log level, defaults to C<ERROR>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1320 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1321 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1322 | =item B<--help|-h> |
| 1323 | |
Akron | 42f48c1 | 2020-02-14 13:08:13 +0100 | [diff] [blame] | 1324 | Print help information. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1325 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1326 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1327 | =item B<--version|-v> |
| 1328 | |
| 1329 | Print version information. |
| 1330 | |
| 1331 | =back |
| 1332 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1333 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1334 | =head1 ANNOTATION SUPPORT |
| 1335 | |
| 1336 | L<KorAP::XML::Krill> has built-in importer for some annotation foundries and layers |
| 1337 | developed in the KorAP project that are part of the KorAP preprocessing pipeline. |
| 1338 | The base foundry with paragraphs, sentences, and the text element are mandatory for |
| 1339 | L<Krill|https://github.com/KorAP/Krill>. |
| 1340 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1341 | Base |
| 1342 | #Paragraphs |
| 1343 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1344 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1345 | Connexor |
| 1346 | #Morpho |
| 1347 | #Phrase |
| 1348 | #Sentences |
| 1349 | #Syntax |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1350 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1351 | CoreNLP |
| 1352 | #Constituency |
| 1353 | #Morpho |
| 1354 | #NamedEntities |
| 1355 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1356 | |
Akron | ce125b6 | 2017-06-19 11:54:36 +0200 | [diff] [blame] | 1357 | CMC |
| 1358 | #Morpho |
| 1359 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1360 | DeReKo |
| 1361 | #Structure |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1362 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 1363 | DGD |
| 1364 | #Morpho |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 1365 | #Structure |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 1366 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1367 | DRuKoLa |
| 1368 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1369 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1370 | Glemm |
| 1371 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1372 | |
Akron | ea1aed5 | 2018-07-19 14:43:34 +0200 | [diff] [blame] | 1373 | HNC |
| 1374 | #Morpho |
| 1375 | |
Akron | 4c67919 | 2018-01-16 17:41:49 +0100 | [diff] [blame] | 1376 | LWC |
| 1377 | #Dependency |
| 1378 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1379 | Malt |
| 1380 | #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1381 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1382 | MarMoT |
| 1383 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1384 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1385 | Mate |
| 1386 | #Dependency |
| 1387 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1388 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1389 | MDParser |
| 1390 | #Dependency |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1391 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1392 | OpenNLP |
| 1393 | #Morpho |
| 1394 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1395 | |
Akron | 07e2477 | 2020-04-23 14:00:54 +0200 | [diff] [blame] | 1396 | RWK |
| 1397 | #Morpho |
| 1398 | #Structure |
| 1399 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1400 | Sgbr |
| 1401 | #Lemma |
| 1402 | #Morpho |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1403 | |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 1404 | Talismane |
| 1405 | #Dependency |
| 1406 | #Morpho |
| 1407 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1408 | TreeTagger |
| 1409 | #Morpho |
| 1410 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1411 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 1412 | XIP |
| 1413 | #Constituency |
| 1414 | #Morpho |
| 1415 | #Sentences |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1416 | |
Akron | c13a170 | 2016-03-15 19:33:14 +0100 | [diff] [blame] | 1417 | |
| 1418 | More importers are in preparation. |
| 1419 | New annotation importers can be defined in the C<KorAP::XML::Annotation> namespace. |
| 1420 | See the built-in annotation importers as examples. |
| 1421 | |
Akron | f73ffb6 | 2018-06-27 12:13:59 +0200 | [diff] [blame] | 1422 | |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1423 | =head1 About KorAP-XML |
| 1424 | |
| 1425 | KorAP-XML (Bański et al. 2012) is an implementation of the KorAP |
| 1426 | data model (Bański et al. 2013), where text data are stored physically |
| 1427 | separated from their interpretations (i.e. annotations). |
| 1428 | A text document in KorAP-XML therefore consists of several files |
| 1429 | containing primary data, metadata and annotations. |
| 1430 | |
| 1431 | The structure of a single KorAP-XML document can be as follows: |
| 1432 | |
| 1433 | - data.xml |
| 1434 | - header.xml |
| 1435 | + base |
| 1436 | - tokens.xml |
| 1437 | - ... |
| 1438 | + struct |
| 1439 | - structure.xml |
| 1440 | - ... |
| 1441 | + corenlp |
| 1442 | - morpho.xml |
| 1443 | - constituency.xml |
| 1444 | - ... |
| 1445 | + tree_tagger |
| 1446 | - morpho.xml |
| 1447 | - ... |
| 1448 | - ... |
| 1449 | |
| 1450 | The C<data.xml> contains the primary data, the C<header.xml> contains |
| 1451 | the metadata, and the annotation layers are stored in subfolders |
| 1452 | like C<base>, C<struct> or C<corenlp> |
| 1453 | (so-called "foundries"; Bański et al. 2013). |
| 1454 | |
| 1455 | Metadata is available in the TEI-P5 variant I5 |
Akron | d4c5c10 | 2020-02-11 11:47:59 +0100 | [diff] [blame] | 1456 | (Lüngen and Sperberg-McQueen 2012). See the documentation in |
| 1457 | L<KorAP::XML::Meta::I5> for translatable fields. |
| 1458 | |
| 1459 | Annotations correspond to a variant of the TEI-P5 feature structures |
| 1460 | (TEI Consortium; Lee et al. 2004). |
Akron | 72bc522 | 2020-02-06 16:00:13 +0100 | [diff] [blame] | 1461 | Annotation feature structures refer to character sequences of the primary text |
| 1462 | inside the C<text> element of the C<data.xml>. |
| 1463 | A single annotation containing the lemma of a token can have the following structure: |
| 1464 | |
| 1465 | <span from="0" to="3"> |
| 1466 | <fs type="lex" xmlns="http://www.tei-c.org/ns/1.0"> |
| 1467 | <f name="lex"> |
| 1468 | <fs> |
| 1469 | <f name="lemma">zum</f> |
| 1470 | </fs> |
| 1471 | </f> |
| 1472 | </fs> |
| 1473 | </span> |
| 1474 | |
| 1475 | The C<from> and C<to> attributes are refering to the character span |
| 1476 | in the primary text. |
| 1477 | Depending on the kind of annotation (e.g. token-based, span-based, relation-based), |
| 1478 | the structure may vary. See L<KorAP::XML::Annotation::*> for various |
| 1479 | annotation preprocessors. |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1480 | |
| 1481 | Multiple KorAP-XML documents are organized on three levels following |
| 1482 | the "IDS Textmodell" (Lüngen and Sperberg-McQueen 2012): |
| 1483 | corpus E<gt> document E<gt> text. On each level metadata information |
| 1484 | can be stored, that C<korapxml2krill> will merge to a single metadata |
| 1485 | object per text. A corpus is therefore structured as follows: |
| 1486 | |
| 1487 | + <corpus> |
| 1488 | - header.xml |
| 1489 | + <document> |
| 1490 | - header.xml |
| 1491 | + <text> |
| 1492 | - data.xml |
| 1493 | - header.xml |
| 1494 | - ... |
| 1495 | - ... |
| 1496 | |
| 1497 | A single text can be identified by the concatenation of |
| 1498 | the corpus identifier, the document identifier and the text identifier. |
| 1499 | This identifier is called the text sigle |
| 1500 | (e.g. a text with the identifier C<18486> in the document C<060> in the |
| 1501 | corpus C<WPD17> has the text sigle C<WPD17/060/18486>, see C<--sigle>). |
| 1502 | |
| 1503 | These corpora are often stored in zip files, with which C<korapxml2krill> |
| 1504 | can deal with. Corpora may also be split in multiple zip archives |
| 1505 | (e.g. one zip file per foundry), which is also supported (see C<--input>). |
| 1506 | |
| 1507 | Examples for KorAP-XML files are included in L<KorAP::XML::Krill> |
| 1508 | in form of a test suite. |
| 1509 | The resulting JSON format merges all annotation layers |
| 1510 | based on a single token stream. |
| 1511 | |
| 1512 | =head2 References |
| 1513 | |
| 1514 | Piotr Bański, Cyril Belica, Helge Krause, Marc Kupietz, Carsten Schnober, Oliver Schonefeld, and Andreas Witt (2011): |
| 1515 | KorAP data model: first approximation, December. |
| 1516 | |
| 1517 | Piotr Bański, Peter M. Fischer, Elena Frick, Erik Ketzan, Marc Kupietz, Carsten Schnober, Oliver Schonefeld and Andreas Witt (2012): |
| 1518 | "The New IDS Corpus Analysis Platform: Challenges and Prospects", |
| 1519 | Proceedings of the Eighth International Conference on Language Resources and Evaluation (LREC 2012). |
| 1520 | L<PDF|http://www.lrec-conf.org/proceedings/lrec2012/pdf/789_Paper.pdf> |
| 1521 | |
| 1522 | Piotr Bański, Elena Frick, Michael Hanl, Marc Kupietz, Carsten Schnober and Andreas Witt (2013): |
| 1523 | "Robust corpus architecture: a new look at virtual collections and data access", |
| 1524 | Corpus Linguistics 2013. Abstract Book. Lancaster: UCREL, pp. 23-25. |
| 1525 | L<PDF|https://ids-pub.bsz-bw.de/frontdoor/deliver/index/docId/4485/file/Ba%c5%84ski_Frick_Hanl_Robust_corpus_architecture_2013.pdf> |
| 1526 | |
| 1527 | Kiyong Lee, Lou Burnard, Laurent Romary, Eric de la Clergerie, Thierry Declerck, |
| 1528 | Syd Bauman, Harry Bunt, Lionel Clément, Tomaz Erjavec, Azim Roussanaly and Claude Roux (2004): |
| 1529 | "Towards an international standard on featurestructure representation", |
| 1530 | Proceedings of the fourth International Conference on Language Resources and Evaluation (LREC 2004), |
| 1531 | pp. 373-376. |
| 1532 | L<PDF|http://www.lrec-conf.org/proceedings/lrec2004/pdf/687.pdf> |
| 1533 | |
| 1534 | Harald Lüngen and C. M. Sperberg-McQueen (2012): |
| 1535 | "A TEI P5 Document Grammar for the IDS Text Model", |
| 1536 | Journal of the Text Encoding Initiative, Issue 3 | November 2012. |
| 1537 | L<PDF|https://journals.openedition.org/jtei/pdf/508> |
| 1538 | |
| 1539 | TEI Consortium, eds: |
| 1540 | "Feature Structures", |
| 1541 | Guidelines for Electronic Text Encoding and Interchange. |
| 1542 | L<html|https://www.tei-c.org/release/doc/tei-p5-doc/en/html/FS.html> |
| 1543 | |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1544 | =head1 AVAILABILITY |
| 1545 | |
| 1546 | https://github.com/KorAP/KorAP-XML-Krill |
| 1547 | |
| 1548 | |
| 1549 | =head1 COPYRIGHT AND LICENSE |
| 1550 | |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1551 | Copyright (C) 2015-2020, L<IDS Mannheim|https://www.ids-mannheim.de/> |
Akron | f7ad89e | 2016-03-16 18:22:47 +0100 | [diff] [blame] | 1552 | |
Akron | 8f69d63 | 2020-01-15 16:58:11 +0100 | [diff] [blame] | 1553 | Author: L<Nils Diewald|https://nils-diewald.de/> |
Akron | 8150010 | 2017-04-07 20:45:44 +0200 | [diff] [blame] | 1554 | |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 1555 | Contributor: Eliza Margaretha |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1556 | |
| 1557 | L<KorAP::XML::Krill> is developed as part of the L<KorAP|http://korap.ids-mannheim.de/> |
| 1558 | Corpus Analysis Platform at the |
Akron | 94262ce | 2019-02-28 21:42:43 +0100 | [diff] [blame] | 1559 | L<Leibniz Institute for the German Language (IDS)|http://ids-mannheim.de/>, |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1560 | member of the |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 1561 | L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/>. |
Akron | 941c1a6 | 2016-02-23 17:41:41 +0100 | [diff] [blame] | 1562 | |
| 1563 | This program is free software published under the |
| 1564 | L<BSD-2 License|https://raw.githubusercontent.com/KorAP/KorAP-XML-Krill/master/LICENSE>. |
| 1565 | |
| 1566 | =cut |