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