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.916. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Algebra::Project; |
15
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
184
|
use strict; |
|
36
|
|
|
|
|
80
|
|
|
36
|
|
|
|
|
946
|
|
17
|
36
|
|
|
36
|
|
186
|
use warnings; |
|
36
|
|
|
|
|
73
|
|
|
36
|
|
|
|
|
1044
|
|
18
|
36
|
|
|
36
|
|
177
|
no warnings 'redefine'; |
|
36
|
|
|
|
|
70
|
|
|
36
|
|
|
|
|
1154
|
|
19
|
36
|
|
|
36
|
|
174
|
use base qw(RDF::Query::Algebra); |
|
36
|
|
|
|
|
76
|
|
|
36
|
|
|
|
|
2694
|
|
20
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
210
|
use Data::Dumper; |
|
36
|
|
|
|
|
80
|
|
|
36
|
|
|
|
|
1648
|
|
22
|
36
|
|
|
36
|
|
200
|
use Set::Scalar; |
|
36
|
|
|
|
|
70
|
|
|
36
|
|
|
|
|
1359
|
|
23
|
36
|
|
|
36
|
|
194
|
use Scalar::Util qw(reftype blessed refaddr); |
|
36
|
|
|
|
|
80
|
|
|
36
|
|
|
|
|
2111
|
|
24
|
36
|
|
|
36
|
|
183
|
use Carp qw(carp croak confess); |
|
36
|
|
|
|
|
77
|
|
|
36
|
|
|
|
|
2057
|
|
25
|
36
|
|
|
36
|
|
194
|
use RDF::Trine::Iterator qw(sgrep); |
|
36
|
|
|
|
|
76
|
|
|
36
|
|
|
|
|
2275
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
###################################################################### |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our ($VERSION); |
30
|
|
|
|
|
|
|
BEGIN { |
31
|
36
|
|
|
36
|
|
91742
|
$VERSION = '2.916'; |
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
|
173
|
|
|
173
|
1
|
355
|
my $class = shift; |
53
|
173
|
|
|
|
|
297
|
my $pattern = shift; |
54
|
173
|
|
|
|
|
295
|
my $vars = shift; |
55
|
173
|
50
|
|
|
|
856
|
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
|
173
|
50
|
33
|
|
|
1535
|
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
|
173
|
|
|
|
|
280
|
my @vars; |
62
|
173
|
|
|
|
|
1196
|
foreach my $v (@$vars) { |
63
|
274
|
100
|
|
|
|
1106
|
if ($v->isa('RDF::Query::Node::Variable')) { |
64
|
245
|
|
|
|
|
593
|
push(@vars, $v); |
65
|
|
|
|
|
|
|
} else { |
66
|
29
|
|
|
|
|
95
|
push(@vars, $v->alias); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
173
|
|
|
|
|
836
|
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
|
438
|
|
|
438
|
1
|
664
|
my $self = shift; |
81
|
438
|
|
|
|
|
998
|
my $pattern = $self->pattern; |
82
|
438
|
|
|
|
|
1083
|
my $vars = $self->vars; |
83
|
438
|
|
|
|
|
1313
|
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
|
826
|
|
|
826
|
1
|
1148
|
my $self = shift; |
94
|
826
|
50
|
|
|
|
1995
|
if (@_) { |
95
|
0
|
|
|
|
|
0
|
$self->[0] = shift; |
96
|
|
|
|
|
|
|
} |
97
|
826
|
|
|
|
|
2574
|
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
|
797
|
|
|
797
|
1
|
1085
|
my $self = shift; |
108
|
797
|
|
|
|
|
1688
|
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
|
322
|
my $self = shift; |
119
|
167
|
|
|
|
|
316
|
my $context = shift; |
120
|
167
|
|
100
|
|
|
742
|
my $prefix = shift || ''; |
121
|
167
|
|
50
|
|
|
611
|
my $indent = $context->{indent} || ' '; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $vars = join(' ', |
124
|
|
|
|
|
|
|
map { |
125
|
281
|
50
|
|
|
|
2094
|
($_->isa('RDF::Query::Node::Variable')) ? '?' . $_->name : $_->sse( $context ) |
126
|
167
|
|
|
|
|
318
|
} @{ $self->vars } |
|
167
|
|
|
|
|
528
|
|
127
|
|
|
|
|
|
|
); |
128
|
167
|
|
|
|
|
1683
|
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
|
27
|
|
|
27
|
1
|
38
|
my $self = shift; |
174
|
27
|
|
50
|
|
|
68
|
my $context = shift || {}; |
175
|
27
|
|
|
|
|
42
|
my $indent = shift; |
176
|
|
|
|
|
|
|
|
177
|
27
|
|
|
|
|
66
|
my $pattern = $self->pattern; |
178
|
27
|
|
|
|
|
63
|
$context->{ force_ggp_braces }++; |
179
|
|
|
|
|
|
|
|
180
|
27
|
|
|
|
|
42
|
my ($vars, $_sparql); |
181
|
27
|
|
|
|
|
63
|
my $vlist = $self->vars; |
182
|
27
|
|
|
|
|
38
|
my (@vars); |
183
|
27
|
|
|
|
|
61
|
foreach my $k (@$vlist) { |
184
|
32
|
50
|
|
|
|
253
|
if ($k->isa('RDF::Query::Expression')) { |
|
|
50
|
|
|
|
|
|
185
|
0
|
|
|
|
|
0
|
push(@vars, $k->sse({}, '')); |
186
|
|
|
|
|
|
|
} elsif ($k->isa('RDF::Query::Node::Variable')) { |
187
|
32
|
|
|
|
|
94
|
push(@vars, '?' . $k->name); |
188
|
|
|
|
|
|
|
} else { |
189
|
0
|
|
|
|
|
0
|
push(@vars, $k); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
27
|
|
|
|
|
161
|
my $aggregate = 0; |
194
|
27
|
|
|
|
|
39
|
my $group = ''; |
195
|
27
|
|
|
|
|
42
|
my $having = ''; |
196
|
27
|
|
|
|
|
36
|
my $order = ''; |
197
|
27
|
|
|
|
|
32
|
my %agg_projections; |
198
|
27
|
|
|
|
|
87
|
my @aggs = $pattern->subpatterns_of_type( 'RDF::Query::Algebra::Aggregate' ); |
199
|
27
|
100
|
|
|
|
74
|
if (@aggs) { |
200
|
|
|
|
|
|
|
# aggregate check |
201
|
1
|
|
|
|
|
1
|
my $p = $pattern; |
202
|
1
|
50
|
|
|
|
7
|
if ($p->isa('RDF::Query::Algebra::Sort')) { |
203
|
1
|
|
|
|
|
3
|
$context->{ skip_sort }++; |
204
|
1
|
|
|
|
|
6
|
$order = $p->_as_sparql_order_exprs( $context, $indent ); |
205
|
1
|
|
|
|
|
5
|
$p = $p->pattern |
206
|
|
|
|
|
|
|
} |
207
|
1
|
50
|
|
|
|
6
|
if ($p->isa('RDF::Query::Algebra::Filter')) { |
208
|
1
|
|
|
|
|
3
|
$context->{ skip_filter }++; |
209
|
1
|
|
|
|
|
4
|
$having = $p->expr->as_sparql( $context, $indent ); |
210
|
1
|
|
|
|
|
16
|
$p = $p->pattern; |
211
|
|
|
|
|
|
|
} |
212
|
1
|
50
|
33
|
|
|
8
|
$p = ($p->patterns)[0] if ($p->isa('RDF::Query::Algebra::GroupGraphPattern') and scalar(@{[$p->patterns]}) == 1); |
|
1
|
|
|
|
|
4
|
|
213
|
1
|
50
|
33
|
|
|
9
|
if ($p->isa('RDF::Query::Algebra::Extend') and $p->pattern->isa('RDF::Query::Algebra::Aggregate')) { |
214
|
1
|
|
|
|
|
5
|
my $pp = $p->pattern; |
215
|
1
|
|
|
|
|
3
|
$context->{ skip_extend }++; |
216
|
1
|
|
|
|
|
4
|
my $vlist = $p->vars; |
217
|
1
|
|
|
|
|
3
|
foreach my $k (@$vlist) { |
218
|
1
|
50
|
|
|
|
8
|
if ($k->isa('RDF::Query::Expression::Alias')) { |
219
|
1
|
|
|
|
|
3
|
my $var = $k->name; |
220
|
1
|
|
|
|
|
9
|
my $expr = $k->expression; |
221
|
1
|
|
|
|
|
2
|
my $exprstr; |
222
|
1
|
50
|
|
|
|
7
|
if ($expr->isa('RDF::Query::Expression::Binary')) { |
223
|
0
|
|
|
|
|
0
|
$exprstr = $expr->as_sparql( $context, $indent ); |
224
|
|
|
|
|
|
|
} else { |
225
|
1
|
|
|
|
|
5
|
$exprstr = $k->expression->name; |
226
|
|
|
|
|
|
|
} |
227
|
1
|
|
|
|
|
7
|
my $str = "($exprstr AS ?$var)"; |
228
|
1
|
|
|
|
|
5
|
$agg_projections{ '?' . $var } = $str; |
229
|
|
|
|
|
|
|
} else { |
230
|
0
|
|
|
|
|
0
|
warn Dumper($k) . ' '; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
1
|
|
|
|
|
5
|
my @groups = $pp->groupby; |
235
|
1
|
50
|
|
|
|
4
|
if (@groups) { |
236
|
1
|
|
|
|
|
3
|
$group = join(' ', map { $_->as_sparql($context, $indent) } @groups); |
|
1
|
|
|
|
|
4
|
|
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
27
|
50
|
|
|
|
161
|
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
|
27
|
100
|
|
|
|
72
|
my $pvars = join(' ', map { my $agg = $agg_projections{ "?$_" }; defined($agg) ? $agg : "?$_" } sort $self->pattern->referenced_variables); |
|
48
|
|
|
|
|
90
|
|
|
48
|
|
|
|
|
167
|
|
269
|
27
|
100
|
|
|
|
75
|
my $svars = join(' ', map { my $agg = $agg_projections{ $_ }; defined($agg) ? $agg : $_ } sort @vars); |
|
32
|
|
|
|
|
56
|
|
|
32
|
|
|
|
|
106
|
|
270
|
27
|
100
|
|
|
|
88
|
$vars = ($pvars eq $svars) ? '*' : join(' ', map { my $agg = $agg_projections{ $_ }; defined($agg) ? $agg : $_ } @vars); |
|
15
|
100
|
|
|
|
23
|
|
|
15
|
|
|
|
|
52
|
|
271
|
27
|
|
|
|
|
114
|
$_sparql = $pattern->as_sparql( $context, $indent ); |
272
|
|
|
|
|
|
|
} |
273
|
27
|
|
|
|
|
79
|
my $sparql = sprintf("%s WHERE %s", $vars, $_sparql); |
274
|
27
|
100
|
|
|
|
69
|
if ($group) { |
275
|
1
|
|
|
|
|
4
|
$sparql .= "\n${indent}GROUP BY $group"; |
276
|
|
|
|
|
|
|
} |
277
|
27
|
100
|
|
|
|
65
|
if ($having) { |
278
|
1
|
|
|
|
|
2
|
$sparql .= "\n${indent}HAVING $having"; |
279
|
|
|
|
|
|
|
} |
280
|
27
|
100
|
|
|
|
64
|
if ($order) { |
281
|
1
|
|
|
|
|
3
|
$sparql .= "\n${indent}ORDER BY $order"; |
282
|
|
|
|
|
|
|
} |
283
|
27
|
|
|
|
|
157
|
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
|
30
|
|
|
30
|
1
|
1333
|
my $self = shift; |
346
|
30
|
|
|
|
|
498
|
my @vars = $self->pattern->referenced_variables; |
347
|
30
|
|
|
|
|
97
|
foreach my $v (@{ $self->vars }) { |
|
30
|
|
|
|
|
81
|
|
348
|
35
|
50
|
|
|
|
154
|
if ($v->isa('RDF::Query::Node::Variable')) { |
349
|
35
|
|
|
|
|
98
|
push(@vars, $v->name); |
350
|
|
|
|
|
|
|
} else { |
351
|
0
|
|
|
|
|
0
|
push(@vars, $v->referenced_variables); |
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
} |
354
|
30
|
|
|
|
|
228
|
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
|
|
|
|
|
2
|
my @vars; |
390
|
|
|
|
|
|
|
# push(@vars, $self->pattern->potentially_bound); |
391
|
1
|
|
|
|
|
3
|
foreach my $v (@{ $self->vars }) { |
|
1
|
|
|
|
|
5
|
|
392
|
1
|
50
|
|
|
|
4
|
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
|
|
|
|
|
8
|
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
|
6
|
my $self = shift; |
409
|
3
|
|
|
|
|
11
|
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
|
821
|
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 |