AtteanX/Functions/CompositeMaps.pm

filter: Statementstmt 35.1% 161 / 458 Branchbran 23.1% 37 / 160 Conditioncond 7.2% 4 / 55 MC/DCmcdc 2.8% 1 / 35 Subroutinesub 52.0% 25 / 48 Podpod 73.0% 19 / 26 totaltotal 31.5% 247 / 782 CC 105 SCAR 46.9
CC
105
Cov
30%
_compare
462.0
equals
306.0
sort_map_keys
56.0
CRAP 109.3
« AtteanX/Functions/CompositeLists.pm ↑ Summary Attean/API/Term.pm »
1 51 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 51 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 51 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 AtteanX::Functions::CompositeMaps - Functions and aggregates to work with composite maps
8  
9 =head1 VERSION
10  
11 This document describes AtteanX::Functions::CompositeMaps version 0.032
12  
13 =head1 SYNOPSIS
14  
15 use v5.14;
16 use Attean;
17  
18 =head1 DESCRIPTION
19  
20 This is a utility package that defines functions and aggregates to work with
21 composite map datatypes.
22  
23 =over 4
24  
25 =cut
26  
27 51 package AtteanX::Functions::CompositeMaps::TurtleLexerWithNull {
28 51 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 51 ▶ use AtteanX::Serializer::TurtleTokens;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 51 ▶ use AtteanX::Parser::Turtle;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 51 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 51 extends 'AtteanX::Parser::Turtle::Lexer';
33  
34 15 ▶ sub get_token {
Subroutine get_token: called CC=8 SCAR=24.9
Pod documented
35 15 my $self = shift;
36 15 while (1) {
37 15 ▶ $self->fill_buffer unless (length($self->buffer));
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->buffer 3 12 15
38  
39 15 my $start_column = $self->column;
40 15 my $start_line = $self->line;
41  
42 15 ▶ if ($self->buffer =~ /^[ \r\n\t]+/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^[ \r\n\t]+/ou) 0 15 15
43 0 my $ws = $self->read_length($+[0]);
44 # we're ignoring whitespace tokens, but we could return them here instead of falling through to the 'next':
45 0 ▶ unless ($self->ignore_whitespace) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->ignore_whitespace) 0 0 0
46 0 return $self->new_token(WS, $start_line, $start_column, $ws);
47 }
48 0 next;
49 }
50  
51 15 my $c = $self->peek_char();
52 15 ▶ return unless (defined($c));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 15 15
53 15 ▶ if ($c eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq ":") 3 12 15
54 3 $self->read_length(1);
55 3 return AtteanX::Parser::Turtle::Token->fast_constructor(PREFIXNAME, -1, -1, -1, -1, [':']);
56 }
57 12 ▶ if ($self->buffer =~ /^null\b/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->buffer =~ /^null\b/u) { } 0 12 12
elsif ($self->buffer =~ /^(true|false)\b/u) { } 0 12 12
58 0 $self->read_length($+[0]);
59 0 return 1;
60 } elsif ($self->buffer =~ /^(true|false)\b/) {
61 0 my $bool = $self->read_length($+[0]);
62 0 return $self->new_token(BOOLEAN, $start_line, $start_column, $bool);
63 }
64 12 return $self->SUPER::get_token();
65 }
66 }
67 }
68  
69 51 package AtteanX::Functions::CompositeMaps 0.032 {
70  
71 51 ▶ use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 51 ▶ use Attean::RDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 51 ▶ use Encode qw(decode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
74 51 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
75 51 ▶ use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
76 51 ▶ use AtteanX::Serializer::TurtleTokens;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 51 ▶ use AtteanX::Parser::Turtle;
Subroutine BEGIN: called CC=1 SCAR=0.0
78 51 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 51 ▶ use AtteanX::Functions::CompositeLists;
Subroutine BEGIN: called CC=1 SCAR=0.0
80
81 51 our $CDT_BASE = 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/';
82 51 our $MAP_TYPE_IRI = "${CDT_BASE}Map";
83  
84 # Assume the opening token of the cdt has already been consumed.
85 # Return either a HASH or ARRAY reference, depending on the closing token.
86 # Does not validate the lexical form with respect to balanced cdt tokens.
87 10 ▶ sub _recursive_lexer_parse_cdt {
Subroutine _recursive_lexer_parse_cdt: called CC=14 SCAR=28.2
88 10 my $p = shift;
89 10 my $lexer = shift;
90 10 my @nodes;
91 10 my $s = AtteanX::Serializer::TurtleTokens->new( suppress_whitespace => 1 );
92 10 ▶ while (my $t = $p->_next_nonws($lexer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = $p->_next_nonws($lexer)) 48 0 48
93 48 ▶ if ($t and not blessed($t)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t and not builtin::blessed($t)) { } 0 48 48
Condition33%1/3
$t and not builtin::blessed($t)
!ll&&!rl&&r
0480
MC/DC0%0/2
$t and not builtin::blessed($t)
$t not builtin::blessed($t)
Truth table33%1/3
A and not(B)
A= $tB= not builtin::blessed($t)
ABresult
0X0
100
111
94 # this is the special value returned from our lexer subclass that indicates a null values
95 0 push(@nodes, undef);
96 } else {
97 48 ▶ next if ($t->type == COMMA);
Branch: 1 branch
BranchTrueFalseTotal
if $t->type == 6 8 40 48
98 40 ▶ next if ($t->type == PREFIXNAME and $t->value eq ':'); # COLON
Branch: 1 branch
BranchTrueFalseTotal
if $t->type == 21 and $t->value eq ":" 6 34 40
Condition66%2/3
$t->type == 21 and $t->value eq ":"
!ll&&!rl&&r
3406
MC/DC50%1/2
$t->type == 21 and $t->value eq ":"
$t->type == 21 $t->value eq ":"
Truth table66%2/3
A and B
A= $t->type == 21B= $t->value eq ":"
ABresult
0X0
100
111
99
100 34 ▶ if ($t->type == LBRACE) {
Branch: 5 branches
BranchTrueFalseTotal
if ($t->type == 16) { } 3 31 34
elsif ($t->type == 22) { } 6 25 31
elsif ($t->type == 17) { } 0 25 25
elsif ($t->type == 2) { } 0 25 25
elsif ($t->type == 23) { } 4 21 25
101 3 my $hash = _recursive_lexer_parse_cdt($p, $lexer);
102 3 push(@nodes, AtteanX::Functions::CompositeMaps::map_to_lex(%$hash));
103 } elsif ($t->type == RBRACE) {
104 6 my %hash;
105 6 ▶ die "odd number of map elements" unless (scalar(@nodes) % 2 == 0);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar(@nodes) % 2 == 0 0 6 6
106 6 ▶ while (my ($k, $v) = splice(@nodes, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@nodes, 0, 2)) 6 6 12
107 6 my @tokens;
108 6 push(@tokens, $k->sparql_tokens->elements);
109 6 my $iter = Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::Parser::Turtle::Token' );
110 6 my $bytes = $s->serialize_iter_to_bytes($iter);
111 6 my $key_string = decode_utf8($bytes);
112
113 6 $hash{ $key_string } = $v;
114 }
115 6 return \%hash;
116 } elsif ($t->type == LBRACKET) {
117 0 my $subnodes = _recursive_lexer_parse_cdt($p, $lexer);
118 0 push(@nodes, AtteanX::Functions::CompositeLists::list_to_lex(@$subnodes));
119 } elsif ($t->type == ANON) {
120 0 my $subnodes = [];
121 0 push(@nodes, AtteanX::Functions::CompositeLists::list_to_lex(@$subnodes));
122 } elsif ($t->type == RBRACKET) {
123 4 return \@nodes;
124 } else {
125 21 my $t = $p->_object($lexer, $t);
126 21 push(@nodes, $t);
127 }
128 }
129 }
130  
131 0 die 'unexpected end of map literal lexical form';
132 }
133  
134 =item C<< lex_to_map($literal) >>
135  
136 Parses $literal as a cdt:Map value and returns a hash of stringified keys and
137 term object values. Use C<< lex_to_maplist >> to get a list of key-value pairs
138 in which the keys are also term objects.
139  
140 =cut
141 3 ▶ sub lex_to_map {
Subroutine lex_to_map: called CC=6 SCAR=18.4
Pod documented
142 3 my $l = shift;
143 3 ▶ Carp::confess 'TypeError: Cannot parse non-literal to cdt:Map: ' . $l->as_string unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 3 3
144 3 my $dt = $l->datatype;
145 3 ▶ die 'TypeError: not a datatype literal' unless ($dt);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt 0 3 3
146 3 ▶ die 'TypeError: Expecting a Map but found ' . $dt->value unless ($dt->value eq $MAP_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI 0 3 3
147 3 my $lex = $l->value;
148 3 $lex =~ s/^\s*//g;
149 3 $lex =~ s/\s*$//g;
150
151 3 ▶ unless ($lex =~ m<^\{(.*)\}$>) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lex =~ /^\{(.*)\}$/u) 0 3 3
152 0 die 'TypeError: Invalid lexical form for cdt:Map literal: ' . $dt->value;
153 }
154
155 3 open(my $fh, '<:encoding(UTF-8)', \$lex);
156 3 my $p = AtteanX::Parser::Turtle->new();
157 3 local($p->{enable_cdt_rewriting}) = 0;
158  
159 # $p->_map->{''} = Attean::IRI->new($MAP_TYPE_IRI);
160 3 my $lexer = AtteanX::Functions::CompositeMaps::TurtleLexerWithNull->new(file => $fh);
161 3 my @nodes;
162 3 my $t = $p->_next_nonws($lexer);
163 3 ▶ if ($t->type == LBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 16) 3 0 3
164 3 my $hash = _recursive_lexer_parse_cdt($p, $lexer);
165 3 push(@nodes, %$hash);
166 }
167  
168 3 return @nodes;
169 }
170  
171 =item C<< map_to_lex(@terms) >>
172  
173 =cut
174 6 ▶ sub map_to_lex {
Subroutine map_to_lex: called CC=4 SCAR=14.8
Pod documented
175  
176 6 my @terms = @_;
177 6 my $s = AtteanX::Serializer::TurtleTokens->new( suppress_whitespace => 1 );
178 6 my $bytes = '';
179 6 open(my $io, '>', \$bytes);
180 6 my $first = 1;
181
182 6 my $p = AtteanX::Parser::Turtle->new();
183 6 local($p->{enable_cdt_rewriting}) = 0;
184  
185 6 ▶ while (my ($key_string, $value) = splice(@terms, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@terms, 0, 2)) 6 6 12
186 6 ▶ unless ($first) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($first) 0 6 6
187 0 my @tokens;
188 0 push(@tokens, AtteanX::Parser::Turtle::Token->fast_constructor(COMMA, -1, -1, -1, -1, [',']));
189 0 push(@tokens, AtteanX::Parser::Turtle::Token->fast_constructor(WS, -1, -1, -1, -1, [' ']));
190 0 my $iter = Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::Parser::Turtle::Token' );
191 0 $s->serialize_iter_to_io($io, $iter);
192 }
193 6 $first = 0;
194  
195 6 my @tokens;
196 6 my $key = $p->parse_node($key_string);
197  
198 6 push(@tokens, $key->sparql_tokens->elements);
199 6 push(@tokens, AtteanX::Parser::Turtle::Token->fast_constructor(WS, -1, -1, -1, -1, [' ']));
200  
201 6 push(@tokens, AtteanX::Parser::Turtle::Token->fast_constructor(PREFIXNAME, -1, -1, -1, -1, [':']));
202 6 ▶ if (blessed($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($value)) { } 6 0 6
203 6 push(@tokens, $value->sparql_tokens->elements);
204 6 my $iter = Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::Parser::Turtle::Token' );
205 6 $s->serialize_iter_to_io($io, $iter);
206 } else {
207 0 my $iter = Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::Parser::Turtle::Token' );
208 0 $s->serialize_iter_to_io($io, $iter);
209 0 print {$io} "null";
210 }
211 }
212 6 close($io);
213 6 my $str = decode_utf8($bytes);
214 6 chomp($str);
215 6 return dtliteral("{${str}}", $MAP_TYPE_IRI);
216 }
217  
218 =item C<< mapCreate(@list) >>
219  
220 =cut
221 0 ▶ sub mapCreate {
Subroutine mapCreate: not called CC=4 SCAR=30.0
Pod documented
222 0 my $model = shift;
223 0 my $active_graph = shift;
224 0 my @map;
225 0 my $s = AtteanX::Serializer::TurtleTokens->new( suppress_whitespace => 1 );
226 0 ▶ while (my ($key, $value) = splice(@_, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
227 0 ▶ next unless (is_valid_map_key($key));
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid_map_key($key) 0 0 0
228 0 my @tokens = $key->sparql_tokens->elements;
229 0 my $iter = Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::Parser::Turtle::Token' );
230 0 my $bytes = $s->serialize_iter_to_bytes($iter);
231 0 my $key_string = decode_utf8($bytes);
232 0 push(@map, $key_string, $value);
233 # $map{$key_string} = $value;
234 }
235 0 my $literal = eval { map_to_lex(@map) };
236 0 ▶ warn "cdt:Map constructor error: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
237 0 return $literal;
238 }
239  
240 =item C<< is_valid_map_key( $value ) >>
241  
242 Returns true if $value is a valid map key (is an IRI or a literal), false otherwise.
243  
244 =cut
245 0 ▶ sub is_valid_map_key {
Subroutine is_valid_map_key: not called CC=4 SCAR=30.0
Pod documented
246 0 my $key = shift;
247 0 ▶ return 0 unless (blessed($key));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($key) 0 0 0
248 0 ▶ return 1 if ($key->does('Attean::API::IRI'));
Branch: 1 branch
BranchTrueFalseTotal
if $key->does("Attean::API::IRI") 0 0 0
249 0 ▶ return 1 if ($key->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
if $key->does("Attean::API::Literal") 0 0 0
250 0 return 0;
251 }
252  
253 0 ▶ sub _map_key_string {
Subroutine _map_key_string: not called CC=1 SCAR=6.9
254 0 my $key = shift;
255 0 my $s = AtteanX::Serializer::TurtleTokens->new( suppress_whitespace => 1 );
256 0 my @tokens = $key->sparql_tokens->elements;
257 0 my $iter = Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::Parser::Turtle::Token' );
258 0 my $bytes = $s->serialize_iter_to_bytes($iter);
259 0 my $key_string = decode_utf8($bytes);
260 0 return $key_string;
261 }
262  
263 =item C<< map_terms ( $map ) >>
264  
265 Map the terms contained in this CDT value using the supplied L<Attean::TermMap>
266 map, returning a new CDT value.
267  
268 =cut
269  
270 3 ▶ sub map_terms {
Subroutine map_terms: called CC=5 SCAR=16.7
Pod documented
271 3 my $self = shift;
272 3 my $map = shift;
273 3 my $l = shift;
274 3 ▶ return $l unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 3 3
275 3 my $dt = $l->datatype;
276 3 ▶ return $l unless ($dt->value eq $MAP_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI 0 3 3
277 3 my %nodes = lex_to_map($l);
278 3 ▶ my @mapped = map { $_ => ($map->map($nodes{$_}) || $_) } keys %nodes;
Condition33%1/3
$map->map($nodes{$_}) || $_
l!l&&r!l&&!r
300
MC/DC0%0/2
$map->map($nodes{$_}) || $_
$map->map($nodes{$_}) $_
Truth table33%1/3
A || B
A= $map->map($nodes{$_})B= $_
ABresult
1X1
011
000
279 3 my $literal = eval { map_to_lex(@mapped) };
280 3 ▶ warn "cdt:Map term-mapping error: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
281 3 return $literal;
282 }
283  
284 =item C<< mapGet($list, $key) >>
285  
286 =cut
287 0 ▶ sub mapGet {
Subroutine mapGet: not called CC=3 SCAR=24.8
Pod documented
288 0 my $model = shift;
289 0 my $active_graph = shift;
290 0 my $l = shift;
291 0 my $key = shift;
292 0 ▶ die 'TypeError' unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 0 0
293 0 my $dt = $l->datatype;
294 0 ▶ die 'TypeError' unless ($dt->value eq $MAP_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI 0 0 0
295 0 my %nodes = lex_to_map($l);
296  
297 0 my $key_string = _map_key_string($key);
298 0 my $value = $nodes{$key_string};
299 0 return $value;
300 }
301  
302 =item C<< mapKeys($map) >>
303  
304 =cut
305 0 ▶ sub mapKeys {
Subroutine mapKeys: not called CC=3 SCAR=24.8
Pod documented
306 0 my $model = shift;
307 0 my $active_graph = shift;
308 0 my $map = shift;
309 0 ▶ die 'TypeError' unless ($map->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $map->does("Attean::API::Literal") 0 0 0
310 0 my $dt = $map->datatype;
311 0 ▶ die 'TypeError' unless ($dt->value eq $MAP_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI 0 0 0
312 0 my %nodes = lex_to_map($map);
313 0 my @key_strings = keys %nodes;
314  
315 0 my $p = AtteanX::Parser::Turtle->new();
316 0 local($p->{enable_cdt_rewriting}) = 0;
317  
318 # $p->_map->{''} = Attean::IRI->new($MAP_TYPE_IRI);
319 my @nodes = map {
320 0 open(my $fh, '<:encoding(UTF-8)', \$_);
321 0 my $lexer = AtteanX::Functions::CompositeMaps::TurtleLexerWithNull->new(file => $fh);
322 0 my $token = $p->_next_nonws($lexer);
323 0 $p->_object($lexer, $token);
324 } @key_strings;
325 0 AtteanX::Functions::CompositeLists::list_to_lex(@nodes);
326 }
327  
328 =item C<< map_key_to_term( @keys ) >>
329  
330 Converts each argument from the stringified version of map keys used as hash
331 keys to a list of term objects.
332  
333 =cut
334 0 ▶ sub map_key_to_term {
Subroutine map_key_to_term: not called CC=2 SCAR=17.9
Pod documented
335 0 my @keys = @_;
336 0 my $p = AtteanX::Parser::Turtle->new();
337 0 local($p->{enable_cdt_rewriting}) = 0;
338  
339 my @terms = map {
340 0 open(my $fh, '<:encoding(UTF-8)', \$_);
341 0 my $lexer = AtteanX::Functions::CompositeMaps::TurtleLexerWithNull->new(file => $fh);
342 0 my $token = $p->_next_nonws($lexer);
343 0 $p->_object($lexer, $token);
344 } @keys;
345
346 0 ▶ return wantarray ? @terms : $terms[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
347 }
348
349 =item C<< lex_to_maplist() >>
350  
351 Parses $literal as a cdt:Map value and returns a (flattened) list of key-value
352 pairs of term values.
353  
354 =cut
355 0 ▶ sub lex_to_maplist {
Subroutine lex_to_maplist: not called CC=2 SCAR=17.9
Pod documented
356 0 my %map = lex_to_map(@_);
357 0 my @key_strings = keys %map;
358 0 my @values = values %map;
359 0 my $p = AtteanX::Parser::Turtle->new();
360 0 local($p->{enable_cdt_rewriting}) = 0;
361  
362 my @keys = map {
363 0 open(my $fh, '<:encoding(UTF-8)', \$_);
364 0 my $lexer = AtteanX::Functions::CompositeMaps::TurtleLexerWithNull->new(file => $fh);
365 0 my $token = $p->_next_nonws($lexer);
366 0 $p->_object($lexer, $token);
367 } @key_strings;
368 0 my @list;
369 0 foreach my $i (0 .. $#keys) {
370 0 push(@list, $keys[$i]);
371 0 push(@list, $values[$i]);
372 }
373 0 return @list;
374 }
375  
376 =item C<< mapPut($map, $key, $value) >>
377  
378 =cut
379 0 ▶ sub mapPut {
Subroutine mapPut: not called CC=5 SCAR=34.0
Pod documented
380 0 my $model = shift;
381 0 my $active_graph = shift;
382 0 my $map = shift;
383 0 my $key = shift;
384 0 ▶ die 'TypeError' unless (is_valid_map_key($key));
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid_map_key($key) 0 0 0
385 0 my $value = shift;
386 0 ▶ die 'TypeError' unless (blessed($map) and $map->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($map) and $map->does("Attean::API::Literal") 0 0 0
Condition0%0/3
builtin::blessed($map) and $map->does("Attean::API::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($map) and $map->does("Attean::API::Literal")
builtin::blessed($map) $map->does("Attean::API::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($map)B= $map->does("Attean::API::Literal")
ABresult
0X0
100
111
387 0 my $dt = $map->datatype;
388 0 ▶ die 'TypeError' unless ($dt->value eq $MAP_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI 0 0 0
389 0 my %nodes = lex_to_map($map);
390 0 my @key_strings = keys %nodes;
391  
392 0 my $key_string = _map_key_string($key);
393 0 $nodes{ $key_string } = $value;
394  
395 0 return map_to_lex(%nodes);
396 }
397  
398 =item C<< mapRemove($map, $key) >>
399  
400 =cut
401 0 ▶ sub mapRemove {
Subroutine mapRemove: not called CC=5 SCAR=34.0
Pod documented
402 0 my $model = shift;
403 0 my $active_graph = shift;
404 0 my $map = shift;
405 0 my $key = shift;
406 0 ▶ die 'TypeError' unless (blessed($map) and $map->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($map) and $map->does("Attean::API::Literal") 0 0 0
Condition0%0/3
builtin::blessed($map) and $map->does("Attean::API::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($map) and $map->does("Attean::API::Literal")
builtin::blessed($map) $map->does("Attean::API::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($map)B= $map->does("Attean::API::Literal")
ABresult
0X0
100
111
407 0 my $dt = $map->datatype;
408 0 ▶ die 'TypeError' unless ($dt->value eq $MAP_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI 0 0 0
409 0 my %nodes = lex_to_map($map);
410 0 my @key_strings = keys %nodes;
411  
412 0 ▶ unless (is_valid_map_key($key)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_valid_map_key($key)) 0 0 0
413 0 return $map;
414 }
415  
416 0 my $key_string = _map_key_string($key);
417 0 delete $nodes{ $key_string };
418  
419 0 return map_to_lex(%nodes);
420 }
421  
422 =item C<< mapSize($list) >>
423  
424 =cut
425 0 ▶ sub mapSize {
Subroutine mapSize: not called CC=4 SCAR=30.0
Pod documented
426 0 my $model = shift;
427 0 my $active_graph = shift;
428 0 my $l = shift;
429 0 ▶ die 'TypeError' unless (blessed($l) and $l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($l) and $l->does("Attean::API::Literal") 0 0 0
Condition0%0/3
builtin::blessed($l) and $l->does("Attean::API::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($l) and $l->does("Attean::API::Literal")
builtin::blessed($l) $l->does("Attean::API::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($l)B= $l->does("Attean::API::Literal")
ABresult
0X0
100
111
430 0 my $dt = $l->datatype;
431 0 ▶ die 'TypeError' unless ($dt->value eq $MAP_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI 0 0 0
432 0 my %nodes = lex_to_map($l);
433 0 my @keys = keys(%nodes);
434 0 return Attean::Literal->integer(scalar(@keys));
435 }
436  
437 =item C<< mapContains($map, $term) >>
438  
439 =cut
440 0 ▶ sub mapContains {
Subroutine mapContains: not called CC=5 SCAR=34.0
Pod documented
441 0 my $model = shift;
442 0 my $active_graph = shift;
443 0 my $l = shift;
444 0 my $term = shift;
445 0 ▶ die 'TypeError: Not a literal' unless (blessed($l) and $l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($l) and $l->does("Attean::API::Literal") 0 0 0
Condition0%0/3
builtin::blessed($l) and $l->does("Attean::API::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($l) and $l->does("Attean::API::Literal")
builtin::blessed($l) $l->does("Attean::API::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($l)B= $l->does("Attean::API::Literal")
ABresult
0X0
100
111
446 0 my $dt = $l->datatype;
447 0 ▶ die 'TypeError: Not a cdt:List' unless ($dt->value eq $MAP_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI 0 0 0
448 0 my %nodes = lex_to_map($l);
449  
450 0 my $s = AtteanX::Serializer::TurtleTokens->new( suppress_whitespace => 1 );
451 0 my @tokens = $term->sparql_tokens->elements;
452 0 my $iter = Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::Parser::Turtle::Token' );
453 0 my $bytes = $s->serialize_iter_to_bytes($iter);
454 0 my $key_string = decode_utf8($bytes);
455
456 0 ▶ return (exists $nodes{ $key_string }) ? Attean::Literal->true : Attean::Literal->false;
Branch: 1 branch
BranchTrueFalseTotal
exists $nodes{$key_string} ? : 0 0 0
457 }
458  
459 =item C<< mapMerge($map1, $map2) >>
460  
461 =cut
462 0 ▶ sub mapMerge {
Subroutine mapMerge: not called CC=1 SCAR=6.9
Pod documented
463 0 my $model = shift;
464 0 my $active_graph = shift;
465 0 my $map1 = shift;
466 0 my $map2 = shift;
467 0 my %nodes1 = lex_to_map($map1);
468 0 my %nodes2 = lex_to_map($map2);
469 0 my %merged = (%nodes2, %nodes1);
470 0 my $merged = map_to_lex(%merged);
471 0 return $merged;
472 }
473  
474 =item C<< mapCreate_agg_start() >>
475  
476 =cut
477 0 ▶ sub mapCreate_agg_start {
Subroutine mapCreate_agg_start: not called CC=1 SCAR=6.9
Pod documented
478 0 my $model = shift;
479 0 my $active_graph = shift;
480 return {
481 0 values => {}
482 };
483 }
484  
485 =item C<< mapCreate_agg_process($thunk, $key, $value) >>
486  
487 =cut
488 0 ▶ sub mapCreate_agg_process {
Subroutine mapCreate_agg_process: not called CC=1 SCAR=6.9
Pod documented
489 0 my $thunk = shift;
490 0 my ($key) = shift;
491 0 my $value = shift;
492 0 $thunk->{'values'}{$key->value} = $value;
493 }
494  
495 =item C<< mapCreate_agg_finalize($thunk) >>
496  
497 =cut
498 0 ▶ sub mapCreate_agg_finalize {
Subroutine mapCreate_agg_finalize: not called CC=1 SCAR=6.9
Pod documented
499 0 my $thunk = shift;
500 0 my %terms = @{ $thunk->{'values' }};
501 0 return map_to_lex(%terms);
502 }
503  
504 =item C<< register() >>
505  
506 =cut
507 23 ▶ sub register {
Subroutine register: called CC=1 SCAR=0.0
Pod documented
508 23 Attean->register_datatype_role(
509 $MAP_TYPE_IRI => 'AtteanX::Functions::CompositeMaps::MapLiteral'
510 );
511
512 23 Attean->register_global_functional_form(
513 "${CDT_BASE}Map" => \&mapCreate,
514 "${CDT_BASE}mapCreate" => \&mapCreate,
515 "${CDT_BASE}put" => \&mapPut,
516 );
517 23 Attean->register_global_function(
518 "${CDT_BASE}mapGet" => \&mapGet,
519 "${CDT_BASE}mapSize" => \&mapSize,
520 "${CDT_BASE}keys" => \&mapKeys,
521 "${CDT_BASE}remove" => \&mapRemove,
522 "${CDT_BASE}containsKey" => \&mapContains,
523 "${CDT_BASE}merge" => \&mapMerge,
524 );
525  
526 23 Attean->register_global_aggregate(
527 "${CDT_BASE}mapAgg" => {
528 start => \&mapCreate_agg_start,
529 process => \&mapCreate_agg_process,
530 finalize => \&mapCreate_agg_finalize,
531 },
532 );
533 }
534 }
535  
536 51 package AtteanX::Functions::CompositeMaps::MapLiteral {
537 51 ▶ use Scalar::Util qw(blessed looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
538 51 ▶ use List::Util qw(min);
Subroutine BEGIN: called CC=1 SCAR=0.0
539  
540 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
541  
542 0 ▶ sub equals {
Subroutine equals: not called CC=17 SCAR=57.2
Pod undocumented
543 0 my $lhs = shift;
544 0 my $rhs = shift;
545 # warn "MAP EQUALS?";
546 # warn "- " . $lhs->as_string . "\n";
547 # warn "- " . $rhs->as_string . "\n";
548 0 ▶ return 0 unless ($rhs->does('Attean::API::Literal') and $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI 0 0 0
Condition0%0/3
$rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI
!ll&&!rl&&r
000
MC/DC0%0/2
$rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI
$rhs->does("Attean::API::Literal") $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI
Truth table0%0/3
A and B
A= $rhs->does("Attean::API::Literal")B= $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI
ABresult
0X0
100
111
549 0 my $lhs_size = eval { AtteanX::Functions::CompositeMaps::mapSize(undef, undef, $lhs)->value };
550 0 ▶ return 0 if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
551 0 my $rhs_size = eval { AtteanX::Functions::CompositeMaps::mapSize(undef, undef, $rhs)->value };
552 0 ▶ return 0 if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
553 0 ▶ return 0 unless ($lhs_size == $rhs_size);
Branch: 1 branch
BranchTrueFalseTotal
unless $lhs_size == $rhs_size 0 0 0
554
555 0 my %lhs_map = AtteanX::Functions::CompositeMaps::lex_to_map($lhs);
556 0 my %rhs_map = AtteanX::Functions::CompositeMaps::lex_to_map($rhs);
557
558 0 my @lhs_keys = sort(keys %lhs_map);
559 0 my @rhs_keys = sort(keys %rhs_map);
560
561 # TODO: handle differing lexical forms for map keys here:
562  
563 0 my $seen_error = 0;
564 0 foreach my $i (0 .. $lhs_size-1) {
565 0 ▶ return 0 unless ($lhs_keys[$i] eq $rhs_keys[$i]);
Branch: 1 branch
BranchTrueFalseTotal
unless $lhs_keys[$i] eq $rhs_keys[$i] 0 0 0
566 0 my $key = $lhs_keys[$i];
567 0 my $lv = $lhs_map{$key};
568 0 my $rv = $rhs_map{$key};
569 0 ▶ if (not blessed($lv) and not blessed($rv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not builtin::blessed($lv) || builtin::blessed($rv)) { } 0 0 0
elsif (not builtin::blessed($lv) && builtin::blessed($rv)) { } 0 0 0
Condition0%0/3
builtin::blessed($lv) || builtin::blessed($rv)
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($lv) || builtin::blessed($rv)
builtin::blessed($lv) builtin::blessed($rv)
Truth table0%0/3
A || B
A= builtin::blessed($lv)B= builtin::blessed($rv)
ABresult
1X1
011
000
570 # both null
571 0 next;
572 ▶ } elsif (not blessed($lv) or not blessed($rv)) {
Condition0%0/3
builtin::blessed($lv) && builtin::blessed($rv)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($lv) && builtin::blessed($rv)
builtin::blessed($lv) builtin::blessed($rv)
Truth table0%0/3
A && B
A= builtin::blessed($lv)B= builtin::blessed($rv)
ABresult
0X0
100
111
573 0 return 0;
574 }
575  
576 0 ▶ if ($lv->does('Attean::API::Blank') and $rv->does('Attean::API::Blank')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lv->does("Attean::API::Blank") and $rv->does("Attean::API::Blank")) 0 0 0
Condition0%0/3
$lv->does("Attean::API::Blank") and $rv->does("Attean::API::Blank")
!ll&&!rl&&r
000
MC/DC0%0/2
$lv->does("Attean::API::Blank") and $rv->does("Attean::API::Blank")
$lv->does("Attean::API::Blank") $rv->does("Attean::API::Blank")
Truth table0%0/3
A and B
A= $lv->does("Attean::API::Blank")B= $rv->does("Attean::API::Blank")
ABresult
0X0
100
111
577 0 ▶ if ($lv->value eq $rv->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lv->value eq $rv->value) { } 0 0 0
578 0 next;
579 } else {
580 0 $seen_error++;
581 0 next;
582 }
583 }
584  
585 0 ▶ return 0 unless ($lv->equals($rv));
Branch: 1 branch
BranchTrueFalseTotal
unless $lv->equals($rv) 0 0 0
586 }
587 0 ▶ if ($seen_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_error) 0 0 0
588 0 die 'TypeError';
589 }
590 0 return 1;
591 }
592
593 0 ▶ sub order {
Subroutine order: not called CC=1 SCAR=6.9
Pod undocumented
594 0 my $self = shift;
595 0 return _compare('order', $self, @_);
596 }
597
598 0 ▶ sub compare {
Subroutine compare: not called CC=1 SCAR=6.9
Pod undocumented
599 0 my $self = shift;
600 0 return _compare('compare', $self, @_);
601 }
602
603 0 ▶ sub _compare {
Subroutine _compare: not called CC=21 SCAR=61.4
604 0 my $cmp_method = shift;
605 0 my $lhs = shift;
606 0 my $rhs = shift;
607 # warn "MAP-LESS-THAN?";
608 # warn "- " . $lhs->as_string . "\n";
609 # warn "- " . $rhs->as_string . "\n";
610 0 ▶ die 'TypeError' unless (blessed($rhs) and $rhs->does('Attean::API::Literal') and $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($rhs) and $rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI 0 0 0
Condition0%0/6
builtin::blessed($rhs) and $rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI
!ll&&!rl&&r
000
builtin::blessed($rhs) and $rhs->does("Attean::API::Literal")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($rhs) and $rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI
builtin::blessed($rhs) $rhs->does("Attean::API::Literal") $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI
Truth table0%0/4
A and B and C
A= builtin::blessed($rhs)B= $rhs->does("Attean::API::Literal")C= $rhs->datatype->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI
ABCresult
0XX0
10X0
1100
1111
611
612 0 my %lhs = AtteanX::Functions::CompositeMaps::lex_to_map($lhs);
613 0 my %rhs = AtteanX::Functions::CompositeMaps::lex_to_map($rhs);
614
615 0 my $lhs_size = scalar(%lhs);
616 0 my $rhs_size = scalar(%rhs);
617
618 0 ▶ if (not($lhs_size) and not($rhs_size)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lhs_size or $rhs_size) 0 0 0
Condition0%0/3
$lhs_size or $rhs_size
l!l&&r!l&&!r
000
MC/DC0%0/2
$lhs_size or $rhs_size
$lhs_size $rhs_size
Truth table0%0/3
A or B
A= $lhs_sizeB= $rhs_size
ABresult
1X1
011
000
619 0 return 0; # empty maps are trivially eq
620 }
621
622
623 0 ▶ if (scalar(%lhs) == 0 and scalar(%rhs) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %lhs == 0 and scalar %rhs == 0) 0 0 0
Condition0%0/3
scalar %lhs == 0 and scalar %rhs == 0
!ll&&!rl&&r
000
MC/DC0%0/2
scalar %lhs == 0 and scalar %rhs == 0
scalar %lhs == 0 scalar %rhs == 0
Truth table0%0/3
A and B
A= scalar %lhs == 0B= scalar %rhs == 0
ABresult
0X0
100
111
624 0 return 0;
625 }
626  
627 0 my @lhs_keys = sort_map_keys(keys %lhs);
628 0 my @rhs_keys = sort_map_keys(keys %rhs);
629
630 0 my $length = min($lhs_size, $rhs_size);
631 0 foreach my $i (0 .. $length-1) {
632 0 my $k1 = AtteanX::Functions::CompositeMaps::map_key_to_term($lhs_keys[$i]);
633 0 my $k2 = AtteanX::Functions::CompositeMaps::map_key_to_term($rhs_keys[$i]);
634
635 0 my $same = sameterm($k1, $k2);
636 0 ▶ if (not($same)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($same) 0 0 0
637 # the keys are not the same
638 0 my @sorted = sort_map_keys($lhs_keys[$i], $rhs_keys[$i]);
639 0 ▶ if ($sorted[0] eq $lhs_keys[$i]) { # k1 is ordered before k2 according tot he map key sorting
Branch: 1 branch
BranchTrueFalseTotal
if ($sorted[0] eq $lhs_keys[$i]) { } 0 0 0
640 0 return -1; # less than
641 } else {
642 0 return 1; # greater than
643 }
644 }
645
646 0 my $v1 = $lhs{$lhs_keys[$i]};
647 0 my $v2 = $rhs{$rhs_keys[$i]};
648  
649 0 ▶ if (not blessed($v1) and not blessed($v2)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not builtin::blessed($v1) || builtin::blessed($v2)) { } 0 0 0
elsif (not builtin::blessed($v1)) { } 0 0 0
elsif (not builtin::blessed($v2)) { } 0 0 0
Condition0%0/3
builtin::blessed($v1) || builtin::blessed($v2)
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($v1) || builtin::blessed($v2)
builtin::blessed($v1) builtin::blessed($v2)
Truth table0%0/3
A || B
A= builtin::blessed($v1)B= builtin::blessed($v2)
ABresult
1X1
011
000
650 # both null
651 0 next;
652 } elsif (not blessed($v1)) {
653 0 ▶ if ($cmp_method eq 'order') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp_method eq 'order') { } 0 0 0
654 0 return -1;
655 } else {
656 0 die 'TypeError';
657 }
658 } elsif (not blessed($v2)) {
659 0 ▶ if ($cmp_method eq 'order') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp_method eq 'order') { } 0 0 0
660 0 return 1;
661 } else {
662 0 die 'TypeError';
663 }
664 }
665
666 0 ▶ if ($cmp_method eq 'compare') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp_method eq "compare") 0 0 0
667 0 foreach my $v ($v1, $v2) {
668 0 ▶ if ($v->does('Attean::API::IRI')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->does("Attean::API::IRI")) 0 0 0
669 0 die 'TypeError'; # IRIs as map values cannot be compared
670 }
671 }
672 }
673
674 0 my $v_cmp = $v1->$cmp_method($v2); # may throw an error
675 0 ▶ if ($v_cmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v_cmp) 0 0 0
676 0 return $v_cmp;
677 }
678 }
679
680 0 return ($lhs_size - $rhs_size); # sort smaller maps ahead of larger maps
681 }
682
683 0 ▶ sub sameterm {
Subroutine sameterm: not called CC=4 SCAR=30.0
Pod undocumented
684 # shared code with SAMETERM handling in SimpleQueryEvaluator. Consider refactoring.
685 0 my $a = shift;
686 0 my $b = shift;
687 0 my $cmp = eval { $a->compare($b) };
688 0 ▶ if (not($@) and $cmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $@ and $cmp) 0 0 0
Condition0%0/3
not $@ and $cmp
!ll&&!rl&&r
000
MC/DC0%0/2
not $@ and $cmp
not $@ $cmp
Truth table0%0/3
not(A) and B
A= not $@B= $cmp
ABresult
0X0
100
111
689 0 return 0;
690 }
691 0 ▶ if ($a->does('Attean::API::Binding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->does('Attean::API::Binding')) { } 0 0 0
692 0 my $ok = ($a->sameTerms($b));
693 0 return $ok;
694 } else {
695 0 my $ok = ($a->value eq $b->value);
696 0 return $ok;
697 }
698 }
699
700 0 ▶ sub sort_map_keys {
Subroutine sort_map_keys: not called CC=7 SCAR=40.3
Pod undocumented
701 0 my @keys = @_;
702 0 my @terms = AtteanX::Functions::CompositeMaps::map_key_to_term(@keys);
703 0 my @iri_i;
704 my @other_i;
705 0 foreach my $i (0 .. $#terms) {
706 0 ▶ if ($terms[$i]->does('Attean::API::IRI')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($terms[$i]->does('Attean::API::IRI')) { } 0 0 0
707 0 push(@iri_i, $i);
708 } else {
709 0 push(@other_i, $i);
710 }
711 }
712 @iri_i = sort {
713 0 my $at = $terms[$a];
714 0 my $bt = $terms[$b];
715 0 $at->compare($bt)
716 } @iri_i;
717 @other_i = sort {
718 0 my $at = $terms[$a];
719 0 my $bt = $terms[$b];
720 0 my $a_value = $at->value;
721 0 my $a_dt = $at->datatype->value;
722 0 ▶ my $a_lang = $at->language // '';
Condition0%0/2
$at->language // ""
l!l
00
MC/DC0%0/1
$at->language // ""
$at->language
Truth table0%0/2
A
A= $at->language
Aresult
11
00
723 0 my $b_value = $bt->value;
724 0 my $b_dt = $bt->datatype->value;
725 0 ▶ my $b_lang = $bt->language // '';
Condition0%0/2
$bt->language // ""
l!l
00
MC/DC0%0/1
$bt->language // ""
$bt->language
Truth table0%0/2
A
A= $bt->language
Aresult
11
00
726
727 0 ▶ if (my $cdt = ($a_dt cmp $b_dt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cdt = $a_dt cmp $b_dt) 0 0 0
728 0 return $cdt;
729 }
730 0 ▶ if (my $cval = ($a_value cmp $b_value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cval = $a_value cmp $b_value) 0 0 0
731 0 return $cval;
732 }
733 0 return $a_lang cmp $b_lang;
734 } @other_i;
735
736 0 return map { $keys[$_] } (@iri_i, @other_i);
737 }
738  
739 0 ▶ sub canonicalized_term {
Subroutine canonicalized_term: not called CC=1 SCAR=6.9
Pod undocumented
740 0 my $self = shift;
741 0 return $self->canonicalized_term_strict();
742 }
743  
744 0 ▶ sub canonicalized_term_strict {
Subroutine canonicalized_term_strict: not called CC=1 SCAR=6.9
Pod undocumented
745 0 my $self = shift;
746 0 my %values = AtteanX::Functions::CompositeMaps::lex_to_map($self);
747 0 my @keys = sort keys %values;
748 0 my @values = map { $_ => $values{$_} } @keys;
749 0 return AtteanX::Functions::CompositeMaps::map_to_lex(@values);
750 }
751  
752 51 with 'Attean::API::Literal';
753 51 with 'Attean::API::CanonicalizingLiteral';
754 }
755  
756 51 1;
757  
758 __END__
« AtteanX/Functions/CompositeLists.pm ↑ Summary Attean/API/Term.pm »