line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Query::Expression::Unary |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Expression::Unary - Class for unary expressions |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Expression::Unary version 2.915_01. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Expression::Unary; |
15
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
180
|
use strict; |
|
36
|
|
|
|
|
63
|
|
|
36
|
|
|
|
|
907
|
|
17
|
36
|
|
|
36
|
|
174
|
use warnings; |
|
36
|
|
|
|
|
63
|
|
|
36
|
|
|
|
|
1017
|
|
18
|
36
|
|
|
36
|
|
209
|
no warnings 'redefine'; |
|
36
|
|
|
|
|
73
|
|
|
36
|
|
|
|
|
1149
|
|
19
|
36
|
|
|
36
|
|
188
|
use base qw(RDF::Query::Expression); |
|
36
|
|
|
|
|
58
|
|
|
36
|
|
|
|
|
2610
|
|
20
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
181
|
use Data::Dumper; |
|
36
|
|
|
|
|
71
|
|
|
36
|
|
|
|
|
1963
|
|
22
|
36
|
|
|
36
|
|
185
|
use Scalar::Util qw(blessed); |
|
36
|
|
|
|
|
61
|
|
|
36
|
|
|
|
|
1668
|
|
23
|
36
|
|
|
36
|
|
528
|
use Carp qw(carp croak confess); |
|
36
|
|
|
|
|
64
|
|
|
36
|
|
|
|
|
2731
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
###################################################################### |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our ($VERSION); |
28
|
|
|
|
|
|
|
BEGIN { |
29
|
36
|
|
|
36
|
|
15992
|
$VERSION = '2.915_01'; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
###################################################################### |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
37
|
|
|
|
|
|
|
L<RDF::Query::Expression> class. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over 4 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item C<< sse >> |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Returns the SSE string for this algebra expression. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub sse { |
50
|
3
|
|
|
3
|
1
|
7
|
my $self = shift; |
51
|
3
|
|
|
|
|
6
|
my $context = shift; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return sprintf( |
54
|
|
|
|
|
|
|
'(%s %s)', |
55
|
|
|
|
|
|
|
$self->op, |
56
|
3
|
|
|
|
|
14
|
map { $_->sse( $context ) } $self->operands, |
|
3
|
|
|
|
|
27
|
|
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item C<< as_sparql >> |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Returns the SPARQL string for this algebra expression. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub as_sparql { |
67
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
68
|
2
|
|
|
|
|
3
|
my $context = shift; |
69
|
2
|
|
|
|
|
5
|
my $indent = shift; |
70
|
2
|
|
|
|
|
7
|
my $op = $self->op; |
71
|
2
|
|
|
|
|
9
|
return sprintf("($op %s)", map { $_->as_sparql( $context, $indent ) } $self->operands); |
|
2
|
|
|
|
|
10
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item C<< evaluate ( $query, \%bound ) >> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Evaluates the expression using the supplied bound variables. |
77
|
|
|
|
|
|
|
Will return a RDF::Query::Node object. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub evaluate { |
82
|
6
|
|
|
6
|
1
|
19
|
my $self = shift; |
83
|
6
|
|
|
|
|
11
|
my $query = shift; |
84
|
6
|
|
|
|
|
8
|
my $bound = shift; |
85
|
6
|
|
|
|
|
12
|
my $context = shift; |
86
|
6
|
|
|
|
|
29
|
my $op = $self->op; |
87
|
6
|
|
|
|
|
26
|
my ($data) = $self->operands; |
88
|
6
|
100
|
100
|
|
|
42
|
if ($op eq '+' or $op eq '-') { |
|
|
50
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $l = $data->isa('RDF::Query::Algebra') |
90
|
|
|
|
|
|
|
? $data->evaluate( $query, $bound, $context, @_ ) |
91
|
|
|
|
|
|
|
: ($data->isa('RDF::Query::Node::Variable')) |
92
|
2
|
50
|
|
|
|
20
|
? $bound->{ $data->name } |
|
|
50
|
|
|
|
|
|
93
|
|
|
|
|
|
|
: $data; |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
4
|
my $value; |
96
|
2
|
100
|
|
|
|
9
|
if ($op eq '+') { |
|
|
50
|
|
|
|
|
|
97
|
1
|
|
|
|
|
4
|
$value = $l->numeric_value; |
98
|
|
|
|
|
|
|
} elsif ($op eq '-') { |
99
|
1
|
|
|
|
|
5
|
$value = -1 * $l->numeric_value; |
100
|
|
|
|
|
|
|
} |
101
|
2
|
|
|
|
|
10
|
return RDF::Query::Node::Literal->new( $value, undef, $l->literal_datatype ); |
102
|
|
|
|
|
|
|
} elsif ($op eq '!') { |
103
|
4
|
|
|
|
|
13
|
my $alg = RDF::Query::Expression::Function->new( "sparql:ebv", $data ); |
104
|
4
|
|
|
|
|
19
|
my $bool = $alg->evaluate( $query, $bound, $context, @_ ); |
105
|
4
|
100
|
|
|
|
11
|
if ($bool->literal_value eq 'true') { |
106
|
1
|
|
|
|
|
9
|
return RDF::Query::Node::Literal->new( 'false', undef, 'http://www.w3.org/2001/XMLSchema#boolean' ); |
107
|
|
|
|
|
|
|
} else { |
108
|
3
|
|
|
|
|
25
|
return RDF::Query::Node::Literal->new( 'true', undef, 'http://www.w3.org/2001/XMLSchema#boolean' ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} else { |
111
|
0
|
|
|
|
|
|
warn "unknown unary op: $op"; |
112
|
0
|
|
|
|
|
|
throw RDF::Query::Error::ExecutionError -text => "Unknown unary op '$op'"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 AUTHOR |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |