| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl | 
 | 2 | use strict; | 
 | 3 | use warnings; | 
 | 4 | use POSIX; | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 5 | use Log::Any '$log'; | 
 | 6 | use Log::Any::Adapter; | 
 | 7 | use Pod::Usage; | 
 | 8 | use Getopt::Long qw(GetOptions :config no_auto_abbrev); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 9 | use Encode; | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 10 |  | 
 | 11 | my $MAX_SENTENCE_LENGTH=10000; | 
 | 12 | my $COMMENT_START="#"; | 
 | 13 |  | 
 | 14 | my $test=0; | 
 | 15 | my $text_no=0; | 
 | 16 | my %opts; | 
 | 17 | my %plain_texts; | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 18 | my %sentence_ends; | 
 | 19 |  | 
| Marc Kupietz | 0ab8a2c | 2021-03-19 16:21:00 +0100 | [diff] [blame] | 20 | our $VERSION = '0.3.900'; | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 21 |  | 
| Marc Kupietz | 0ab8a2c | 2021-03-19 16:21:00 +0100 | [diff] [blame] | 22 | our $VERSION_MSG = "\nkorapxml2conllu - v$VERSION\n"; | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 23 |  | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 24 | use constant { | 
 | 25 |   # Set to 1 for minimal more debug output (no need to be parametrized) | 
 | 26 |   DEBUG => $ENV{KORAPXMLCONLLU_DEBUG} // 0 | 
 | 27 | }; | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 28 |  | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 29 | GetOptions( | 
 | 30 |   'sigle-pattern|p=s'            => \(my $sigle_pattern = ''), | 
 | 31 |   'log|l=s'                      => \(my $log_level = 'warn'), | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 32 |  | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 33 |   'help|h'                       => sub { | 
 | 34 |     pod2usage( | 
 | 35 |       -verbose  => 99, | 
 | 36 |       -sections => 'NAME|DESCRIPTION|SYNOPSIS|ARGUMENTS|OPTIONS|EXAMPLES', | 
 | 37 |       -msg      => $VERSION_MSG, | 
 | 38 |       -output   => '-' | 
 | 39 |     ) | 
 | 40 |   }, | 
 | 41 |   'version|v'                    => sub { | 
 | 42 |     pod2usage( | 
 | 43 |       -verbose => 0, | 
 | 44 |       -msg     => $VERSION_MSG, | 
 | 45 |       -output  => '-' | 
 | 46 |     ); | 
 | 47 |   } | 
 | 48 | ); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 49 |  | 
 | 50 |  ZIPSIGLEPATTERN='-x "*15/FEB*" "*15/MAR*"' $0 /vol/corpora/DeReKo/current/KorAP/zip/zca15.tree_tagger.zip | 
 | 51 |  | 
 | 52 |  Results will be written to stdout | 
 | 53 | EOF | 
 | 54 |  | 
 | 55 | getopts('dhp:', \%opts); | 
 | 56 | die $usage if($opts{h} || @ARGV == 0); | 
 | 57 | my $debug=($opts{d}? 1 : 0); | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 58 | # Establish logger | 
 | 59 | binmode(STDERR, ':encoding(UTF-8)'); | 
 | 60 | Log::Any::Adapter->set('Stderr', log_level => $log_level); | 
 | 61 | $log->notice('Debugging is activated') if DEBUG; | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 62 |  | 
 | 63 | my $docid=""; | 
 | 64 | my ($current_id, $current_from, $current_to, $token); | 
 | 65 | my $current; | 
 | 66 | my ($unknown, $known) = (0, 0); | 
 | 67 | my @current_lines; | 
 | 68 | my %processedFilenames; | 
 | 69 | my $zipsiglepattern = (defined($ENV{ZIPSIGLEPATTERN})? $ENV{ZIPSIGLEPATTERN} : ""); | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 70 | my $baseOnly; | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 71 |  | 
 | 72 | my ($ID_idx, $FORM_idx, $LEMMA_idx, $UPOS_idx, $XPOS_idx, $FEATS_idx, $HEAD_idx, $DEPREC_idx, $DEPS_idx, $MISC_idx) = (0..9); | 
 | 73 |  | 
