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.916. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Algebra::Union; |
15
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
180
|
use strict; |
|
36
|
|
|
|
|
73
|
|
|
36
|
|
|
|
|
903
|
|
17
|
36
|
|
|
36
|
|
180
|
use warnings; |
|
36
|
|
|
|
|
62
|
|
|
36
|
|
|
|
|
926
|
|
18
|
36
|
|
|
36
|
|
178
|
no warnings 'redefine'; |
|
36
|
|
|
|
|
63
|
|
|
36
|
|
|
|
|
1167
|
|
19
|
36
|
|
|
36
|
|
180
|
use base qw(RDF::Query::Algebra); |
|
36
|
|
|
|
|
71
|
|
|
36
|
|
|
|
|
2631
|
|
20
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
205
|
use Data::Dumper; |
|
36
|
|
|
|
|
68
|
|
|
36
|
|
|
|
|
1739
|
|
22
|
36
|
|
|
36
|
|
215
|
use Set::Scalar; |
|
36
|
|
|
|
|
69
|
|
|
36
|
|
|
|
|
1274
|
|
23
|
36
|
|
|
36
|
|
183
|
use Log::Log4perl; |
|
36
|
|
|
|
|
65
|
|
|
36
|
|
|
|
|
261
|
|
24
|
36
|
|
|
36
|
|
1637
|
use Scalar::Util qw(blessed); |
|
36
|
|
|
|
|
59
|
|
|
36
|
|
|
|
|
1670
|
|
25
|
36
|
|
|
36
|
|
173
|
use Carp qw(carp croak confess); |
|
36
|
|
|
|
|
79
|
|
|
36
|
|
|
|
|
2525
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
###################################################################### |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our ($VERSION); |
30
|
|
|
|
|
|
|
BEGIN { |
31
|
36
|
|
|
36
|
|
21944
|
$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 ( $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
|
|
|
|
|
18
|
my $left = shift; |
54
|
8
|
|
|
|
|
14
|
my $right = shift; |
55
|
8
|
|
|
|
|
58
|
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
|
39
|
my $self = shift; |
67
|
23
|
|
|
|
|
60
|
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
|
65
|
my $self = shift; |
78
|
45
|
|
|
|
|
181
|
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
|
64
|
my $self = shift; |
101
|
45
|
|
|
|
|
158
|
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
|
15
|
my $self = shift; |
112
|
9
|
|
|
|
|
17
|
my $context = shift; |
113
|
9
|
|
100
|
|
|
49
|
my $prefix = shift || ''; |
114
|
9
|
|
50
|
|
|
27
|
my $indent = $context->{indent} || ' '; |
115
|
|
|
|
|
|
|
|
116
|
9
|
|
|
|
|
33
|
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
|
3
|
my $self = shift; |
131
|
2
|
|
|
|
|
6
|
my $context = shift; |
132
|
2
|
|
|
|
|
3
|
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
|
|
|
|
|
13
|
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
|
8
|
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
|
9
|
my $self = shift; |
186
|
3
|
|
|
|
|
8
|
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
|
|
|
|
|
339
|
my $setb = Set::Scalar->new( $self->second->definite_variables ); |
199
|
1
|
|
|
|
|
65
|
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 |