line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Query::Algebra::Optional |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Algebra::Optional - Algebra class for Optional patterns |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Algebra::Optional version 2.916. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Algebra::Optional; |
15
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
782
|
use strict; |
|
36
|
|
|
|
|
78
|
|
|
36
|
|
|
|
|
951
|
|
17
|
36
|
|
|
36
|
|
206
|
use warnings; |
|
36
|
|
|
|
|
67
|
|
|
36
|
|
|
|
|
1017
|
|
18
|
36
|
|
|
36
|
|
175
|
no warnings 'redefine'; |
|
36
|
|
|
|
|
66
|
|
|
36
|
|
|
|
|
1175
|
|
19
|
36
|
|
|
36
|
|
177
|
use base qw(RDF::Query::Algebra); |
|
36
|
|
|
|
|
69
|
|
|
36
|
|
|
|
|
2615
|
|
20
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
189
|
use Data::Dumper; |
|
36
|
|
|
|
|
78
|
|
|
36
|
|
|
|
|
1795
|
|
22
|
36
|
|
|
36
|
|
187
|
use Carp qw(carp croak confess); |
|
36
|
|
|
|
|
76
|
|
|
36
|
|
|
|
|
2207
|
|
23
|
36
|
|
|
36
|
|
245
|
use RDF::Trine::Iterator qw(smap sgrep swatch); |
|
36
|
|
|
|
|
84
|
|
|
36
|
|
|
|
|
2908
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
###################################################################### |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our ($VERSION); |
28
|
|
|
|
|
|
|
BEGIN { |
29
|
36
|
|
|
36
|
|
24930
|
$VERSION = '2.916'; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
###################################################################### |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
37
|
|
|
|
|
|
|
L<RDF::Query::Algebra> class. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over 4 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item C<new ( $pattern, $opt_pattern )> |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Returns a new Optional structure. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
50
|
14
|
|
|
14
|
1
|
32
|
my $class = shift; |
51
|
14
|
|
|
|
|
27
|
my $pattern = shift; |
52
|
14
|
|
|
|
|
38
|
my $opt = shift; |
53
|
14
|
|
|
|
|
63
|
return bless( [ 'OPTIONAL', $pattern, $opt ], $class ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item C<< construct_args >> |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Returns a list of arguments that, passed to this class' constructor, |
59
|
|
|
|
|
|
|
will produce a clone of this algebra pattern. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub construct_args { |
64
|
52
|
|
|
52
|
1
|
78
|
my $self = shift; |
65
|
52
|
|
|
|
|
133
|
return ($self->pattern, $self->optional); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item C<< pattern >> |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Returns the base pattern (LHS) onto which the optional pattern joins. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub pattern { |
75
|
109
|
|
|
109
|
1
|
143
|
my $self = shift; |
76
|
109
|
|
|
|
|
411
|
return $self->[1]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item C<< optional >> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Returns the optional pattern (RHS). |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub optional { |
86
|
107
|
|
|
107
|
1
|
149
|
my $self = shift; |
87
|
107
|
|
|
|
|
379
|
return $self->[2]; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item C<< sse >> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Returns the SSE string for this algebra expression. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub sse { |
97
|
38
|
|
|
38
|
1
|
60
|
my $self = shift; |
98
|
38
|
|
|
|
|
54
|
my $context = shift; |
99
|
38
|
|
100
|
|
|
134
|
my $prefix = shift || ''; |
100
|
38
|
|
50
|
|
|
107
|
my $indent = $context->{indent} || ' '; |
101
|
|
|
|
|
|
|
|
102
|
38
|
|
|
|
|
145
|
return sprintf( |
103
|
|
|
|
|
|
|
"(leftjoin\n${prefix}${indent}%s\n${prefix}${indent}%s)", |
104
|
|
|
|
|
|
|
$self->pattern->sse( $context, "${prefix}${indent}" ), |
105
|
|
|
|
|
|
|
$self->optional->sse( $context, "${prefix}${indent}" ) |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item C<< as_sparql >> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Returns the SPARQL string for this algebra expression. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub as_sparql { |
116
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
117
|
2
|
|
|
|
|
4
|
my $context = shift; |
118
|
2
|
|
|
|
|
4
|
my $indent = shift; |
119
|
2
|
|
|
|
|
8
|
my $string = sprintf( |
120
|
|
|
|
|
|
|
"%s\n${indent}OPTIONAL %s", |
121
|
|
|
|
|
|
|
$self->pattern->as_sparql( $context, $indent ), |
122
|
|
|
|
|
|
|
$self->optional->as_sparql( { %$context, force_ggp_braces => 1 }, $indent ), |
123
|
|
|
|
|
|
|
); |
124
|
2
|
|
|
|
|
9
|
return $string; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item C<< as_spin ( $model ) >> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Adds statements to the given model to represent this algebra object in the |
130
|
|
|
|
|
|
|
SPARQL Inferencing Notation (L<http://www.spinrdf.org/>). |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub as_spin { |
135
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
136
|
0
|
|
|
|
|
0
|
my $model = shift; |
137
|
0
|
|
|
|
|
0
|
my $spin = RDF::Trine::Namespace->new('http://spinrdf.org/spin#'); |
138
|
0
|
|
|
|
|
0
|
my $rdf = RDF::Trine::Namespace->new('http://www.w3.org/1999/02/22-rdf-syntax-ns#'); |
139
|
0
|
|
|
|
|
0
|
my @lhs = $self->pattern->as_spin($model); |
140
|
0
|
|
|
|
|
0
|
my @rhs = $self->optional->as_spin($model); |
141
|
0
|
|
|
|
|
0
|
my $opt = RDF::Query::Node::Blank->new(); |
142
|
0
|
|
|
|
|
0
|
my $list = $model->add_list( @rhs ); |
143
|
0
|
|
|
|
|
0
|
$model->add_statement( RDF::Trine::Statement->new($opt, $rdf->type, $spin->Optional) ); |
144
|
0
|
|
|
|
|
0
|
$model->add_statement( RDF::Trine::Statement->new($opt, $spin->elements, $list) ); |
145
|
0
|
|
|
|
|
0
|
return (@lhs, $opt); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item C<< as_hash >> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Returns the query as a nested set of plain data structures (no objects). |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub as_hash { |
155
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
156
|
0
|
|
|
|
|
0
|
my $context = shift; |
157
|
|
|
|
|
|
|
return { |
158
|
0
|
|
|
|
|
0
|
type => lc($self->type), |
159
|
|
|
|
|
|
|
pattern => $self->pattern->as_hash, |
160
|
|
|
|
|
|
|
optional => $self->optional->as_hash, |
161
|
|
|
|
|
|
|
}; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item C<< type >> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Returns the type of this algebra expression. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub type { |
171
|
0
|
|
|
0
|
1
|
0
|
return 'OPTIONAL'; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item C<< referenced_variables >> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub referenced_variables { |
181
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
182
|
2
|
|
|
|
|
7
|
return RDF::Query::_uniq($self->pattern->referenced_variables, $self->optional->referenced_variables); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item C<< potentially_bound >> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression that will |
188
|
|
|
|
|
|
|
bind values during execution. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub potentially_bound { |
193
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
194
|
2
|
|
|
|
|
8
|
return RDF::Query::_uniq($self->pattern->potentially_bound, $self->optional->potentially_bound); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item C<< definite_variables >> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Returns a list of the variable names that will be bound after evaluating this algebra expression. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub definite_variables { |
204
|
2
|
|
|
2
|
1
|
3
|
my $self = shift; |
205
|
2
|
|
|
|
|
6
|
return $self->pattern->definite_variables; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
__END__ |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=back |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 AUTHOR |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |