line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Query::Algebra::Union |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Algebra::Union - Algebra class for Union patterns |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Algebra::Union version 2.915_01. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Algebra::Union; |
15
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
207
|
use strict; |
|
36
|
|
|
|
|
65
|
|
|
36
|
|
|
|
|
885
|
|
17
|
36
|
|
|
36
|
|
176
|
use warnings; |
|
36
|
|
|
|
|
66
|
|
|
36
|
|
|
|
|
905
|
|
18
|
36
|
|
|
36
|
|
171
|
no warnings 'redefine'; |
|
36
|
|
|
|
|
60
|
|
|
36
|
|
|
|
|
1127
|
|
19
|
36
|
|
|
36
|
|
214
|
use base qw(RDF::Query::Algebra); |
|
36
|
|
|
|
|
62
|
|
|
36
|
|
|
|
|
2670
|
|
20
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
194
|
use Data::Dumper; |
|
36
|
|
|
|
|
66
|
|
|
36
|
|
|
|
|
1645
|
|
22
|
36
|
|
|
36
|
|
184
|
use Set::Scalar; |
|
36
|
|
|
|
|
84
|
|
|
36
|
|
|
|
|
1245
|
|
23
|
36
|
|
|
36
|
|
214
|
use Log::Log4perl; |
|
36
|
|
|
|
|
71
|
|
|
36
|
|
|
|
|
263
|
|
24
|
36
|
|
|
36
|
|
1638
|
use Scalar::Util qw(blessed); |
|
36
|
|
|
|
|
64
|
|
|
36
|
|
|
|
|
1621
|
|
25
|
36
|
|
|
36
|
|
177
|
use Carp qw(carp croak confess); |
|
36
|
|
|
|
|
92
|
|
|
36
|
|
|
|
|
2573
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
###################################################################### |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our ($VERSION); |
30
|
|
|
|
|
|
|
BEGIN { |
31
|
36
|
|
|
36
|
|
21629
|
$VERSION = '2.915_01'; |
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 ( $left, $right )> |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Returns a new Union structure. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new { |
52
|
8
|
|
|
8
|
1
|
17
|
my $class = shift; |
53
|
8
|
|
|
|
|
17
|
my $left = shift; |
54
|
8
|
|
|
|
|
15
|
my $right = shift; |
55
|
8
|
|
|
|
|
53
|
return bless( [ 'UNION', $left, $right ], $class ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item C<< construct_args >> |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns a list of arguments that, passed to this class' constructor, |
61
|
|
|
|
|
|
|
will produce a clone of this algebra pattern. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub construct_args { |
66
|
23
|
|
|
23
|
1
|
33
|
my $self = shift; |
67
|
23
|
|
|
|
|
58
|
return ($self->first, $self->second); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item C<< first >> |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Returns the first pattern (LHS) of the union. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub first { |
77
|
45
|
|
|
45
|
1
|
62
|
my $self = shift; |
78
|
45
|
|
|
|
|
177
|
return $self->[1]; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item C<< second >> |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Returns the second pattern (RHS) of the union. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item C<< patterns >> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns the two patterns belonging to the UNION pattern. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub patterns { |
95
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
96
|
2
|
|
|
|
|
5
|
return ($self->first, $self->second); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub second { |
100
|
45
|
|
|
45
|
1
|
67
|
my $self = shift; |
101
|
45
|
|
|
|
|
162
|
return $self->[2]; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item C<< sse >> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns the SSE string for this algebra expression. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub sse { |
111
|
9
|
|
|
9
|
1
|
14
|
my $self = shift; |
112
|
9
|
|
|
|
|
17
|
my $context = shift; |
113
|
9
|
|
100
|
|
|
43
|
my $prefix = shift || ''; |
114
|
9
|
|
50
|
|
|
27
|
my $indent = $context->{indent} || ' '; |
115
|
|
|
|
|
|
|
|
116
|
9
|
|
|
|
|
34
|
return sprintf( |
117
|
|
|
|
|
|
|
"(union\n${prefix}${indent}%s\n${prefix}${indent}%s)", |
118
|
|
|
|
|
|
|
$self->first->sse( $context, "${prefix}${indent}" ), |
119
|
|
|
|
|
|
|
$self->second->sse( $context, "${prefix}${indent}" ) |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item C<< as_sparql >> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns the SPARQL string for this algebra expression. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub as_sparql { |
130
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
131
|
2
|
|
|
|
|
4
|
my $context = shift; |
132
|
2
|
|
|
|
|
5
|
my $indent = shift; |
133
|
2
|
|
|
|
|
9
|
my $string = sprintf( |
134
|
|
|
|
|
|
|
"%s\n${indent}UNION\n${indent}%s", |
135
|
|
|
|
|
|
|
$self->first->as_sparql( { %$context, force_ggp_braces => 1 }, $indent ), |
136
|
|
|
|
|
|
|
$self->second->as_sparql( { %$context, force_ggp_braces => 1 }, $indent ), |
137
|
|
|
|
|
|
|
); |
138
|
2
|
|
|
|
|
12
|
return $string; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item C<< as_hash >> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Returns the query as a nested set of plain data structures (no objects). |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub as_hash { |
148
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
149
|
0
|
|
|
|
|
0
|
my $context = shift; |
150
|
|
|
|
|
|
|
return { |
151
|
|
|
|
|
|
|
type => lc($self->type), |
152
|
0
|
|
|
|
|
0
|
patterns => [ map { $_->as_hash } $self->patterns ], |
|
0
|
|
|
|
|
0
|
|
153
|
|
|
|
|
|
|
}; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item C<< type >> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Returns the type of this algebra expression. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub type { |
163
|
0
|
|
|
0
|
1
|
0
|
return 'UNION'; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item C<< referenced_variables >> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub referenced_variables { |
173
|
5
|
|
|
5
|
1
|
9
|
my $self = shift; |
174
|
5
|
|
|
|
|
15
|
return RDF::Query::_uniq($self->first->referenced_variables, $self->second->referenced_variables); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item C<< potentially_bound >> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression that will |
180
|
|
|
|
|
|
|
bind values during execution. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub potentially_bound { |
185
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
186
|
3
|
|
|
|
|
9
|
return RDF::Query::_uniq($self->first->potentially_bound, $self->second->potentially_bound); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item C<< definite_variables >> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Returns a list of the variable names that will be bound after evaluating this algebra expression. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub definite_variables { |
196
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
197
|
1
|
|
|
|
|
4
|
my $seta = Set::Scalar->new( $self->first->definite_variables ); |
198
|
1
|
|
|
|
|
283
|
my $setb = Set::Scalar->new( $self->second->definite_variables ); |
199
|
1
|
|
|
|
|
67
|
return $seta->intersection( $setb )->members; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
1; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
__END__ |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=back |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 AUTHOR |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=cut |