CAB/Format/TT.pm

filter: Statementstmt 7.2% 22 / 305 Branchbran 0.0% 0 / 288 Conditioncond 0.0% 0 / 49 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 26.9% 7 / 26 Podpod 63.1% 12 / 19 totaltotal 5.7% 41 / 712 CC 170 SCAR 83.4
CC
170
Cov
3%
token2buf
7832.0
parseTTString
2450.0
parseTokenizerString
210.0
CRAP 4170.3
↑ Summary CAB/Format/CONLLU.pm »
1 ## -*- Mode: CPerl -*-
2 ##
3 ## File: DTA::CAB::Format::TT.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: Datum parser: one-token-per-line text
6  
7 package DTA::CAB::Format::TT;
8 1 ▶use DTA::CAB::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DTA::CAB::Datum ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 ##==============================================================================
15 ## Globals
16 ##==============================================================================
17  
18 1 our @ISA = qw(DTA::CAB::Format);
19  
20 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
21 1 DTA::CAB::Format->registerFormat(name=>__PACKAGE__, filenameRegex=>qr/\.(?i:t|tt|ttt|cab\-t|cab\-tt|cab\-ttt)$/);
22 DTA::CAB::Format->registerFormat(name=>__PACKAGE__, short=>$_)
23 1 foreach (qw(t t0 cab-t cab-tt));
24 }
25  
26 ##==============================================================================
27 ## Constructors etc.
28 ##==============================================================================
29  
30 ## $fmt = CLASS_OR_OBJ->new(%args)
31 ## + object structure: assumed HASH
32 ## {
33 ## ##-- Input
34 ## doc => $doc, ##-- buffered input document
35 ##
36 ## ##-- Output
37 ## outbuf => $stringBuffer, ##-- buffered output
38 ## #level => $formatLevel, ##-- n/a
39 ##
40 ## ##-- Common
41 ## raw => $bool, ##-- attempt to load/save raw data
42 ## fh => $fh, ##-- IO::Handle for read/write
43 ## utf8 => $bool, ##-- read/write utf8?
44 ## tloc => $attr, ##-- if non-empty, parseTokenizerString() sets $w->{$attr}="$off $len"; default=0
45 ## defaultFieldName => $name, ##-- default name for unnamed fields; parsed into @{$tok->{other}{$name}}; default=''
46 ## }
47  
48 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
49 0 my $that = shift;
50 0 ▶ my $fmt = bless({
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
51 ##-- input
52 doc => undef,
53  
54 ##-- common
55 utf8 => 1,
56 defaultFieldName => '',
57 #tloc => undef,
58  
59 ##-- user args
60 @_
61 }, ref($that)||$that);
62 0 return $fmt;
63 }
64  
65 ##==============================================================================
66 ## Methods: Persistence
67 ##==============================================================================
68  
69 ## @keys = $class_or_obj->noSaveKeys()
70 ## + returns list of keys not to be saved
71 ## + default just returns empty list
72 0 ▶sub noSaveKeys {
Subroutine noSaveKeys: not called CC=1 SCAR=6.9
Pod documented
73 0 return ($_[0]->SUPER::noSaveKeys, qw(doc outbuf));
74 }
75  
76 ##==============================================================================
77 ## Methods: I/O: Generic
78 ##==============================================================================
79  
80 ## $fmt = $fmt->close()
81 ## + inherited
82  
83 ##==============================================================================
84 ## Methods: I/O: Block-wise
85 ##==============================================================================
86  
87 ##--------------------------------------------------------------
88 ## Methods: I/O: Block-wise: Generic
89  
90 ## %blockOpts = $CLASS_OR_OBJECT->blockDefaults()
91 ## + returns default block options as for blockOptions()
92 ## + inherited default just returns as for $CLASS_OR_OBJECT->blockOptions('128k@w')
93  
94 ##--------------------------------------------------------------
95 ## Methods: I/O: Block-wise: Input
96  
97 ## \%head = blockScanHead(\$buf,$io,\%opts)
98 ## + gets header offset, length from (mmaped) \$buf
99 ## + %opts are as for blockScan()
100 0 ▶sub blockScanHead {
Subroutine blockScanHead: not called CC=2 SCAR=17.9
Pod undocumented
101 0 my ($fmt,$bufr,$io,$opts) = @_;
102 0 ▶ return [0,$+[0]] if ($$bufr =~ m(\A\n*+(?:%% base=.*\n++)?));
Branch: 1 branch
BranchTrueFalseTotal
if $$bufr =~ /\A\n*+(?:%% base=.*\n++)?/ 0 0 0
103 0 return [0,0];
104 }
105  
106 ## \%head = blockScanFoot(\$buf,$io,\%opts)
107 ## + gets footer offset, length from (mmaped) \$buf
108 ## + %opts are as for blockScan()
109 ## + override returns empty
110 0 ▶sub blockScanFoot {
Subroutine blockScanFoot: not called CC=1 SCAR=6.9
Pod undocumented
111 0 my ($fmt,$bufr,$io,$opts) = @_;
112 0 return [0,0];
113 }
114  
115 ## \@blocks = $fmt->blockScanBody(\$buf,\%opts)
116 ## + scans $filename for block boundaries according to \%opts
117 0 ▶sub blockScanBody {
Subroutine blockScanBody: not called CC=7 SCAR=40.3
Pod undocumented
118 0 my ($fmt,$bufr,$opts) = @_;
119  
120 ##-- scan blocks into head, body, foot
121 0 my $fsize = $opts->{ifsize};
122 0 my $bsize = $opts->{bsize};
123 0 ▶ my $eob = $opts->{eob} =~ /^s/i ? 's' : 'w';
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'eob'} =~ /^s/i ? : 0 0 0
124 0 my $blocks = [];
125  
126 0 my ($off0,$off1,$blk);
127 0 ▶ for ($off0=$opts->{ihead}[0]+$opts->{ihead}[1]; $off0 < $fsize; $off0=$off1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off0 < $fsize) 0 0 0
128 0 push(@$blocks, $blk={bsize=>$bsize,eob=>$eob,ioff=>$off0});
129 0 ▶ pos($$bufr) = ($off0+$bsize < $fsize ? $off0+$bsize : $fsize);
Branch: 1 branch
BranchTrueFalseTotal
$off0 + $bsize < $fsize ? : 0 0 0
130 0 ▶ if ($eob eq 's' ? $$bufr=~m/\n{2,}/sg : $$bufr=~m/\n{1,}/sg) {
Branch: 2 branches
BranchTrueFalseTotal
if ($eob eq 's' ? $$bufr =~ /\n{2,}/gs : $$bufr =~ /\n{1,}/gs) { } 0 0 0
$eob eq 's' ? : 0 0 0
131 0 $off1 = $+[0];
132 0 ▶ $blk->{eos} = $+[0]-$-[0] > 1 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$+[0] - $-[0] > 1 ? : 0 0 0
133 } else {
134 0 $off1 = $fsize;
135 0 $blk->{eos} = 1;
136 }
137 0 $blk->{ilen} = $off1-$off0;
138 }
139  
140 0 return $blocks;
141 }
142  
143 ##--------------------------------------------------------------
144 ## Methods: I/O: Block-wise: Output
145  
146 ## $blk = $fmt->blockStore(\$odata,$blk,$bopt)
147 ## + store output buffer \$buf in $blk->{odata}
148 ## + additionally store keys qw(ofmt ohead odata ofoot) relative to $blk->{odata}
149 ## + override truncates trailing newlines according to $blk->{eos} before calling inherited method
150 0 ▶sub blockStore {
Subroutine blockStore: not called CC=2 SCAR=12.2
Pod undocumented
151 0 my ($fmt,$bufr,$blk,$bopt) = @_;
152  
153 ##-- truncate extraneous newlines from data
154 1 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
155 0 ▶ if (!$blk->{eos}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $blk->{'eos'}) { } 0 0 0
156 0 $$bufr =~ s/\n\K(\n+)\z//s;
157 } else {
158 0 $$bufr =~ s/\n\n\K(\n+)\z//s;
159 }
160  
161 0 return $fmt->SUPER::blockStore($bufr,$blk,$bopt);
162 }
163  
164 ## $fmt_or_undef = $fmt->blockAppend($block,$filename)
165 ## + append a block $block to a file $filename
166 ## + $block is a HASH-ref as returned by blockScan()
167 ## + INHERITED from DTA::CAB::Format
168  
169  
170 ##==============================================================================
171 ## Methods: Input
172 ##==============================================================================
173  
174 ##--------------------------------------------------------------
175 ## Methods: Input: Input selection
176  
177 ## $fmt = $fmt->fromFh($filename_or_handle)
178 ## + override calls fromFh_str()
179 0 ▶sub fromFh {
Subroutine fromFh: not called CC=1 SCAR=6.9
Pod documented
180 0 return $_[0]->fromFh_str(@_[1..$#_]);
181 }
182  
183 ## $fmt = $fmt->fromString(\$string)
184 ## + select input from string $string
185 0 ▶sub fromString {
Subroutine fromString: not called CC=2 SCAR=17.9
Pod documented
186 0 my $fmt = shift;
187 0 $fmt->close();
188 0 ▶ return $fmt->parseTTString(ref($_[0]) ? $_[0] : \$_[0]);
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
189 }
190  
191 ##--------------------------------------------------------------
192 ## Methods: Input: Local
193  
194 ## $fmt = $fmt->parseTTString(\$str)
195 ## + guts for fromString(): parse string $str into local document buffer.
196 0 ▶sub parseTTString {
Subroutine parseTTString: not called CC=49 SCAR=78.0
Pod documented
197 0 my ($fmt,$src) = @_;
198 0 ▶ utf8::decode($$src) if ($fmt->{utf8} && !utf8::is_utf8($$src));
Branch: 1 branch
BranchTrueFalseTotal
if $fmt->{"utf8"} and not utf8::is_utf8($$src) 0 0 0
Condition0%0/3
$fmt->{"utf8"} and not utf8::is_utf8($$src)
!ll&&!rl&&r
000
MC/DC0%0/2
$fmt->{"utf8"} and not utf8::is_utf8($$src)
$fmt->{"utf8"} not utf8::is_utf8($$src)
Truth table0%0/3
A and not(B)
A= $fmt->{"utf8"}B= not utf8::is_utf8($$src)
ABresult
0X0
100
111
199  
200 0 my %f2key =
201 ('morph/lat'=>'mlatin',
202 'morph/la'=>'mlatin',
203 'morph/extra' => 'mextra',
204 );
205  
206 ##-- split by sentence
207 0 my ($toks,$tok,$rw,$text,@fields,$fieldi,$field, $fkey,$fval,$fobj);
208 0 my (%sa,%doca);
209 my $sents =
210 [
211 map {
212 0 %sa=qw();
213 $toks=
214 [
215 map {
216 0 ▶ if ($_ =~ /^\%\% (?:xml\:)?base=(.*)$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($_ =~ /^\%\% (?:xml\:)?base=(.*)$/) { } 0 0 0
elsif ($_ =~ /^\%\% Sentence (.*)$/) { } 0 0 0
elsif ($_ =~ /^\%\% \$txt=(.*)$/) { } 0 0 0
elsif ($_ =~ /^\%\% \$s:(.*)=(.*)$/) { } 0 0 0
elsif ($_ =~ /^\%\%(.*)$/) { } 0 0 0
elsif ($_ =~ /^$/) { } 0 0 0
217 ##-- special comment: document attribute: xml:base
218 0 $doca{'base'} = $1;
219 0 qw()
220 } elsif ($_ =~ /^\%\% Sentence (.*)$/) {
221 ##-- special comment: sentence attribute: xml:id
222 0 $sa{'id'} = $1;
223 0 ▶ if ($sa{'id'} =~ /(\S+)\t=(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sa{"id"} =~ /(\S+)\t=(.*)$/) 0 0 0
224 ##-- dtigerdb 'stxt'
225 0 $sa{'id'} = $1;
226 0 $sa{'stxt'} = $2;
227 }
228 qw()
229 0 } elsif ($_ =~ /^\%\% \$txt=(.*)$/) {
230 ##-- special comment: sentence attribute: stxt (raw sentence text)
231 0 $sa{'stxt'} = $1;
232 0 qw()
233 } elsif ($_ =~ /^\%\% \$s:(.*)=(.*)$/) {
234 ##-- special comment: sentence attribute
235 0 $sa{$1} = $2;
236 0 qw()
237 } elsif ($_ =~ /^\%\%(.*)$/) {
238 ##-- generic line: add to '_cmts' attribute of current sentence (or doc)
239 0 push(@{$sa{_cmts}},$1); ##-- generic doc- or sentence-level comment
240 0 qw()
241 } elsif ($_ =~ /^$/) {
242 ##-- blank line: ignore
243 0 qw()
244 } else {
245 ##-- token
246 0 ($text,@fields) = split(/\t/,$_);
247 0 $tok={text=>$text};
248 0 foreach $fieldi (0..$#fields) {
249 0 $field = $fields[$fieldi];
250 0 ▶ if (($fieldi == 0 && $field =~ m/^([0-9]+) ([0-9]+)$/) || ($field =~ m/^\[loc\] (?:off=)?([0-9]+) (?:len=)?([0-9]+)$/)) {
Branch: 13 branches
BranchTrueFalseTotal
if ($fieldi == 0 and $field =~ /^([0-9]+) ([0-9]+)$/ or $field =~ /^\[loc\] (?:off=)?([0-9]+) (?:len=)?([0-9]+)$/) { } 0 0 0
elsif ($field =~ /^\[(?:xml\:?)?(id|chars)\] (.*)$/) { } 0 0 0
elsif ($field =~ /^\[(exlex|pnd|mapclass|errid|freq|xc|xr|xp|pb|lb|bb|c|b|coff|clen|boff|blen|(?:syncope|ner)_(?:type|loc|tag)|has(?:morph|lts|rw|eqphox|dmoota|moota))\] (.*)$/) { } 0 0 0
elsif ($field =~ /^\[xlit\] /) { } 0 0 0
elsif ($field =~ m(^\[(lts|morph|mlatin|morph/lat?|mextra|morph/extra|rw|rw/lts|rw/morph|moot/morph|dmoot/morph|eq(?:pho(?:x?)|rw|lemma|tagh))\] (.*)$)) { } 0 0 0
elsif ($field =~ m(^\[(ner|syncope)\]\ ##-- $1: syncope analyzer (?:(\w+))? ##-- $2: syncope node id (terminal/@id | nonterminal/@id) (?:\ (\#\S*))? ##-- $3: syncope label name (terminal/label/@name) (?:\ ([0-9]*))? ##-- $4: syncope label id (terminal/label/@id) (?:\ \:\ (\S*))? ##-- $5: syncope category (terminal/category/@name | nonterminal/category-close/@name) (?:\ \/ (\S*?))? ##-- $6: syncope function (terminal/function/@name) OR teiws-parsed type (//name/@type) (?:\ \<([0-9]+)\>)? ##-- $7: syncope depth (nonterminal/@depth) (?:\ \@ (\S*?))? ##-- $8: teiws-parsed reference-URL (//name/@ref) $ )x) { } 0 0 0
elsif ($field =~ m(^\[m(?:orph/)?safe\] ([0-9])$)) { } 0 0 0
elsif ($field =~ m(^\[(.*?moot)/(tag|word|lemma)\]\s?(.*)$)) { } 0 0 0
elsif ($field =~ m(^\[(.*?moot)/analysis\]\s?(\S+)(?:\s\@\s(\S+))?\s(?:\~\s)?(.*?)(?: <([0-9\.\+\-eE]+)>)?$)) { } 0 0 0
elsif ($field =~ m(^\[(.*?moot)/details\]\s?(\S*)(?:\s\@\s(\S+))?\s(?:\~\s)?(.*?)(?: <([0-9\.\+\-eE]+)>)?$)) { } 0 0 0
elsif ($field =~ /^\[((?:gn|ot)\-(?:hyper|hypo|isa|asi|syn))\]\s(\S+)$/) { } 0 0 0
elsif ($field =~ /^\[(toka|tokpp|lang)\]\s?(.*)$/) { } 0 0 0
elsif ($field =~ /^\[([^\]]*)\]\s?(.*)$/) { } 0 0 0
Condition0%0/6
$fieldi == 0 and $field =~ /^([0-9]+) ([0-9]+)$/ or $field =~ /^\[loc\] (?:off=)?([0-9]+) (?:len=)?([0-9]+)$/
l!l&&r!l&&!r
000
$fieldi == 0 and $field =~ /^([0-9]+) ([0-9]+)$/
!ll&&!rl&&r
000
MC/DC0%0/3
$fieldi == 0 and $field =~ /^([0-9]+) ([0-9]+)$/ or $field =~ /^\[loc\] (?:off=)?([0-9]+) (?:len=)?([0-9]+)$/
$fieldi == 0 $field =~ /^([0-9]+) ([0-9]+)$/ $field =~ /^\[loc\] (?:off=)?([0-9]+) (?:len=)?([0-9]+)$/
Truth table0%0/5
A and B or C
A= $fieldi == 0B= $field =~ /^([0-9]+) ([0-9]+)$/C= $field =~ /^\[loc\] (?:off=)?([0-9]+) (?:len=)?([0-9]+)$/
ABCresult
11X1
0X11
1011
0X00
1000
251 ##-- token: field: loc
252 0 $tok->{loc} = { off=>$1,len=>$2 };
253 } elsif ($field =~ m/^\[(?:xml\:?)?(id|chars)\] (.*)$/) {
254 ##-- token: field: DTA::TokWrap special fields: (id|chars|xml:id|xml:chars)
255 0 $tok->{$1} = $2;
256 } elsif ($field =~ m/^\[(exlex|pnd|mapclass|errid|freq|xc|xr|xp|pb|lb|bb|c|b|coff|clen|boff|blen|(?:syncope|ner)_(?:type|loc|tag)|has(?:morph|lts|rw|eqphox|dmoota|moota))\] (.*)$/) {
257 ##-- token: field: other scalar field (exlex, pnd, mapclass, errid, freq, ...)
258 0 $tok->{$1} = $2;
259 } elsif ($field =~ m/^\[xlit\] /) {
260 ##-- token: field: xlit
261 0 ▶ if ($field =~ m/^\[xlit\] (?:isLatin1|l1)=([01]) (?:isLatinExt|lx)=([01]) (?:latin1Text|l1s)=(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^\[xlit\] (?:isLatin1|l1)=([01]) (?:isLatinExt|lx)=([01]) (?:latin1Text|l1s)=(.*)$/) { } 0 0 0
262 0 ▶ $tok->{xlit} = { isLatin1=>($1||0), isLatinExt=>($2||0), latin1Text=>$3 };
Condition0%0/4
$1 || 0
l!l
00
$2 || 0
l!l
00
MC/DC0%0/1
$1 || 0
$1
MC/DC0%0/1
$2 || 0
$2
Truth table0%0/2
A
A= $1
Aresult
11
00
Truth table0%0/2
A
A= $2
Aresult
11
00
263 } else {
264 0 $tok->{xlit} = { isLatin1=>'', isLatinExt=>'', latin1Text=>substr($field,7) };
265 }
266 } elsif ($field =~ m/^\[(lts|morph|mlatin|morph\/lat?|mextra|morph\/extra|rw|rw\/lts|rw\/morph|moot\/morph|dmoot\/morph|eq(?:pho(?:x?)|rw|lemma|tagh))\] (.*)$/) {
267 ##-- token fields: fst analysis: (lts|eqpho|eqphox|morph|mlatin|mextra|rw|rw/lts|rw/morph|eqrw|moot/morph|dmoot/morph|...)
268 0 ($fkey,$fval) = ($1,$2);
269 0 ▶ if ($fkey =~ s/^rw\///) {
Branch: 3 branches
BranchTrueFalseTotal
if ($fkey =~ s[^rw/][]) { } 0 0 0
elsif ($fkey =~ s[^dmoot/][]) { } 0 0 0
elsif ($fkey =~ s[^moot/][]) { } 0 0 0
270 0 ▶ $tok->{rw} = [ {} ] if (!$tok->{rw});
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->{"rw"} 0 0 0
271 0 $fobj = $tok->{rw}[$#{$tok->{rw}}];
272 } elsif ($fkey =~ s/^dmoot\///) {
273 0 ▶ $tok->{dmoot} = {} if (!$tok->{dmoot});
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->{"dmoot"} 0 0 0
274 0 $fobj = $tok->{dmoot};
275 } elsif ($fkey =~ s/^moot\///) {
276 0 ▶ $tok->{moot} = {} if (!$tok->{moot});
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->{"moot"} 0 0 0
277 0 $fobj = $tok->{moot};
278 } else {
279 0 $fobj = $tok;
280 }
281 0 ▶ $fkey = $f2key{$fkey} if (defined($f2key{$fkey}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $f2key{$fkey} 0 0 0
282 0 ▶ if ($fval =~ /^(?:(.*?) \: )?(?:(.*?) \@ )?(.*?)(?: \<([0-9\.\+\-eE]+)\>)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fval =~ /^(?:(.*?) \: )?(?:(.*?) \@ )?(.*?)(?: \<([0-9\.\+\-eE]+)\>)?$/) { } 0 0 0
283 0 ▶ push(@{$fobj->{$fkey}}, {(defined($1) ? (lo=>$1) : qw()), (defined($2) ? (lemma=>$2) : qw()), hi=>$3, w=>($4||0)});
Branch: 2 branches
BranchTrueFalseTotal
defined $1 ? : 0 0 0
defined $2 ? : 0 0 0
Condition0%0/2
$4 || 0
l!l
00
MC/DC0%0/1
$4 || 0
$4
Truth table0%0/2
A
A= $4
Aresult
11
00
284 } else {
285 0 $fmt->warn("parseTTString(): could not parse FST analysis field '$fkey' for token '$text': $field");
286 }
287 }
288 elsif ($field =~ m{^\[(ner|syncope)\]\ ##-- $1: syncope analyzer
289 (?:(\w+))? ##-- $2: syncope node id (terminal/@id | nonterminal/@id)
290 (?:\ (\#\S*))? ##-- $3: syncope label name (terminal/label/@name)
291 (?:\ ([0-9]*))? ##-- $4: syncope label id (terminal/label/@id)
292 (?:\ \:\ (\S*))? ##-- $5: syncope category (terminal/category/@name | nonterminal/category-close/@name)
293 (?:\ \/ (\S*?))? ##-- $6: syncope function (terminal/function/@name) OR teiws-parsed type (//name/@type)
294 (?:\ \<([0-9]+)\>)? ##-- $7: syncope depth (nonterminal/@depth)
295 (?:\ \@ (\S*?))? ##-- $8: teiws-parsed reference-URL (//name/@ref)
296 $
297 }x)
298 {
299 ##-- token fields: ne-recognizer analysis: syncope
300 0 ▶ push(@{$tok->{$1}}, { nid=>$2,
Branch: 6 branches
BranchTrueFalseTotal
defined $3 ? : 0 0 0
defined $4 ? : 0 0 0
defined $5 ? : 0 0 0
defined $6 ? : 0 0 0
defined $7 ? : 0 0 0
defined $8 ? : 0 0 0
301 (defined($3) ? (label=>$3) : qw()),
302 (defined($4) ? (labid=>$4) : qw()),
303 (defined($5) ? (cat=>$5) : qw()),
304 (defined($6) ? (func=>$6) : qw()),
305 (defined($7) ? (depth=>$7) : qw()),
306 (defined($8) ? (depth=>$8) : qw()),
307 });
308 } elsif ($field =~ m/^\[m(?:orph\/)?safe\] ([0-9])$/) {
309 ##-- token: field: morph-safety check (msafe|morph/safe)
310 0 $tok->{msafe} = $1;
311 } elsif ($field =~ m/^\[(.*?moot)\/(tag|word|lemma)\]\s?(.*)$/) {
312 ##-- token: field: (moot|dmoot)/(tag|word|lemma)
313 0 $tok->{$1}{$2} = $3;
314 } elsif ($field =~ m/^\[(.*?moot)\/analysis\]\s?(\S+)(?:\s\@\s(\S+))?\s(?:\~\s)?(.*?)(?: <([0-9\.\+\-eE]+)>)?$/) {
315 ##-- token: field: moot/analysis|dmoot/analysis
316 0 push(@{$tok->{$1}{analyses}}, {tag=>$2,lemma=>$3,details=>$4,prob=>$5});
317 } elsif ($field =~ m/^\[(.*?moot)\/details\]\s?(\S*)(?:\s\@\s(\S+))?\s(?:\~\s)?(.*?)(?: <([0-9\.\+\-eE]+)>)?$/) {
318 ##-- token: field: moot/details|dmoot/details
319 0 $tok->{$1}{details} = {tag=>$2,lemma=>$3,details=>$4,prob=>$5};
320 } elsif ($field =~ m/^\[((?:gn|ot)\-(?:hyper|hypo|isa|asi|syn))\]\s(\S+)$/) {
321 ##-- token: field: list field (GermaNet|OpenThesaurus hyperonyms / hyponyms)
322 0 push(@{$tok->{$1}}, $2);
323 } elsif ($field =~ m/^\[(toka|tokpp|lang)\]\s?(.*)$/) {
324 ##-- token: field: other known list field: (toka|tokpp)
325 0 push(@{$tok->{$1}}, $2);
326 } elsif ($field =~ m/^\[([^\]]*)\]\s?(.*)$/) {
327 ##-- token: field: unknown named field "[$name] $val", parse into $tok->{other}{$name} = \@vals
328 0 push(@{$tok->{other}{$1}}, $2);
329 } else {
330 ##-- token: field: unnamed field
331 #$fmt->warn("parseTTString(): could not parse token field '$field' for token '$text'");
332 0 ▶ push(@{$tok->{other}{$fmt->{defaultFieldName}||''}}, $field);
Condition0%0/2
$fmt->{'defaultFieldName'} || ''
l!l
00
MC/DC0%0/1
$fmt->{'defaultFieldName'} || ''
$fmt->{'defaultFieldName'}
Truth table0%0/2
A
A= $fmt->{'defaultFieldName'}
Aresult
11
00
333 }
334 }
335 $tok
336 0 }
337 }
338 split(/\n/, $_)
339 ];
340 0 ▶ (%sa || @$toks ? {%sa,tokens=>$toks} : qw())
Branch: 1 branch
BranchTrueFalseTotal
%sa || @$toks ? : 0 0 0
Condition0%0/3
%sa or @$toks
l!l&&r!l&&!r
000
MC/DC0%0/2
%sa or @$toks
%sa @$toks
Truth table0%0/3
A or B
A= %saB= @$toks
ABresult
1X1
011
000
341 } split(/\n\n+/, $$src)
342 ];
343  
344 ##-- construct & buffer document
345 #$_ = bless($_,'DTA::CAB::Sentence') foreach (@$sents);
346 0 $fmt->{doc} = bless({%doca,body=>$sents}, 'DTA::CAB::Document');
347 0 return $fmt;
348 }
349  
350 ## $doc = $CLASS_OR_OBJECT->parseTokenizerString(\$string,\%opts)
351 ## + scaled-down version of parseTTString() suitable for use with dwds_tomastotath or moot/waste tokenizer output
352 0 ▶sub parseTokenizerString {
Subroutine parseTokenizerString: not called CC=14 SCAR=53.5
Pod undocumented
353 0 my ($that,$tstr,$opts) = @_;
354 0 ▶ utf8::decode($$tstr) if (!utf8::is_utf8($$tstr));
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($$tstr) 0 0 0
355  
356 my $tloc = ($opts && exists($opts->{tloc}) ? $opts->{tloc}
357 : (ref($that) ? $that->{tloc}
358 0 ▶ : undef));
Branch: 2 branches
BranchTrueFalseTotal
$opts && exists $opts->{'tloc'} ? : 0 0 0
ref $that ? : 0 0 0
Condition0%0/3
$opts and exists $opts->{"tloc"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts and exists $opts->{"tloc"}
$opts exists $opts->{"tloc"}
Truth table0%0/3
A and B
A= $optsB= exists $opts->{"tloc"}
ABresult
0X0
100
111
359 0 my ($toks,%sa);
360 my $sents =
361 [
362 map {
363 0 %sa=qw();
364 $toks=
365 [
366 map {
367 0 ▶ if ($_ =~ /^\%\%(.*)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_ =~ /^\%\%(.*)$/) { } 0 0 0
elsif ($_ =~ /^$/) { } 0 0 0
elsif (/^([^\t]*)\t([0-9]+) ([0-9]+)(?:\t(.*))?$/) { } 0 0 0
368 ##-- generic line: add to '_cmts' attribute of current sentence
369 0 ▶ push(@{$sa{_cmts}},$1) if ($1 !~ /^\$[WS]B\$$/); ##-- generic comment, treated as sentence attribute
Branch: 1 branch
BranchTrueFalseTotal
unless $1 =~ /^\$[WS]B\$$/ 0 0 0
370 0 qw()
371 } elsif ($_ =~ /^$/) {
372 ##-- blank line: ignore
373 0 qw()
374 } elsif (/^([^\t]*)\t([0-9]+) ([0-9]+)(?:\t(.*))?$/) {
375 ##-- token
376 {text=>$1,
377 #loc=>{off=>$2,len=>$3},
378 ($tloc ? ($tloc=>"$2 $3") : qw()),
379 0 ▶ ($4 ? (toka=>[map {/^\[(.*)\]$/ ? $1 : $_} split(/\t/,$4)]) : qw())
Branch: 3 branches
BranchTrueFalseTotal
$tloc ? : 0 0 0
$4 ? : 0 0 0
/^\[(.*)\]$/ ? : 0 0 0
380 }
381 }
382 }
383 split(/\n/, $_)
384 ];
385 0 ▶ (%sa || @$toks ? {%sa,tokens=>$toks} : qw())
Branch: 1 branch
BranchTrueFalseTotal
%sa || @$toks ? : 0 0 0
Condition0%0/3
%sa or @$toks
l!l&&r!l&&!r
000
MC/DC0%0/2
%sa or @$toks
%sa @$toks
Truth table0%0/3
A or B
A= %saB= @$toks
ABresult
1X1
011
000
386 } split(/\n\n+/, $$tstr)
387 ];
388  
389 ##-- construct & buffer document
390 0 return bless({body=>$sents}, 'DTA::CAB::Document');
391 }
392  
393 ##--------------------------------------------------------------
394 ## Methods: Input: Generic API
395  
396 ## $doc = $fmt->parseDocument()
397 0 ▶sub parseDocument { return $_[0]{doc}; }
Subroutine parseDocument: not called CC=1 SCAR=6.9
Pod documented
398  
399  
400 ##==============================================================================
401 ## Methods: Output
402 ##==============================================================================
403  
404 ##--------------------------------------------------------------
405 ## Methods: Output: Generic
406  
407 ## $type = $fmt->mimeType()
408 ## + default returns text/plain
409 0 ▶sub mimeType { return 'text/plain'; }
Subroutine mimeType: not called CC=1 SCAR=6.9
Pod documented
410  
411 ## $ext = $fmt->defaultExtension()
412 ## + returns default filename extension for this format
413 0 ▶sub defaultExtension { return '.tt'; }
Subroutine defaultExtension: not called CC=1 SCAR=6.9
Pod documented
414  
415 ## $str = $fmt->toString()
416 ## + select output to byte-string
417 ## + flush buffered output document to byte-string
418  
419 ## $fmt_or_undef = $fmt->toFile($filename_or_handle, $formatLevel)
420 ## + select output to named file $filename.
421 ## + default implementation calls $fmt->toFh()
422  
423 ## $fmt_or_undef = $fmt->toFh($fh,$formatLevel)
424 ## + select output to an open filehandle $fh.
425 ## + default implementation calls to $fmt->formatString($formatLevel)
426 0 ▶sub toFh {
Subroutine toFh: not called CC=1 SCAR=6.9
Pod documented
427 0 $_[0]->DTA::CAB::Format::toFh(@_[1..$#_]);
428 0 $_[0]->setLayers();
429 0 return $_[0];
430 }
431  
432 ##--------------------------------------------------------------
433 ## Methods: Output: Generic API
434  
435 ## \$buf = $fmt->token2buf($tok,\$buf)
436 ## + buffer output for a single token
437 ## + called by putToken()
438 0 ▶sub token2buf {
Subroutine token2buf: not called CC=88 SCAR=89.7
Pod undocumented
439 0 my ($fmt,$tok,$bufr) = @_;
440 0 ▶ $bufr = \(my $buf='') if (!defined($bufr));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bufr 0 0 0
441 0 $$bufr = '';
442  
443 ##-- pre-token comments
444 0 ▶ $$bufr .= join('', map {"%%$_\n"} map {split(/\n/,$_)} @{$tok->{_cmts}}) if ($tok->{_cmts});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"_cmts"} 0 0 0
445  
446 ##-- text
447 0 $$bufr .= $tok->{text};
448  
449 ##-- Location ('loc'), moot compatibile
450 0 ▶ $$bufr .= "\t" . (UNIVERSAL::isa($tok->{loc},'HASH') ? "$tok->{loc}{off} $tok->{loc}{len}" : $tok->{loc}) if ($tok->{loc});
Branch: 2 branches
BranchTrueFalseTotal
if $tok->{"loc"} 0 0 0
UNIVERSAL::isa($tok->{'loc'}, 'HASH') ? : 0 0 0
451  
452  
453 ##-- SynCoPe location (for syncope-tab format)
454 0 ▶ $$bufr .= "\t[syncope_tag] $tok->{syncope_tag}" if (defined($tok->{syncope_tag}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok->{"syncope_tag"} 0 0 0
455 0 ▶ $$bufr .= "\t[syncope_type] $tok->{syncope_type}" if (defined($tok->{syncope_type}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok->{"syncope_type"} 0 0 0
456 0 ▶ $$bufr .= "\t[syncope_loc] $tok->{syncope_loc}" if (defined($tok->{syncope_loc}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok->{"syncope_loc"} 0 0 0
457  
458 ##-- character list
459 #$$bufr .= "\t[chars] $tok->{chars}" if (defined($tok->{chars}));
460  
461 ##-- literal fields
462 0 foreach (grep {defined($tok->{$_})} qw(id exlex pnd mapclass errid xc xr xp pb lb bb c coff clen b boff blen)) {
463 0 $$bufr .= "\t[$_] $tok->{$_}"
464 }
465  
466 ##-- detected language
467 0 ▶ $$bufr .= join('', map {"\t[lang] $_"} grep {defined($_)} @{$tok->{lang}}) if ($tok->{lang});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"lang"} 0 0 0
468  
469 ##-- cab token-preprocessor analyses
470 0 ▶ $$bufr .= join('', map {"\t[tokpp] $_"} grep {defined($_)} @{$tok->{tokpp}}) if ($tok->{tokpp});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"tokpp"} 0 0 0
471  
472 ##-- tokenizer-supplied analyses
473 0 ▶ $$bufr .= join('', map {"\t[toka] $_"} grep {defined($_)} @{$tok->{toka}}) if ($tok->{toka});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"toka"} 0 0 0
474  
475 ##-- Transliterator ('xlit')
476 $$bufr .= "\t[xlit] l1=$tok->{xlit}{isLatin1} lx=$tok->{xlit}{isLatinExt} l1s=$tok->{xlit}{latin1Text}"
477 0 ▶ if (defined($tok->{xlit}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok->{"xlit"} 0 0 0
478  
479 ##-- LTS ('lts')
480 0 ▶ $$bufr .= join('', map { "\t[lts] ".(defined($_->{lo}) ? "$_->{lo} : " : '')."$_->{hi} <$_->{w}>" } @{$tok->{lts}})
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'lo'} ? : 0 0 0
481 0 ▶ if ($tok->{lts});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"lts"} 0 0 0
482  
483 ##-- phonetic digests ('soundex', 'koeln', 'metaphone')
484 0 ▶ $$bufr .= "\t[soundex] $tok->{soundex}" if (defined($tok->{soundex}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok->{"soundex"} 0 0 0
485 0 ▶ $$bufr .= "\t[koeln] $tok->{koeln}" if (defined($tok->{koeln}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok->{"koeln"} 0 0 0
486 0 ▶ $$bufr .= "\t[metaphone] $tok->{metaphone}" if (defined($tok->{metaphone}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok->{"metaphone"} 0 0 0
487  
488 ##-- Phonetic Equivalents ('eqpho')
489 0 ▶ $$bufr .= join('', map { "\t[eqpho] ".(ref($_) ? "$_->{hi} <$_->{w}>" : $_) } grep {defined($_)} @{$tok->{eqpho}})
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
490 0 ▶ if ($tok->{eqpho});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"eqpho"} 0 0 0
491  
492 ##-- Known Phonetic Equivalents ('eqphox')
493 0 ▶ $$bufr .= join('', map { "\t[eqphox] ".(ref($_) ? "$_->{hi} <$_->{w}>" : $_) } grep {defined($_)} @{$tok->{eqphox}})
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
494 0 ▶ if ($tok->{eqphox});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"eqphox"} 0 0 0
495  
496 ##-- Morph ('morph')
497 0 ▶ if ($tok->{morph}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->{"morph"}) 0 0 0
498 $$bufr .= join('',
499 map {("\t[morph] "
500 .(defined($_->{lo}) ? "$_->{lo} : " : '')
501 0 ▶ .(defined($_->{lemma}) ? "$_->{lemma} @ " : '')
Branch: 2 branches
BranchTrueFalseTotal
defined $_->{'lo'} ? : 0 0 0
defined $_->{'lemma'} ? : 0 0 0
502 ."$_->{hi} <$_->{w}>")
503 0 } @{$tok->{morph}});
504 }
505  
506 ##-- hasmorph
507 0 ▶ $$bufr .= "\t[hasmorph] ".($tok->{hasmorph} ? '1' : '0') if (exists $tok->{hasmorph});
Branch: 2 branches
BranchTrueFalseTotal
if exists $tok->{"hasmorph"} 0 0 0
$tok->{'hasmorph'} ? : 0 0 0
508  
509 ##-- Morph::Latin ('morph/lat')
510 0 ▶ $$bufr .= join('', map { "\t[morph/lat] ".(defined($_->{lo}) ? "$_->{lo} : " : '')."$_->{hi} <$_->{w}>" } @{$tok->{mlatin}})
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'lo'} ? : 0 0 0
511 0 ▶ if ($tok->{mlatin});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"mlatin"} 0 0 0
512  
513 ##-- Morph::Extra::* ('morph/extra')
514 0 ▶ $$bufr .= join('', map { "\t[morph/extra] ".(defined($_->{lo}) ? "$_->{lo} : " : '')."$_->{hi} <$_->{w}>" } @{$tok->{mextra}})
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'lo'} ? : 0 0 0
515 0 ▶ if ($tok->{mextra});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"mextra"} 0 0 0
516  
517 ##-- MorphSafe ('morph/safe')
518 0 ▶ $$bufr .= "\t[morph/safe] ".($tok->{msafe} ? 1 : 0) if (exists($tok->{msafe}));
Branch: 2 branches
BranchTrueFalseTotal
if exists $tok->{"msafe"} 0 0 0
$tok->{'msafe'} ? : 0 0 0
519  
520 ##-- Rewrites + analyses
521 $$bufr .= join('',
522 map {
523 ("\t[rw] ".(defined($_->{lo}) ? "$_->{lo} : " : '')."$_->{hi} <$_->{w}>",
524 (##-- rw/lts
525 $_->{lts}
526 0 ▶ ? map { "\t[rw/lts] ".(defined($_->{lo}) ? "$_->{lo} : " : '')."$_->{hi} <$_->{w}>" } @{$_->{lts}}
Branch: 2 branches
BranchTrueFalseTotal
defined $_->{'lo'} ? : 0 0 0
$_->{'morph'} ? : 0 0 0
527 : qw()),
528 (##-- rw/morph
529 $_->{morph}
530 ? map {("\t[rw/morph] "
531 .(defined($_->{lo}) ? "$_->{lo} : " : '')
532 0 ▶ .(defined($_->{lemma}) ? "$_->{lemma} @ " : '')
Branch: 2 branches
BranchTrueFalseTotal
defined $_->{'lo'} ? : 0 0 0
defined $_->{'lemma'} ? : 0 0 0
533 ."$_->{hi} <$_->{w}>"
534 0 ▶ )} @{$_->{morph}}
Branch: 2 branches
BranchTrueFalseTotal
defined $_->{'lo'} ? : 0 0 0
$_->{'lts'} ? : 0 0 0
535 : qw()),
536 )
537 0 } @{$tok->{rw}})
538 0 ▶ if ($tok->{rw});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"rw"} 0 0 0
539  
540 ##-- Rewrite Equivalents ('eqrw')
541 0 ▶ $$bufr .= join('', map { "\t[eqrw] ".(ref($_) ? "$_->{hi} <$_->{w}>" : $_) } grep {defined($_)} @{$tok->{eqrw}})
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
542 0 ▶ if ($tok->{eqrw});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"eqrw"} 0 0 0
543  
544 ##-- dmoot
545 0 ▶ if ($tok->{dmoot}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->{"dmoot"}) 0 0 0
546 ##-- dmoot/tag
547 0 $$bufr .= "\t[dmoot/tag] $tok->{dmoot}{tag}";
548  
549 ##-- dmoot/details
550 $$bufr .= ("\t[dmoot/details] $tok->{dmoot}{details}{tag} ~ $tok->{dmoot}{details}{details} <"
551 .($tok->{dmoot}{details}{prob}||$tok->{dmoot}{details}{cost}||0).">"
552 )
553 0 ▶ if ($tok->{dmoot}{details});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"dmoot"}{"details"} 0 0 0
Condition0%0/5
$tok->{'dmoot'}{'details'}{'prob'} || $tok->{'dmoot'}{'details'}{'cost'} || 0
l!l
00
$tok->{"dmoot"}{"details"}{"prob"} or $tok->{"dmoot"}{"details"}{"cost"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tok->{'dmoot'}{'details'}{'prob'} || $tok->{'dmoot'}{'details'}{'cost'} || 0
$tok->{"dmoot"}{"details"}{"prob"} $tok->{"dmoot"}{"details"}{"cost"}
Truth table0%0/3
A or B
A= $tok->{"dmoot"}{"details"}{"prob"}B= $tok->{"dmoot"}{"details"}{"cost"}
ABresult
1X1
011
000
554  
555 ##-- dmoot/morph
556 $$bufr .= join('', map {("\t[dmoot/morph] "
557 .(defined($_->{lo}) ? "$_->{lo} : " : '')
558 0 ▶ .(defined($_->{lemma}) ? "$_->{lemma} @ " : '')
Branch: 2 branches
BranchTrueFalseTotal
defined $_->{'lo'} ? : 0 0 0
defined $_->{'lemma'} ? : 0 0 0
559 ."$_->{hi} <$_->{w}>"
560 0 )} @{$tok->{dmoot}{morph}})
561 0 ▶ if ($tok->{dmoot}{morph});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"dmoot"}{"morph"} 0 0 0
562  
563 ##-- dmoot/analyses
564 0 ▶ $$bufr .= join('', map {"\t[dmoot/analysis] $_->{tag} ~ $_->{details} <".($_->{prob}||$_->{cost}||0).">"} @{$tok->{dmoot}{analyses}})
Condition0%0/5
$_->{'prob'} || $_->{'cost'} || 0
l!l
00
$_->{"prob"} or $_->{"cost"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->{'prob'} || $_->{'cost'} || 0
$_->{"prob"} $_->{"cost"}
Truth table0%0/3
A or B
A= $_->{"prob"}B= $_->{"cost"}
ABresult
1X1
011
000
565 0 ▶ if ($tok->{dmoot}{analyses});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"dmoot"}{"analyses"} 0 0 0
566 }
567  
568 ##-- moot
569 0 ▶ if ($tok->{moot}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->{"moot"}) 0 0 0
570 ##-- moot/word
571 0 ▶ $$bufr .= "\t[moot/word] $tok->{moot}{word}" if (defined($tok->{moot}{word}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok->{"moot"}{"word"} 0 0 0
572  
573 ##-- moot/tag
574 0 $$bufr .= "\t[moot/tag] $tok->{moot}{tag}";
575  
576 ##-- moot/lemma
577 0 ▶ $$bufr .= "\t[moot/lemma] $tok->{moot}{lemma}" if (defined($tok->{moot}{lemma}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok->{"moot"}{"lemma"} 0 0 0
578  
579 ##-- moot/details
580 $$bufr .= ("\t[moot/details] $tok->{moot}{details}{tag}"
581 .(defined($tok->{moot}{details}{lemma}) ? " \@ $tok->{moot}{details}{lemma}" : '')
582 ." ~ $tok->{moot}{details}{details} <".($tok->{moot}{details}{prob}||$tok->{moot}{details}{cost}||0).">"
583 )
584 0 ▶ if ($tok->{moot}{details});
Branch: 2 branches
BranchTrueFalseTotal
if $tok->{"moot"}{"details"} 0 0 0
defined $tok->{'moot'}{'details'}{'lemma'} ? : 0 0 0
Condition0%0/5
$tok->{'moot'}{'details'}{'prob'} || $tok->{'moot'}{'details'}{'cost'} || 0
l!l
00
$tok->{"moot"}{"details"}{"prob"} or $tok->{"moot"}{"details"}{"cost"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tok->{'moot'}{'details'}{'prob'} || $tok->{'moot'}{'details'}{'cost'} || 0
$tok->{"moot"}{"details"}{"prob"} $tok->{"moot"}{"details"}{"cost"}
Truth table0%0/3
A or B
A= $tok->{"moot"}{"details"}{"prob"}B= $tok->{"moot"}{"details"}{"cost"}
ABresult
1X1
011
000
585  
586 ##-- moot/analyses
587 $$bufr .= join('', map {("\t[moot/analysis] $_->{tag}"
588 .(defined($_->{lemma}) ? " \@ $_->{lemma}" : '')
589 0 ▶ ." ~ $_->{details} <".($_->{prob}||$_->{cost}||0).">"
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'lemma'} ? : 0 0 0
Condition0%0/5
$_->{'prob'} || $_->{'cost'} || 0
l!l
00
$_->{"prob"} or $_->{"cost"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->{'prob'} || $_->{'cost'} || 0
$_->{"prob"} $_->{"cost"}
Truth table0%0/3
A or B
A= $_->{"prob"}B= $_->{"cost"}
ABresult
1X1
011
000
590 0 )} @{$tok->{moot}{analyses}})
591 0 ▶ if ($tok->{moot}{analyses});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"moot"}{"analyses"} 0 0 0
592 }
593  
594 ##-- lemma equivalents
595 $$bufr .= join('', map {("\t[eqlemma] "
596 .(ref($_)
597 ? (ref($_) eq 'HASH'
598 ? ((defined($_->{lo}) ? "$_->{lo} : " : '')
599 .$_->{hi}
600 0 ▶ .(defined($_->{w}) ? " <$_->{w}>" : ''))
Branch: 4 branches
BranchTrueFalseTotal
ref $_ ? : 0 0 0
ref $_ eq 'HASH' ? : 0 0 0
defined $_->{'lo'} ? : 0 0 0
defined $_->{'w'} ? : 0 0 0
601 : $_)
602 : $_)
603 0 )} grep {defined($_)} @{$tok->{eqlemma}})
604 0 ▶ if ($tok->{eqlemma});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"eqlemma"} 0 0 0
605  
606 ##-- lemma equivalents / tagh
607 $$bufr .= join('', map {("\t[eqtagh] "
608 .(defined($_->{lo}) ? "$_->{lo} : " : '')
609 .$_->{hi}
610 0 ▶ .(defined($_->{w}) ? " <$_->{w}>" : '')
Branch: 2 branches
BranchTrueFalseTotal
defined $_->{'lo'} ? : 0 0 0
defined $_->{'w'} ? : 0 0 0
611 0 )} grep {defined($_)} @{$tok->{eqtagh}})
612 0 ▶ if ($tok->{eqtagh});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"eqtagh"} 0 0 0
613  
614 ##-- relation closure / GermaNet
615 0 ▶ $$bufr .= join('', map {"\t[gn-syn] $_"} grep {defined($_)} @{$tok->{'gn-syn'}}) if ($tok->{'gn-syn'});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"gn-syn"} 0 0 0
616 0 ▶ $$bufr .= join('', map {"\t[gn-isa] $_"} grep {defined($_)} @{$tok->{'gn-isa'}}) if ($tok->{'gn-isa'});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"gn-isa"} 0 0 0
617 0 ▶ $$bufr .= join('', map {"\t[gn-asi] $_"} grep {defined($_)} @{$tok->{'gn-asi'}}) if ($tok->{'gn-asi'});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"gn-asi"} 0 0 0
618  
619 ##-- relation closure / OpenThesaurus
620 0 ▶ $$bufr .= join('', map {"\t[ot-syn] $_"} grep {defined($_)} @{$tok->{'ot-syn'}}) if ($tok->{'ot-syn'});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"ot-syn"} 0 0 0
621 0 ▶ $$bufr .= join('', map {"\t[ot-isa] $_"} grep {defined($_)} @{$tok->{'ot-isa'}}) if ($tok->{'ot-isa'});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"ot-isa"} 0 0 0
622 0 ▶ $$bufr .= join('', map {"\t[ot-asi] $_"} grep {defined($_)} @{$tok->{'ot-asi'}}) if ($tok->{'ot-asi'});
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"ot-asi"} 0 0 0
623  
624 ##-- NE-recognizer ('ner')
625 0 ▶ if ($tok->{ner}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->{"ner"}) 0 0 0
626 $$bufr .= join('',
627 map {("\t[ner] "
628 .(defined($_->{nid}) ? $_->{nid} : '')
629 .(defined($_->{label}) ? " $_->{label}" : '')
630 .(defined($_->{labid}) ? " $_->{labid}" : '')
631 .(defined($_->{cat}) ? " : $_->{cat}" : '')
632 .(defined($_->{func}) ? " / $_->{func}" : '')
633 .(defined($_->{depth}) ? " <$_->{depth}>" : '')
634 0 ▶ .(defined($_->{ref}) ? " @ $_->{ref}" : '')
Branch: 7 branches
BranchTrueFalseTotal
defined $_->{'nid'} ? : 0 0 0
defined $_->{'label'} ? : 0 0 0
defined $_->{'labid'} ? : 0 0 0
defined $_->{'cat'} ? : 0 0 0
defined $_->{'func'} ? : 0 0 0
defined $_->{'depth'} ? : 0 0 0
defined $_->{'ref'} ? : 0 0 0
635 0 )} @{$tok->{ner}});
636 }
637  
638 ##-- unparsed fields (pass-through)
639 0 ▶ if ($tok->{other}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->{"other"}) 0 0 0
640 0 my ($name);
641 $$bufr .= ("\t"
642 .join("\t",
643 0 ▶ (map { $name=$_; map { "[$name] $_" } (ref($tok->{other}{$name}) ? @{$tok->{other}{$name}} : $tok->{other}{$name}) }
Branch: 1 branch
BranchTrueFalseTotal
ref $tok->{'other'}{$name} ? : 0 0 0
644 0 ▶ sort grep {$_ ne $fmt->{defaultFieldName}} keys %{$tok->{other}}
Branch: 1 branch
BranchTrueFalseTotal
$tok->{'other'}{$fmt->{'defaultFieldName'}} ? : 0 0 0
645 ),
646 ($tok->{other}{$fmt->{defaultFieldName}}
647 0 ? @{$tok->{other}{$fmt->{defaultFieldName}}}
648 : qw()
649 ))
650 );
651 }
652  
653 ##-- return
654 0 $$bufr .= "\n";
655 0 return $bufr;
656 }
657  
658 ## $fmt = $fmt->putToken($tok)
659 ## $fmt = $fmt->putToken($tok,\$buf)
660 0 ▶sub putToken {
Subroutine putToken: not called CC=1 SCAR=6.9
Pod documented
661 0 $_[0]{fh}->print(${$_[0]->token2buf(@_[1..$#_])});
662 0 return $_[0];
663 }
664  
665 ## $fmt = $fmt->putSentence($sent)
666 ## $fmt = $fmt->putSentence($sent,\$buf)
667 ## + concatenates formatted tokens, adding sentence-id comment if available
668 0 ▶sub putSentence {
Subroutine putSentence: not called CC=7 SCAR=40.3
Pod documented
669 0 my ($fmt,$sent,$bufr) = @_;
670 0 ▶ $bufr = \(my $buf='') if (!defined($bufr));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bufr 0 0 0
671 0 ▶ $fmt->{fh}->print(join('', map {"%%$_\n"} map {split(/\n/,$_)} @{$sent->{_cmts}})) if ($sent->{_cmts});
Branch: 1 branch
BranchTrueFalseTotal
if $sent->{"_cmts"} 0 0 0
672 0 ▶ $fmt->{fh}->print("%% Sentence $sent->{id}\n") if (defined($sent->{id}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $sent->{"id"} 0 0 0
673 0 ▶ $fmt->{fh}->print("%% \$stxt=$sent->{stxt}\n") if (defined($sent->{stxt}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $sent->{"stxt"} 0 0 0
674 0 $fmt->{fh}->print("%% \$s:$_=$sent->{$_}\n") foreach (grep {$_ !~ /^(?:id|stxt|tokens|_cmts)$/} keys %$sent);
675 0 $fmt->putToken($_,$bufr) foreach (@{toSentence($sent)->{tokens}});
676 0 $fmt->{fh}->print("\n");
677 0 return $fmt;
678 }
679  
680 ## $fmt = $fmt->putDocument($doc)
681 ## $fmt = $fmt->putDocument($doc,\$buf)
682 ## + concatenates formatted sentences, adding document 'xmlbase' comment if available
683 0 ▶sub putDocument {
Subroutine putDocument: not called CC=5 SCAR=34.0
Pod documented
684 0 my ($fmt,$doc,$bufr) = @_;
685 0 ▶ $bufr = \(my $buf='') if (!defined($bufr));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bufr 0 0 0
686 0 ▶ $fmt->{fh}->print(join('', map {"%%$_\n"} map {split(/\n/,$_)} @{$doc->{_cmts}})) if ($doc->{_cmts});
Branch: 1 branch
BranchTrueFalseTotal
if $doc->{"_cmts"} 0 0 0
687 0 ▶ $fmt->{fh}->print("%% base=$doc->{base}\n\n") if (defined($doc->{base}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $doc->{"base"} 0 0 0
688 0 $fmt->putSentence($_,$bufr) foreach (@{toDocument($doc)->{body}});
689 0 return $fmt;
690 }
691  
692 ## $fmt = $fmt->putData($data)
693 ## + puts raw data (uses forceDocument())
694 0 ▶sub putData {
Subroutine putData: not called CC=1 SCAR=6.9
Pod undocumented
695 0 $_[0]->putDocument($_[0]->forceDocument($_[1]));
696 }
697  
698  
699 1 1; ##-- be happy
700  
701 __END__
↑ Summary CAB/Format/CONLLU.pm »