Query/Algebra/Path.pm

filter: Statementstmt 65.3% 81 / 124 Branchbran 26.7% 15 / 56 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 75.0% 18 / 24 Podpod 100% 14 / 14 totaltotal 58.9% 132 / 224 CC 33 SCAR 37.9
CC
33
Cov
54%
_bounded_length
90.0
_expand_path
80.0
distinguish_bnode_variables
12.0
CRAP 44.3
« Query/Plan/Minus.pm ↑ Summary Query/Plan/Join.pm »
1 # RDF::Query::Algebra::Path
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Algebra::Path - Algebra class for path patterns
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Algebra::Path version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Algebra::Path;
15  
16 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 36 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 36 ▶use base qw(RDF::Query::Algebra);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 36 ▶use Set::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 36 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 ######################################################################
26  
27 36 our ($VERSION, $debug, $lang, $languri);
28 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
29 36 $debug = 0;
30 36 $VERSION = '2.919';
31 }
32  
33 ######################################################################
34  
35 =head1 METHODS
36  
37 Beyond the methods documented below, this class inherits methods from the
38 L<RDF::Query::Algebra> class.
39  
40 =over 4
41  
42 =cut
43  
44 =item C<new ( $start, [ $op, @paths ], $end, $graph )>
45  
46 Returns a new Path structure.
47  
48 =cut
49  
50 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
51 5 my $class = shift;
52 5 my $start = shift;
53 5 my $path = shift;
54 5 my $end = shift;
55 5 my $graph = shift;
56 5 return bless( [ $start, $path, $end, $graph ], $class );
57 }
58  
59 =item C<< construct_args >>
60  
61 Returns a list of arguments that, passed to this class' constructor,
62 will produce a clone of this algebra pattern.
63  
64 =cut
65  
66 30 ▶sub construct_args {
Subroutine construct_args: called CC=1 SCAR=0.0
Pod documented
67 30 my $self = shift;
68 30 return ($self->start, $self->path, $self->end, $self->graph);
69 }
70  
71 =item C<< path >>
72  
73 Returns the path description for this path expression.
74  
75 =cut
76  
77 60 ▶sub path {
Subroutine path: called CC=1 SCAR=0.0
Pod documented
78 60 my $self = shift;
79 60 return $self->[1];
80 }
81  
82 =item C<< start >>
83  
84 Returns the path origin node.
85  
86 =cut
87  
88 64 ▶sub start {
Subroutine start: called CC=1 SCAR=0.0
Pod documented
89 64 my $self = shift;
90 64 return $self->[0];
91 }
92  
93 =item C<< end >>
94  
95 Returns the path destination node.
96  
97 =cut
98  
99 64 ▶sub end {
Subroutine end: called CC=1 SCAR=0.0
Pod documented
100 64 my $self = shift;
101 64 return $self->[2];
102 }
103  
104 =item C<< graph >>
105  
106 Returns the named graph.
107  
108 =cut
109  
110 51 ▶sub graph {
Subroutine graph: called CC=1 SCAR=0.0
Pod documented
111 51 my $self = shift;
112 51 return $self->[3];
113 }
114  
115 =item C<< distinguish_bnode_variables >>
116  
117 Returns a new Path object with blank nodes replaced by distinguished variables.
118  
119 =cut
120  
121 0 ▶sub distinguish_bnode_variables {
Subroutine distinguish_bnode_variables: not called CC=3 SCAR=24.8
Pod documented
122 0 my $self = shift;
123 0 my $class = ref($self);
124 0 my @nodes = ($self->start, $self->end);
125 0 foreach my $i (0 .. $#nodes) {
126 0 ▶ if ($nodes[$i]->isa('RDF::Query::Node::Blank')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nodes[$i]->isa("RDF::Query::Node::Blank")) 0 0 0
127 0 $nodes[$i] = $nodes[$i]->make_distinguished_variable;
128 }
129 }
130 0 return $class->new( $nodes[0], $self->path, $nodes[1] );
131 }
132  
133 =item C<< bounded_length >>
134  
135 Returns true if the path is of bounded length.
136  
137 =cut
138  
139 0 ▶sub bounded_length {
Subroutine bounded_length: not called CC=1 SCAR=6.9
Pod documented
140 0 my $self = shift;
141 0 return $self->_bounded_length( $self->path );
142 }
143  
144 0 ▶sub _bounded_length {
Subroutine _bounded_length: not called CC=9 SCAR=45.0
145 0 my $self = shift;
146 0 my $array = shift;
147 0 ▶ return 1 if blessed($array);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($array) 0 0 0
148 0 my ($op, @nodes) = @$array;
149 0 ▶ return 1 if ($op eq '?');
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "?" 0 0 0
150 0 ▶ return 0 if ($op =~ /^[*+]$/);
Branch: 1 branch
BranchTrueFalseTotal
if $op =~ /^[*+]$/ 0 0 0
151 0 ▶ return 1 if ($op =~ /^\d+(-\d+)?$/);
Branch: 1 branch
BranchTrueFalseTotal
if $op =~ /^\d+(-\d+)?$/ 0 0 0
152 0 ▶ return 0 if ($op =~ /^\d+-$/);
Branch: 1 branch
BranchTrueFalseTotal
if $op =~ /^\d+-$/ 0 0 0
153 0 ▶ if ($op =~ m<^[/|^]$>) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ m[^[/|^]$]) 0 0 0
154 0 my @fixed = map { $self->_bounded_length($_) } @nodes;
155 0 foreach my $f (@fixed) {
156 0 ▶ return 0 unless ($f);
Branch: 1 branch
BranchTrueFalseTotal
unless $f 0 0 0
157 }
158 0 return 1;
159 }
160 }
161  
162 =item C<< sse >>
163  
164 Returns the SSE string for this algebra expression.
165  
166 =cut
167  
168 21 ▶sub sse {
Subroutine sse: called CC=3 SCAR=11.2
Pod documented
169 21 my $self = shift;
170 21 my $context = shift;
171 21 ▶ my $prefix = shift || '';
Condition100%2/2
shift() || ''
l!l
138
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
172 21 my $indent = $context->{indent};
173 21 my $start = $self->start->sse( $context, $prefix );
174 21 my $end = $self->end->sse( $context, $prefix );
175 21 my $path = $self->path;
176 21 my $psse = $self->_expand_path( $path, 'sse' );
177 21 ▶ if ($self->graph) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->graph) { } 0 21 21
178 0 my $graph = $self->graph->sse( $context, $prefix );
179 0 return sprintf( '(path %s %s %s %s)', $start, $psse, $end, $graph );
180 } else {
181 21 return sprintf( '(path %s %s %s)', $start, $psse, $end );
182 }
183 }
184  
185 =item C<< as_sparql >>
186  
187 Returns the SPARQL string for this algebra expression.
188  
189 =cut
190  
191 4 ▶sub as_sparql {
Subroutine as_sparql: called CC=2 SCAR=6.9
Pod documented
192 4 my $self = shift;
193 4 my $context = shift;
194 4 ▶ my $prefix = shift || '';
Condition50%1/2
shift() || ''
l!l
40
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
195 4 my $indent = $context->{indent};
196 4 my $start = $self->start->as_sparql( $context, $prefix );
197 4 my $end = $self->end->as_sparql( $context, $prefix );
198 4 my $path = $self->path;
199 4 my $psse = $self->_expand_path( $path, 'as_sparql' );
200 4 return sprintf( '%s %s %s .', $start, $psse, $end );
201 }
202  
203 87 ▶sub _expand_path {
Subroutine _expand_path: called CC=20 SCAR=43.8
204 87 my $self = shift;
205 87 my $array = shift;
206 87 my $method = shift;
207 87 ▶ if (blessed($array)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($array)) { } 50 37 87
208 50 my $string = $array->$method({}, '');
209 50 ▶ if ($string eq '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>') {
Branch: 1 branch
BranchTrueFalseTotal
if ($string eq '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>') { } 0 50 50
210 0 return 'a';
211 } else {
212 50 return $string;
213 }
214 } else {
215 37 my ($op, @nodes) = @$array;
216 37 my @nodessse = map { $self->_expand_path($_, $method) } @nodes;
217 37 my $psse;
218 # if ($op eq 'DISTINCT') {
219 # $psse = 'DISTINCT(' . join('/', @nodessse) . ')';
220 # }
221 37 ▶ if ($op eq '+') {
Branch: 10 branches
BranchTrueFalseTotal
if ($op eq '+') { } 6 31 37
elsif ($op eq '*') { } 6 25 31
elsif ($op eq '?') { } 0 25 25
elsif ($op eq '!') { } 0 25 25
elsif ($op eq '^') { } 0 25 25
elsif ($op eq '/') { } 25 0 25
elsif ($op eq '|') { } 0 0 0
elsif ($op =~ /^(\d+)$/) { } 0 0 0
elsif ($op =~ /^(\d+)-(\d+)$/) { } 0 0 0
elsif ($op =~ /^(\d+)-$/) { } 0 0 0
222 6 ▶ $psse = (scalar(@nodessse) == 1) ? $nodessse[0] . $op : '(' . join('/', @nodessse) . ')' . $op;
Branch: 1 branch
BranchTrueFalseTotal
scalar @nodessse == 1 ? : 6 0 6
223 } elsif ($op eq '*') {
224 6 ▶ $psse = (scalar(@nodessse) == 1) ? $nodessse[0] . $op : '(' . join('/', @nodessse) . ')' . $op;
Branch: 1 branch
BranchTrueFalseTotal
scalar @nodessse == 1 ? : 6 0 6
225 } elsif ($op eq '?') {
226 0 ▶ $psse = (scalar(@nodessse) == 1) ? $nodessse[0] . $op : '(' . join('/', @nodessse) . ')' . $op;
Branch: 1 branch
BranchTrueFalseTotal
scalar @nodessse == 1 ? : 0 0 0
227 } elsif ($op eq '!') {
228 0 ▶ $psse = (scalar(@nodessse) == 1) ? '!' . $nodessse[0] : '!(' . join('|', @nodessse) . ')';
Branch: 1 branch
BranchTrueFalseTotal
scalar @nodessse == 1 ? : 0 0 0
229 } elsif ($op eq '^') {
230 0 ▶ $psse = (scalar(@nodessse) == 1) ? $op . $nodessse[0] : '(' . join('/', map { "${op}$_" } @nodessse) . ')';
Branch: 1 branch
BranchTrueFalseTotal
scalar @nodessse == 1 ? : 0 0 0
231 } elsif ($op eq '/') {
232 25 ▶ $psse = (scalar(@nodessse) == 1) ? $nodessse[0] : '(' . join('/', @nodessse) . ')';
Branch: 1 branch
BranchTrueFalseTotal
scalar @nodessse == 1 ? : 0 25 25
233 } elsif ($op eq '|') {
234 0 ▶ $psse = (scalar(@nodessse) == 1) ? $nodessse[0] : '(' . join('|', @nodessse) . ')';
Branch: 1 branch
BranchTrueFalseTotal
scalar @nodessse == 1 ? : 0 0 0
235 } elsif ($op =~ /^(\d+)$/) {
236 0 $psse = join('/', @nodessse) . '{' . $op . '}';
237 } elsif ($op =~ /^(\d+)-(\d+)$/) {
238 0 $psse = join('/', @nodessse) . "{$1,$2}";
239 } elsif ($op =~ /^(\d+)-$/) {
240 0 $psse = join('/', @nodessse) . "{$1,}";
241 } else {
242 0 confess "Serialization of unknown path type $op";
243 }
244 37 return $psse;
245 }
246 }
247  
248 =item C<< type >>
249  
250 Returns the type of this algebra expression.
251  
252 =cut
253  
254 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
255 0 return 'PATH';
256 }
257  
258 =item C<< referenced_variables >>
259  
260 Returns a list of the variable names used in this algebra expression.
261  
262 =cut
263  
264 0 ▶sub referenced_variables {
Subroutine referenced_variables: not called CC=1 SCAR=6.9
Pod documented
265 0 my $self = shift;
266 0 my @vars = grep { $_->isa('RDF::Query::Node::Variable') } ($self->start, $self->end);
267 0 return RDF::Query::_uniq(map { $_->name } @vars);
268 }
269  
270 =item C<< potentially_bound >>
271  
272 Returns a list of the variable names used in this algebra expression that will
273 bind values during execution.
274  
275 =cut
276  
277 4 ▶sub potentially_bound {
Subroutine potentially_bound: called CC=1 SCAR=0.0
Pod documented
278 4 my $self = shift;
279 4 my @vars = grep { $_->isa('RDF::Query::Node::Variable') } ($self->start, $self->end);
280 4 return RDF::Query::_uniq(map { $_->name } @vars);
281 }
282  
283 =item C<< definite_variables >>
284  
285 Returns a list of the variable names that will be bound after evaluating this algebra expression.
286  
287 =cut
288  
289 0 ▶sub definite_variables {
Subroutine definite_variables: not called CC=1 SCAR=6.9
Pod documented
290 0 my $self = shift;
291 0 return $self->referenced_variables;
292 }
293  
294 36 1;
295  
296 __END__
« Query/Plan/Minus.pm ↑ Summary Query/Plan/Join.pm »