| 1 | 50 | ▶ | use v5.14; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 50 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | |||||||||||||||
| 4 | =head1 NAME | ||||||||||||||
| 5 | |||||||||||||||
| 6 | Attean::Expression - SPARQL Expressions | ||||||||||||||
| 7 | |||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||
| 9 | |||||||||||||||
| 10 | This document describes Attean::Expression version 0.040 | ||||||||||||||
| 11 | |||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||
| 13 | |||||||||||||||
| 14 | use v5.14; | ||||||||||||||
| 15 | use Attean; | ||||||||||||||
| 16 | |||||||||||||||
| 17 | my $binding = Attean::Result->new(); | ||||||||||||||
| 18 | my $value = Attean::ValueExpression->new( value => Attean::Literal->integer(2) ); | ||||||||||||||
| 19 | my $plus = Attean::BinaryExpression->new( children => [$value, $value], operator => '+' ); | ||||||||||||||
| 20 | my $result = $plus->evaluate($binding); | ||||||||||||||
| 21 | say $result->numeric_value; # 4 | ||||||||||||||
| 22 | |||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||
| 24 | |||||||||||||||
| 25 | This is a utility package that defines all the Attean SPARQL expression classes | ||||||||||||||
| 26 | consisting of logical, numeric, and function operators, constant terms, and | ||||||||||||||
| 27 | variables. Expressions may be evaluated in the context of a | ||||||||||||||
| 28 | L<Attean::API::Result> object, and either return a L<Attean::API::Term> object | ||||||||||||||
| 29 | or throw a type error exception. | ||||||||||||||
| 30 | |||||||||||||||
| 31 | The expression classes are: | ||||||||||||||
| 32 | |||||||||||||||
| 33 | =over 4 | ||||||||||||||
| 34 | |||||||||||||||
| 35 | =cut | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 50 | ▶ | use Attean::API::Expression; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 38 | |||||||||||||||
| 39 | =item * L<Attean::ValueExpression> | ||||||||||||||
| 40 | |||||||||||||||
| 41 | =cut | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 50 | package Attean::ValueExpression 0.040 { | |||||||||||||
| 44 | 50 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 45 | 50 | ▶ | use Types::Standard qw(ConsumerOf); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 46 | 50 | ▶ | use AtteanX::SPARQL::Constants; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 47 | 50 | ▶ | use AtteanX::SPARQL::Token; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 48 | 50 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | 50 | with 'Attean::API::SPARQLSerializable'; | |||||||||||||
| 51 | 50 | with 'Attean::API::Expression'; | |||||||||||||
| 52 | |||||||||||||||
| 53 | 50 | has 'value' => (is => 'ro', isa => ConsumerOf['Attean::API::TermOrVariableOrTriplePattern']); | |||||||||||||
| 54 | |||||||||||||||
| 55 | 1 | ▶ | sub arity { return 0 } | ||||||||||||
|
Subroutine
arity: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 56 | 1439 | ▶ | sub BUILDARGS { | ||||||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 57 | 1439 | my $class = shift; | |||||||||||||
| 58 | 1439 | return $class->SUPER::BUILDARGS(@_, operator => '_value'); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | 9 | ▶ | sub tree_attributes { return qw(operator) } | ||||||||||||
|
Subroutine
tree_attributes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 62 | |||||||||||||||
| 63 | 0 | ▶ | sub is_stable { | ||||||||||||
|
Subroutine
is_stable: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 64 | 0 | return 1; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 29 | ▶ | sub as_string { | ||||||||||||
|
Subroutine
as_string: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 68 | 29 | my $self = shift; | |||||||||||||
| 69 | 29 | my $str = $self->value->ntriples_string; | |||||||||||||
| 70 | 29 | ▶ | if ($str =~ m[^"(true|false)"\^\^<http://www[.]w3[.]org/2001/XMLSchema#boolean>$]) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 71 | 6 | return $1; | |||||||||||||
| 72 | } elsif ($str =~ m[^"(\d+)"\^\^<http://www[.]w3[.]org/2001/XMLSchema#integer>$]) { | ||||||||||||||
| 73 | 4 | return $1 | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | 19 | return $str; | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 0 | ▶ | sub in_scope_variables { | ||||||||||||
|
Subroutine
in_scope_variables: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||
| 80 | 0 | ▶ | if ($self->value->does('Attean::API::Variable')) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 81 | 0 | return $self->value->value; | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | 0 | return; | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | 22 | ▶ | sub sparql_tokens { | ||||||||||||
|
Subroutine
sparql_tokens: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 87 | 22 | my $self = shift; | |||||||||||||
| 88 | 22 | return $self->value->sparql_tokens; | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 1 | ▶ | sub unaggregated_variables { | ||||||||||||
|
Subroutine
unaggregated_variables: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||
| 92 | 1 | my $self = shift; | |||||||||||||
| 93 | 1 | ▶ | if ($self->value->does('Attean::API::Variable')) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 94 | 1 | return $self->value; | |||||||||||||
| 95 | } | ||||||||||||||
| 96 | 0 | return; | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | } | ||||||||||||||
| 99 | |||||||||||||||
| 100 | =item * L<Attean::UnaryExpression> | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =cut | ||||||||||||||
| 103 | |||||||||||||||
| 104 | 50 | package Attean::UnaryExpression 0.040 { | |||||||||||||
| 105 | 50 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 106 | 50 | ▶ | use Types::Standard qw(Enum); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 107 | 50 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 108 | |||||||||||||||
| 109 | 50 | with 'Attean::API::UnaryExpression', 'Attean::API::Expression', 'Attean::API::UnaryQueryTree'; | |||||||||||||
| 110 | |||||||||||||||
| 111 | 50 | my %map = ('NOT' => '!'); | |||||||||||||
| 112 | 3 | ▶ | around 'BUILDARGS' => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 113 | 3 | my $orig = shift; | |||||||||||||
| 114 | 3 | my $class = shift; | |||||||||||||
| 115 | 3 | my $args = $class->$orig(@_); | |||||||||||||
| 116 | 3 | my $op = $args->{operator}; | |||||||||||||
| 117 | 3 | ▶ | $args->{operator} = $map{uc($op)} if (exists $map{uc($op)}); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 118 | 3 | return $args; | |||||||||||||
| 119 | 50 | }; | |||||||||||||
| 120 | 3 | ▶ | sub BUILD { | ||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 121 | 3 | my $self = shift; | |||||||||||||
| 122 | 3 | state $type = Enum[qw(+ - !)]; | |||||||||||||
| 123 | 3 | $type->assert_valid($self->operator); | |||||||||||||
| 124 | } | ||||||||||||||
| 125 | |||||||||||||||
| 126 | 0 | ▶ | sub tree_attributes { return qw(operator) } | ||||||||||||
|
Subroutine
tree_attributes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 127 | |||||||||||||||
| 128 | 0 | ▶ | sub is_stable { | ||||||||||||
|
Subroutine
is_stable: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 129 | 0 | my $self = shift; | |||||||||||||
| 130 | 0 | foreach my $c (@{ $self->children }) { | |||||||||||||
| 131 | 0 | ▶ | return 0 unless ($c->is_stable); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 132 | } | ||||||||||||||
| 133 | 0 | return 1; | |||||||||||||
| 134 | } | ||||||||||||||
| 135 | } | ||||||||||||||
| 136 | |||||||||||||||
| 137 | =item * L<Attean::BinaryExpression> | ||||||||||||||
| 138 | |||||||||||||||
| 139 | =cut | ||||||||||||||
| 140 | |||||||||||||||
| 141 | 50 | package Attean::BinaryExpression 0.040 { | |||||||||||||
| 142 | 50 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 143 | 50 | ▶ | use Types::Standard qw(Enum); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 144 | 50 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 145 | |||||||||||||||
| 146 | 50 | with 'Attean::API::BinaryExpression'; | |||||||||||||
| 147 | |||||||||||||||
| 148 | 39 | ▶ | sub BUILD { | ||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 149 | 39 | my $self = shift; | |||||||||||||
| 150 | 39 | state $type = Enum[qw(+ - * / < <= > >= != = && ||)]; | |||||||||||||
| 151 | 39 | $type->assert_valid($self->operator); | |||||||||||||
| 152 | } | ||||||||||||||
| 153 | |||||||||||||||
| 154 | 3 | ▶ | sub tree_attributes { return qw(operator) } | ||||||||||||
|
Subroutine
tree_attributes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 155 | |||||||||||||||
| 156 | 0 | ▶ | sub is_stable { | ||||||||||||
|
Subroutine
is_stable: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 157 | 0 | my $self = shift; | |||||||||||||
| 158 | 0 | foreach my $c (@{ $self->children }) { | |||||||||||||
| 159 | 0 | ▶ | return 0 unless ($c->is_stable); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 160 | } | ||||||||||||||
| 161 | 0 | return 1; | |||||||||||||
| 162 | } | ||||||||||||||
| 163 | } | ||||||||||||||
| 164 | |||||||||||||||
| 165 | =item * L<Attean::FunctionExpression> | ||||||||||||||
| 166 | |||||||||||||||
| 167 | =cut | ||||||||||||||
| 168 | |||||||||||||||
| 169 | 50 | package Attean::FunctionExpression 0.040 { | |||||||||||||
| 170 | 50 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 171 | 50 | ▶ | use Types::Standard qw(Enum ConsumerOf HashRef); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 172 | 50 | ▶ | use Types::Common::String qw(UpperCaseStr); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 173 | 50 | ▶ | use AtteanX::SPARQL::Constants; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 174 | 50 | ▶ | use AtteanX::SPARQL::Token; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 175 | 50 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 176 | |||||||||||||||
| 177 | 50 | has 'operator' => (is => 'ro', isa => UpperCaseStr, coerce => UpperCaseStr->coercion, required => 1); | |||||||||||||
| 178 | 50 | has 'base' => (is => 'rw', isa => ConsumerOf['Attean::IRI'], predicate => 'has_base'); | |||||||||||||
| 179 | |||||||||||||||
| 180 | 50 | with 'Attean::API::NaryExpression'; | |||||||||||||
| 181 | 50 | with 'Attean::API::SPARQLSerializable'; | |||||||||||||
| 182 | |||||||||||||||
| 183 | |||||||||||||||
| 184 | 6 | ▶ | around 'BUILDARGS' => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||
| 185 | 6 | my $orig = shift; | |||||||||||||
| 186 | 6 | my $class = shift; | |||||||||||||
| 187 | 6 | my $args = $class->$orig(@_); | |||||||||||||
| 188 | 6 | ▶ | if ($args->{operator} eq 'ISURI') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 189 | 0 | $args->{operator} = 'ISIRI'; | |||||||||||||
| 190 | } | ||||||||||||||
| 191 | 6 | $args->{operator} = UpperCaseStr->coercion->($args->{operator}); | |||||||||||||
| 192 | 6 | return $args; | |||||||||||||
| 193 | 50 | }; | |||||||||||||
| 194 | |||||||||||||||
| 195 | 6 | ▶ | sub BUILD { | ||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 196 | 6 | my $self = shift; | |||||||||||||
| 197 | 6 | state $type = Enum[qw(INVOKE IN NOTIN STR LANG LANGDIR LANGMATCHES DATATYPE BOUND IRI URI BNODE RAND ABS CEIL FLOOR ROUND CONCAT SUBSTR STRLEN REPLACE UCASE LCASE ENCODE_FOR_URI CONTAINS STRSTARTS STRENDS STRBEFORE STRAFTER YEAR MONTH DAY HOURS MINUTES SECONDS TIMEZONE TZ NOW UUID STRUUID MD5 SHA1 SHA256 SHA384 SHA512 COALESCE IF STRLANG STRLANGDIR STRDT SAMETERM ISIRI ISBLANK ISLITERAL ISNUMERIC REGEX TRIPLE ISTRIPLE SUBJECT PREDICATE OBJECT HASLANG HASLANGDIR)]; | |||||||||||||
| 198 | 6 | $type->assert_valid($self->operator); | |||||||||||||
| 199 | } | ||||||||||||||
| 200 | |||||||||||||||
| 201 | 0 | ▶ | sub tree_attributes { return qw(operator) } | ||||||||||||
|
Subroutine
tree_attributes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 202 | |||||||||||||||
| 203 | 0 | ▶ | sub is_stable { | ||||||||||||
|
Subroutine
is_stable: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 204 | 0 | my $self = shift; | |||||||||||||
| 205 | 0 | ▶ | return 0 if ($self->operator =~ m/^(?:RAND|BNODE|UUID|STRUUID|NOW)$/); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 206 | 0 | foreach my $c (@{ $self->children }) { | |||||||||||||
| 207 | 0 | ▶ | return 0 unless ($c->is_stable); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 208 | } | ||||||||||||||
| 209 | 0 | return 1; | |||||||||||||
| 210 | } | ||||||||||||||
| 211 | |||||||||||||||
| 212 | 3 | ▶ | sub sparql_tokens { | ||||||||||||
|
Subroutine
sparql_tokens: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||
| 213 | 3 | my $self = shift; | |||||||||||||
| 214 | 3 | my $func = AtteanX::SPARQL::Token->keyword($self->operator); | |||||||||||||
| 215 | 3 | my $lparen = AtteanX::SPARQL::Token->lparen; | |||||||||||||
| 216 | 3 | my $rparen = AtteanX::SPARQL::Token->rparen; | |||||||||||||
| 217 | 3 | my $comma = AtteanX::SPARQL::Token->comma; | |||||||||||||
| 218 | |||||||||||||||
| 219 | 3 | my @tokens; | |||||||||||||
| 220 | 3 | my @children = @{ $self->children }; | |||||||||||||
| 221 | 3 | ▶ | if ($self->operator eq 'INVOKE') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 222 | 0 | my $iri = shift(@children); | |||||||||||||
| 223 | 0 | push(@tokens, $iri->sparql_tokens->elements); | |||||||||||||
| 224 | 0 | push(@tokens, $lparen); | |||||||||||||
| 225 | } else { | ||||||||||||||
| 226 | 3 | push(@tokens, $func, $lparen); | |||||||||||||
| 227 | } | ||||||||||||||
| 228 | |||||||||||||||
| 229 | 3 | foreach my $t (@children) { | |||||||||||||
| 230 | 3 | push(@tokens, $t->sparql_tokens->elements); | |||||||||||||
| 231 | 3 | push(@tokens, $comma); | |||||||||||||
| 232 | } | ||||||||||||||
| 233 | 3 | ▶ | if (scalar(@tokens) > 2) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 234 | 3 | pop(@tokens); # remove the last comma | |||||||||||||
| 235 | } | ||||||||||||||
| 236 | 3 | push(@tokens, $rparen); | |||||||||||||
| 237 | 3 | return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' ); | |||||||||||||
| 238 | } | ||||||||||||||
| 239 | } | ||||||||||||||
| 240 | |||||||||||||||
| 241 | 50 | package Attean::AggregateExpression 0.040 { | |||||||||||||
| 242 | 50 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 243 | 50 | ▶ | use Types::Standard qw(Bool Enum Str HashRef ConsumerOf Maybe ArrayRef); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 244 | 50 | ▶ | use Types::Common::String qw(UpperCaseStr); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 245 | 50 | ▶ | use AtteanX::SPARQL::Constants; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 246 | 50 | ▶ | use AtteanX::SPARQL::Token; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 247 | 50 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 248 | |||||||||||||||
| 249 | 9 | ▶ | around 'BUILDARGS' => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 250 | 9 | my $orig = shift; | |||||||||||||
| 251 | 9 | my $class = shift; | |||||||||||||
| 252 | 9 | my $args = $class->$orig(@_); | |||||||||||||
| 253 | 9 | $args->{operator} = UpperCaseStr->coercion->($args->{operator}); | |||||||||||||
| 254 | 9 | return $args; | |||||||||||||
| 255 | 50 | }; | |||||||||||||
| 256 | 9 | ▶ | sub BUILD { | ||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 257 | 9 | my ($self, $args) = @_; | |||||||||||||
| 258 | |||||||||||||||
| 259 | 9 | state $type = Enum[qw(COUNT SUM MIN MAX AVG GROUP_CONCAT SAMPLE RANK CUSTOM FOLD)]; | |||||||||||||
| 260 | 9 | $type->assert_valid(shift->operator); | |||||||||||||
| 261 | } | ||||||||||||||
| 262 | |||||||||||||||
| 263 | 50 | has 'custom_iri' => (is => 'ro', isa => Maybe[Str]); | |||||||||||||
| 264 | 50 | has 'operator' => (is => 'ro', isa => UpperCaseStr, coerce => UpperCaseStr->coercion, required => 1); | |||||||||||||
| 265 | 0 | ▶ | has 'scalar_vars' => (is => 'ro', isa => HashRef, default => sub { +{} }); | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||
| 266 | 50 | has 'distinct' => (is => 'ro', isa => Bool, default => 0); | |||||||||||||
| 267 | 50 | has 'variable' => (is => 'ro', isa => ConsumerOf['Attean::API::Variable'], required => 1); | |||||||||||||
| 268 | 9 | ▶ | has 'order' => (is => 'ro', isa => ArrayRef, required => 1, default => sub { [] }); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 269 | |||||||||||||||
| 270 | 50 | with 'Attean::API::AggregateExpression'; | |||||||||||||
| 271 | 50 | with 'Attean::API::SPARQLSerializable'; | |||||||||||||
| 272 | |||||||||||||||
| 273 | 0 | ▶ | sub tree_attributes { return qw(operator scalar_vars variable) } | ||||||||||||
|
Subroutine
tree_attributes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 274 | |||||||||||||||
| 275 | 0 | ▶ | sub is_stable { | ||||||||||||
|
Subroutine
is_stable: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 276 | 0 | my $self = shift; | |||||||||||||
| 277 | 0 | foreach my $expr (@{ $self->groups }, values %{ $self->aggregates }) { | |||||||||||||
| 278 | 0 | ▶ | return 0 unless ($expr->is_stable); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 279 | } | ||||||||||||||
| 280 | 0 | return 1; | |||||||||||||
| 281 | } | ||||||||||||||
| 282 | |||||||||||||||
| 283 | 1 | ▶ | sub sparql_tokens { | ||||||||||||
|
Subroutine
sparql_tokens: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||
| 284 | 1 | my $self = shift; | |||||||||||||
| 285 | 1 | my $distinct = AtteanX::SPARQL::Token->keyword('DISTINCT'); | |||||||||||||
| 286 | 1 | my $func = AtteanX::SPARQL::Token->keyword($self->operator); | |||||||||||||
| 287 | 1 | my $lparen = AtteanX::SPARQL::Token->lparen; | |||||||||||||
| 288 | 1 | my $rparen = AtteanX::SPARQL::Token->rparen; | |||||||||||||
| 289 | 1 | my $comma = AtteanX::SPARQL::Token->comma; | |||||||||||||
| 290 | |||||||||||||||
| 291 | 1 | my @tokens; | |||||||||||||
| 292 | 1 | push(@tokens, $func); | |||||||||||||
| 293 | 1 | push(@tokens, $lparen); | |||||||||||||
| 294 | 1 | ▶ | if ($self->distinct) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 295 | 0 | push(@tokens, $distinct); | |||||||||||||
| 296 | } | ||||||||||||||
| 297 | 1 | foreach my $t (@{ $self->children }) { | |||||||||||||
| 298 | 1 | push(@tokens, $t->sparql_tokens->elements); | |||||||||||||
| 299 | 1 | push(@tokens, $comma); | |||||||||||||
| 300 | } | ||||||||||||||
| 301 | 1 | ▶ | if (scalar(@tokens) > 2) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 302 | 1 | pop(@tokens); # remove the last comma | |||||||||||||
| 303 | } | ||||||||||||||
| 304 | 1 | my $vars = $self->scalar_vars; | |||||||||||||
| 305 | 1 | my @keys = keys %$vars; | |||||||||||||
| 306 | 1 | ▶ | if (scalar(@keys)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 307 | 0 | die "TODO: Implement SPARQL serialization for aggregate scalar vars"; | |||||||||||||
| 308 | } | ||||||||||||||
| 309 | 1 | push(@tokens, $rparen); | |||||||||||||
| 310 | 1 | return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' ); | |||||||||||||
| 311 | } | ||||||||||||||
| 312 | } | ||||||||||||||
| 313 | |||||||||||||||
| 314 | 50 | package Attean::CastExpression 0.040 { | |||||||||||||
| 315 | 50 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 316 | 50 | ▶ | use Types::Standard qw(Enum ConsumerOf); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 317 | 50 | ▶ | use AtteanX::SPARQL::Constants; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 318 | 50 | ▶ | use AtteanX::SPARQL::Token; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 319 | 50 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 320 | |||||||||||||||
| 321 | 50 | with 'Attean::API::SPARQLSerializable'; | |||||||||||||
| 322 | 50 | with 'Attean::API::UnaryExpression', 'Attean::API::Expression', 'Attean::API::UnaryQueryTree'; | |||||||||||||
| 323 | |||||||||||||||
| 324 | 50 | has 'datatype' => (is => 'ro', isa => ConsumerOf['Attean::API::IRI']); | |||||||||||||
| 325 | 2 | ▶ | sub BUILDARGS { | ||||||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 326 | 2 | my $class = shift; | |||||||||||||
| 327 | 2 | return $class->SUPER::BUILDARGS(@_, operator => '_cast'); | |||||||||||||
| 328 | } | ||||||||||||||
| 329 | 2 | ▶ | sub BUILD { | ||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 330 | 2 | my $self = shift; | |||||||||||||
| 331 | 2 | state $type = Enum[map { "http://www.w3.org/2001/XMLSchema#$_" } qw(integer decimal float double string boolean dateTime)]; | |||||||||||||
| 332 | 2 | $type->assert_valid($self->datatype->value); | |||||||||||||
| 333 | } | ||||||||||||||
| 334 | |||||||||||||||
| 335 | 0 | ▶ | sub tree_attributes { return qw(operator datatype) } | ||||||||||||
|
Subroutine
tree_attributes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 336 | |||||||||||||||
| 337 | 0 | ▶ | sub is_stable { | ||||||||||||
|
Subroutine
is_stable: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 338 | 0 | my $self = shift; | |||||||||||||
| 339 | 0 | foreach my $c (@{ $self->children }) { | |||||||||||||
| 340 | 0 | ▶ | return 0 unless ($c->is_stable); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 341 | } | ||||||||||||||
| 342 | 0 | return 1; | |||||||||||||
| 343 | } | ||||||||||||||
| 344 | |||||||||||||||
| 345 | 1 | ▶ | sub sparql_tokens { | ||||||||||||
|
Subroutine
sparql_tokens: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 346 | 1 | my $self = shift; | |||||||||||||
| 347 | 1 | my $dt = AtteanX::SPARQL::Token->fast_constructor( IRI, -1, -1, -1, -1, [$self->datatype->value] ), | |||||||||||||
| 348 | my $lparen = AtteanX::SPARQL::Token->lparen; | ||||||||||||||
| 349 | 1 | my $rparen = AtteanX::SPARQL::Token->rparen; | |||||||||||||
| 350 | 1 | my $comma = AtteanX::SPARQL::Token->comma; | |||||||||||||
| 351 | |||||||||||||||
| 352 | 1 | my @tokens; | |||||||||||||
| 353 | 1 | push(@tokens, $dt, $lparen); | |||||||||||||
| 354 | 1 | foreach my $t (@{ $self->children }) { | |||||||||||||
| 355 | 1 | push(@tokens, $t->sparql_tokens->elements); | |||||||||||||
| 356 | 1 | push(@tokens, $comma); | |||||||||||||
| 357 | } | ||||||||||||||
| 358 | 1 | ▶ | if (scalar(@tokens) > 2) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 359 | 1 | pop(@tokens); # remove the last comma | |||||||||||||
| 360 | } | ||||||||||||||
| 361 | 1 | push(@tokens, $rparen); | |||||||||||||
| 362 | 1 | return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' ); | |||||||||||||
| 363 | } | ||||||||||||||
| 364 | } | ||||||||||||||
| 365 | |||||||||||||||
| 366 | 50 | package Attean::ExistsExpression 0.040 { | |||||||||||||
| 367 | 50 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 368 | 50 | ▶ | use AtteanX::SPARQL::Constants; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 369 | 50 | ▶ | use AtteanX::SPARQL::Token; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 370 | 50 | ▶ | use Types::Standard qw(ConsumerOf); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 371 | 50 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 372 | |||||||||||||||
| 373 | 50 | with 'Attean::API::SPARQLSerializable'; | |||||||||||||
| 374 | 50 | with 'Attean::API::Expression'; | |||||||||||||
| 375 | |||||||||||||||
| 376 | 0 | ▶ | sub arity { return 0 } | ||||||||||||
|
Subroutine
arity: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 377 | 1 | ▶ | sub BUILDARGS { | ||||||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 378 | 1 | my $class = shift; | |||||||||||||
| 379 | 1 | return $class->SUPER::BUILDARGS(@_, operator => '_exists'); | |||||||||||||
| 380 | } | ||||||||||||||
| 381 | 50 | has 'pattern' => (is => 'ro', isa => ConsumerOf['Attean::API::Algebra']); | |||||||||||||
| 382 | 0 | ▶ | sub as_string { | ||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 383 | 0 | my $self = shift; | |||||||||||||
| 384 | 0 | my $sparql = $self->pattern->as_sparql; | |||||||||||||
| 385 | 0 | $sparql =~ s/\s+/ /g; | |||||||||||||
| 386 | 0 | return "EXISTS { $sparql }"; | |||||||||||||
| 387 | } | ||||||||||||||
| 388 | |||||||||||||||
| 389 | 0 | ▶ | sub tree_attributes { return qw(operator pattern) } | ||||||||||||
|
Subroutine
tree_attributes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 390 | |||||||||||||||
| 391 | 0 | ▶ | sub is_stable { | ||||||||||||
|
Subroutine
is_stable: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 392 | 0 | my $self = shift; | |||||||||||||
| 393 | # TODO: need deep analysis of exists pattern to tell if this is stable | ||||||||||||||
| 394 | # (there might be an unstable filter expression deep inside the pattern) | ||||||||||||||
| 395 | 0 | return 0; | |||||||||||||
| 396 | } | ||||||||||||||
| 397 | |||||||||||||||
| 398 | 1 | ▶ | sub sparql_tokens { | ||||||||||||
|
Subroutine
sparql_tokens: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 399 | 1 | my $self = shift; | |||||||||||||
| 400 | 1 | my $exists = AtteanX::SPARQL::Token->keyword('EXISTS'); | |||||||||||||
| 401 | 1 | my $lbrace = AtteanX::SPARQL::Token->lbrace; | |||||||||||||
| 402 | 1 | my $rbrace = AtteanX::SPARQL::Token->rbrace; | |||||||||||||
| 403 | 1 | my $child = $self->pattern; | |||||||||||||
| 404 | |||||||||||||||
| 405 | 1 | my @tokens; | |||||||||||||
| 406 | 1 | push(@tokens, $exists, $lbrace); | |||||||||||||
| 407 | 1 | push(@tokens, $child->sparql_tokens->elements); | |||||||||||||
| 408 | 1 | push(@tokens, $rbrace); | |||||||||||||
| 409 | 1 | return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' ); | |||||||||||||
| 410 | } | ||||||||||||||
| 411 | |||||||||||||||
| 412 | 0 | ▶ | sub unaggregated_variables { | ||||||||||||
|
Subroutine
unaggregated_variables: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 413 | 0 | my $self = shift; | |||||||||||||
| 414 | 0 | return map { Attean::Variable->new($_) } $self->pattern->in_scope_variables; | |||||||||||||
| 415 | } | ||||||||||||||
| 416 | } | ||||||||||||||
| 417 | |||||||||||||||
| 418 | 50 | package Attean::ExistsPlanExpression 0.040 { | |||||||||||||
| 419 | 50 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 420 | 50 | ▶ | use Types::Standard qw(ConsumerOf); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 421 | 50 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 422 | |||||||||||||||
| 423 | 50 | with 'Attean::API::Expression'; | |||||||||||||
| 424 | 0 | ▶ | sub arity { return 0 } | ||||||||||||
|
Subroutine
arity: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 425 | 0 | ▶ | sub BUILDARGS { | ||||||||||||
|
Subroutine
BUILDARGS: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 426 | 0 | my $class = shift; | |||||||||||||
| 427 | 0 | return $class->SUPER::BUILDARGS(@_, operator => '_existsplan'); | |||||||||||||
| 428 | } | ||||||||||||||
| 429 | 50 | has 'plan' => (is => 'ro', isa => ConsumerOf['Attean::API::BindingSubstitutionPlan']); | |||||||||||||
| 430 | 0 | ▶ | sub as_string { | ||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 431 | 0 | my $self = shift; | |||||||||||||
| 432 | # TODO: implement as_string for EXISTS patterns | ||||||||||||||
| 433 | 0 | return "Attean::ExistsPlanExpression { ... }"; | |||||||||||||
| 434 | } | ||||||||||||||
| 435 | 0 | ▶ | sub as_sparql { | ||||||||||||
|
Subroutine
as_sparql: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 436 | 0 | my $self = shift; | |||||||||||||
| 437 | 0 | my %args = @_; | |||||||||||||
| 438 | 0 | ▶ | my $level = $args{level} // 0; | ||||||||||||
|
Condition0%0/2
$args{"level"} // 0
MC/DC0%0/1
$args{"level"} // 0
$args{"level"}
Truth table0%0/2
A
A= $args{"level"}
| |||||||||||||||
| 439 | 0 | ▶ | my $sp = $args{indent} // ' '; | ||||||||||||
|
Condition0%0/2
$args{"indent"} // " "
MC/DC0%0/1
$args{"indent"} // " "
$args{"indent"}
Truth table0%0/2
A
A= $args{"indent"}
| |||||||||||||||
| 440 | 0 | my $indent = $sp x $level; | |||||||||||||
| 441 | |||||||||||||||
| 442 | # TODO: implement as_string for EXISTS patterns | ||||||||||||||
| 443 | 0 | return "EXISTS { " . $self->pattern->as_sparql( level => $level+1, indent => $sp ) . " }"; | |||||||||||||
| 444 | } | ||||||||||||||
| 445 | |||||||||||||||
| 446 | 0 | ▶ | sub tree_attributes { return qw(operator plan) } | ||||||||||||
|
Subroutine
tree_attributes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 447 | |||||||||||||||
| 448 | 0 | ▶ | sub is_stable { | ||||||||||||
|
Subroutine
is_stable: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 449 | 0 | my $self = shift; | |||||||||||||
| 450 | # TODO: need deep analysis of exists pattern to tell if this is stable | ||||||||||||||
| 451 | # (there might be an unstable filter expression deep inside the pattern) | ||||||||||||||
| 452 | 0 | return 0; | |||||||||||||
| 453 | } | ||||||||||||||
| 454 | |||||||||||||||
| 455 | 0 | ▶ | sub unaggregated_variables { | ||||||||||||
|
Subroutine
unaggregated_variables: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 456 | 0 | my $self = shift; | |||||||||||||
| 457 | 0 | die "unaggregated_variables cannot be called on Attean::ExistsPlanExpression"; | |||||||||||||
| 458 | } | ||||||||||||||
| 459 | } | ||||||||||||||
| 460 | |||||||||||||||
| 461 | |||||||||||||||
| 462 | 50 | 1; | |||||||||||||
| 463 | |||||||||||||||
| 464 | __END__ | ||||||||||||||