| 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.918. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Algebra::Optional; |
|
15
|
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
586
|
use strict; |
|
|
36
|
|
|
|
|
51
|
|
|
|
36
|
|
|
|
|
870
|
|
|
17
|
36
|
|
|
36
|
|
126
|
use warnings; |
|
|
36
|
|
|
|
|
44
|
|
|
|
36
|
|
|
|
|
790
|
|
|
18
|
36
|
|
|
36
|
|
117
|
no warnings 'redefine'; |
|
|
36
|
|
|
|
|
38
|
|
|
|
36
|
|
|
|
|
899
|
|
|
19
|
36
|
|
|
36
|
|
124
|
use base qw(RDF::Query::Algebra); |
|
|
36
|
|
|
|
|
48
|
|
|
|
36
|
|
|
|
|
2133
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
143
|
use Data::Dumper; |
|
|
36
|
|
|
|
|
52
|
|
|
|
36
|
|
|
|
|
1432
|
|
|
22
|
36
|
|
|
36
|
|
129
|
use Carp qw(carp croak confess); |
|
|
36
|
|
|
|
|
52
|
|
|
|
36
|
|
|
|
|
1513
|
|
|
23
|
36
|
|
|
36
|
|
157
|
use RDF::Trine::Iterator qw(smap sgrep swatch); |
|
|
36
|
|
|
|
|
38
|
|
|
|
36
|
|
|
|
|
1966
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
###################################################################### |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our ($VERSION); |
|
28
|
|
|
|
|
|
|
BEGIN { |
|
29
|
36
|
|
|
36
|
|
16889
|
$VERSION = '2.918'; |
|
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
|
26
|
my $class = shift; |
|
51
|
14
|
|
|
|
|
16
|
my $pattern = shift; |
|
52
|
14
|
|
|
|
|
23
|
my $opt = shift; |
|
53
|
14
|
|
|
|
|
48
|
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
|
56
|
my $self = shift; |
|
65
|
52
|
|
|
|
|
92
|
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
|
86
|
my $self = shift; |
|
76
|
109
|
|
|
|
|
285
|
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
|
107
|
my $self = shift; |
|
87
|
107
|
|
|
|
|
233
|
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
|
35
|
my $self = shift; |
|
98
|
38
|
|
|
|
|
36
|
my $context = shift; |
|
99
|
38
|
|
100
|
|
|
97
|
my $prefix = shift || ''; |
|
100
|
38
|
|
50
|
|
|
73
|
my $indent = $context->{indent} || ' '; |
|
101
|
|
|
|
|
|
|
|
|
102
|
38
|
|
|
|
|
97
|
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
|
3
|
my $self = shift; |
|
117
|
2
|
|
|
|
|
3
|
my $context = shift; |
|
118
|
2
|
|
|
|
|
1
|
my $indent = shift; |
|
119
|
2
|
|
|
|
|
6
|
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
|
|
|
|
|
6
|
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
|
3
|
my $self = shift; |
|
182
|
2
|
|
|
|
|
5
|
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
|
3
|
my $self = shift; |
|
194
|
2
|
|
|
|
|
7
|
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
|
2
|
my $self = shift; |
|
205
|
2
|
|
|
|
|
4
|
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 |