blib/lib/PMLTQ/Common.pm

filter: Statementstmt 7.6% 49 / 645 Branchbran 0.0% 0 / 440 Conditioncond 0.0% 0 / 184 MC/DCmcdc 0.0% 0 / 107 Subroutinesub 15.4% 11 / 71 Podpod 0.0% 0 / 49 totaltotal 4.0% 60 / 1496 CC 296 SCAR 68.7
CC
296
Cov
4%
compute_expression_data_type_pt
3080.0
tq_serialize
2550.0
GetRelativeQueryNodeType
1190.0
CRAP 962.3
« blib/lib/PMLTQ/PML2BASE.pm ↑ Summary blib/lib/PMLTQ/Command/query.pm »
1 package PMLTQ::Common;
2 15 our $AUTHORITY = 'cpan:MATY';
3 15 $PMLTQ::Common::VERSION = '1.2.2';
4 # ABSTRACT: Helper functions mainly for PML manipulations
5  
6 15 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Treex::PML::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use UNIVERSAL::DOES;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use List::Util qw(first min max);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #BEGIN {
17 # import TredMacro qw(uniq SeqV AltV ListV)
18 #}
19  
20 BEGIN {
21 15 use constant do {
22 15 %PMLTQ::Common::constants = (
23 COL_UNKNOWN => 0,
24 COL_STRING => 1,
25 COL_NUMERIC => 2,
26 );
27 15 \%PMLTQ::Common::constants
28 15 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 15 ▶ require Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 15 our @ISA = qw(Exporter);
32  
33 # Items to export into callers namespace by default. Note: do not export
34 # names by default without a very good reason. Use EXPORT_OK instead.
35 # Do not simply export all your public functions/methods/constants.
36  
37 # This allows declaration use PMLTQ::Common ':all';
38 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
39 # will save memory.
40  
41 15 $PMLTQ::pmlrf_relations = '';
42 15 $PMLTQ::user_defined = '';
43  
44 15 our %operator_precedence = (
45 div => 2,
46 mod => 2,
47 '*' => 2,
48 '+' => 1,
49 '-' => 1,
50 '&' => 1,
51 );
52  
53 15 our %EXPORT_TAGS = ( 'all' => [ qw(
54 tq_serialize
55 as_text
56 occ_as_text
57 rel_as_text
58 _group
59 make_string
60 make_string_with_tags
61 query_parser
62 parse_query
63 parse_node
64 parse_conditions
65 parse_expression
66 parse_column_expression
67 cmp_subquery_scope
68 sort_children_by_node_type
69  
70 SetRelation
71 GetRelationTypes
72 GetRelativeQueryNodeType
73 CreateRelation
74 FilterQueryNodes
75 Schema
76 CompleteMissingNodeTypes
77 compute_column_data_type
78 compute_expression_data_type
79 compute_expression_data_type_pt
80 ),
81 keys(%PMLTQ::Common::constants)
82 ],
83 'tredmacro' => [ qw(
84 first min max uniq ListV AltV SeqV
85 )],
86 'constants' => [
87 keys %PMLTQ::Common::constants,
88 ],
89 );
90  
91 15 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} }, @{ $EXPORT_TAGS{'tredmacro'} } );
92 15 our @EXPORT = qw( );
93 } # BEGIN
94  
95  
96  
97 0 ▶sub uniq { my %a; grep { !($a{$_}++) } @_ }
Subroutine uniq: not called CC=1 SCAR=6.9
Pod undocumented
98 0 ▶sub AltV { UNIVERSAL::DOES::does($_[0], 'Treex::PML::Alt') ? @{$_[0]} : $_[0] }
Subroutine AltV: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::DOES::does($_[0], 'Treex::PML::Alt') ? : 0 0 0
99 0 ▶sub ListV { UNIVERSAL::DOES::does($_[0], 'Treex::PML::List') ? @{$_[0]} : () }
Subroutine ListV: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::DOES::does($_[0], 'Treex::PML::List') ? : 0 0 0
100 0 ▶sub SeqV { UNIVERSAL::DOES::does($_[0], 'Treex::PML::Seq') ? $_[0]->elements : () }
Subroutine SeqV: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::DOES::does($_[0], 'Treex::PML::Seq') ? : 0 0 0
101  
102  
103  
104 sub user_defined_relations_re {
105 0 ▶ my ($type_mapper) = @_;
Subroutine user_defined_relations_re: not called CC=2 SCAR=17.9
Pod undocumented
106 0 my $relations = $PMLTQ::user_defined;
107 0 ▶ if ($type_mapper) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_mapper) 0 0 0
108 0 $relations = _user_defined_relations_regexp($type_mapper->get_user_defined_relations());
109 }
110 0 return $relations;
111 }
112  
113 sub pmlrf_relations_re {
114 0 ▶ my ($type_mapper) = @_;
Subroutine pmlrf_relations_re: not called CC=2 SCAR=17.9
Pod undocumented
115 0 my $relations = $PMLTQ::pmlrf_relations;
116 0 ▶ if ($type_mapper) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_mapper) 0 0 0
117 0 $relations = _pmlrf_relations_regexp($type_mapper->get_pmlrf_relations());
118 }
119 0 return $relations;
120 }
121  
122 15 my %reversed_relations = (
123 'descendant' => 'ancestor',
124 'ancestor' => 'descendant',
125 'parent' => 'child',
126 'sibling' => 'sibling',
127 'child' => 'parent',
128 'same-tree-as' => 'same-tree-as',
129 'same-document-as' => 'same-document-as',
130 'order-precedes' => 'order-follows',
131 'order-follows' => 'order-precedes',
132 'depth-first-precedes' => 'depth-first-follows',
133 'depth-first-follows' => 'depth-first-precedes',
134 );
135 15 my %type = (
136 ':descendant' => '#descendant',
137 ':ancestor' => '#ancestor',
138 ':child' => '#child',
139 ':parent' => '#parent',
140 ':sibling' => '#sibling',
141 ':depth-first-precedes' => '#same_doc',
142 ':depth-first-follows' => '#same_doc',
143 ':order-precedes' => '#same_doc',
144 ':order-follows' => '#same_doc',
145 ':same-tree-as' => '#same_doc',
146 ':same-document-as' => '#same_doc',
147 ':member' => '#member',
148 );
149  
150 sub reversed_relation {
151 0 ▶ my ($schema_name,$node_type,$name)=@_;
Subroutine reversed_relation: not called CC=2 SCAR=17.9
Pod undocumented
152 0 ▶ if ($name=~s{^implementation:}{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/^implementation://) 0 0 0
153 0 return PMLTQ::Relation->reversed_relation($schema_name,$node_type,$name);
154 }
155 0 return $reversed_relations{$name};
156 }
157  
158 sub standard_relations {
159 0 ▶ return ['descendant' , 'ancestor' , 'child' , 'sibling', 'parent' ,
Subroutine standard_relations: not called CC=1 SCAR=6.9
Pod undocumented
160 'depth-first-precedes' , 'depth-first-follows' ,
161 'order-precedes' , 'order-follows' , 'same-tree-as' ,
162 'same-document-as' , 'member'];
163 }
164  
165 # Preloaded methods go here.
166  
167 15 my $query_schema;
168 sub Schema {
169 0 ▶ return ($query_schema ||= Treex::PML::Schema->new({filename => 'tree_query_schema.xml',use_resources=>1}));
Subroutine Schema: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/3
$query_schema ||= "Treex::PML::Schema"->new({"filename", "tree_query_schema.xml", "use_resources", 1})
l!l&&r!l&&!r
000
MC/DC0%0/2
$query_schema ||= "Treex::PML::Schema"->new({"filename", "tree_query_schema.xml", "use_resources", 1})
$query_schema "Treex::PML::Schema"->new({"filename", "tree_query_schema.xml", "use_resources", 1})
Truth table0%0/3
A ||= B
A= $query_schemaB= "Treex::PML::Schema"->new({"filename", "tree_query_schema.xml", "use_resources", 1})
ABresult
1X1
011
000
170 }
171  
172 sub DetermineNodeType {
173 0 ▶ my ($ref)=@_;
Subroutine DetermineNodeType: not called CC=3 SCAR=24.8
Pod undocumented
174 0 ▶ if (exists &Treex::PML::Document::determine_node_type) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists &Treex::PML::Document::determine_node_type) { } 0 0 0
elsif (exists &TredMacro::DetermineNodeType) { } 0 0 0
175 0 return Treex::PML::Document->determine_node_type($ref);
176 } elsif (exists &TredMacro::DetermineNodeType) {
177 0 return TredMacro::DetermineNodeType($ref);
178 }
179 0 return;
180 }
181  
182  
183 sub GetQueryNodeType {
184 0 ▶ my ($node,$type_mapper)=@_;
Subroutine GetQueryNodeType: not called CC=14 SCAR=53.5
Pod undocumented
185 0 my $p;
186 0 ▶ return unless $node;
Branch: 1 branch
BranchTrueFalseTotal
unless $node 0 0 0
187 0 ▶ $node=$p while (($p=$node->parent) && $node->{'#name'} !~ /^(?:node|subquery)$/);
Branch: 1 branch
BranchTrueFalseTotal
$p = $node->parent and not $node->{"#name"} =~ /^(?:node|subquery)$/ and do { $node = $p } 0 0 0
Condition0%0/3
$p = $node->parent and not $node->{"#name"} =~ /^(?:node|subquery)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$p = $node->parent and not $node->{"#name"} =~ /^(?:node|subquery)$/
$p = $node->parent not $node->{"#name"} =~ /^(?:node|subquery)$/
Truth table0%0/3
A and not(B)
A= $p = $node->parentB= not $node->{"#name"} =~ /^(?:node|subquery)$/
ABresult
0X0
100
111
188 0 ▶ if (IsMemberNode($node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (IsMemberNode($node)) 0 0 0
189 0 return GetMemberNodeType($node,$type_mapper);
190 }
191 0 ▶ if ($type_mapper) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_mapper) { } 0 0 0
192 return $node->{'node-type'} || ($p && $p->parent
193 ? ( wantarray
194 ? uniq map GetRelativeQueryNodeType($_,$type_mapper,SeqV($node->{relation})), GetQueryNodeType($p,$type_mapper)
195 : GetRelativeQueryNodeType(scalar(GetQueryNodeType($p,$type_mapper)),$type_mapper,SeqV($node->{relation})))
196 : (wantarray
197 0 ▶ ? @{$type_mapper->get_node_types||[]}
Branch: 1 branch
BranchTrueFalseTotal
$type_mapper->get_node_types or [] 0 0 0
198 0 ▶ : do {
Branch: 3 branches
BranchTrueFalseTotal
$p && $p->parent ? : 0 0 0
wantarray ? : 0 0 0
wantarray ? : 0 0 0
Condition0%0/6
$node->{'node-type'} || ($p && $p->parent ? wantarray ? uniq(map(GetRelativeQueryNodeType($_, $type_mapper, SeqV($node->{'relation'})), GetQueryNodeType($p, $type_mapper))) : GetRelativeQueryNodeType(scalar GetQueryNodeType($p, $type_mapper), $type_mapper, SeqV($node->{'relation'})) : (wantarray ? @{$type_mapper->get_node_types or [];} : do { my $t = $type_mapper->get_node_types; @$t == 1 ? $t->[0] : () }))
l!l&&r!l&&!r
000
$p and $p->parent
!ll&&!rl&&r
000
MC/DC0%0/3
$node->{'node-type'} || ($p && $p->parent ? wantarray ? uniq(map(GetRelativeQueryNodeType($_, $type_mapper, SeqV($node->{'relation'})), GetQueryNodeType($p, $type_mapper))) : GetRelativeQueryNodeType(scalar GetQueryNodeType($p, $type_mapper), $type_mapper, SeqV($node->{'relation'})) : (wantarray ? @{$type_mapper->get_node_types or [];} : do { my $t = $type_mapper->get_node_types; @$t == 1 ? $t->[0] : () }))
$node->{'node-type'} $p $p->parent
Truth table0%0/4
A || B and C
A= $node->{'node-type'}B= $pC= $p->parent
ABCresult
1XX1
0111
00X0
0100
199 0 my $t = $type_mapper->get_node_types;
200 0 ▶ @$t==1 ? $t->[0] : ()
Branch: 1 branch
BranchTrueFalseTotal
@$t == 1 ? : 0 0 0
201 })
202 );
203 } else {
204 0 ▶ return $node->{'node-type'} || $node->root->{'node-type'};
Condition0%0/3
$node->{'node-type'} || $node->root->{'node-type'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$node->{'node-type'} || $node->root->{'node-type'}
$node->{'node-type'} $node->root->{'node-type'}
Truth table0%0/3
A || B
A= $node->{'node-type'}B= $node->root->{'node-type'}
ABresult
1X1
011
000
205 }
206 }
207  
208  
209 sub DeclToQueryType {
210 0 ▶ my ($decl)=@_;
Subroutine DeclToQueryType: not called CC=2 SCAR=17.9
Pod undocumented
211 0 ▶ $decl = $decl->get_content_decl if $decl->get_decl_type == PML_ELEMENT_DECL;
Branch: 1 branch
BranchTrueFalseTotal
if $decl->get_decl_type == 13 0 0 0
212 0 return DeclPathToQueryType( $decl->get_decl_path );
213 }
214 sub DeclPathToQueryType {
215 0 ▶ my ($path) = @_;
Subroutine DeclPathToQueryType: not called CC=3 SCAR=24.8
Pod undocumented
216 0 ▶ return unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
217 0 $path =~ s/\[LIST\]/LM/;
218 0 $path =~ s/\[ALT\]/AM/;
219 0 ▶ $path =~ s/^!// unless $path =~ s{^!([^/]+)\.type\b}{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ s[^!([^/]+)\.type\b][$1] 0 0 0
220 0 return $path;
221 }
222 sub QueryTypeToDecl {
223 0 ▶ my ($type,@schemas)=@_;
Subroutine QueryTypeToDecl: not called CC=11 SCAR=48.8
Pod undocumented
224 0 my $path = '!'.$type;
225 0 $path =~ s/content\(\)|\[\]/#content/g;
226 0 my $decl;
227 0 for my $schema (@schemas) {
228 0 $decl = $schema->find_type_by_path($path);
229 0 ▶ last if $decl;
Branch: 1 branch
BranchTrueFalseTotal
if $decl 0 0 0
230 }
231 0 ▶ if (!$decl and $path=~s{(/|$)}{.type$1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $decl and $path =~ s[(/|$)][.type$1]) 0 0 0
Condition0%0/3
not $decl and $path =~ s[(/|$)][.type$1]
!ll&&!rl&&r
000
MC/DC0%0/2
not $decl and $path =~ s[(/|$)][.type$1]
not $decl $path =~ s[(/|$)][.type$1]
Truth table0%0/3
not(A) and B
A= not $declB= $path =~ s[(/|$)][.type$1]
ABresult
0X0
100
111
232 0 for my $schema (@schemas) {
233 0 $decl = $schema->find_type_by_path($path);
234 0 ▶ last if $decl;
Branch: 1 branch
BranchTrueFalseTotal
if $decl 0 0 0
235 }
236 }
237 0 ▶ if ($decl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl) 0 0 0
238 0 ▶ unless($type=~m{/\.$}) { # trailing /. means do not expand trailing Alts and Lists
Branch: 1 branch
BranchTrueFalseTotal
unless ($type =~ m[/\.$]) 0 0 0
239 0 my $decl_is = $decl->get_decl_type;
240 0 ▶ while ($decl_is == PML_LIST_DECL or $decl_is == PML_ALT_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl_is == 6 or $decl_is == 7) 0 0 0
Condition0%0/3
$decl_is == 6 or $decl_is == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl_is == 6 or $decl_is == 7
$decl_is == 6 $decl_is == 7
Truth table0%0/3
A or B
A= $decl_is == 6B= $decl_is == 7
ABresult
1X1
011
000
241 0 $decl = $decl->get_knit_content_decl;
242 0 $decl_is = $decl->get_decl_type;
243 }
244 }
245 0 return $decl;
246 }
247 0 confess( "Did not find type '!$type'" );
248 }
249  
250 sub CompleteMissingNodeTypes {
251 0 ▶ my ($type_mapper,$subtree)=@_;
Subroutine CompleteMissingNodeTypes: not called CC=14 SCAR=53.5
Pod undocumented
252 0 ▶ my @nodes = grep { ($_->{'#name'}||'') =~ /^(?:node|subquery)$/ } $subtree,$subtree->descendants;
Condition0%0/2
$_->{'#name'} || ''
l!l
00
MC/DC0%0/1
$_->{'#name'} || ''
$_->{'#name'}
Truth table0%0/2
A
A= $_->{'#name'}
Aresult
11
00
253 # try to complete missing node-types
254 0 my $node_types = $type_mapper->get_node_types;
255 0 my %node_types = map { $_=> 1 } @$node_types;
256 0 my $query_tree = $subtree->root;
257 0 ▶ undef $query_tree if $query_tree->{'#name'};
Branch: 1 branch
BranchTrueFalseTotal
if $query_tree->{"#name"} 0 0 0
258 0 ▶ my $default_type = $query_tree && $query_tree->{'node-type'};
Condition0%0/3
$query_tree && $query_tree->{'node-type'}
!ll&&!rl&&r
000
MC/DC0%0/2
$query_tree && $query_tree->{'node-type'}
$query_tree $query_tree->{'node-type'}
Truth table0%0/3
A && B
A= $query_treeB= $query_tree->{'node-type'}
ABresult
0X0
100
111
259 0 ▶ if ($default_type and !$node_types{$default_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default_type and not $node_types{$default_type}) 0 0 0
Condition0%0/3
$default_type and not $node_types{$default_type}
!ll&&!rl&&r
000
MC/DC0%0/2
$default_type and not $node_types{$default_type}
$default_type not $node_types{$default_type}
Truth table0%0/3
A and not(B)
A= $default_typeB= not $node_types{$default_type}
ABresult
0X0
100
111
260 0 die "The query specifies an invalid type '$default_type' as default node type!";
261 }
262 0 for my $node (@nodes) {
263 0 ▶ if ($node->{'node-type'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{'node-type'}) { } 0 0 0
264 0 ▶ if ( !$node_types{$node->{'node-type'}} and !IsMemberNode($node)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node_types{$node->{"node-type"}} or IsMemberNode($node)) 0 0 0
Condition0%0/3
$node_types{$node->{"node-type"}} or IsMemberNode($node)
l!l&&r!l&&!r
000
MC/DC0%0/2
$node_types{$node->{"node-type"}} or IsMemberNode($node)
$node_types{$node->{"node-type"}} IsMemberNode($node)
Truth table0%0/3
A or B
A= $node_types{$node->{"node-type"}}B= IsMemberNode($node)
ABresult
1X1
011
000
265 0 my ($rel) = SeqV($node->{relation});
266 0 ▶ $rel = $rel ? $rel->name : '';
Branch: 1 branch
BranchTrueFalseTotal
$rel ? : 0 0 0
267 0 die "The query specifies an invalid type '$node->{'node-type'}' for node: ".PMLTQ::Common::as_text($node)." in relation $rel\n";
268 }
269 } else {
270 0 my $parent = $node->parent;
271 my @types =
272 $parent ?
273 (GetRelativeQueryNodeType(
274 $parent->{'node-type'},
275 $type_mapper,
276 0 ▶ SeqV($node->{relation}))
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
277 ) : @$node_types;
278 0 ▶ if (@types == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@types == 1) { } 0 0 0
elsif ($default_type) { } 0 0 0
279 0 $node->{'node-type'} = $types[0];
280 } elsif ($default_type) {
281 0 $node->{'node-type'} = $default_type;
282 } else {
283 0 die "Could not determine node type of node "
284 .PMLTQ::Common::as_text($node)."\n"
285 ."Possible types are: ".join(',',@types)." !\n";
286 }
287 }
288 }
289 }
290 sub GetRelativeQueryNodeType {
291 0 ▶ my ($type,$type_mapper,$rel)=@_;
Subroutine GetRelativeQueryNodeType: not called CC=34 SCAR=70.8
Pod undocumented
292 0 ▶ $type ||= '';
Condition0%0/2
$type ||= ""
l!l
00
MC/DC0%0/1
$type ||= ""
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
293 # TODO: if $type is void, we could check if there is just one node-type in the schema and return it if so
294 0 ▶ my $name = $rel ? $rel->name : 'child';
Branch: 1 branch
BranchTrueFalseTotal
$rel ? : 0 0 0
295 # $name .= ':'.$rel->value->{label} if $name eq 'user-defined';
296 my $reltype = ($name eq 'user-defined' ?
297 $type_mapper->get_relation_target_type($type,$rel->value->{label},0,$rel->value->{category})
298 0 ▶ : ($type{$type.':'.$name} || $type{':'.$name})) || return;
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'user-defined' ? : 0 0 0
Condition0%0/5
($name eq 'user-defined' ? $type_mapper->get_relation_target_type($type, $rel->value->{'label'}, 0, $rel->value->{'category'}) : $type{$type . ':' . $name} || $type{':' . $name}) || (return)
l!l
00
$type{$type . ':' . $name} or $type{':' . $name}
l!l&&r!l&&!r
000
MC/DC0%0/1
($name eq 'user-defined' ? $type_mapper->get_relation_target_type($type, $rel->value->{'label'}, 0, $rel->value->{'category'}) : $type{$type . ':' . $name} || $type{':' . $name}) || (return)
($name eq 'user-defined' ? $type_mapper->get_relation_target_type($type, $rel->value->{'label'}, 0, $rel->value->{'category'}) : $type{$type . ':' . $name} || $type{':' . $name})
MC/DC0%0/2
$type{$type . ':' . $name} or $type{':' . $name}
$type{$type . ':' . $name} $type{':' . $name}
Truth table0%0/2
A
A= ($name eq 'user-defined' ? $type_mapper->get_relation_target_type($type, $rel->value->{'label'}, 0, $rel->value->{'category'}) : $type{$type . ':' . $name} || $type{':' . $name})
Aresult
11
00
Truth table0%0/3
A or B
A= $type{$type . ':' . $name}B= $type{':' . $name}
ABresult
1X1
011
000
299 0 my @decls;
300 0 my ($schema,$schema_name);
301 0 my @t;
302  
303 0 ▶ if ($type=~m{^([^/]+):\*$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ m[^([^/]+):\*$]) { } 0 0 0
304 0 $schema_name=$1;
305 0 $schema = $type_mapper->get_schema($schema_name);
306 0 @decls = $schema->node_types()
307 } else {
308 0 $schema = $type_mapper->get_schema_for_type($type);
309 0 $schema_name = $schema->get_root_name;
310 0 @decls = ($type_mapper->get_decl_for($type));
311 }
312 0 ▶ unless (@decls) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@decls) 0 0 0
313 0 die "Cannot translate type $type to a schema type declaration (for schema $schema_name)!\n";
314 }
315 0 ▶ unless (first { $_->get_role eq '#NODE' } @decls) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless (&first(sub { $_->get_role eq "#NODE"; } , @decls)) 0 0 0
316 0 ▶ return unless $reltype eq '#member' or $name eq 'user-defined';
Branch: 1 branch
BranchTrueFalseTotal
unless $reltype eq "#member" or $name eq "user-defined" 0 0 0
Condition0%0/3
$reltype eq "#member" or $name eq "user-defined"
l!l&&r!l&&!r
000
MC/DC0%0/2
$reltype eq "#member" or $name eq "user-defined"
$reltype eq "#member" $name eq "user-defined"
Truth table0%0/3
A or B
A= $reltype eq "#member"B= $name eq "user-defined"
ABresult
1X1
011
000
317 }
318 0 ▶ if ($reltype eq '#same') {
Branch: 8 branches
BranchTrueFalseTotal
if ($reltype eq '#same') { } 0 0 0
elsif ($reltype eq '#member') { } 0 0 0
elsif ($reltype =~ /^(#ancestor|#same_doc)/) { } 0 0 0
elsif ($reltype eq '#any') { } 0 0 0
elsif ($reltype eq '#descendant') { } 0 0 0
elsif ($reltype eq '#child') { } 0 0 0
elsif ($reltype eq '#parent') { } 0 0 0
elsif ($reltype eq '#sibling') { } 0 0 0
319 0 @t=@decls;
320 } elsif ($reltype eq '#member') {
321 0 @t=map { GetMemberPaths($_,$type_mapper) } @decls;
322 } elsif ($reltype =~ /^(#ancestor|#same_doc)/) {
323 0 ▶ return unless $schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema 0 0 0
324 0 @t = @{$type_mapper->get_node_types($schema_name)};
325 } elsif ($reltype eq '#any') {
326 0 @t = @{$type_mapper->get_node_types};
327 } elsif ($reltype eq '#descendant') {
328 0 ▶ return unless $schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema 0 0 0
329 0 @t = uniq map $_->get_childnodes_decls, @decls;
330 0 my %seen; @seen{@t}=();
331 0 my $i=0;
332 0 ▶ while ($i<@t) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @t) 0 0 0
333 0 for my $t ($t[$i]->get_childnodes_decls) {
334 0 ▶ if (!exists($seen{$t})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $seen{$t}) 0 0 0
335 0 push @t, $t;
336 0 $seen{$t}=undef;
337 }
338 }
339 0 $i++;
340 }
341 } elsif ($reltype eq '#child') {
342 0 ▶ return unless $schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema 0 0 0
343 0 @t = map $_->get_childnodes_decls, @decls;
344 } elsif ($reltype eq '#parent') {
345 0 ▶ return unless $schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema 0 0 0
346 0 my %decls; @decls{@decls}=();
347 @t = grep {
348 0 first {
349 0 ▶ exists($decls{$_})
Subroutine __ANON__: not called CC=1 SCAR=6.9
350 }
351 map {
352 0 ▶ ($_->get_decl_type == PML_ELEMENT_DECL) ? ($_,$_->get_content_decl) : $_
Branch: 1 branch
BranchTrueFalseTotal
$_->get_decl_type == 13 ? : 0 0 0
353 } $_->get_childnodes_decls
354 } $schema->node_types;
355 } elsif ($reltype eq '#sibling') {
356 0 ▶ return unless $schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema 0 0 0
357 0 my %decls; @decls{@decls}=();
358 @t = map {
359 0 ▶ my @c = map { ($_->get_decl_type == PML_ELEMENT_DECL) ? $_->get_content_decl : $_ }
Branch: 1 branch
BranchTrueFalseTotal
$_->get_decl_type == 13 ? : 0 0 0
360 $_->get_childnodes_decls;
361 0 ▶ (first { exists($decls{$_}) } @c) ? @c : ()
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { exists $decls{$_}; } , @c) ? : 0 0 0
362 } $schema->node_types;
363 } else {
364 0 return $reltype;
365 }
366 0 ▶ @t = uniq map {ref($_) ? DeclToQueryType( $_ ) : $_} @t;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
367 0 ▶ return if !wantarray and @t!=1;
Branch: 1 branch
BranchTrueFalseTotal
if not wantarray and @t != 1 0 0 0
Condition0%0/3
not wantarray and @t != 1
!ll&&!rl&&r
000
MC/DC0%0/2
not wantarray and @t != 1
not wantarray @t != 1
Truth table0%0/3
not(A) and B
A= not wantarrayB= @t != 1
ABresult
0X0
100
111
368 0 ▶ return wantarray ? @t : $t[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
369 }
370  
371 sub CreateRelation {
372 0 ▶ my ($type,$opts)=@_;
Subroutine CreateRelation: not called CC=6 SCAR=37.4
Pod undocumented
373 0 ▶ if ($type=~s/ \((user-defined|implementation|pmlrf)\)$// and !($opts and $opts->{label})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ s/ \((user-defined|implementation|pmlrf)\)$// and not $opts && $opts->{"label"}) 0 0 0
Condition0%0/6
$type =~ s/ \((user-defined|implementation|pmlrf)\)$// and not $opts && $opts->{"label"}
!ll&&!rl&&r
000
$opts && $opts->{'label'}
!ll&&!rl&&r
000
MC/DC0%0/3
$type =~ s/ \((user-defined|implementation|pmlrf)\)$// and not $opts && $opts->{"label"}
$type =~ s/ \((user-defined|implementation|pmlrf)\)$// $opts $opts->{'label'}
Truth table0%0/4
A and not(B && C)
A= $type =~ s/ \((user-defined|implementation|pmlrf)\)$//B= $optsC= $opts->{'label'}
ABCresult
0XX0
1110
10X1
1101
374 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
375 0 $opts->{label}=$type;
376 0 $type = 'user-defined';
377 0 ▶ $opts->{category}=$1 unless $1 eq 'user-defined';
Branch: 1 branch
BranchTrueFalseTotal
unless $1 eq "user-defined" 0 0 0
378 }
379 0 return Treex::PML::Seq::Element->new(
380 $type => Treex::PML::Factory->createContainer(undef,$opts)
381 );
382 }
383  
384 sub SetRelation {
385 0 ▶ my ($node,$type,$opts)=@_;
Subroutine SetRelation: not called CC=2 SCAR=17.9
Pod undocumented
386 0 my $rel = CreateRelation( $type, $opts );
387 0 ▶ $node->{relation}||=Treex::PML::Factory->createSeq();
Condition0%0/3
$node->{"relation"} ||= "Treex::PML::Factory"->createSeq
l!l&&r!l&&!r
000
MC/DC0%0/2
$node->{"relation"} ||= "Treex::PML::Factory"->createSeq
$node->{"relation"} "Treex::PML::Factory"->createSeq
Truth table0%0/3
A ||= B
A= $node->{"relation"}B= "Treex::PML::Factory"->createSeq
ABresult
1X1
011
000
388 0 @{$node->{relation}->elements_list}=( $rel );
389 0 return $rel;
390 }
391  
392 sub GetRelationTypes {
393 0 ▶ my ($node,$type_mapper,$direct)=@_;
Subroutine GetRelationTypes: not called CC=4 SCAR=30.0
Pod undocumented
394 0 my $node_type = GetQueryNodeType($node,$type_mapper);
395 return [
396 map {
397 0 my $name = $_->get_name;
398 0 ▶ if ($name eq 'user-defined') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'user-defined') { } 0 0 0
399 ($type_mapper
400 ? (
401 0 (map { qq{$_ (implementation)} } @{$type_mapper->get_user_defined_relations($node_type)}),
402 0 ▶ (map { qq{$_ (pmlrf)} } @{$type_mapper->get_pmlrf_relations($node_type)}),
Branch: 1 branch
BranchTrueFalseTotal
$type_mapper ? : 0 0 0
403 ) : ())
404 } else {
405 0 ▶ $name;
Branch: 1 branch
BranchTrueFalseTotal
$direct ? : 0 0 0
406 }
407 } $node->type->schema->get_type_by_name(
408 $direct ? 'q-relation.type' : 'q-ref-relation.type'
409 )->get_content_decl->get_elements(),
410 ];
411 }
412  
413 # select only those paths that make sense
414 # to be used on a member edge
415 sub _map_path_to_ambiguous_subpaths {
416 0 ▶ my ($path)=@_;
Subroutine _map_path_to_ambiguous_subpaths: not called CC=11 SCAR=48.8
417 0 my @steps = split '/',$path;
418 0 my $base='';
419 0 my $base_trail='';
420 0 my @paths;
421 0 ▶ while (@steps) {
Branch: 1 branch
BranchTrueFalseTotal
if (@steps) 0 0 0
422 0 my $step = shift @steps;
423 0 ▶ if ($step =~/^[LA]M$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($step =~ /^[LA]M$/) { } 0 0 0
elsif ($step =~ s/\[\d+\]//) { } 0 0 0
424 0 my $base_with_trail = join('/',grep length, ($base, $base_trail));
425 0 ▶ if (@paths) {
Branch: 2 branches
BranchTrueFalseTotal
if (@paths) { } 0 0 0
elsif (@steps) { } 0 0 0
426 0 push @paths, $base_with_trail.'/.';
427 } elsif (@steps) {
428 0 ▶ push @paths, $base unless $base_trail;
Branch: 1 branch
BranchTrueFalseTotal
unless $base_trail 0 0 0
429 }
430 0 ▶ $base_trail=$base_trail ? $base_trail.'/'.$step : $step;
Branch: 1 branch
BranchTrueFalseTotal
$base_trail ? : 0 0 0
431 } elsif ($step=~s/\[\d+\]//) {
432 0 $base_trail='';
433 0 ▶ $base=$base ? $base.'/'.$step : $step;
Branch: 1 branch
BranchTrueFalseTotal
$base ? : 0 0 0
434 0 ▶ push @paths, $base if @steps;
Branch: 1 branch
BranchTrueFalseTotal
if @steps 0 0 0
435 } else {
436 0 $base_trail='';
437 0 ▶ $base=$base ? $base.'/'.$step : $step;
Branch: 1 branch
BranchTrueFalseTotal
$base ? : 0 0 0
438 }
439 }
440 0 return @paths;
441 }
442  
443 sub GetMemberPaths {
444 0 ▶ my ($ptype,$type_mapper)=@_;
Subroutine GetMemberPaths: not called CC=8 SCAR=42.8
Pod undocumented
445 0 ▶ return unless $type_mapper;
Branch: 1 branch
BranchTrueFalseTotal
unless $type_mapper 0 0 0
446 0 my $decl;
447 0 ▶ if (ref($ptype)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ptype) { } 0 0 0
elsif ($ptype =~ m[^(?:([^/]+):)?\*$]) { } 0 0 0
448 0 $decl = $ptype;
449 } elsif ($ptype=~m{^(?:([^/]+):)?\*$}) {
450 0 return uniq map GetMemberPaths($_,$type_mapper), @{$type_mapper->get_node_types($1)};
451 } else {
452 0 $decl = $type_mapper->get_decl_for($ptype);
453 }
454 0 ▶ warn "Didn't find type $ptype" unless $decl;
Branch: 1 branch
BranchTrueFalseTotal
unless $decl 0 0 0
455 my @node_members =
456 0 ▶ grep { defined && length }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ 0 0 0
457 0 ▶ $decl->get_schema->find_decl(sub { $_[0]->get_role eq '#NODE' },$decl,{
Subroutine __ANON__: not called CC=1 SCAR=6.9
458 no_childnodes => 1,
459 with_Seq_brackets => 1,
460 });
461 0 my $node_member_re = _list_to_regexp(\@node_members);
462  
463 0 ▶ return unless $decl;
Branch: 1 branch
BranchTrueFalseTotal
unless $decl 0 0 0
464 return
465 uniq
466 0 map { my $t = $_; $t=~s{#content}{[]}g; $t }
467 (@node_members,
468 map _map_path_to_ambiguous_subpaths($_),
469 0 ▶ grep { $node_member_re ? !m{^$node_member_re(?:\[|/|$)} : 1 }
Branch: 1 branch
BranchTrueFalseTotal
$node_member_re ? : 0 0 0
470 $decl->get_paths_to_atoms({
471 no_childnodes => 1,
472 with_LM=>1,
473 with_AM=>1,
474 with_Seq_brackets => 1,
475 }));
476 }
477  
478 sub FilterQueryNodes {
479 0 ▶ my ($tree)=@_;
Subroutine FilterQueryNodes: not called CC=7 SCAR=40.3
Pod undocumented
480 0 my @nodes;
481 0 my $n = $tree;
482 0 ▶ while ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
483 0 ▶ my $name = $n->{'#name'}||'';
Condition0%0/2
$n->{'#name'} || ''
l!l
00
MC/DC0%0/1
$n->{'#name'} || ''
$n->{'#name'}
Truth table0%0/2
A
A= $n->{'#name'}
Aresult
11
00
484 0 ▶ if ($name eq 'node' or
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'node' or $n == $tree and $name eq 'subquery') { } 0 0 0
elsif ($n->parent) { } 0 0 0
Condition0%0/6
$name eq "node" or $n == $tree and $name eq "subquery"
l!l&&r!l&&!r
000
$n == $tree and $name eq "subquery"
!ll&&!rl&&r
000
MC/DC0%0/3
$name eq "node" or $n == $tree and $name eq "subquery"
$name eq "node" $n == $tree $name eq "subquery"
Truth table0%0/4
A or B and C
A= $name eq "node"B= $n == $treeC= $name eq "subquery"
ABCresult
1XX1
0111
00X0
0100
485 ($n==$tree and $name eq 'subquery')) {
486 0 push @nodes, $n;
487 } elsif ($n->parent) {
488 0 $n = $n->following_right_or_up($tree);
489 0 next;
490 }
491 0 $n = $n->following($tree);
492 }
493 0 return @nodes;
494 }
495  
496 sub IsMemberNode {
497 0 ▶ my ($node)=@_;
Subroutine IsMemberNode: not called CC=3 SCAR=24.8
Pod undocumented
498 0 ▶ return unless ref $node;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node 0 0 0
499 0 my ($rel) = SeqV($node->{relation});
500 0 ▶ return $rel && $rel->name eq 'member';
Condition0%0/3
$rel && $rel->name eq 'member'
!ll&&!rl&&r
000
MC/DC0%0/2
$rel && $rel->name eq 'member'
$rel $rel->name eq 'member'
Truth table0%0/3
A && B
A= $relB= $rel->name eq 'member'
ABresult
0X0
100
111
501 }
502  
503 sub GetMemberNodeType {
504 0 ▶ my ($node,$type_mapper)=@_;
Subroutine GetMemberNodeType: not called CC=4 SCAR=30.0
Pod undocumented
505 0 my $type = $node->{'node-type'};
506 0 my $p = $node->parent;
507 0 my $mtype;
508 0 ▶ while ($p) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p) 0 0 0
509 0 ▶ if ($p->{'#name'} =~ /^(node|subquery)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"#name"} =~ /^(node|subquery)$/) 0 0 0
510 0 $mtype = GetQueryNodeType($p,$type_mapper).'/'.$type;
511 0 last;
512 }
513 0 $p = $p->parent;
514 }
515 0 ▶ if (!defined $mtype) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mtype) 0 0 0
516 0 $mtype = '/'.$type;
517 }
518 ### THIS BREAKS get_scheama_for($type) on SQL search
519 ### which requires the type name to start with
520 ### a node path:
521 #
522 # Need to reengeneer type mapping!
523 #
524 # if ($type_mapper) {
525 # my $decl = $type_mapper->get_decl_for($mtype);
526 # $mtype = DeclToQueryType($decl) if $decl;
527 # }
528 0 return $mtype;
529 }
530  
531 sub GetElementNamesForDecl {
532 0 ▶ my ($decl)=@_;
Subroutine GetElementNamesForDecl: not called CC=1 SCAR=6.9
Pod undocumented
533 0 my %names;
534 $decl->get_schema->for_each_decl(
535 sub {
536 0 ▶ my ($d)=@_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
537 0 ▶ if ($d->get_decl_type == PML_ELEMENT_DECL
Branch: 1 branch
BranchTrueFalseTotal
if ($d->get_decl_type == 13 and $d->get_content_decl == $decl) 0 0 0
Condition0%0/3
$d->get_decl_type == 13 and $d->get_content_decl == $decl
!ll&&!rl&&r
000
MC/DC0%0/2
$d->get_decl_type == 13 and $d->get_content_decl == $decl
$d->get_decl_type == 13 $d->get_content_decl == $decl
Truth table0%0/3
A and B
A= $d->get_decl_type == 13B= $d->get_content_decl == $decl
ABresult
0X0
100
111
538 and $d->get_content_decl == $decl) {
539 0 $names{ $d->get_name } = 1;
540 }
541 }
542 0 );
543 0 return [sort keys %names];
544 }
545  
546 ### Query serialization
547  
548 sub cmp_subquery_scope {
549 0 ▶ my ($node,$ref_node) = @_;
Subroutine cmp_subquery_scope: not called CC=9 SCAR=45.0
Pod undocumented
550 0 ▶ return 0 if $node==$ref_node;
Branch: 1 branch
BranchTrueFalseTotal
if $node == $ref_node 0 0 0
551 0 ▶ while ($node->parent and $node->{'#name'} ne 'subquery') {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->parent and $node->{"#name"} ne "subquery") 0 0 0
Condition0%0/3
$node->parent and $node->{"#name"} ne "subquery"
!ll&&!rl&&r
000
MC/DC0%0/2
$node->parent and $node->{"#name"} ne "subquery"
$node->parent $node->{"#name"} ne "subquery"
Truth table0%0/3
A and B
A= $node->parentB= $node->{"#name"} ne "subquery"
ABresult
0X0
100
111
552 0 $node=$node->parent;
553 }
554 0 ▶ while ($ref_node->parent and $ref_node->{'#name'} ne 'subquery') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_node->parent and $ref_node->{"#name"} ne "subquery") 0 0 0
Condition0%0/3
$ref_node->parent and $ref_node->{"#name"} ne "subquery"
!ll&&!rl&&r
000
MC/DC0%0/2
$ref_node->parent and $ref_node->{"#name"} ne "subquery"
$ref_node->parent $ref_node->{"#name"} ne "subquery"
Truth table0%0/3
A and B
A= $ref_node->parentB= $ref_node->{"#name"} ne "subquery"
ABresult
0X0
100
111
555 0 $ref_node=$ref_node->parent;
556 }
557 #return 0 if $node==$ref_node;
558 0 my $subquery_level = 0;
559 0 for ($node, $node->ancestors) {
560 0 ▶ return $subquery_level if ($_==$ref_node);
Branch: 1 branch
BranchTrueFalseTotal
if $_ == $ref_node 0 0 0
561 0 ▶ $subquery_level++ if $_->{'#name'} eq 'subquery';
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"#name"} eq "subquery" 0 0 0
562 }
563 # return 1 if first { $_==$ref_node } $node->ancestors;
564 0 return -1;
565 }
566  
567 sub occ_as_text {
568 0 ▶ my ($node)=@_;
Subroutine occ_as_text: not called CC=11 SCAR=48.8
Pod undocumented
569 0 ▶ return '' unless ($node->{'#name'}||'') eq 'subquery';
Branch: 1 branch
BranchTrueFalseTotal
unless ($node->{"#name"} || "") eq "subquery" 0 0 0
Condition0%0/2
$node->{'#name'} || ''
l!l
00
MC/DC0%0/1
$node->{'#name'} || ''
$node->{'#name'}
Truth table0%0/2
A
A= $node->{'#name'}
Aresult
11
00
570 0 return join('|', grep { /\d/ } map {
571 0 my ($min,$max)=($_->{min},$_->{max});
572 0 ▶ $min='' if !defined $min;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min 0 0 0
573 0 ▶ $max='' if !defined $max;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max 0 0 0
574 0 ▶ if (length($min) and length($max)) {
Branch: 3 branches
BranchTrueFalseTotal
if (length $min and length $max) { } 0 0 0
elsif (length $min) { } 0 0 0
elsif (length $max) { } 0 0 0
Condition0%0/3
length $min and length $max
!ll&&!rl&&r
000
MC/DC0%0/2
length $min and length $max
length $min length $max
Truth table0%0/3
A and B
A= length $minB= length $max
ABresult
0X0
100
111
575 0 ▶ if (int($min)==int($max)) {
Branch: 1 branch
BranchTrueFalseTotal
if (int $min == int $max) { } 0 0 0
576 0 int($min)
577 } else {
578 0 int($min).'..'.int($max)
579 }
580 } elsif (length($min)) {
581 0 int($min).'+'
582 } elsif (length($max)) {
583 0 ▶ if (int($max)==0) {
Branch: 1 branch
BranchTrueFalseTotal
if (int $max == 0) { } 0 0 0
584 0 '0'
585 } else {
586 0 int($max).'-'
587 }
588 } else {
589 0 '1+'
590 }
591 0 } AltV($node->{occurrences}));
592 }
593  
594  
595 15 my %child_order = (
596 test=>1,
597 not=>2,
598 or=>3,
599 and=>4,
600 ref=>5,
601 subquery=>6,
602 node=>7,
603 );
604  
605 sub sort_children_by_node_type {
606 0 ▶ my ($node)=@_;
Subroutine sort_children_by_node_type: not called CC=1 SCAR=6.9
Pod undocumented
607 0 return map { $_->[0] }
608 0 sort { $a->[1]<=>$b->[1] }
609 0 map { [$_,int($child_order{$_->{'#name'}})] } $node->children;
610 }
611  
612 sub rel_length_as_text {
613 0 ▶ my ($rv)=@_;
Subroutine rel_length_as_text: not called CC=7 SCAR=40.3
Pod undocumented
614 0 ▶ if ( (defined($rv->{min_length}) && length($rv->{min_length}))||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rv->{"min_length"} and length $rv->{"min_length"} or defined $rv->{"max_length"} and length $rv->{"max_length"}) 0 0 0
Condition0%0/9
defined $rv->{"min_length"} and length $rv->{"min_length"} or defined $rv->{"max_length"} and length $rv->{"max_length"}
l!l&&r!l&&!r
000
defined $rv->{"min_length"} and length $rv->{"min_length"}
!ll&&!rl&&r
000
defined $rv->{"max_length"} and length $rv->{"max_length"}
!ll&&!rl&&r
000
MC/DC0%0/4
defined $rv->{"min_length"} and length $rv->{"min_length"} or defined $rv->{"max_length"} and length $rv->{"max_length"}
defined $rv->{"min_length"} length $rv->{"min_length"} defined $rv->{"max_length"} length $rv->{"max_length"}
Truth table0%0/7
A and B or C and D
A= defined $rv->{"min_length"}B= length $rv->{"min_length"}C= defined $rv->{"max_length"}D= length $rv->{"max_length"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
615 (defined($rv->{max_length}) && length($rv->{max_length}))) {
616 0 ▶ return '{'.($rv->{min_length}||'').','.($rv->{max_length}||'').'}'
Condition0%0/4
$rv->{'min_length'} || ''
l!l
00
$rv->{'max_length'} || ''
l!l
00
MC/DC0%0/1
$rv->{'min_length'} || ''
$rv->{'min_length'}
MC/DC0%0/1
$rv->{'max_length'} || ''
$rv->{'max_length'}
Truth table0%0/2
A
A= $rv->{'min_length'}
Aresult
11
00
Truth table0%0/2
A
A= $rv->{'max_length'}
Aresult
11
00
617 }
618 0 return '';
619 }
620  
621 sub rel_as_text {
622 0 ▶ my ($node)=@_;
Subroutine rel_as_text: not called CC=6 SCAR=37.4
Pod undocumented
623 0 my ($rel) = SeqV($node->{relation});
624 0 ▶ if ($rel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel) { } 0 0 0
625 0 my ($rn,$rv)=($rel->name,$rel->value);
626 0 ▶ if ($rn eq 'user-defined') {
Branch: 3 branches
BranchTrueFalseTotal
if ($rn eq 'user-defined') { } 0 0 0
elsif ($rn =~ /^(?:ancestor|descendant|sibling|order-precedes|order-follows|depth-first-precedes|depth-first-follows)/) { } 0 0 0
elsif ($rn eq 'child') { } 0 0 0
627 0 my $label = $rv->{label}.rel_length_as_text($rv);
628 0 ▶ if ($rv->{label} =~ /^(?:member|ancestor|descendant|sibling|child|parent|same-tree-as|same-document-as|depth-first-precedes|depth-first-follows|order-precedes|order-follows)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv->{"label"} =~ /^(?:member|ancestor|descendant|sibling|child|parent|same-tree-as|same-document-as|depth-first-precedes|depth-first-follows|order-precedes|order-follows)$/) 0 0 0
629 0 $label.='->';
630 }
631 # FIXME: if a PMLRF relation collides with a user-defined relation
632 # append -> as well; this requires a type_mapper!
633 0 return $label;
634 } elsif ($rn =~ /^(?:ancestor|descendant|sibling|order-precedes|order-follows|depth-first-precedes|depth-first-follows)/) {
635 0 return $rn.rel_length_as_text($rv);
636 } elsif ($rn eq 'child') {
637 0 return ''; # child
638 } else {
639 0 return $rn;
640 }
641 } else {
642 0 return ''; # child
643 }
644 }
645  
646 sub tq_serialize {
647 0 ▶ my ($node,$opts)=@_;
Subroutine tq_serialize: not called CC=50 SCAR=78.4
Pod undocumented
648 0 my $indent = $opts->{indent};
649 0 my $do_wrap = $opts->{wrap};
650 0 my $query_node = $opts->{query_node};
651 0 my $name = $node->{'#name'};
652 0 ▶ $indent||='';
Condition0%0/2
$indent ||= ""
l!l
00
MC/DC0%0/1
$indent ||= ""
$indent
Truth table0%0/2
A
A= $indent
Aresult
11
00
653 0 my @ret;
654 0 ▶ my $wrap=($do_wrap||0) ? "\n$indent" : " ";
Branch: 1 branch
BranchTrueFalseTotal
$do_wrap || 0 ? : 0 0 0
Condition0%0/2
$do_wrap or 0
l!l
00
MC/DC0%0/1
$do_wrap or 0
$do_wrap
Truth table0%0/2
A
A= $do_wrap
Aresult
11
00
655 0 ▶ $name = '' if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
656 0 ▶ if (!(length $name) and !$node->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length $name || $node->parent) { } 0 0 0
Condition0%0/3
length $name || $node->parent
l!l&&r!l&&!r
000
MC/DC0%0/2
length $name || $node->parent
length $name $node->parent
Truth table0%0/3
A || B
A= length $nameB= $node->parent
ABresult
1X1
011
000
657 0 ▶ my $desc = (!$opts->{no_description} && $node->{description})||'';
Condition0%0/5
!$opts->{'no_description'} && $node->{'description'} || ''
l!l
00
not $opts->{"no_description"} and $node->{"description"}
!ll&&!rl&&r
000
MC/DC0%0/2
!$opts->{'no_description'} && $node->{'description'} || ''
not $opts->{"no_description"} $node->{"description"}
Truth table0%0/3
not(A) and B
A= not $opts->{"no_description"}B= $node->{"description"}
ABresult
111
0X0
100
658 0 $desc=~s{\n}{\n# }g;
659 0 ▶ my $fwrap = $do_wrap ? "\n " : " ";
Branch: 1 branch
BranchTrueFalseTotal
$do_wrap ? : 0 0 0
660 return [
661 [(length($desc) ? '# '.$desc."\n" : ''),$node,-foreground=>'brown'],
662 0 ▶ ($opts->{no_childnodes} ? () : (map { (@{tq_serialize($_,$opts)},($opts->{where} ? [" "] : [";\n"])) } $node->children)),
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'where'} ? : 0 0 0
663 map {
664 [join('',
665 ' >>',
666 (ref($_->{where}) ?
667 (' filter '.make_string(tq_serialize($_->{where},{%$opts,where=>1,no_childnodes=>0})))
668 : (
669 (ListV($_->{'group-by'}) ? (' for ',join(',',ListV($_->{'group-by'})),
670 "${fwrap}give ") : (' give ')),
671 ($_->{distinct} ? ('distinct ') : ()),
672 join(',',ListV($_->{return})),
673 0 ▶ (ListV($_->{'sort-by'}) ? ("${fwrap}sort by ",join(',',ListV($_->{'sort-by'}))) : ())
Branch: 5 branches
BranchTrueFalseTotal
ref $_->{'where'} ? : 0 0 0
ListV($_->{'group-by'}) ? : 0 0 0
$_->{'distinct'} ? : 0 0 0
ListV($_->{'sort-by'}) ? : 0 0 0
$opts->{'no_filters'} ? : 0 0 0
674 )),
675 "\n"
676 ), $node, -foreground=>'brown' ]
677 0 ▶ } $opts->{no_filters} ? () : ListV($node->{'output-filters'})
Branch: 2 branches
BranchTrueFalseTotal
length $desc ? : 0 0 0
$opts->{'no_childnodes'} ? : 0 0 0
678 ]
679 } else {
680 0 my $copts = {%$opts,no_childnodes=>0,no_refs=>0,indent=>$indent." "};
681 0 ▶ my @children = $opts->{no_childnodes} ? (grep { $_->{'#name'} ne 'node' } $node->children) : $node->children;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'no_childnodes'} ? : 0 0 0
682 0 ▶ if ($name eq 'subquery' or $name eq 'node') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "subquery" or $name eq "node") 0 0 0
Condition0%0/3
$name eq "subquery" or $name eq "node"
l!l&&r!l&&!r
000
MC/DC0%0/2
$name eq "subquery" or $name eq "node"
$name eq "subquery" $name eq "node"
Truth table0%0/3
A or B
A= $name eq "subquery"B= $name eq "node"
ABresult
1X1
011
000
683 0 my %order = (
684 test => 1,
685 not => 2,
686 or => 3,
687 ref => 4,
688 subquery => 5,
689 );
690 0 $copts->{query_node}=$node;
691 0 ▶ @children = sort { ($order{$a->{'#name'}}||100)<=>($order{$b->{'#name'}}||100) } @children;
Condition0%0/4
$order{$PMLTQ::Common::a->{'#name'}} || 100
l!l
00
$order{$PMLTQ::Common::b->{'#name'}} || 100
l!l
00
MC/DC0%0/1
$order{$PMLTQ::Common::a->{'#name'}} || 100
$order{$PMLTQ::Common::a->{'#name'}}
MC/DC0%0/1
$order{$PMLTQ::Common::b->{'#name'}} || 100
$order{$PMLTQ::Common::b->{'#name'}}
Truth table0%0/2
A
A= $order{$PMLTQ::Common::a->{'#name'}}
Aresult
11
00
Truth table0%0/2
A
A= $order{$PMLTQ::Common::b->{'#name'}}
Aresult
11
00
692 }
693  
694 0 my @r = map [tq_serialize($_,$copts)], @children;
695 0 ▶ if ($name eq 'test') {
Branch: 4 branches
BranchTrueFalseTotal
if ($name eq 'test') { } 0 0 0
elsif ($name =~ /^(?:not|or|and)$/) { } 0 0 0
elsif ($name eq 'ref') { } 0 0 0
elsif ($name eq 'subquery' or $name eq 'node') { } 0 0 0
696 0 my $op = $node->{operator};
697 # if ($node->parent and ($node->parent->{'#name'}||'') eq 'not' and !$node->rbrother and !$node->lbrother and $op =~ /^[~=]/) {
698 # $op='!'.$op;
699 # }
700 0 my $test= $node->{a}.' '.$op.' '.$node->{b};
701 0 @ret = ( [$test,$node,$query_node] );
702 } elsif ($name=~/^(?:not|or|and)$/) {
703 0 ▶ if ($name eq 'not') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "not") 0 0 0
704 #my $f = $node->firstson;
705 #unless ($f and ($f->{'#name'}||'') eq 'test' and !$f->rbrother and $f->{operator} =~ /^[~=]/) {
706 0 push @ret,['!',$node,$query_node,'-foreground=>darkcyan'];
707 #}
708 0 $name='and';
709 }
710 0 ▶ if (@r) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r) 0 0 0
711 push @ret,( @r==1 ? $r[0] : (['(',$node,$query_node,'-foreground=>darkcyan'],
712 0 ▶ @{_group(\@r,["${wrap}$name ",$node,$query_node,'-foreground=>darkcyan'])},
Branch: 1 branch
BranchTrueFalseTotal
@r == 1 ? : 0 0 0
713 [')',$node,$query_node,'-foreground=>darkcyan']) );
714 }
715 } elsif ($name eq 'ref') {
716 0 ▶ my $rel=rel_as_text($node) || 'child';
Condition0%0/2
rel_as_text($node) || 'child'
l!l
00
MC/DC0%0/1
rel_as_text($node) || 'child'
rel_as_text($node)
Truth table0%0/2
A
A= rel_as_text($node)
Aresult
11
00
717 0 my $arrow = $rel;
718 0 $arrow=~s/{.*//;
719 0 ▶ my $color=ref($opts->{arrow_colors}) ? $opts->{arrow_colors}{$arrow} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $opts->{'arrow_colors'} ? : 0 0 0
720 0 ▶ push @ret,
Branch: 1 branch
BranchTrueFalseTotal
$color ? : 0 0 0
721 [$rel.' ',$node,$query_node,($color ? ('-foreground=>'.$color) : ())];
722 0 ▶ my $ref = $node->{target} || '???';
Condition0%0/2
$node->{'target'} || '???'
l!l
00
MC/DC0%0/1
$node->{'target'} || '???'
$node->{'target'}
Truth table0%0/2
A
A= $node->{'target'}
Aresult
11
00
723 0 push @ret,["\$$ref",$node,$query_node,'-foreground=>darkblue'];
724 ▶ } elsif ($name eq 'subquery' or $name eq 'node') {
Condition0%0/3
$name eq "subquery" or $name eq "node"
l!l&&r!l&&!r
000
MC/DC0%0/2
$name eq "subquery" or $name eq "node"
$name eq "subquery" $name eq "node"
Truth table0%0/3
A or B
A= $name eq "subquery"B= $name eq "node"
ABresult
1X1
011
000
725 0 ▶ if ($name eq 'subquery') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'subquery') { } 0 0 0
726 0 push @ret, [occ_as_text($node).'x ',$node,'-foreground=>darkgreen'];
727 } else {
728 0 ▶ if ($node->{optional}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"optional"}) 0 0 0
729 0 push @ret, ['?',$node,'-foreground=>darkgreen'];
730 }
731 0 ▶ if ($node->{overlapping}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"overlapping"}) 0 0 0
732 0 push @ret, ['+',$node,'-foreground=>darkgreen'];
733 }
734 }
735  
736 0 my $rel='';
737 0 ▶ if ($node->parent and $node->parent->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->parent and $node->parent->parent) 0 0 0
Condition0%0/3
$node->parent and $node->parent->parent
!ll&&!rl&&r
000
MC/DC0%0/2
$node->parent and $node->parent->parent
$node->parent $node->parent->parent
Truth table0%0/3
A and B
A= $node->parentB= $node->parent->parent
ABresult
0X0
100
111
738 0 $rel=rel_as_text($node);
739 0 my $arrow = $rel;
740 0 $arrow=~s/{.*//;
741 0 ▶ my $color=ref($opts->{arrow_colors}) ? $opts->{arrow_colors}{$arrow} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $opts->{'arrow_colors'} ? : 0 0 0
742 0 ▶ push @ret,[$rel.' ',$node,($color ? ('-foreground=>'.$color) : ())];
Branch: 1 branch
BranchTrueFalseTotal
$color ? : 0 0 0
743 }
744 0 my $type=$node->{'node-type'}; #
745 0 ▶ $type = GetQueryNodeType($node) if !$type and $opts->{resolve_types};
Branch: 1 branch
BranchTrueFalseTotal
if not $type and $opts->{"resolve_types"} 0 0 0
Condition0%0/3
not $type and $opts->{"resolve_types"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $type and $opts->{"resolve_types"}
not $type $opts->{"resolve_types"}
Truth table0%0/3
not(A) and B
A= not $typeB= $opts->{"resolve_types"}
ABresult
0X0
100
111
746  
747 0 ▶ push @ret,[$type.' ',$node] if $type; #FIXME:
Branch: 1 branch
BranchTrueFalseTotal
if $type 0 0 0
748 0 ▶ if ($node->{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"name"}) 0 0 0
749 0 push @ret,['$'.$node->{name},$node,'-foreground=>darkblue'],[' := ',$node];
750 }
751 0 ▶ if ($do_wrap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_wrap) { } 0 0 0
752 0 ▶ if (@r) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r) { } 0 0 0
753 push @ret, (["[ ",$node],["${wrap} "],
754 0 @{_group(\@r,[",${wrap} "])},
755 ["${wrap}"],[" ]",$node]);
756 } else {
757 0 push @ret, (["[ ]",$node]);
758 }
759 } else {
760 0 ▶ unshift @ret,["\n${indent}"] if $node->lbrother;
Branch: 1 branch
BranchTrueFalseTotal
if $node->lbrother 0 0 0
761 0 ▶ if (@r) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r) { } 0 0 0
762 push @ret,["\n${indent}"],["[ ",$node],
763 0 @{_group(\@r,[", ",$node])},
764 [" ]",$node];
765 } else {
766 0 push @ret, (["[ ]",$node]);
767 }
768 }
769 } else {
770 0 @ret = (['## unknown: '.$name."\n",$node]);
771 }
772 }
773 0 return \@ret;
774 }
775  
776 sub as_text {
777 0 ▶ my ($node,$opts)=@_;
Subroutine as_text: not called CC=1 SCAR=6.9
Pod undocumented
778 0 make_string(tq_serialize($node,$opts));
779 }
780  
781 sub _group {
782 0 ▶ my ($array,$and_or) = @_;
Subroutine _group: not called CC=2 SCAR=17.9
783 return [ map {
784 0 ▶ ($_==0) ? ($array->[$_]) : ($and_or,$array->[$_])
Branch: 1 branch
BranchTrueFalseTotal
$_ == 0 ? : 0 0 0
785 } 0..$#$array ];
786 }
787  
788 sub make_string {
789 0 ▶ my ($array) = @_;
Subroutine make_string: not called CC=3 SCAR=24.8
Pod undocumented
790 0 ▶ Carp::cluck "not an array" unless ref($array) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $array eq "ARRAY" 0 0 0
791 return join '', map {
792 0 ▶ ref($_->[0]) ? make_string($_->[0]) : $_->[0]
Branch: 1 branch
BranchTrueFalseTotal
ref $_->[0] ? : 0 0 0
793 } @$array;
794 }
795  
796 sub make_string_with_tags {
797 0 ▶ my ($array,$tags) = @_;
Subroutine make_string_with_tags: not called CC=2 SCAR=17.9
Pod undocumented
798 return [map {
799 0 ▶ ref($_->[0]) ? @{make_string_with_tags($_->[0],[uniq(@$tags,@{$_}[1..$#$_])])} : [$_->[0], uniq(@$tags,@{$_}[1..$#$_])]
Branch: 1 branch
BranchTrueFalseTotal
ref $_->[0] ? : 0 0 0
800 } @$array];
801 }
802  
803 sub _list_to_regexp {
804 0 ▶ my ($values)=@_;
Subroutine _list_to_regexp: not called CC=3 SCAR=24.8
805 0 ▶ return unless defined($values) and @$values;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $values and @$values 0 0 0
Condition0%0/3
defined $values and @$values
!ll&&!rl&&r
000
MC/DC0%0/2
defined $values and @$values
defined $values @$values
Truth table0%0/3
A and B
A= defined $valuesB= @$values
ABresult
0X0
100
111
806 0 return '\b(?:'.join('|',map quotemeta, sort { $b cmp $a } @$values).')\b';
807 }
808 sub _pmlrf_relations_regexp {
809 0 ▶ my ($names)=@_;
Subroutine _pmlrf_relations_regexp: not called CC=2 SCAR=17.9
810 0 ▶ return _list_to_regexp($names) || $PMLTQ::pmlrf_relations;
Condition0%0/3
_list_to_regexp($names) || $PMLTQ::pmlrf_relations
l!l&&r!l&&!r
000
MC/DC0%0/2
_list_to_regexp($names) || $PMLTQ::pmlrf_relations
_list_to_regexp($names) $PMLTQ::pmlrf_relations
Truth table0%0/3
A || B
A= _list_to_regexp($names)B= $PMLTQ::pmlrf_relations
ABresult
1X1
011
000
811 }
812 sub _user_defined_relations_regexp {
813 0 ▶ my ($names)=@_;
Subroutine _user_defined_relations_regexp: not called CC=2 SCAR=17.9
814 0 ▶ return _list_to_regexp($names) || $PMLTQ::user_defined;
Condition0%0/3
_list_to_regexp($names) || $PMLTQ::user_defined
l!l&&r!l&&!r
000
MC/DC0%0/2
_list_to_regexp($names) || $PMLTQ::user_defined
_list_to_regexp($names) $PMLTQ::user_defined
Truth table0%0/3
A || B
A= _list_to_regexp($names)B= $PMLTQ::user_defined
ABresult
1X1
011
000
815 }
816  
817 ### Query parsing
818  
819 sub merge_and_nodes {
820 0 ▶ my ($n1,$n2)=@_;
Subroutine merge_and_nodes: not called CC=5 SCAR=34.0
Pod undocumented
821 0 ▶ if ($n1->{'#name'} eq 'and') {
Branch: 2 branches
BranchTrueFalseTotal
if ($n1->{'#name'} eq 'and') { } 0 0 0
elsif ($n2->{'#name'} eq 'and') { } 0 0 0
822 0 ▶ for my $c ( ($n2->{'#name'} eq 'and') ? $n2->children : $n2) {
Branch: 1 branch
BranchTrueFalseTotal
$n2->{'#name'} eq 'and' ? : 0 0 0
823 0 $c->cut()->paste_on($n1);
824 }
825 0 return $n1;
826 } elsif ($n2->{'#name'} eq 'and') {
827 0 return merge_and_nodes($n2,$n1);
828 } else {
829 0 return _new_node({'#name'=>'and'},[$n1,$n2]);
830 }
831 }
832  
833 #
834 # merge_filters translates 'filter' output filters
835 # to a where clause of the following filter
836 #
837 sub merge_filters {
838 0 ▶ my ($filters)=@_;
Subroutine merge_filters: not called CC=7 SCAR=40.3
Pod undocumented
839 0 my @out;
840 my $last_where;
841 0 ▶ return unless $filters;
Branch: 1 branch
BranchTrueFalseTotal
unless $filters 0 0 0
842 0 ▶ while (@$filters) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$filters) 0 0 0
843 0 my $f = shift @$filters;
844 0 ▶ if ($f->{'return'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f->{'return'}) { } 0 0 0
elsif ($f->{'where'}) { } 0 0 0
845 0 push @out, $f;
846 0 $f->{where} = $last_where;
847 0 $last_where=undef;
848 } elsif ($f->{'where'}) {
849 0 ▶ if ($last_where) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_where) { } 0 0 0
850 0 $last_where = merge_and_nodes($last_where,$f->{where});
851 } else {
852 0 $last_where = $f->{where};
853 }
854 } else {
855 0 die "unexpected filter type: @$f\n";
856 }
857 }
858 0 ▶ if ($last_where) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_where) 0 0 0
859 # copy columns from the last filter
860 push @out, Treex::PML::Factory->createStructure({
861 0 'return' => Treex::PML::Factory->createList([map { '$'.$_ } 1..@{$out[-1]{return}}],1),
862 'where' => $last_where,
863 });
864 }
865 0 return @out;
866 }
867  
868 #
869 # merge_filters translates 'filter' output filters
870 # to a having clause of the preceding filter
871 #
872 sub merge_filters_2 {
873 0 ▶ my ($filters)=@_;
Subroutine merge_filters_2: not called CC=7 SCAR=40.3
Pod undocumented
874 0 my @out;
875 my $last_filter;
876 0 ▶ return unless $filters;
Branch: 1 branch
BranchTrueFalseTotal
unless $filters 0 0 0
877 0 ▶ while (@$filters) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$filters) 0 0 0
878 0 my $f = shift @$filters;
879 0 ▶ if ($f->{'return'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f->{'return'}) { } 0 0 0
elsif ($f->{'where'}) { } 0 0 0
880 0 push @out, $f;
881 0 $last_filter = $f;
882 } elsif ($f->{'where'}) {
883 0 ▶ if ($last_filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_filter) { } 0 0 0
884 0 ▶ if ($last_filter->{having}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_filter->{'having'}) { } 0 0 0
885 0 merge_and_nodes($last_filter->{having},$f->{where});
886 } else {
887 0 $last_filter->{having} = $f->{where};
888 }
889 } else {
890 0 die "Output-filter 'filter' must be preceded by at least one filter with a 'give' clause\n";
891 }
892 } else {
893 0 die "unexpected filter type: @$f\n";
894 }
895 }
896 0 return @out;
897 }
898  
899  
900 sub _new_node {
901 0 ▶ my ($hash,$children)=@_;
Subroutine _new_node: not called CC=5 SCAR=34.0
902 0 my $new = Treex::PML::Factory->createNode($hash,1);
903 0 ▶ if ($children) {
Branch: 1 branch
BranchTrueFalseTotal
if ($children) 0 0 0
904 0 ▶ if (ref($children) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $children eq 'ARRAY') { } 0 0 0
905 0 for (reverse @$children) {
906 0 ▶ if (UNIVERSAL::DOES::does($_, 'Treex::PML::Node')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::DOES::does($_, 'Treex::PML::Node')) { } 0 0 0
907 0 $_->paste_on($new)
908 } else {
909 0 warn "new_node: child of $hash->{'#name'} is not a node:\n".
910 Data::Dumper::Dumper([$_]);
911 }
912 }
913 } else {
914 0 warn "new_node: 2nd argument of constructor to $hash->{'#name'} is not an ARRAYref:\n".
915 Data::Dumper::Dumper([$children]);
916 }
917 }
918 0 return $new;
919 }
920  
921 15 my $parser;
922 sub query_parser {
923 0 ▶ return $parser if defined $parser;
Subroutine query_parser: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if defined $parser 0 0 0
924 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require PMLTQ::_Parser; $parser = "PMLTQ::_Parser"->new; 1 } } and return $parser 0 0 0
925 0 require PMLTQ::_Parser;
926 0 $parser = PMLTQ::_Parser->new();
927 0 1;
928 } and return $parser;
929  
930 0 die "Cannot create query parser";
931 }
932  
933 sub parse_query {
934 0 ▶ my ($query,$opts)=@_;
Subroutine parse_query: not called CC=2 SCAR=17.9
Pod undocumented
935 # $query =~ s{\Q[]\E(?=/)|(?<=/)\Q[]\E}{content()}g;
936 0 local $PMLTQ::pmlrf_relations = _pmlrf_relations_regexp($opts->{pmlrf_relations});
937 0 local $PMLTQ::user_defined = _user_defined_relations_regexp($opts->{user_defined_relations});
938 0 my $ret = eval {query_parser()->parse_query($query)};
939 0 ▶ confess($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
940 0 $ret->set_type(Schema()->find_type_by_path('!q-query.type'));
941 0 return $ret;
942 }
943 sub parse_filters {
944 0 ▶ my ($filters,$opts)=@_;
Subroutine parse_filters: not called CC=2 SCAR=17.9
Pod undocumented
945 0 my $ret = eval {query_parser()->parse_filters($filters)};
946 0 ▶ confess($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
947 0 return $ret;
948 }
949 sub parse_expression {
950 0 ▶ my ($query,$opts)=@_;
Subroutine parse_expression: not called CC=2 SCAR=17.9
Pod undocumented
951 0 my $ret = eval { query_parser()->parse_expression($query) };
952 0 ▶ confess($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
953 0 return $ret;
954 }
955 sub parse_flat_expression {
956 0 ▶ my ($query,$opts)=@_;
Subroutine parse_flat_expression: not called CC=2 SCAR=17.9
Pod undocumented
957 0 my $ret = eval { query_parser()->parse_flat_expression($query) };
958 0 ▶ confess($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
959 0 return $ret;
960 }
961 sub parse_column_expression {
962 0 ▶ my ($query,$opts)=@_;
Subroutine parse_column_expression: not called CC=2 SCAR=17.9
Pod undocumented
963 0 my $ret = eval { query_parser()->parse_column_expression($query) };
964 0 ▶ confess($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
965 0 return $ret;
966 }
967  
968 sub parse_node {
969 0 ▶ my ($query,$opts)=@_;
Subroutine parse_node: not called CC=2 SCAR=17.9
Pod undocumented
970 0 local $PMLTQ::pmlrf_relations = _pmlrf_relations_regexp($opts->{pmlrf_relations});
971 0 local $PMLTQ::user_defined = _user_defined_relations_regexp($opts->{user_defined_relations});
972 0 my $ret = eval { query_parser()->parse_node($query) };
973 0 ▶ confess($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
974 0 return $ret;
975 }
976  
977 sub parse_conditions {
978 0 ▶ my ($query,$opts)=@_;
Subroutine parse_conditions: not called CC=2 SCAR=17.9
Pod undocumented
979 0 local $PMLTQ::pmlrf_relations = _pmlrf_relations_regexp($opts->{pmlrf_relations});
980 0 local $PMLTQ::user_defined = _user_defined_relations_regexp($opts->{user_defined_relations});
981 0 my $ret = eval { query_parser()->parse_conditions($query) };
982 0 ▶ confess($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
983 0 return $ret;
984 }
985  
986 # returns:
987 # COL_NUMERIC for numeric type
988 # COL_STRING for string type
989 # COL_UNKNOWN for any other type
990  
991 # $self must support the following methods:
992 #
993 # $type_mapper_object = $self->type_mapper()
994 # $type_name = $self->get_type_of_node($name)
995 #
996  
997 sub compute_column_data_type {
998 0 ▶ my ($self,$column,$opts)=@_;
Subroutine compute_column_data_type: not called CC=4 SCAR=30.0
Pod undocumented
999 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
1000 0 my $pt;
1001 0 ▶ if (ref($column)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $column) { } 0 0 0
1002 0 $pt = $column;
1003 } else {
1004 # column is a PT:
1005 0 $pt = PMLTQ::Common::parse_column_expression($column); # $pt stands for parse tree
1006 0 ▶ die "Invalid column expression '$column'" unless defined $pt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pt 0 0 0
1007 }
1008 0 compute_expression_data_type_pt($self,$pt,$opts);
1009 }
1010  
1011 sub compute_expression_data_type {
1012 0 ▶ my ($self,$exp,$opts)=@_;
Subroutine compute_expression_data_type: not called CC=4 SCAR=30.0
Pod undocumented
1013 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
1014 0 my $pt;
1015 0 ▶ if (ref($exp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $exp) { } 0 0 0
1016 0 $pt = $exp;
1017 } else {
1018 # column is a PT:
1019 0 $pt = PMLTQ::Common::parse_expression($exp); # $pt stands for parse tree
1020 0 ▶ die "Invalid expression '$exp'" unless defined $pt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pt 0 0 0
1021 }
1022 0 compute_expression_data_type_pt($self,$pt,$opts);
1023 }
1024  
1025 sub compute_expression_data_type_pt {
1026 ## BUG in numeric comparison (it create expression with string equation when reference like $[0-9]+ is used)
1027 0 ▶ my ($self,$pt,$opts)=@_;
Subroutine compute_expression_data_type_pt: not called CC=55 SCAR=80.3
Pod undocumented
1028 0 ▶ if (ref $pt) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pt) { } 0 0 0
1029 0 my ($type) = @$pt;
1030 0 ▶ if (!defined $type) {
Branch: 7 branches
BranchTrueFalseTotal
if (not defined $type) { } 0 0 0
elsif ($type eq 'EVERY') { } 0 0 0
elsif ($type eq 'ATTR' or $type eq 'REF_ATTR') { } 0 0 0
elsif ($type eq 'ANALYTIC_FUNC') { } 0 0 0
elsif ($type eq 'FUNC') { } 0 0 0
elsif ($type eq 'IF') { } 0 0 0
elsif ($type eq 'EXP') { } 0 0 0
1031 0 Carp::cluck("Computing type of an undefined kind: ".join(",",@$pt)."\n");
1032 } elsif ($type eq 'EVERY') {
1033 0 return compute_expression_data_type_pt($self,$pt->[1],$opts);
1034 ▶ } elsif ($type eq 'ATTR' or $type eq 'REF_ATTR') {
Condition0%0/3
$type eq "ATTR" or $type eq "REF_ATTR"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "ATTR" or $type eq "REF_ATTR"
$type eq "ATTR" $type eq "REF_ATTR"
Truth table0%0/3
A or B
A= $type eq "ATTR"B= $type eq "REF_ATTR"
ABresult
1X1
011
000
1035 0 my $node_type_decl;
1036 my $target;
1037 0 ▶ if ($type eq 'REF_ATTR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'REF_ATTR') { } 0 0 0
1038 0 $target = $pt->[1];
1039 0 $pt=$pt->[2];
1040 } else {
1041 0 $target=$opts->{id};
1042 }
1043 0 my $cast;
1044 0 my $node_type = $self->get_type_of_node($target);
1045 0 ▶ if($pt->[1] =~ /^(.+)\?$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pt->[1] =~ /^(.+)\?$/) { } 0 0 0
elsif ($node_type =~ m[^(?:([^/]+):)?\*$]) { } 0 0 0
1046 0 $cast = $1; # shift @$pt;
1047 } elsif ($node_type=~m{^(?:([^/]+):)?\*$}) {
1048 0 my $node_types = $self->type_mapper->get_node_types($1);
1049 0 my @possibilities;
1050 0 ▶ my $path = join '/',map { $_ eq '[]' ? '#content' : $_ } @$pt[1..$#$pt];
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '[]' ? : 0 0 0
1051 0 for my $nt (@$node_types) {
1052 0 my $decl = $self->type_mapper->get_decl_for($nt);
1053 0 ▶ my $attr_decl = $decl && $decl->find($path);
Condition0%0/3
$decl && $decl->find($path)
!ll&&!rl&&r
000
MC/DC0%0/2
$decl && $decl->find($path)
$decl $decl->find($path)
Truth table0%0/3
A && B
A= $declB= $decl->find($path)
ABresult
0X0
100
111
1054 0 ▶ $attr_decl=$attr_decl->get_content_decl
Branch: 1 branch
BranchTrueFalseTotal
$attr_decl and $attr_decl->get_decl_type == 6 || $attr_decl->get_decl_type == 7 and do { $attr_decl = $attr_decl->get_content_decl } 0 0 0
Condition0%0/6
$attr_decl and $attr_decl->get_decl_type == 6 || $attr_decl->get_decl_type == 7
!ll&&!rl&&r
000
$attr_decl->get_decl_type == 6 or $attr_decl->get_decl_type == 7
l!l&&r!l&&!r
000
MC/DC0%0/3
$attr_decl and $attr_decl->get_decl_type == 6 || $attr_decl->get_decl_type == 7
$attr_decl $attr_decl->get_decl_type == 6 $attr_decl->get_decl_type == 7
Truth table0%0/4
A and B or C
A= $attr_declB= $attr_decl->get_decl_type == 6C= $attr_decl->get_decl_type == 7
ABCresult
0XX0
1000
11X1
1011
1055 while ($attr_decl and ($attr_decl->get_decl_type == PML_LIST_DECL or
1056 $attr_decl->get_decl_type == PML_ALT_DECL));
1057 0 ▶ push @possibilities,
Branch: 2 branches
BranchTrueFalseTotal
if $attr_decl and $attr_decl->is_atomic 0 0 0
$type eq 'REF_ATTR' ? : 0 0 0
Condition0%0/3
$attr_decl and $attr_decl->is_atomic
!ll&&!rl&&r
000
MC/DC0%0/2
$attr_decl and $attr_decl->is_atomic
$attr_decl $attr_decl->is_atomic
Truth table0%0/3
A and B
A= $attr_declB= $attr_decl->is_atomic
ABresult
0X0
100
111
1058 $type eq 'REF_ATTR' ? ['REF_ATTR',$target,['ATTR',$nt.'?',@$pt[1..$#$pt]]] : ['ATTR',$nt.'?',@$pt[1..$#$pt]]
1059 if ($attr_decl and $attr_decl->is_atomic);
1060 }
1061 0 ▶ if (!@possibilities) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @possibilities) { } 0 0 0
elsif (@possibilities == 1) { } 0 0 0
1062 0 die "The attribute path '$path' is not valid for any node type matched by the '$node_type' wildcard: @$node_types\n";
1063 } elsif (@possibilities == 1) {
1064 0 return compute_expression_data_type_pt($self,$possibilities[0],$opts);
1065 } else {
1066 0 return compute_expression_data_type_pt($self,['FUNC','first_defined',\@possibilities],$opts);
1067 }
1068 }
1069 0 ▶ $node_type_decl = $self->type_mapper->get_decl_for($cast || $node_type);
Condition0%0/3
$cast || $node_type
l!l&&r!l&&!r
000
MC/DC0%0/2
$cast || $node_type
$cast $node_type
Truth table0%0/3
A || B
A= $castB= $node_type
ABresult
1X1
011
000
1070 0 ▶ my $attr=join('/',@{$pt}[($cast ? 2 : 1)..$#$pt]);
Branch: 1 branch
BranchTrueFalseTotal
$cast ? : 0 0 0
1071 0 $attr=~s{\[\]}{#content}g;
1072 0 $attr=~s{/\[[^\]]*\]}{}g;
1073 0 my $decl = $node_type_decl->find($attr);
1074 0 ▶ my $decl_is = $decl && $decl->get_decl_type;
Condition0%0/3
$decl && $decl->get_decl_type
!ll&&!rl&&r
000
MC/DC0%0/2
$decl && $decl->get_decl_type
$decl $decl->get_decl_type
Truth table0%0/3
A && B
A= $declB= $decl->get_decl_type
ABresult
0X0
100
111
1075 0 ▶ while ($decl and
Branch: 1 branch
BranchTrueFalseTotal
if ($decl and $decl_is == 6 || $decl_is == 7 || $decl_is == 12 || $decl_is == 13) 0 0 0
Condition0%0/12
$decl and $decl_is == 6 || $decl_is == 7 || $decl_is == 12 || $decl_is == 13
!ll&&!rl&&r
000
$decl_is == 6 or $decl_is == 7 or $decl_is == 12 or $decl_is == 13
l!l&&r!l&&!r
000
$decl_is == 6 or $decl_is == 7 or $decl_is == 12
l!l&&r!l&&!r
000
$decl_is == 6 or $decl_is == 7
l!l&&r!l&&!r
000
MC/DC0%0/5
$decl and $decl_is == 6 || $decl_is == 7 || $decl_is == 12 || $decl_is == 13
$decl $decl_is == 6 $decl_is == 7 $decl_is == 12 $decl_is == 13
Truth table0%0/6
A and B or C or D or E
A= $declB= $decl_is == 6C= $decl_is == 7D= $decl_is == 12E= $decl_is == 13
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
1076 ($decl_is == PML_LIST_DECL or
1077 $decl_is == PML_ALT_DECL or
1078 $decl_is == PML_MEMBER_DECL or
1079 $decl_is == PML_ELEMENT_DECL)) {
1080 0 $decl = $decl->get_content_decl;
1081 0 $decl_is = $decl->get_decl_type;
1082 }
1083 0 ▶ if ($decl and $decl->is_atomic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl and $decl->is_atomic) { } 0 0 0
Condition0%0/3
$decl and $decl->is_atomic
!ll&&!rl&&r
000
MC/DC0%0/2
$decl and $decl->is_atomic
$decl $decl->is_atomic
Truth table0%0/3
A and B
A= $declB= $decl->is_atomic
ABresult
0X0
100
111
1084 0 ▶ if ($decl_is == PML_CHOICE_DECL or
Branch: 1 branch
BranchTrueFalseTotal
if ($decl_is == 9 or $decl_is == 10) { } 0 0 0
Condition0%0/3
$decl_is == 9 or $decl_is == 10
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl_is == 9 or $decl_is == 10
$decl_is == 9 $decl_is == 10
Truth table0%0/3
A or B
A= $decl_is == 9B= $decl_is == 10
ABresult
1X1
011
000
1085 $decl_is == PML_CONSTANT_DECL) {
1086 0 my @values = $decl->get_values;
1087 0 ▶ if (@values and !grep { !/^(?:0|-?[1-9][0-9]*(?:\.[0-9]*[1-9])?)$/ } @values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values and not grep({not /^(?:0|-?[1-9][0-9]*(?:\.[0-9]*[1-9])?)$/;} @values)) { } 0 0 0
Condition0%0/3
@values and not grep({not /^(?:0|-?[1-9][0-9]*(?:\.[0-9]*[1-9])?)$/;} @values)
!ll&&!rl&&r
000
MC/DC0%0/2
@values and not grep({not /^(?:0|-?[1-9][0-9]*(?:\.[0-9]*[1-9])?)$/;} @values)
@values not grep({not /^(?:0|-?[1-9][0-9]*(?:\.[0-9]*[1-9])?)$/;} @values)
Truth table0%0/3
A and not(B)
A= @valuesB= not grep({not /^(?:0|-?[1-9][0-9]*(?:\.[0-9]*[1-9])?)$/;} @values)
ABresult
0X0
100
111
1088 0 return COL_NUMERIC;
1089 } else {
1090 0 return COL_STRING;
1091 }
1092 } else {
1093 0 my $format = $decl->get_format;
1094 0 ▶ if ($format =~ /(integer$|int$|short$|byte|long|decimal$|float$|double$)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /(integer$|int$|short$|byte|long|decimal$|float$|double$)/i) { } 0 0 0
1095 0 return COL_NUMERIC;
1096 } else {
1097 0 return COL_STRING;
1098 }
1099 }
1100 } else {
1101 0 return COL_UNKNOWN;
1102 }
1103 } elsif ($type eq 'ANALYTIC_FUNC') {
1104 0 ▶ if ($pt->[1] eq 'concat') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pt->[1] eq 'concat') { } 0 0 0
1105 0 return COL_STRING;
1106 } else {
1107 0 return COL_NUMERIC;
1108 }
1109 } elsif ($type eq 'FUNC') {
1110 0 my $name = $pt->[1];
1111 0 ▶ if ($name=~/^(?:descendants|lbrothers|rbrothers|sons|depth_first_order|order_span_min|order_span_max|depth|length|abs|floor|ceil|round|trunc|tree_no)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^(?:descendants|lbrothers|rbrothers|sons|depth_first_order|order_span_min|order_span_max|depth|length|abs|floor|ceil|round|trunc|tree_no)$/) { } 0 0 0
elsif ($name eq 'first_defined') { } 0 0 0
1112 0 return COL_NUMERIC;
1113 } elsif ($name eq 'first_defined') {
1114 0 return min(map compute_expression_data_type_pt($self,$_,$opts), @{$pt->[2]});
1115 } else {
1116 0 return COL_STRING;
1117 }
1118 } elsif ($type eq 'IF') {
1119 0 return min(map compute_expression_data_type_pt($self,$_,$opts), ($pt->[2],$pt->[3]));
1120 } elsif ($type eq 'EXP') {
1121 0 my @exp = @$pt;
1122 0 shift @exp; # shift EXP
1123 0 ▶ return compute_expression_data_type_pt($self,$exp[0],$opts) if @exp==1;
Branch: 1 branch
BranchTrueFalseTotal
if @exp == 1 0 0 0
1124 0 my $lowest_precedence;
1125 my $last_lowest_precedence_op;
1126 0 ▶ while (@exp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exp) 0 0 0
1127 0 shift @exp; # shift an operand
1128 0 ▶ if (@exp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exp) 0 0 0
1129 0 my $op = shift @exp;
1130 0 my $precedence =$PMLTQ::Common::operator_precedence{$op};
1131 0 ▶ if (!defined($lowest_precedence) or $precedence<=$lowest_precedence) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $lowest_precedence or $precedence <= $lowest_precedence) 0 0 0
Condition0%0/3
not defined $lowest_precedence or $precedence <= $lowest_precedence
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $lowest_precedence or $precedence <= $lowest_precedence
not defined $lowest_precedence $precedence <= $lowest_precedence
Truth table0%0/3
not(A) or B
A= not defined $lowest_precedenceB= $precedence <= $lowest_precedence
ABresult
1X1
011
000
1132 0 $last_lowest_precedence_op = $op;
1133 0 $lowest_precedence = $precedence;
1134 }
1135 }
1136 }
1137 0 ▶ if ($last_lowest_precedence_op eq '&') {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_lowest_precedence_op eq '&') { } 0 0 0
1138 0 return COL_STRING;
1139 } else {
1140 0 return COL_NUMERIC;
1141 }
1142 }
1143 } else {
1144 0 ▶ if ($pt=~/^[-0-9]/) { # literal number
Branch: 3 branches
BranchTrueFalseTotal
if ($pt =~ /^[-0-9]/) { } 0 0 0
elsif ($pt =~ /^['"]/) { } 0 0 0
elsif ($pt =~ /^\$/) { } 0 0 0
1145 0 return COL_NUMERIC;
1146 } elsif ($pt=~/^['"]/) { # literal string
1147 0 return COL_STRING;
1148 } elsif ($pt=~/^\$/) {
1149 0 my $var = $pt; $var=~s/^\$//;
1150 0 ▶ if ($var =~ /^[1-9][0-9]*$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($var =~ /^[1-9][0-9]*$/) { } 0 0 0
elsif ($var eq '$') { } 0 0 0
1151 0 return $opts->{column_types}[$var - 1];
1152 } elsif ($var eq '$') { # this cause BUGGY behaviour
1153 0 ▶ return UNIVERSAL::DOES::does($self,'PMLTQ::SQLEvaluator') ? COL_NUMERIC : COL_UNKNOWN;
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::DOES::does($self, 'PMLTQ::SQLEvaluator') ? : 0 0 0
1154 } else {
1155 0 ▶ return UNIVERSAL::DOES::does($self,'PMLTQ::SQLEvaluator') ? COL_NUMERIC : COL_UNKNOWN;
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::DOES::does($self, 'PMLTQ::SQLEvaluator') ? : 0 0 0
1156 }
1157 } else {
1158 0 confess( "Unrecognized sub-expression: $pt\n" );
1159 }
1160 }
1161 }
1162  
1163 sub NewQueryFileInstance {
1164 0 ▶ my ($filename)=@_;
Subroutine NewQueryFileInstance: not called CC=1 SCAR=6.9
Pod undocumented
1165 0 return Treex::PML::Instance->load({
1166 filename => $filename,
1167 config => $Treex::PML::Backend::PML::config,
1168 string => <<"END" });
1169 <?xml version="1.0" encoding="utf-8"?>
1170 <tree_query xmlns="http://ufal.mff.cuni.cz/pdt/pml/">
1171 <head>
1172 <schema href="tree_query_schema.xml" />
1173 </head>
1174 <q-trees>
1175 </q-trees>
1176 </tree_query>
1177 END
1178 }
1179  
1180 sub NewQueryDocument {
1181 0 ▶ return NewQueryFileInstance(@_)->convert_to_fsfile();
Subroutine NewQueryDocument: not called CC=1 SCAR=6.9
Pod undocumented
1182 }
1183  
1184 15 1; # End of PMLTQ::Common
1185  
1186 __END__
« blib/lib/PMLTQ/PML2BASE.pm ↑ Summary blib/lib/PMLTQ/Command/query.pm »