line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Query::Node |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Node - Base class for RDF Nodes |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Node version 2.915_01. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 METHODS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=over 4 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package RDF::Query::Node; |
19
|
|
|
|
|
|
|
|
20
|
36
|
|
|
36
|
|
59955
|
use strict; |
|
36
|
|
|
|
|
70
|
|
|
36
|
|
|
|
|
926
|
|
21
|
36
|
|
|
36
|
|
179
|
use warnings; |
|
36
|
|
|
|
|
66
|
|
|
36
|
|
|
|
|
980
|
|
22
|
36
|
|
|
36
|
|
180
|
no warnings 'redefine'; |
|
36
|
|
|
|
|
62
|
|
|
36
|
|
|
|
|
1173
|
|
23
|
36
|
|
|
36
|
|
177
|
use Scalar::Util qw(blessed); |
|
36
|
|
|
|
|
62
|
|
|
36
|
|
|
|
|
1573
|
|
24
|
|
|
|
|
|
|
|
25
|
36
|
|
|
36
|
|
21045
|
use RDF::Query::Node::Blank; |
|
36
|
|
|
|
|
96
|
|
|
36
|
|
|
|
|
1656
|
|
26
|
36
|
|
|
36
|
|
21938
|
use RDF::Query::Node::Literal; |
|
36
|
|
|
|
|
107
|
|
|
36
|
|
|
|
|
1921
|
|
27
|
36
|
|
|
36
|
|
21143
|
use RDF::Query::Node::Resource; |
|
36
|
|
|
|
|
135
|
|
|
36
|
|
|
|
|
1761
|
|
28
|
36
|
|
|
36
|
|
216
|
use RDF::Query::Node::Variable; |
|
36
|
|
|
|
|
84
|
|
|
36
|
|
|
|
|
4490
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS); |
31
|
|
|
|
|
|
|
BEGIN { |
32
|
36
|
|
|
36
|
|
91
|
$VERSION = '2.915_01'; |
33
|
|
|
|
|
|
|
|
34
|
36
|
|
|
|
|
195
|
require Exporter; |
35
|
36
|
|
|
|
|
2415
|
@ISA = qw(Exporter); |
36
|
36
|
|
|
|
|
292
|
@EXPORT_OK = qw(iri blank literal variable); |
37
|
36
|
|
|
|
|
10646
|
%EXPORT_TAGS = ( 'all' => [qw(iri blank literal variable)] ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item C<< is_variable >> |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Returns true if this RDF node is a variable, false otherwise. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub is_variable { |
47
|
1875
|
|
|
1875
|
1
|
451401
|
my $self = shift; |
48
|
1875
|
|
66
|
|
|
14577
|
return (blessed($self) and $self->isa('RDF::Query::Node::Variable')); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item C<< compare ( $a, $b ) >> |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Returns -1, 0, or 1 if $a is less than, equal to, or greater than $b, respectively, |
54
|
|
|
|
|
|
|
according to the SPARQL sorting rules. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub compare { |
59
|
|
|
|
|
|
|
my $a = shift; |
60
|
|
|
|
|
|
|
my $b = shift; |
61
|
|
|
|
|
|
|
warn 'compare'; |
62
|
|
|
|
|
|
|
for ($a, $b) { |
63
|
|
|
|
|
|
|
unless ($_->isa('RDF::Query::Node')) { |
64
|
|
|
|
|
|
|
$_ = RDF::Query::Node->from_trine( $_ ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
local($RDF::Query::Node::Literal::LAZY_COMPARISONS) = 1; |
69
|
|
|
|
|
|
|
return $a <=> $b; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item C<< from_trine ( $node ) >> |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Returns a new RDF::Query::Node object with the same value as $node, a |
75
|
|
|
|
|
|
|
RDF::Trine::Node object. This essentially promotes C<< $node >> to a |
76
|
|
|
|
|
|
|
node object with extra functionality provided by the RDF::Query package |
77
|
|
|
|
|
|
|
(like SPARQL-defined ordering). |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub from_trine { |
82
|
1117
|
|
|
1117
|
1
|
2414
|
my $class = shift; |
83
|
1117
|
|
|
|
|
1538
|
my $n = shift; |
84
|
1117
|
50
|
|
|
|
11422
|
if ($n->isa('RDF::Trine::Node::Variable')) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
return RDF::Query::Node::Variable->new( $n->name ); |
86
|
|
|
|
|
|
|
} elsif ($n->isa('RDF::Trine::Node::Literal')) { |
87
|
293
|
|
|
|
|
831
|
return RDF::Query::Node::Literal->new( $n->literal_value, $n->literal_value_language, $n->literal_datatype ); |
88
|
|
|
|
|
|
|
} elsif ($n->isa('RDF::Trine::Node::Resource')) { |
89
|
375
|
|
|
|
|
1147
|
return RDF::Query::Node::Resource->new( $n->uri_value ); |
90
|
|
|
|
|
|
|
} elsif ($n->isa('RDF::Trine::Node::Blank')) { |
91
|
91
|
|
|
|
|
309
|
return RDF::Query::Node::Blank->new( $n->blank_identifier ); |
92
|
|
|
|
|
|
|
} elsif ($n->isa('RDF::Trine::Node::Nil')) { |
93
|
358
|
|
|
|
|
1330
|
return $n; |
94
|
|
|
|
|
|
|
} else { |
95
|
36
|
|
|
36
|
|
211
|
use Data::Dumper; |
|
36
|
|
|
|
|
75
|
|
|
36
|
|
|
|
|
7727
|
|
96
|
0
|
|
|
|
|
0
|
Carp::confess "from_trine called with unrecognized node type:" . Dumper($n); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item C<< from_attean ( $node ) >> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Likewise, but from L<Attean>. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub from_attean { |
107
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
108
|
0
|
|
|
|
|
0
|
my $n = shift; |
109
|
0
|
0
|
|
|
|
0
|
if ($n->does('Attean::API::Variable')) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
110
|
0
|
|
|
|
|
0
|
return RDF::Query::Node::Variable->new( $n->value ); |
111
|
|
|
|
|
|
|
} elsif ($n->does('Attean::API::Literal')) { |
112
|
0
|
|
|
|
|
0
|
return RDF::Query::Node::Literal->new( $n->value, $n->language, $n->datatype ); |
113
|
|
|
|
|
|
|
} elsif ($n->does('Attean::API::IRI')) { |
114
|
0
|
|
|
|
|
0
|
return RDF::Query::Node::Resource->new( $n->as_string ); |
115
|
|
|
|
|
|
|
} elsif ($n->does('Attean::API::Blank')) { |
116
|
0
|
|
|
|
|
0
|
return RDF::Query::Node::Blank->new( $n->value ); |
117
|
|
|
|
|
|
|
} else { |
118
|
36
|
|
|
36
|
|
200
|
use Data::Dumper; |
|
36
|
|
|
|
|
73
|
|
|
36
|
|
|
|
|
14179
|
|
119
|
0
|
|
|
|
|
0
|
Carp::confess "from_attean called with unrecognized node type:" . Dumper($n); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item C<< explain >> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns a string serialization of the node appropriate for display on the |
126
|
|
|
|
|
|
|
command line. This method is primarily used by the C<< explain >> method of |
127
|
|
|
|
|
|
|
the subclasses of RDF::Query::Plan. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub explain { |
132
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
133
|
0
|
|
|
|
|
0
|
my $s = shift; |
134
|
0
|
|
|
|
|
0
|
my $count = shift; |
135
|
0
|
|
|
|
|
0
|
my $indent = $s x $count; |
136
|
0
|
|
|
|
|
0
|
my $string = "${indent}" . $self->as_sparql . "\n"; |
137
|
0
|
|
|
|
|
0
|
return $string; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 FUNCTIONS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over 4 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item C<< compare ( $node_a, $node_b ) >> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Returns -1, 0, or 1 if $node_a sorts less than, equal to, or greater than |
149
|
|
|
|
|
|
|
$node_b in the defined SPARQL ordering, respectively. This function may be |
150
|
|
|
|
|
|
|
used as the function argument to C<<sort>>. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub compare { |
155
|
0
|
|
|
0
|
1
|
0
|
my $a = shift; |
156
|
0
|
|
|
|
|
0
|
my $b = shift; |
157
|
0
|
|
|
|
|
0
|
warn 'compare'; |
158
|
0
|
|
|
|
|
0
|
for ($a, $b) { |
159
|
0
|
0
|
|
|
|
0
|
unless ($_->isa('RDF::Query::Node')) { |
160
|
0
|
|
|
|
|
0
|
$_ = RDF::Query::Node->from_trine( $_ ); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
0
|
local($RDF::Query::Node::Literal::LAZY_COMPARISONS) = 1; |
165
|
0
|
|
|
|
|
0
|
return $a <=> $b; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item C<< iri ( $iri ) >> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Returns a RDF::Query::Node::Resource object with the given IRI value. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub iri { |
176
|
25
|
|
|
25
|
1
|
15664
|
my $iri = shift; |
177
|
25
|
|
|
|
|
153
|
return RDF::Query::Node::Resource->new( $iri ); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item C<< blank ( $id ) >> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Returns a RDF::Query::Node::Blank object with the given identifier. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub blank { |
187
|
0
|
|
|
0
|
1
|
|
my $id = shift; |
188
|
0
|
|
|
|
|
|
return RDF::Query::Node::Blank->new( $id ); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item C<< literal ( $value, $lang, $dt ) >> |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Returns a RDF::Query::Node::Literal object with the given value and optional |
194
|
|
|
|
|
|
|
language/datatype. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub literal { |
199
|
0
|
|
|
0
|
1
|
|
return RDF::Query::Node::Literal->new( @_ ); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item C<< variable ( $name ) >> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Returns a RDF::Query::Node::Variable object with the given variable name. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub variable { |
209
|
0
|
|
|
0
|
1
|
|
my $name = shift; |
210
|
0
|
|
|
|
|
|
return RDF::Query::Node::Variable->new( $name ); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
1; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
__END__ |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=back |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 AUTHOR |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |