| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# RDF::Query::Algebra::Project |
|
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Algebra::Project - Algebra class for projection |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Algebra::Project version 2.918. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Algebra::Project; |
|
15
|
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
148
|
use strict; |
|
|
36
|
|
|
|
|
56
|
|
|
|
36
|
|
|
|
|
917
|
|
|
17
|
36
|
|
|
36
|
|
131
|
use warnings; |
|
|
36
|
|
|
|
|
49
|
|
|
|
36
|
|
|
|
|
795
|
|
|
18
|
36
|
|
|
36
|
|
121
|
no warnings 'redefine'; |
|
|
36
|
|
|
|
|
50
|
|
|
|
36
|
|
|
|
|
920
|
|
|
19
|
36
|
|
|
36
|
|
138
|
use base qw(RDF::Query::Algebra); |
|
|
36
|
|
|
|
|
46
|
|
|
|
36
|
|
|
|
|
2213
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
154
|
use Data::Dumper; |
|
|
36
|
|
|
|
|
45
|
|
|
|
36
|
|
|
|
|
1439
|
|
|
22
|
36
|
|
|
36
|
|
145
|
use Set::Scalar; |
|
|
36
|
|
|
|
|
82
|
|
|
|
36
|
|
|
|
|
1080
|
|
|
23
|
36
|
|
|
36
|
|
132
|
use Scalar::Util qw(reftype blessed refaddr); |
|
|
36
|
|
|
|
|
72
|
|
|
|
36
|
|
|
|
|
1662
|
|
|
24
|
36
|
|
|
36
|
|
137
|
use Carp qw(carp croak confess); |
|
|
36
|
|
|
|
|
55
|
|
|
|
36
|
|
|
|
|
1561
|
|
|
25
|
36
|
|
|
36
|
|
146
|
use RDF::Trine::Iterator qw(sgrep); |
|
|
36
|
|
|
|
|
49
|
|
|
|
36
|
|
|
|
|
1767
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
###################################################################### |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our ($VERSION); |
|
30
|
|
|
|
|
|
|
BEGIN { |
|
31
|
36
|
|
|
36
|
|
61126
|
$VERSION = '2.918'; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
###################################################################### |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
|
39
|
|
|
|
|
|
|
L<RDF::Query::Algebra> class. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=over 4 |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item C<< new ( $pattern, \@vars_and_exprs ) >> |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Returns a new Project structure. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new { |
|
52
|
175
|
|
|
175
|
1
|
254
|
my $class = shift; |
|
53
|
175
|
|
|
|
|
228
|
my $pattern = shift; |
|
54
|
175
|
|
|
|
|
277
|
my $vars = shift; |
|
55
|
175
|
50
|
|
|
|
685
|
unless (blessed($pattern)) { |
|
56
|
0
|
|
|
|
|
0
|
throw RDF::Query::Error::MethodInvocationError -text => "Sub-pattern in RDF::Query::Algebra::Project constructor must be a valid algebra object"; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
175
|
50
|
33
|
|
|
1288
|
unless (reftype($vars) eq 'ARRAY' and not(blessed($vars))) { |
|
59
|
0
|
|
|
|
|
0
|
throw RDF::Query::Error::MethodInvocationError -text => "Variable list in RDF::Query::Algebra::Project constructor must be an ARRAY reference"; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
175
|
|
|
|
|
224
|
my @vars; |
|
62
|
175
|
|
|
|
|
1024
|
foreach my $v (@$vars) { |
|
63
|
280
|
100
|
|
|
|
794
|
if ($v->isa('RDF::Query::Node::Variable')) { |
|
64
|
251
|
|
|
|
|
392
|
push(@vars, $v); |
|
65
|
|
|
|
|
|
|
} else { |
|
66
|
29
|
|
|
|
|
75
|
push(@vars, $v->alias); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
175
|
|
|
|
|
676
|
return bless( [ $pattern, \@vars ], $class ); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item C<< construct_args >> |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Returns a list of arguments that, passed to this class' constructor, |
|
75
|
|
|
|
|
|
|
will produce a clone of this algebra pattern. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub construct_args { |
|
80
|
440
|
|
|
440
|
1
|
422
|
my $self = shift; |
|
81
|
440
|
|
|
|
|
760
|
my $pattern = $self->pattern; |
|
82
|
440
|
|
|
|
|
767
|
my $vars = $self->vars; |
|
83
|
440
|
|
|
|
|
897
|
return ($pattern, $vars); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item C<< pattern >> |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns the pattern to be sorted. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub pattern { |
|
93
|
834
|
|
|
834
|
1
|
744
|
my $self = shift; |
|
94
|
834
|
50
|
|
|
|
1455
|
if (@_) { |
|
95
|
0
|
|
|
|
|
0
|
$self->[0] = shift; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
834
|
|
|
|
|
1816
|
return $self->[0]; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item C<< vars >> |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Returns the vars to be projected to. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub vars { |
|
107
|
803
|
|
|
803
|
1
|
728
|
my $self = shift; |
|
108
|
803
|
|
|
|
|
1103
|
return $self->[1]; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item C<< sse >> |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Returns the SSE string for this algebra expression. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub sse { |
|
118
|
167
|
|
|
167
|
1
|
240
|
my $self = shift; |
|
119
|
167
|
|
|
|
|
201
|
my $context = shift; |
|
120
|
167
|
|
100
|
|
|
560
|
my $prefix = shift || ''; |
|
121
|
167
|
|
50
|
|
|
439
|
my $indent = $context->{indent} || ' '; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $vars = join(' ', |
|
124
|
|
|
|
|
|
|
map { |
|
125
|
281
|
50
|
|
|
|
1589
|
($_->isa('RDF::Query::Node::Variable')) ? '?' . $_->name : $_->sse( $context ) |
|
126
|
167
|
|
|
|
|
255
|
} @{ $self->vars } |
|
|
167
|
|
|
|
|
381
|
|
|
127
|
|
|
|
|
|
|
); |
|
128
|
167
|
|
|
|
|
1403
|
return sprintf( |
|
129
|
|
|
|
|
|
|
"(project (%s)\n${prefix}${indent}%s\n${prefix})", |
|
130
|
|
|
|
|
|
|
$vars, |
|
131
|
|
|
|
|
|
|
$self->pattern->sse( $context, "${prefix}${indent}" ), |
|
132
|
|
|
|
|
|
|
); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub _from_sse { |
|
136
|
0
|
|
|
0
|
|
0
|
my $class = shift; |
|
137
|
0
|
|
|
|
|
0
|
my $context = $_[1]; |
|
138
|
0
|
|
|
|
|
0
|
for ($_[0]) { |
|
139
|
0
|
0
|
|
|
|
0
|
if (m/^[(]project\s+[(]\s*/) { |
|
140
|
0
|
|
|
|
|
0
|
my @nodes; |
|
141
|
0
|
|
|
|
|
0
|
s/^[(]project\s+[(]\s*//; |
|
142
|
0
|
|
|
|
|
0
|
do { |
|
143
|
0
|
|
|
|
|
0
|
push(@nodes, RDF::Trine::Node->from_sse( $_[0], $context )); |
|
144
|
|
|
|
|
|
|
} until (m/\s*[)]/); |
|
145
|
0
|
0
|
|
|
|
0
|
if (m/^\s*[)]/) { |
|
146
|
0
|
|
|
|
|
0
|
s/^\s*[)]\s*//; |
|
147
|
|
|
|
|
|
|
} else { |
|
148
|
0
|
|
|
|
|
0
|
throw RDF::Trine::Error -text => "Cannot parse end-of-project-vars from SSE string: >>$_<<"; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
0
|
my ($pattern) = RDF::Query::Algebra->from_sse( $context, $_[0] ); |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
0
|
if (m/^\s*[)]/) { |
|
154
|
0
|
|
|
|
|
0
|
s/^\s*[)]\s*//; |
|
155
|
0
|
|
|
|
|
0
|
warn "project: " . Dumper(\@nodes); |
|
156
|
0
|
|
|
|
|
0
|
return RDF::Query::Algebra::Project->new( $pattern, \@nodes ); |
|
157
|
|
|
|
|
|
|
} else { |
|
158
|
0
|
|
|
|
|
0
|
throw RDF::Trine::Error -text => "Cannot parse end-of-project from SSE string: >>$_<<"; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
} else { |
|
161
|
0
|
|
|
|
|
0
|
throw RDF::Trine::Error -text => "Cannot parse project from SSE string: >>$_<<"; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item C<< as_sparql >> |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns the SPARQL string for this algebra expression. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub as_sparql { |
|
173
|
29
|
|
|
29
|
1
|
36
|
my $self = shift; |
|
174
|
29
|
|
50
|
|
|
60
|
my $context = shift || {}; |
|
175
|
29
|
|
|
|
|
31
|
my $indent = shift; |
|
176
|
|
|
|
|
|
|
|
|
177
|
29
|
|
|
|
|
54
|
my $pattern = $self->pattern; |
|
178
|
29
|
|
|
|
|
66
|
$context->{ force_ggp_braces }++; |
|
179
|
|
|
|
|
|
|
|
|
180
|
29
|
|
|
|
|
29
|
my ($vars, $_sparql); |
|
181
|
29
|
|
|
|
|
64
|
my $vlist = $self->vars; |
|
182
|
29
|
|
|
|
|
40
|
my (@vars); |
|
183
|
29
|
|
|
|
|
49
|
foreach my $k (@$vlist) { |
|
184
|
38
|
50
|
|
|
|
239
|
if ($k->isa('RDF::Query::Expression')) { |
|
|
|
50
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
0
|
push(@vars, $k->sse({}, '')); |
|
186
|
|
|
|
|
|
|
} elsif ($k->isa('RDF::Query::Node::Variable')) { |
|
187
|
38
|
|
|
|
|
79
|
push(@vars, '?' . $k->name); |
|
188
|
|
|
|
|
|
|
} else { |
|
189
|
0
|
|
|
|
|
0
|
push(@vars, $k); |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
29
|
|
|
|
|
133
|
my $aggregate = 0; |
|
194
|
29
|
|
|
|
|
32
|
my $group = ''; |
|
195
|
29
|
|
|
|
|
28
|
my $having = ''; |
|
196
|
29
|
|
|
|
|
32
|
my $order = ''; |
|
197
|
29
|
|
|
|
|
34
|
my %agg_projections; |
|
198
|
29
|
|
|
|
|
83
|
my @aggs = $pattern->subpatterns_of_type( 'RDF::Query::Algebra::Aggregate' ); |
|
199
|
29
|
100
|
|
|
|
75
|
if (@aggs) { |
|
200
|
|
|
|
|
|
|
# aggregate check |
|
201
|
1
|
|
|
|
|
2
|
my $p = $pattern; |
|
202
|
1
|
50
|
|
|
|
5
|
if ($p->isa('RDF::Query::Algebra::Sort')) { |
|
203
|
1
|
|
|
|
|
2
|
$context->{ skip_sort }++; |
|
204
|
1
|
|
|
|
|
6
|
$order = $p->_as_sparql_order_exprs( $context, $indent ); |
|
205
|
1
|
|
|
|
|
2
|
$p = $p->pattern |
|
206
|
|
|
|
|
|
|
} |
|
207
|
1
|
50
|
|
|
|
5
|
if ($p->isa('RDF::Query::Algebra::Filter')) { |
|
208
|
1
|
|
|
|
|
3
|
$context->{ skip_filter }++; |
|
209
|
1
|
|
|
|
|
3
|
$having = $p->expr->as_sparql( $context, $indent ); |
|
210
|
1
|
|
|
|
|
13
|
$p = $p->pattern; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
1
|
50
|
33
|
|
|
7
|
$p = ($p->patterns)[0] if ($p->isa('RDF::Query::Algebra::GroupGraphPattern') and scalar(@{[$p->patterns]}) == 1); |
|
|
1
|
|
|
|
|
4
|
|
|
213
|
1
|
50
|
33
|
|
|
7
|
if ($p->isa('RDF::Query::Algebra::Extend') and $p->pattern->isa('RDF::Query::Algebra::Aggregate')) { |
|
214
|
1
|
|
|
|
|
3
|
my $pp = $p->pattern; |
|
215
|
1
|
|
|
|
|
2
|
$context->{ skip_extend }++; |
|
216
|
1
|
|
|
|
|
3
|
my $vlist = $p->vars; |
|
217
|
1
|
|
|
|
|
2
|
foreach my $k (@$vlist) { |
|
218
|
1
|
50
|
|
|
|
4
|
if ($k->isa('RDF::Query::Expression::Alias')) { |
|
219
|
1
|
|
|
|
|
4
|
my $var = $k->name; |
|
220
|
1
|
|
|
|
|
6
|
my $expr = $k->expression; |
|
221
|
1
|
|
|
|
|
1
|
my $exprstr; |
|
222
|
1
|
50
|
|
|
|
5
|
if ($expr->isa('RDF::Query::Expression::Binary')) { |
|
223
|
0
|
|
|
|
|
0
|
$exprstr = $expr->as_sparql( $context, $indent ); |
|
224
|
|
|
|
|
|
|
} else { |
|
225
|
1
|
|
|
|
|
3
|
$exprstr = $k->expression->name; |
|
226
|
|
|
|
|
|
|
} |
|
227
|
1
|
|
|
|
|
5
|
my $str = "($exprstr AS ?$var)"; |
|
228
|
1
|
|
|
|
|
4
|
$agg_projections{ '?' . $var } = $str; |
|
229
|
|
|
|
|
|
|
} else { |
|
230
|
0
|
|
|
|
|
0
|
warn Dumper($k) . ' '; |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
} |
|
233
|
|
|
|
|
|
|
|
|
234
|
1
|
|
|
|
|
4
|
my @groups = $pp->groupby; |
|
235
|
1
|
50
|
|
|
|
4
|
if (@groups) { |
|
236
|
1
|
|
|
|
|
2
|
$group = join(' ', map { $_->as_sparql($context, $indent) } @groups); |
|
|
1
|
|
|
|
|
4
|
|
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
|
|
241
|
29
|
50
|
|
|
|
136
|
if ($pattern->isa('RDF::Query::Algebra::Extend')) { |
|
242
|
0
|
|
|
|
|
0
|
my %seen; |
|
243
|
0
|
|
|
|
|
0
|
my $vlist = $pattern->vars; |
|
244
|
0
|
|
|
|
|
0
|
foreach my $k (@$vlist) { |
|
245
|
0
|
0
|
|
|
|
0
|
if ($k->isa('RDF::Query::Expression::Alias')) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
0
|
$seen{ '?' . $k->name } = $k->as_sparql({}, ''); |
|
247
|
|
|
|
|
|
|
} elsif ($k->isa('RDF::Query::Expression')) { |
|
248
|
0
|
|
|
|
|
0
|
push(@vars, $k->as_sparql({}, '')); |
|
249
|
|
|
|
|
|
|
} elsif ($k->isa('RDF::Query::Node::Variable')) { |
|
250
|
0
|
|
|
|
|
0
|
push(@vars, '?' . $k->name); |
|
251
|
|
|
|
|
|
|
} else { |
|
252
|
0
|
|
|
|
|
0
|
push(@vars, $k); |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
} |
|
255
|
0
|
0
|
|
|
|
0
|
@vars = map { exists($seen{$_}) ? $seen{$_} : $_ } @vars; |
|
|
0
|
|
|
|
|
0
|
|
|
256
|
0
|
|
|
|
|
0
|
$vars = join(' ', @vars); |
|
257
|
0
|
|
|
|
|
0
|
my $pp = $pattern->pattern; |
|
258
|
0
|
0
|
|
|
|
0
|
if ($pp->isa('RDF::Query::Algebra::Aggregate')) { |
|
259
|
0
|
|
|
|
|
0
|
$_sparql = $pp->pattern->as_sparql( $context, $indent ); |
|
260
|
0
|
|
|
|
|
0
|
my @groups = $pp->groupby; |
|
261
|
0
|
0
|
|
|
|
0
|
if (@groups) { |
|
262
|
0
|
|
|
|
|
0
|
$group = join(' ', map { $_->as_sparql($context, $indent) } @groups); |
|
|
0
|
|
|
|
|
0
|
|
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
} else { |
|
265
|
0
|
|
|
|
|
0
|
$_sparql = $pp->as_sparql( $context, $indent ); |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
} else { |
|
268
|
29
|
100
|
|
|
|
73
|
my $pvars = join(' ', map { my $agg = $agg_projections{ "?$_" }; defined($agg) ? $agg : "?$_" } sort $self->pattern->referenced_variables); |
|
|
54
|
|
|
|
|
93
|
|
|
|
54
|
|
|
|
|
170
|
|
|
269
|
29
|
100
|
|
|
|
67
|
my $svars = join(' ', map { my $agg = $agg_projections{ $_ }; defined($agg) ? $agg : $_ } sort @vars); |
|
|
38
|
|
|
|
|
69
|
|
|
|
38
|
|
|
|
|
89
|
|
|
270
|
29
|
100
|
|
|
|
97
|
$vars = ($pvars eq $svars) ? '*' : join(' ', map { my $agg = $agg_projections{ $_ }; defined($agg) ? $agg : $_ } @vars); |
|
|
15
|
100
|
|
|
|
22
|
|
|
|
15
|
|
|
|
|
39
|
|
|
271
|
29
|
|
|
|
|
109
|
$_sparql = $pattern->as_sparql( $context, $indent ); |
|
272
|
|
|
|
|
|
|
} |
|
273
|
29
|
|
|
|
|
79
|
my $sparql = sprintf("%s WHERE %s", $vars, $_sparql); |
|
274
|
29
|
100
|
|
|
|
70
|
if ($group) { |
|
275
|
1
|
|
|
|
|
3
|
$sparql .= "\n${indent}GROUP BY $group"; |
|
276
|
|
|
|
|
|
|
} |
|
277
|
29
|
100
|
|
|
|
68
|
if ($having) { |
|
278
|
1
|
|
|
|
|
2
|
$sparql .= "\n${indent}HAVING $having"; |
|
279
|
|
|
|
|
|
|
} |
|
280
|
29
|
100
|
|
|
|
63
|
if ($order) { |
|
281
|
1
|
|
|
|
|
3
|
$sparql .= "\n${indent}ORDER BY $order"; |
|
282
|
|
|
|
|
|
|
} |
|
283
|
29
|
|
|
|
|
137
|
return $sparql; |
|
284
|
|
|
|
|
|
|
} |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=item C<< as_hash >> |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
Returns the query as a nested set of plain data structures (no objects). |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=cut |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
sub as_hash { |
|
293
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
294
|
0
|
|
|
|
|
0
|
my $context = shift; |
|
295
|
|
|
|
|
|
|
return { |
|
296
|
|
|
|
|
|
|
type => lc($self->type), |
|
297
|
0
|
|
|
|
|
0
|
variables => [ map { $_->as_hash } @{ $self->vars } ], |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
298
|
|
|
|
|
|
|
pattern => $self->pattern->as_hash, |
|
299
|
|
|
|
|
|
|
}; |
|
300
|
|
|
|
|
|
|
} |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=item C<< as_spin ( $model ) >> |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
Adds statements to the given model to represent this algebra object in the |
|
305
|
|
|
|
|
|
|
SPARQL Inferencing Notation (L<http://www.spinrdf.org/>). |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=cut |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
sub as_spin { |
|
310
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
311
|
0
|
|
|
|
|
0
|
my $model = shift; |
|
312
|
0
|
|
|
|
|
0
|
my $spin = RDF::Trine::Namespace->new('http://spinrdf.org/spin#'); |
|
313
|
0
|
|
|
|
|
0
|
my $rdf = RDF::Trine::Namespace->new('http://www.w3.org/1999/02/22-rdf-syntax-ns#'); |
|
314
|
0
|
|
|
|
|
0
|
my $q = RDF::Query::Node::Blank->new(); |
|
315
|
0
|
|
|
|
|
0
|
my @nodes = $self->pattern->as_spin( $model ); |
|
316
|
|
|
|
|
|
|
|
|
317
|
0
|
|
|
|
|
0
|
$model->add_statement( RDF::Trine::Statement->new($q, $rdf->type, $spin->Select) ); |
|
318
|
|
|
|
|
|
|
|
|
319
|
0
|
|
|
|
|
0
|
my @vars = map { RDF::Query::Node::Blank->new( "variable_" . $_->name ) } @{ $self->vars }; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
320
|
0
|
|
|
|
|
0
|
my $vlist = $model->add_list( @vars ); |
|
321
|
0
|
|
|
|
|
0
|
$model->add_statement( RDF::Trine::Statement->new($q, $spin->resultVariables, $vlist) ); |
|
322
|
|
|
|
|
|
|
|
|
323
|
0
|
|
|
|
|
0
|
my $list = $model->add_list( @nodes ); |
|
324
|
0
|
|
|
|
|
0
|
$model->add_statement( RDF::Trine::Statement->new($q, $spin->where, $list) ); |
|
325
|
0
|
|
|
|
|
0
|
return $q; |
|
326
|
|
|
|
|
|
|
} |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
=item C<< type >> |
|
329
|
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
Returns the type of this algebra expression. |
|
331
|
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=cut |
|
333
|
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
sub type { |
|
335
|
0
|
|
|
0
|
1
|
0
|
return 'PROJECT'; |
|
336
|
|
|
|
|
|
|
} |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=item C<< referenced_variables >> |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression. |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
=cut |
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
sub referenced_variables { |
|
345
|
32
|
|
|
32
|
1
|
1540
|
my $self = shift; |
|
346
|
32
|
|
|
|
|
80
|
my @vars = $self->pattern->referenced_variables; |
|
347
|
32
|
|
|
|
|
55
|
foreach my $v (@{ $self->vars }) { |
|
|
32
|
|
|
|
|
77
|
|
|
348
|
41
|
50
|
|
|
|
134
|
if ($v->isa('RDF::Query::Node::Variable')) { |
|
349
|
41
|
|
|
|
|
92
|
push(@vars, $v->name); |
|
350
|
|
|
|
|
|
|
} else { |
|
351
|
0
|
|
|
|
|
0
|
push(@vars, $v->referenced_variables); |
|
352
|
|
|
|
|
|
|
} |
|
353
|
|
|
|
|
|
|
} |
|
354
|
32
|
|
|
|
|
133
|
return RDF::Query::_uniq(@vars); |
|
355
|
|
|
|
|
|
|
} |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=item C<< bind_variables ( \%bound ) >> |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
Returns a new algebra pattern with variables named in %bound replaced by their corresponding bound values. |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
=cut |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
sub bind_variables { |
|
364
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
365
|
0
|
|
|
|
|
0
|
my $class = ref($self); |
|
366
|
0
|
|
|
|
|
0
|
my $bound = shift; |
|
367
|
0
|
|
|
|
|
0
|
my $pattern = $self->pattern->bind_variables( $bound ); |
|
368
|
0
|
|
|
|
|
0
|
my $vars = $self->vars; |
|
369
|
0
|
|
|
|
|
0
|
my @vars; |
|
370
|
0
|
|
|
|
|
0
|
foreach my $v (@$vars) { |
|
371
|
0
|
0
|
0
|
|
|
0
|
if (blessed($v) and $v->isa('RDF::Query::Node::Variable') and exists $bound->{ $v->name }) { |
|
|
|
|
0
|
|
|
|
|
|
372
|
0
|
|
|
|
|
0
|
push(@vars, $bound->{ $v->name }); |
|
373
|
|
|
|
|
|
|
} else { |
|
374
|
0
|
|
|
|
|
0
|
push(@vars, $v); |
|
375
|
|
|
|
|
|
|
} |
|
376
|
|
|
|
|
|
|
} |
|
377
|
0
|
|
|
|
|
0
|
return $class->new( $pattern, \@vars ); |
|
378
|
|
|
|
|
|
|
} |
|
379
|
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
=item C<< potentially_bound >> |
|
381
|
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression that will |
|
383
|
|
|
|
|
|
|
bind values during execution. |
|
384
|
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
=cut |
|
386
|
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
sub potentially_bound { |
|
388
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
389
|
1
|
|
|
|
|
1
|
my @vars; |
|
390
|
|
|
|
|
|
|
# push(@vars, $self->pattern->potentially_bound); |
|
391
|
1
|
|
|
|
|
2
|
foreach my $v (@{ $self->vars }) { |
|
|
1
|
|
|
|
|
5
|
|
|
392
|
1
|
50
|
|
|
|
3
|
if ($v->isa('RDF::Query::Node::Variable')) { |
|
393
|
1
|
|
|
|
|
5
|
push(@vars, $v->name); |
|
394
|
|
|
|
|
|
|
} else { |
|
395
|
0
|
|
|
|
|
0
|
push(@vars, $v->potentially_bound); |
|
396
|
|
|
|
|
|
|
} |
|
397
|
|
|
|
|
|
|
} |
|
398
|
1
|
|
|
|
|
6
|
return RDF::Query::_uniq(@vars); |
|
399
|
|
|
|
|
|
|
} |
|
400
|
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
=item C<< definite_variables >> |
|
402
|
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
Returns a list of the variable names that will be bound after evaluating this algebra expression. |
|
404
|
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
=cut |
|
406
|
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
sub definite_variables { |
|
408
|
3
|
|
|
3
|
1
|
4
|
my $self = shift; |
|
409
|
3
|
|
|
|
|
8
|
return $self->pattern->definite_variables; |
|
410
|
|
|
|
|
|
|
} |
|
411
|
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
=item C<< is_solution_modifier >> |
|
413
|
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
Returns true if this node is a solution modifier. |
|
415
|
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
=cut |
|
417
|
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
sub is_solution_modifier { |
|
419
|
134
|
|
|
134
|
1
|
558
|
return 1; |
|
420
|
|
|
|
|
|
|
} |
|
421
|
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
1; |
|
424
|
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
__END__ |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
=back |
|
428
|
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
=head1 AUTHOR |
|
430
|
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
=cut |