| Marc Kupietz | c7d1b93 | 2020-09-23 13:17:17 +0200 | [diff] [blame] | 74 | my $UNZIP = `sh -c 'command -v unzip'`; | 
 | 75 | chomp $UNZIP; | 
 | 76 |  | 
 | 77 |  | 
 | 78 | if ($UNZIP eq '') { | 
 | 79 |   warn('No unzip executable found in PATH.'); | 
 | 80 |   return 0; | 
 | 81 | }; | 
 | 82 |  | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 83 | foreach my $morpho_zip (@ARGV) { | 
 | 84 |   die "cannot open $morpho_zip" if(! -r $morpho_zip); | 
 | 85 |   my $data_zip = $morpho_zip; | 
 | 86 |   if ($data_zip !~ /\.zip/ && $data_zip =~ /\.conllu?/i) { | 
 | 87 |     open(CONLL, "<$data_zip") or die "cannot open $data_zip"; | 
 | 88 |     while(<CONLL>) { | 
 | 89 |       print; | 
 | 90 |     } | 
 | 91 |     close(CONLL); | 
 | 92 |     next; | 
 | 93 |   } | 
 | 94 |   $data_zip =~ s/\.([^.]+)\.zip$/.zip/; | 
 | 95 |   my $foundry = $1; | 
 | 96 |   die "cannot open data file $data_zip corresponding to $morpho_zip" if(! -r $data_zip); | 
 | 97 |    | 
 | 98 |   my $first=1; | 
 | 99 |   my $pattern = (defined($opts{p})? $opts{p} : ''); | 
 | 100 |   my @conll = ("_") x 10; | 
 | 101 |   my $filename; | 
 | 102 |  | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 103 |   $baseOnly = $morpho_zip eq $data_zip; | 
 | 104 |   my ($morphoOrTokenCommand, $plaintextAndStructureCommand); | 
 | 105 |   if(!$baseOnly) { | 
 | 106 |     $morphoOrTokenCommand = "$UNZIP -c $morpho_zip '*/${pattern}*/*/*/morpho.xml' $zipsiglepattern |"; | 
 | 107 |     $plaintextAndStructureCommand = "$UNZIP -c $data_zip '*/${pattern}*/*/data.xml' $zipsiglepattern |"; | 
 | 108 |   } else { | 
 | 109 |     $foundry = "base"; | 
 | 110 |     $morphoOrTokenCommand = "$UNZIP -c $morpho_zip '*/${pattern}*/*/*/tokens.xml' $zipsiglepattern |"; | 
 | 111 |     $plaintextAndStructureCommand = "$UNZIP -c $data_zip '*/${pattern}*/*/[sd][ta]*.xml' $zipsiglepattern |"; | 
 | 112 |   } | 
 | 113 |  | 
 | 114 |   open (MORPHO_OR_TOKENPIPE, $morphoOrTokenCommand) or die "cannot unzip $morpho_zip"; | 
 | 115 |   open (PLAINTEXTPIPE, $plaintextAndStructureCommand) or die "cannot unzip $data_zip"; | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 116 |   print "$COMMENT_START foundry = $foundry\n"; | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 117 |   while (<MORPHO_OR_TOKENPIPE>) { | 
| Marc Kupietz | 30c41b1 | 2020-09-22 14:32:34 +0200 | [diff] [blame] | 118 |     if (/^  inflating: (.*)/) { | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 119 |       $filename=$1; | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 120 |       while($processedFilenames{$filename} && !eof(MORPHO_OR_TOKENPIPE)) { | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 121 |         $log->warn("$filename already processed"); | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 122 |         while (<MORPHO_OR_TOKENPIPE>) { | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 123 |           last if(/\s+inflating:\s+(.*)/); | 
 | 124 |         } | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 125 |         $filename=$1 if(!eof(MORPHO_OR_TOKENPIPE) && /\s+inflating:\s+(.*)/); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 126 |       } | 
| Marc Kupietz | 30c41b1 | 2020-09-22 14:32:34 +0200 | [diff] [blame] | 127 |     } elsif(m@^\s*<layer\s+.*docid="([^"]+)"@) { | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 128 |       last if($test && $text_no++ > 3); | 
 | 129 |       if(!$first) { | 
 | 130 |         closeDoc(0); | 
 | 131 |       } | 
 | 132 |       $processedFilenames{$filename}=1; | 
 | 133 |       $docid=$1; | 
 | 134 |       @current_lines=(); | 
 | 135 |       $known=$unknown=0; | 
 | 136 |       $current=""; | 
 | 137 |       if ($first) { | 
 | 138 |           $first = 0; | 
 | 139 |       } | 
 | 140 |       if(!fetch_plaintext($docid)) { # skip this text | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 141 |         while (<MORPHO_OR_TOKENPIPE>) { | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 142 |           last if(m@</layer>@); | 
 | 143 |         } | 
 | 144 |       } | 
 | 145 |       print STDOUT "$COMMENT_START filename = $filename\n$COMMENT_START text_id = $docid\n"; | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 146 |       $log->debug("Analyzing $docid"); | 
| Marc Kupietz | 30c41b1 | 2020-09-22 14:32:34 +0200 | [diff] [blame] | 147 |     } elsif (m@^\s*<f\s+.*name="([^"]+)">([^<]+)</f>@) { | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 148 |       if ($1 eq "lemma") { | 
 | 149 |         $conll[$LEMMA_idx] = $2; | 
 | 150 |         $conll[$LEMMA_idx] =~ s/[\t\n\r]//g; # make sure that lemmas never contain tabs or newlines | 
 | 151 |         if($conll[$LEMMA_idx] eq 'UNKNOWN') { | 
 | 152 |           $conll[$LEMMA_idx] = "--"; | 
 | 153 |           $unknown++; | 
 | 154 |         } else { | 
 | 155 |           $known++; | 
 | 156 |         } | 
 | 157 |       } elsif ($1 eq 'pos' || $1 eq "ctag") { | 
 | 158 |         $unknown++; | 
 | 159 |         $conll[$XPOS_idx] = $conll[$UPOS_idx] = $2; | 
 | 160 |       } elsif ($1 eq 'msd') { | 
 | 161 |         $conll[$FEATS_idx] = $2; | 
 | 162 |       } elsif ($1 eq 'certainty') { | 
 | 163 |         $conll[$MISC_idx] = $2; | 
 | 164 |       } | 
 | 165 |     } elsif (/<span /) { | 
 | 166 |       ($current_id) = /id="[^0-9]*([^\"]*)"/; | 
 | 167 |       ($current_from) = /from="([^\"]*)"/; | 
 | 168 |       ($current_to) = /to="([^\"]*)"/; | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 169 |       $log->debug("found span: $current_id $current_from $current_to"); | 
| Marc Kupietz | 7e71a82 | 2020-06-22 17:14:30 +0200 | [diff] [blame] | 170 |       $token = substr($plain_texts{$docid}, $current_from, $current_to - $current_from); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 171 |       if (!defined $token) { | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 172 |         $log->warn("could not retrieve token for $docid at $current_from-$current_to/", length($plain_texts{$docid}), " - ending with: ", substr($plain_texts{$docid},length($plain_texts{$docid})-10)); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 173 |         $token = "_"; | 
 | 174 |       } | 
 | 175 |       $token=~s/[\t\n\r]//g; # make sure that tokens never contain tabs or newlines | 
 | 176 |       @conll = ("_") x 10; | 
 | 177 |       $conll[$FORM_idx] = encode("utf-8", $token); | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 178 |       if($baseOnly) { | 
 | 179 |         my @vals = ($current_from, $current_to); | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 180 |         $log->debug("joining : ", join(" ", @vals)); | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 181 |         push @current_lines, \@vals; | 
 | 182 |         $known++; | 
 | 183 |         $conll[$ID_idx] = $#current_lines+1; | 
 | 184 |         $current .= join("\t", @conll) . "\n"; # conll columns | 
 | 185 |         fetch_plaintext($docid); | 
 | 186 |         if ($sentence_ends{$docid}{$current_to}) { | 
 | 187 |           $current .= "\n"; | 
 | 188 |           printTokenRanges(); | 
 | 189 |           print STDOUT $current; | 
 | 190 |           $current = ""; | 
 | 191 |           $known = 0; | 
 | 192 |           $unknown = 0; | 
 | 193 |           @current_lines = (); | 
 | 194 |         } | 
 | 195 |       } | 
| Marc Kupietz | 30c41b1 | 2020-09-22 14:32:34 +0200 | [diff] [blame] | 196 |     } elsif (m@^\s*</fs>@) { | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 197 |       my @vals = ($current_from, $current_to); | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 198 |       $log->debug("joining : ", join(" ", @vals)); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 199 |       push @current_lines, \@vals; | 
 | 200 |       # convert gathered information to CONLL | 
 | 201 |       $conll[$ID_idx] = $#current_lines+1; | 
 | 202 |       $current .= join("\t", @conll) . "\n"; # conll columns | 
 | 203 |       if($conll[$XPOS_idx] eq '$.' || ($conll[$XPOS_idx] eq 'SENT' && $token eq '.') || $known + $unknown >= $MAX_SENTENCE_LENGTH) { | 
 | 204 |         $current .= "\n"; | 
 | 205 |         if($known + $unknown > 0) { # only print sentence if it contains some words | 
 | 206 |           printTokenRanges(); | 
 | 207 |           print STDOUT $current; | 
 | 208 |         } | 
 | 209 |         $current=""; $known=0; $unknown=0; | 
 | 210 |         @current_lines = (); | 
 | 211 |       } | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 212 |       while (<MORPHO_OR_TOKENPIPE>) { | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 213 |         last if (m@</span>@);    # only consider first interpretation | 
 | 214 |       } | 
 | 215 |     } | 
 | 216 |   } | 
 | 217 |   $current .= "\n"; | 
 | 218 |   closeDoc(1); | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 219 |   close(MORPHO_OR_TOKENPIPE); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 220 |   close(PLAINTEXTPIPE); | 
 | 221 | } | 
 | 222 | exit; | 
 | 223 |  | 
 | 224 | sub printTokenRanges { | 
 | 225 |   print "$COMMENT_START start_offsets = ", $current_lines[0]->[0]; | 
 | 226 |   foreach my $t (@current_lines) { | 
 | 227 |     print STDOUT " $t->[0]"; | 
 | 228 |   } | 
 | 229 |   print "\n$COMMENT_START end_offsets = ", $current_lines[$#current_lines]->[1]; | 
 | 230 |   foreach my $t (@current_lines) { | 
 | 231 |     print STDOUT " $t->[1]"; | 
 | 232 |   } | 
 | 233 |   print "\n"; | 
 | 234 | } | 
 | 235 |  | 
 | 236 | sub closeDoc { | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 237 |   $log->debug("closing doc"); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 238 |   if($known + $unknown > 0) { # only parse a sentence if it has some words | 
 | 239 |     chomp $current; | 
 | 240 |     chomp $current; | 
 | 241 |     chomp $current; | 
 | 242 |     $current .= "\n\n"; | 
 | 243 |     printTokenRanges(); | 
 | 244 |     print STDOUT $current; | 
 | 245 |   } | 
 | 246 | } | 
 | 247 |  | 
 | 248 | # read data.xml to figure out the tokens | 
 | 249 | # (ideally tokens should also be in in morpho.xml, but they are not) | 
 | 250 | sub fetch_plaintext { | 
 | 251 |   my ($target_id) = @_; | 
 | 252 |   my $docid; | 
 | 253 |   my $text_started=0; | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 254 |   my ($current_id, $current_from, $current_to); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 255 |  | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 256 |   if($plain_texts{$target_id} && (!$baseOnly || $sentence_ends{$target_id}{-1})) { | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 257 | #    print STDERR "already got $target_id\n"; | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 258 |     return 1; | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 259 |   } | 
 | 260 |   while(<PLAINTEXTPIPE>) { | 
 | 261 |     if(/<raw_text[^>]+docid="([^"]*)/) { | 
 | 262 |       $docid=$1; | 
 | 263 |       $text_started=0; | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 264 |     } elsif(/<layer[^>]+docid="([^"]*)/) { | 
 | 265 |       $docid=$1; | 
 | 266 |       $sentence_ends{$docid}{-1}=1; | 
 | 267 |     } elsif(m@<span @) { | 
 | 268 |         ($current_id) = /id="[^0-9]*([^\"]*)"/; | 
 | 269 |         ($current_from) = /from="([^\"]*)"/; | 
 | 270 |         ($current_to) = /to="([^\"]*)"/; | 
 | 271 |     } elsif(m@<f\s[^>]*>s</f>@) { | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 272 |       $log->debug("Found sentence end for $docid \@$current_to"); | 
| Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 273 |       $sentence_ends{$docid}{$current_to}=1; | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 274 |     } elsif (m@<text>(.*)</text>@) { | 
 | 275 |       $_= decode("utf-8", $1, Encode::FB_DEFAULT); | 
 | 276 |       s/</</go; | 
 | 277 |       s/>/>/go; | 
 | 278 |       s/&/&/go; | 
 | 279 |       tr/…•⋅»«ˮ“”„›‹ʼ‘’‚′‐‑‒–—―⁓⁻₋−﹣-/...""""""'''''''-/; | 
 | 280 |       $plain_texts{$docid} = $_; | 
 | 281 |       last if($docid eq $target_id); | 
 | 282 |     } elsif (m@<text>(.*)@) { | 
 | 283 |       $_= decode("utf-8", $1, Encode::FB_DEFAULT); | 
 | 284 |       s/</</go; | 
 | 285 |       s/>/>/go; | 
 | 286 |       s/&/&/go; | 
 | 287 |       tr/…•⋅»«ˮ“”„›‹ʼ‘’‚′‐‑‒–—―⁓⁻₋−﹣-/...""""""'''''''-/; | 
 | 288 |       $plain_texts{$docid} = "$_ "; | 
 | 289 |       $text_started=1; | 
 | 290 |     } elsif ($text_started && m@(.*)</text>@) { | 
 | 291 |       $_= decode("utf-8", $1, Encode::FB_DEFAULT); | 
 | 292 |       s/</</go; | 
 | 293 |       s/>/>/go; | 
 | 294 |       s/&/&/go; | 
 | 295 |       tr/…•⋅»«ˮ“”„›‹ʼ‘’‚′‐‑‒–—―⁓⁻₋−﹣-/...""""""'''''''-/; | 
 | 296 |       $plain_texts{$docid} .= $_; | 
 | 297 |       $text_started=0; | 
 | 298 |       last if($docid eq $target_id); | 
 | 299 |     } elsif ($text_started) { | 
 | 300 |       chomp; | 
 | 301 |       $_ = decode("utf-8", $_, Encode::FB_DEFAULT) . ' '; | 
 | 302 |       s/</</go; | 
 | 303 |       s/>/>/go; | 
 | 304 |       s/&/&/go; | 
 | 305 |       tr/…•⋅»«ˮ“”„›‹ʼ‘’‚′‐‑‒–—―⁓⁻₋−﹣-/...""""""'''''''-/; | 
 | 306 |       $plain_texts{$docid} .= $_; | 
 | 307 |     } | 
 | 308 |   } | 
 | 309 |   if(defined($ENV{PLAINTEXTFILTER})) { | 
 | 310 |     if ($plain_texts{$docid} !~ $ENV{PLAINTEXTFILTER}) { | 
 | 311 |       $plain_texts{$docid} = undef; | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 312 |       $log->info("Skipping $docid"); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 313 |       return(undef); | 
 | 314 |     } else { | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 315 |       $log->debug("Using $docid"); | 
| Marc Kupietz | 5e7f20a | 2020-02-17 18:17:11 +0100 | [diff] [blame] | 316 |     } | 
 | 317 |   }  | 
 | 318 |   return(1); | 
 | 319 | } | 
| Marc Kupietz | 6a79cad | 2021-03-19 16:26:58 +0100 | [diff] [blame^] | 320 |  | 
 | 321 | =pod | 
 | 322 |  | 
 | 323 | =encoding utf8 | 
 | 324 |  | 
 | 325 | =head1 NAME | 
 | 326 |  | 
 | 327 | korapxml2conllu - Conversion of KorAP-XML zips to CoNLL-U | 
 | 328 |  | 
 | 329 | =head1 SYNOPSIS | 
 | 330 |  | 
 | 331 |   korapxml2conllu zca15.tree_tagger.zip > zca15.conllu | 
 | 332 |  | 
 | 333 | =head1 DESCRIPTION | 
 | 334 |  | 
 | 335 | C<korapxml2conllu> is a script to Convert L<KorAP-XML format|https://github.com/KorAP/KorAP-XML-Krill#about-korap-xml> base or morpho zips to CoNLL(-U) format with all information necessary | 
 | 336 |  for reconstruction in comment lines. | 
 | 337 |  | 
 | 338 | =head1 INSTALLATION | 
 | 339 |  | 
 | 340 |   $ cpanm https://github.com/KorAP/KorAP-XML-CoNLL-U.git | 
 | 341 |  | 
 | 342 | =head1 OPTIONS | 
 | 343 |  | 
 | 344 | =over 2 | 
 | 345 |  | 
 | 346 | =item B<--sigle-pattern|-p> | 
 | 347 |  | 
 | 348 | Convert only texts from the KorAP XML zip files with folder names (i.e. sigles) matching the glob pattern. | 
 | 349 | =item B<--help|-h> | 
 | 350 |  | 
 | 351 | Print help information. | 
 | 352 |  | 
 | 353 | =item B<--version|-v> | 
 | 354 |  | 
 | 355 | Print version information. | 
 | 356 |  | 
 | 357 |  | 
 | 358 | =item B<--log|-l> | 
 | 359 |  | 
 | 360 | Loglevel for I<Log::Any>. Defaults to C<warn>. | 
 | 361 |  | 
 | 362 | =back | 
 | 363 |  | 
 | 364 | =head1 EXAMPLES | 
 | 365 | =head1 COPYRIGHT AND LICENSE | 
 | 366 |  | 
 | 367 | Copyright (C) 2021, L<IDS Mannheim|https://www.ids-mannheim.de/> | 
 | 368 |  | 
 | 369 | Author: Marc Kupietz | 
 | 370 |  | 
 | 371 | Contributors: Nils Diewald | 
 | 372 |  | 
 | 373 | L<KorAP::XML::CoNNL-U> is developed as part of the L<KorAP|https://korap.ids-mannheim.de/> | 
 | 374 | Corpus Analysis Platform at the | 
 | 375 | L<Leibniz Institute for the German Language (IDS)|http://ids-mannheim.de/>, | 
 | 376 | member of the | 
 | 377 | L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/>. | 
 | 378 |  | 
 | 379 | This program is free software published under the | 
 | 380 | L<BSD-2 License|https://opensource.org/licenses/BSD-2-Clause>. |