line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Query::Algebra::Distinct |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Algebra::Distinct - Algebra class for distinct query results |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Algebra::Distinct version 2.915_01. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Algebra::Distinct; |
15
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
181
|
use strict; |
|
36
|
|
|
|
|
69
|
|
|
36
|
|
|
|
|
962
|
|
17
|
36
|
|
|
36
|
|
174
|
use warnings; |
|
36
|
|
|
|
|
128
|
|
|
36
|
|
|
|
|
936
|
|
18
|
36
|
|
|
36
|
|
212
|
no warnings 'redefine'; |
|
36
|
|
|
|
|
66
|
|
|
36
|
|
|
|
|
1190
|
|
19
|
36
|
|
|
36
|
|
185
|
use base qw(RDF::Query::Algebra); |
|
36
|
|
|
|
|
71
|
|
|
36
|
|
|
|
|
3199
|
|
20
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
190
|
use Data::Dumper; |
|
36
|
|
|
|
|
71
|
|
|
36
|
|
|
|
|
1758
|
|
22
|
36
|
|
|
36
|
|
189
|
use Set::Scalar; |
|
36
|
|
|
|
|
67
|
|
|
36
|
|
|
|
|
1437
|
|
23
|
36
|
|
|
36
|
|
486
|
use Scalar::Util qw(blessed); |
|
36
|
|
|
|
|
72
|
|
|
36
|
|
|
|
|
1756
|
|
24
|
36
|
|
|
36
|
|
192
|
use Carp qw(carp croak confess); |
|
36
|
|
|
|
|
71
|
|
|
36
|
|
|
|
|
1985
|
|
25
|
36
|
|
|
36
|
|
186
|
use RDF::Trine::Iterator qw(sgrep); |
|
36
|
|
|
|
|
74
|
|
|
36
|
|
|
|
|
2240
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
###################################################################### |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our ($VERSION); |
30
|
|
|
|
|
|
|
BEGIN { |
31
|
36
|
|
|
36
|
|
19328
|
$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 ( $pattern ) >> |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Returns a new Sort structure. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new { |
52
|
12
|
|
|
12
|
1
|
35
|
my $class = shift; |
53
|
12
|
|
|
|
|
24
|
my $pattern = shift; |
54
|
12
|
|
|
|
|
51
|
return bless( [ $pattern ], $class ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item C<< construct_args >> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Returns a list of arguments that, passed to this class' constructor, |
60
|
|
|
|
|
|
|
will produce a clone of this algebra pattern. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub construct_args { |
65
|
12
|
|
|
12
|
1
|
29
|
my $self = shift; |
66
|
12
|
|
|
|
|
840
|
my $pattern = $self->pattern; |
67
|
12
|
|
|
|
|
44
|
return ($pattern); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item C<< pattern >> |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Returns the pattern to be sorted. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub pattern { |
77
|
41
|
|
|
41
|
1
|
63
|
my $self = shift; |
78
|
41
|
50
|
|
|
|
100
|
if (@_) { |
79
|
0
|
|
|
|
|
0
|
$self->[0] = shift; |
80
|
|
|
|
|
|
|
} |
81
|
41
|
|
|
|
|
254
|
return $self->[0]; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item C<< sse >> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Returns the SSE string for this algebra expression. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub sse { |
91
|
15
|
|
|
15
|
1
|
31
|
my $self = shift; |
92
|
15
|
|
|
|
|
25
|
my $context = shift; |
93
|
15
|
|
100
|
|
|
75
|
my $prefix = shift || ''; |
94
|
15
|
|
50
|
|
|
48
|
my $indent = $context->{indent} || ' '; |
95
|
|
|
|
|
|
|
|
96
|
15
|
|
|
|
|
93
|
return sprintf( |
97
|
|
|
|
|
|
|
"(distinct\n${prefix}${indent}%s)", |
98
|
|
|
|
|
|
|
$self->pattern->sse( $context, "${prefix}${indent}" ), |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item C<< as_sparql >> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns the SPARQL string for this algebra expression. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub as_sparql { |
109
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
110
|
2
|
|
|
|
|
3
|
my $context = shift; |
111
|
2
|
|
|
|
|
4
|
my $indent = shift; |
112
|
|
|
|
|
|
|
|
113
|
2
|
|
|
|
|
6
|
return 'DISTINCT ' . $self->pattern->as_sparql( $context, $indent ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item C<< as_hash >> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Returns the query as a nested set of plain data structures (no objects). |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub as_hash { |
123
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
124
|
0
|
|
|
|
|
0
|
my $context = shift; |
125
|
|
|
|
|
|
|
return { |
126
|
0
|
|
|
|
|
0
|
type => lc($self->type), |
127
|
|
|
|
|
|
|
pattern => $self->pattern->as_hash, |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item C<< as_spin ( $model ) >> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Adds statements to the given model to represent this algebra object in the |
134
|
|
|
|
|
|
|
SPARQL Inferencing Notation (L<http://www.spinrdf.org/>). |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub as_spin { |
139
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
140
|
0
|
|
|
|
|
0
|
my $model = shift; |
141
|
0
|
|
|
|
|
0
|
my $spin = RDF::Trine::Namespace->new('http://spinrdf.org/spin#'); |
142
|
0
|
|
|
|
|
0
|
my $xsd = RDF::Trine::Namespace->new('http://www.w3.org/2001/XMLSchema#'); |
143
|
0
|
|
|
|
|
0
|
my $q = $self->pattern->as_spin( $model ); |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
0
|
$model->add_statement( RDF::Trine::Statement->new($q, $spin->distinct, RDF::Query::Node::Literal->new('true', undef, $xsd->boolean)) ); |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
0
|
return $q; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item C<< type >> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Returns the type of this algebra expression. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub type { |
157
|
0
|
|
|
0
|
1
|
0
|
return 'DISTINCT'; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item C<< referenced_variables >> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub referenced_variables { |
167
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
168
|
2
|
|
|
|
|
7
|
return RDF::Query::_uniq($self->pattern->referenced_variables); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item C<< potentially_bound >> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression that will |
174
|
|
|
|
|
|
|
bind values during execution. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub potentially_bound { |
179
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
180
|
0
|
|
|
|
|
0
|
return $self->pattern->potentially_bound; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item C<< definite_variables >> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Returns a list of the variable names that will be bound after evaluating this algebra expression. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub definite_variables { |
190
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
191
|
0
|
|
|
|
|
0
|
return $self->pattern->definite_variables; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item C<< is_solution_modifier >> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Returns true if this node is a solution modifier. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub is_solution_modifier { |
201
|
10
|
|
|
10
|
1
|
54
|
return 1; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
__END__ |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=back |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 AUTHOR |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |