| 1 | package RDF::LDF; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use feature qw(state); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Data::Compare; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use RDF::NS; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use RDF::Trine; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use RDF::Query; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use Log::Any (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Cache::LRU; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use Clone qw(clone); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use URI::Template; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use RDF::LDF::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | our $VERSION = '0.251'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | has url => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | is => 'ro' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | required => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | has sn => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'ro' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | builder => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_sn: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | RDF::NS->new->REVERSE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | has lru => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | is => 'ro' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | builder => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_lru: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | Cache::LRU->new( size => 100 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | has log => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | builder => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_log: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | Log::Any->get_logger(category => ref(shift)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Public method | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | ▶ | sub is_fragment_server { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_fragment_server: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | my $federated = ref($self->url) ? $self->url : [ $self->url ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | for my $part (@$federated) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | ▶ | return 0 unless $self->get_query_pattern($part); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # Public method | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Optimized method to find all bindings matching a pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # See: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # Verborgh, Ruben, et al. Querying Datasets on the Web with High Availability. ISWC2014 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # http://linkeddatafragments.org/publications/iswc2014.pdf | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | ▶ | sub get_pattern { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_pattern: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 7 | my ($self,$bgp,$context,%args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 7 | ▶ | unless (defined $bgp) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | RDF::LDF::Error->throw(text => "can't execute get_pattern for an empty pattern"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | ▶ | my (@triples) = ($bgp->isa('RDF::Trine::Statement') or $bgp->isa('RDF::Query::Algebra::Filter')) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$bgp->isa("RDF::Trine::Statement") or $bgp->isa("RDF::Query::Algebra::Filter")
MC/DC50%1/2
$bgp->isa("RDF::Trine::Statement") or $bgp->isa("RDF::Query::Algebra::Filter")
$bgp->isa("RDF::Trine::Statement")
$bgp->isa("RDF::Query::Algebra::Filter")
Truth table66%2/3
A or B
A= $bgp->isa("RDF::Trine::Statement")B= $bgp->isa("RDF::Query::Algebra::Filter")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ? $bgp | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | : $bgp->triples; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | ▶ | unless (@triples) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | RDF::LDF::Error->throw(text => "can't execute get_pattern for an empty pattern"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | my @vars = $bgp->referenced_variables; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | my @bgps = map { $self->_parse_triple_pattern($_)} @triples; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 12 | ▶ | my $sub = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 12 | state $it = $self->_find_variable_bindings(\@bgps); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 12 | my $b = $it->(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 12 | ▶ | return undef unless $b; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 10 | my $binding = RDF::Trine::VariableBindings->new({}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 10 | for my $key (keys %$b) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 26 | my $val = $b->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 26 | $key =~ s{^\?}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 26 | $binding->set($key => $val); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 10 | $binding; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | RDF::Trine::Iterator::Bindings->new($sub,\@vars); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 14 | ▶ | sub _find_variable_bindings { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_variable_bindings: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 14 | my $bgps = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 14 | ▶ | my $bindings = shift // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // {}
MC/DC100%1/1
shift() // {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 26 | ▶ | my $iterator = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 26 | state $it; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 26 | ▶ | state $results = sub {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 26 | my $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Loop over all variabe bindings with multiple matches | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 26 | ▶ | while (!defined($ret = $results->())) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 28 | ▶ | unless (defined $it) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # Find the an binding iterator for the best pattern from $bgpgs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 14 | ($it,$bgps) = $self->_find_variable_bindings_($bgps); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 14 | ▶ | return undef unless $it; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # Update all the other bgps with the current binding.. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 28 | my $this_binding = $it->(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 28 | ▶ | return undef unless $this_binding; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 18 | $bindings = { %$bindings , %$this_binding }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 18 | ▶ | return $bindings unless @$bgps; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # Apply all the bindings to the rest of the bgps; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 8 | my $bgps_prime = $self->_apply_binding($this_binding,$bgps); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | $results = $self->_find_variable_bindings($bgps_prime,$bindings); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 14 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 14 | $iterator; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # Given an array ref of patterns return the variable bindings for the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # pattern with the least number of triples. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # my ($iterator, $rest) = $self->_find_variable_bindings([ {pattern} , {pattern} , ... ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # where: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # $iterator - Iterator for variable bindings for the winnnig pattern, or undef when no | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # patterns are provided or we get zero results | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # $rest - An array ref of patterns not containing the best pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 14 | ▶ | sub _find_variable_bindings_ { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_variable_bindings_: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 14 | my ($self,$bgps) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 14 | ▶ | return (undef, undef) unless _is_array_ref($bgps) && @$bgps > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
_is_array_ref($bgps) and @$bgps > 0
MC/DC0%0/2
_is_array_ref($bgps) and @$bgps > 0
_is_array_ref($bgps)
@$bgps > 0
Truth table33%1/3
A and B
A= _is_array_ref($bgps)B= @$bgps > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 14 | my ($pattern,$rest) = $self->_find_best_pattern($bgps); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 14 | ▶ | return (undef,undef) unless defined $pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 14 | my $it = $self->get_statements($pattern); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # Build a mapping of variable bindings to Triple nodes. E.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # '?s' => 'subject' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # '?p' => 'predicate' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # '?o' => 'object' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | #} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 14 | ▶ | my %pattern_var_map = map { $pattern->{$_} =~ /^\?/ ? ($pattern->{$_} , $_) : () } keys %$pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 14 | my $num_of_bindings = keys %pattern_var_map; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 28 | ▶ | my $sub = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 28 | my $triple = $it->(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 28 | ▶ | return undef unless defined $triple; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 18 | my %var_map = %pattern_var_map; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 18 | for (keys %var_map) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 30 | my $method = $var_map{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 30 | $var_map{$_} = $triple->$method; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 18 | return {%var_map}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 14 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 14 | return ($sub,$rest); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 8 | ▶ | sub _apply_binding { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_binding: called CC=7 SCAR=20.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 8 | my ($self,$binding,$bgps) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 8 | ▶ | return unless _is_array_ref($bgps) && @$bgps > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
_is_array_ref($bgps) and @$bgps > 0
MC/DC0%0/2
_is_array_ref($bgps) and @$bgps > 0
_is_array_ref($bgps)
@$bgps > 0
Truth table33%1/3
A and B
A= _is_array_ref($bgps)B= @$bgps > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 8 | my $copy = clone $bgps; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 8 | my @new = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 8 | for my $pattern (@$copy) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 8 | for (qw(subject predicate object)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 24 | my $val = $pattern->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 24 | ▶ | if (defined($val) && $binding->{$val}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $val and $binding->{$val}
MC/DC0%0/2
defined $val and $binding->{$val}
defined $val
$binding->{$val}
Truth table33%1/3
A and B
A= defined $valB= $binding->{$val}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 8 | my $str_val = $self->_node_as_string($binding->{$val}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | $pattern->{$_} = $str_val | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 8 | push @new, $pattern; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 8 | return \@new; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # Create a pattern which binds to the graph pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # my $triples = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # { subject => ... , predicate => ... , object => ... } , #tp1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # { subject => ... , predicate => ... , object => ... } , #tp2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # ... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # { subject => ... , predicate => ... , object => ... } , #tpN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # my ($pattern, $rest) = $self->_find_best_pattern($triples); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # $pattern => Pattern in $triples which least amount of results | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # $rest => All patterns in $triples except $pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 14 | ▶ | sub _find_best_pattern { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_best_pattern: called CC=10 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 14 | my ($self,$triples) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 14 | ▶ | return undef unless @$triples > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # If we only have one tripple pattern, the use it to create the bind | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 14 | ▶ | if (@$triples == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 12 | return $triples->[0] , []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | my $best_pattern = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | my $best_count = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 2 | for my $pattern (@$triples) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | ▶ | my $count = $self->_total_triples($pattern) // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_total_triples($pattern) // 0
MC/DC0%0/1
$self->_total_triples($pattern) // 0
$self->_total_triples($pattern)
Truth table50%1/2
A
A= $self->_total_triples($pattern)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | ▶ | if ($count == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | $best_pattern = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $best_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | ▶ | elsif (!defined $best_count || $count < $best_count) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not defined $best_count or $count < $best_count
MC/DC50%1/2
not defined $best_count or $count < $best_count
not defined $best_count
$count < $best_count
Truth table66%2/3
not(A) or B
A= not defined $best_countB= $count < $best_count
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | $best_count = $count; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | $best_pattern = $pattern; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | ▶ | return (undef,$triples) unless defined $best_pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | ▶ | my @rest_triples = map { Data::Compare::Compare($_,$best_pattern) ? () : ($_) } @$triples; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | return ($best_pattern, \@rest_triples); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # Find the total number of triples available for a pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # my $count = $self->_total_triples( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # { subject => ... , predicate => ... , object => ...} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # Where | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # $count is a number | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | ▶ | sub _total_triples { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_total_triples: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 4 | my ($self,$pattern) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # Retrieve one... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 4 | my $iterator = $self->get_statements($pattern); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 4 | ▶ | return 0 unless $iterator; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 4 | my ($model,$info) = $iterator->(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 4 | $info->{hydra_totalItems}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 32 | ▶ | sub _node_as_string { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_node_as_string: called CC=5 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 32 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 32 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 32 | ▶ | if (_is_blessed($node) && $node->isa('RDF::Trine::Node')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
_is_blessed($node) and $node->isa("RDF::Trine::Node")
MC/DC0%0/2
_is_blessed($node) and $node->isa("RDF::Trine::Node")
_is_blessed($node)
$node->isa("RDF::Trine::Node")
Truth table33%1/3
A and B
A= _is_blessed($node)B= $node->isa("RDF::Trine::Node")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 32 | ▶ | if ($node->isa('RDF::Trine::Node::Variable')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 16 | return $node->as_string; # ?foo | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } elsif ($node->isa('RDF::Trine::Node::Literal')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return $node->as_string; # includes quotes and any language or datatype | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 16 | return $node->value; # the raw IRI or blank node identifier value, without other syntax | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # For an BGP triple create a fragment pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 8 | ▶ | sub _parse_triple_pattern { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_triple_pattern: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 8 | my ($self,$triple) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 8 | my $subject = $self->_node_as_string($triple->subject); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 8 | my $predicate = $self->_node_as_string($triple->predicate); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 8 | my $object = $self->_node_as_string($triple->object); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 8 | my $hash = { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | subject => $subject , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | predicate => $predicate, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | object => $object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 8 | return $hash; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # Dynamic find out which triple patterns need to be used to query the fragment server | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # Returns a hash: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # rdf_subject => <name_of_subject_variable> , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # rdf_predicate => <name_of_predicate_variable> , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # rdf_object => <name_of_object_variable> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # hydra_template => <endpoint_for_tripple_pattern> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 42 | ▶ | sub get_query_pattern { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_query_pattern: called CC=10 SCAR=23.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 42 | my ($self,$url) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 42 | my $fragment = $self->get_model_and_info($url); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 42 | ▶ | return undef unless defined $fragment; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 42 | my $info = $fragment->{info}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 42 | my $pattern; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 42 | ▶ | return undef unless _is_hash_ref($info); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 42 | ▶ | return undef unless $info->{hydra_template}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 42 | for (keys %$info) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 716 | ▶ | next unless _is_hash_ref($info->{$_}) && $info->{$_}->{hydra_property}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_is_hash_ref($info->{$_}) and $info->{$_}{"hydra_property"}
MC/DC100%2/2
_is_hash_ref($info->{$_}) and $info->{$_}{"hydra_property"}
_is_hash_ref($info->{$_})
$info->{$_}{"hydra_property"}
Truth table100%3/3
A and B
A= _is_hash_ref($info->{$_})B= $info->{$_}{"hydra_property"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 126 | my $property = join "_" , $self->sn->qname($info->{$_}->{hydra_property}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 126 | my $variable = $info->{$_}->{hydra_variable}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 126 | $pattern->{$property} = $variable; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 42 | ▶ | return undef unless $pattern->{rdf_subject}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 42 | ▶ | return undef unless $pattern->{rdf_predicate}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 42 | ▶ | return undef unless $pattern->{rdf_object}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 42 | $pattern->{hydra_template} = $info->{hydra_template}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 42 | $pattern; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | #---------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # Public method | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 19 | ▶ | sub get_statements { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_statements: called CC=19 SCAR=31.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 19 | my ($self,@triple) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 19 | my ($subject,$predicate,$object); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 19 | ▶ | if (@triple == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ($subject,$predicate,$object) = @triple; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | elsif (_is_hash_ref($triple[0])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 18 | $subject = $triple[0]->{subject}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 18 | $predicate = $triple[0]->{predicate}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 18 | $object = $triple[0]->{object}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 19 | ▶ | $subject = $subject->value if (_is_blessed($subject) && $subject->isa('RDF::Trine::Node') and not $subject->is_variable); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
_is_blessed($subject) and $subject->isa("RDF::Trine::Node") and not $subject->is_variable
_is_blessed($subject) and $subject->isa("RDF::Trine::Node")
MC/DC0%0/3
_is_blessed($subject) and $subject->isa("RDF::Trine::Node") and not $subject->is_variable
_is_blessed($subject)
$subject->isa("RDF::Trine::Node")
not $subject->is_variable
Truth table25%1/4
A and B and not(C)
A= _is_blessed($subject)B= $subject->isa("RDF::Trine::Node")C= not $subject->is_variable
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 19 | ▶ | $predicate = $predicate->value if (_is_blessed($predicate) && $predicate->isa('RDF::Trine::Node') and not $predicate->is_variable); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
_is_blessed($predicate) and $predicate->isa("RDF::Trine::Node") and not $predicate->is_variable
_is_blessed($predicate) and $predicate->isa("RDF::Trine::Node")
MC/DC0%0/3
_is_blessed($predicate) and $predicate->isa("RDF::Trine::Node") and not $predicate->is_variable
_is_blessed($predicate)
$predicate->isa("RDF::Trine::Node")
not $predicate->is_variable
Truth table25%1/4
A and B and not(C)
A= _is_blessed($predicate)B= $predicate->isa("RDF::Trine::Node")C= not $predicate->is_variable
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 19 | ▶ | if (_is_blessed($object) && $object->isa('RDF::Trine::Node') and not $object->is_variable) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
_is_blessed($object) and $object->isa("RDF::Trine::Node") and not $object->is_variable
_is_blessed($object) and $object->isa("RDF::Trine::Node")
MC/DC0%0/3
_is_blessed($object) and $object->isa("RDF::Trine::Node") and not $object->is_variable
_is_blessed($object)
$object->isa("RDF::Trine::Node")
not $object->is_variable
Truth table25%1/4
A and B and not(C)
A= _is_blessed($object)B= $object->isa("RDF::Trine::Node")C= not $object->is_variable
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | $object = ($object->isa('RDF::Trine::Node::Literal')) ? $object->as_string : $object->value; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # Do a federated search over all the URLs provided | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 19 | ▶ | my $parts = ref($self->url) ? $self->url : [ $self->url ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 19 | my @federated; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 19 | for my $part (@$parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 37 | my $pattern = $self->get_query_pattern($part); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 37 | ▶ | return undef unless defined $pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 37 | my %params; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 37 | ▶ | $params{ $pattern->{rdf_subject} } = $subject if _is_string($subject); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 37 | ▶ | $params{ $pattern->{rdf_predicate} } = $predicate if _is_string($predicate); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 37 | ▶ | $params{ $pattern->{rdf_object} } = $object if _is_string($object); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 37 | my $template = URI::Template->new($pattern->{hydra_template}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 37 | push @federated , $template->process(%params)->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 34 | ▶ | my $sub = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 34 | state $model; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 34 | state $info; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 34 | state $iterator; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 34 | state $url = shift(@federated); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 34 | my $triple; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 34 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $triple and defined($url = pop @federated)
MC/DC100%2/2
not defined $triple and defined($url = pop @federated)
not defined $triple
defined($url = pop @federated)
Truth table100%3/3
not(A) and B
A= not defined $tripleB= defined($url = pop @federated)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 44 | ▶ | unless (defined $model) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # When no more result pages are available switch | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # to the next federated url... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 37 | ▶ | return unless defined($url) || defined($url = pop(@federated)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $url or defined($url = pop @federated)
MC/DC100%2/2
defined $url or defined($url = pop @federated)
defined $url
defined($url = pop @federated)
Truth table100%3/3
A or B
A= defined $urlB= defined($url = pop @federated)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 31 | my $fragment = $self->get_model_and_info($url); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 31 | ▶ | return unless defined $fragment->{model}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 31 | $model = $fragment->{model}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 31 | $info = $fragment->{info}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 31 | $url = $info->{hydra_next}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 31 | $iterator = $model->get_statements; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 38 | $triple = $iterator->next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 38 | ▶ | unless ($iterator->peek) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 23 | $model = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | while (!defined $triple && defined($url = pop(@federated))); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 28 | ▶ | wantarray ? ($triple,$info) : $triple; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 19 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 19 | $sub; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # Fetch a fragment page and extract the metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 73 | ▶ | sub get_model_and_info { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_model_and_info: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 73 | my ($self,$url) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 73 | ▶ | if (my $cache = $self->lru->get($url)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 49 | return $cache; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 24 | my $model = $self->get_fragment($url); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 24 | my $info = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 24 | ▶ | if (defined $model) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 24 | $info = $self->_model_metadata($model,$url, clean => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 24 | my $fragment = { model => $model , info => $info }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 24 | $self->lru->set($url => $fragment); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 24 | $fragment; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # Fetch a result page from fragment server | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 24 | ▶ | sub get_fragment { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_fragment: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 24 | my ($self,$url) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 24 | ▶ | return undef unless $url; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 24 | $self->log->info("fetching: $url"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 24 | my $model = RDF::Trine::Model->temporary_model; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # JSON support in RDF::Trine isn't JSON-LD | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # Set the accept header quality parameter at a minimum for this format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 24 | my $ua = clone(RDF::Trine->default_useragent); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 24 | $ua->agent("RDF:::LDF/$RDF::LDF::VERSION " . $ua->_agent); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 24 | $ua->default_header('Accept','text/turtle;q=1.0,application/turtle;q=1.0,application/x-turtle;q=1.0,application/rdf+xml;q=0.9,text/x-nquads;q=0.9,application/json;q=0.1,application/x-rdf+json;q=0.1'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 24 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # Need to explicitly set the useragent to keep the accept headers | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 24 | RDF::Trine::Parser->parse_url_into_model($url, $model, useragent => $ua); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 24 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | $self->log->error("failed to parse input"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 24 | return $model; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # Create a hash with fragment metadata from a RDF::Trine::Model | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # $model - RDF::Trine::Model | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # $this_uri - result page URL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # %opts | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # clean => 1 - remove the metadata from the model | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 24 | ▶ | sub _model_metadata { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_model_metadata: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 24 | my ($self,$model,$this_uri,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 24 | my $info = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 24 | $self->_build_metadata($model, { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | subject => RDF::Trine::Node::Resource->new($this_uri) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } , $info); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 24 | ▶ | if ($opts{clean}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 24 | $model->remove_statements( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | RDF::Trine::Node::Resource->new($this_uri), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 24 | $model->remove_statements( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | RDF::Trine::Node::Resource->new($this_uri) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 24 | for my $predicate ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 'http://www.w3.org/ns/hydra/core#variable' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 'http://www.w3.org/ns/hydra/core#property' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 'http://www.w3.org/ns/hydra/core#mapping' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 'http://www.w3.org/ns/hydra/core#template' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 'http://www.w3.org/ns/hydra/core#member' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 'http://www.w3.org/ns/hydra/core#variableRepresentation' , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 144 | $self->_build_metadata($model, { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | predicate => RDF::Trine::Node::Resource->new($predicate) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | }, $info); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 144 | ▶ | if ($opts{clean}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 144 | $model->remove_statements( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | RDF::Trine::Node::Resource->new($predicate) , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 24 | ▶ | my $source = $info->{dct_source}->[0] if _is_array_ref($info->{dct_source}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 24 | ▶ | if ($source) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 24 | $self->_build_metadata($model, { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | subject => RDF::Trine::Node::Resource->new($source) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | }, $info); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 24 | ▶ | if ($opts{clean}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 24 | $model->remove_statements( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | RDF::Trine::Node::Resource->new($source), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 24 | $model->remove_statements( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | RDF::Trine::Node::Resource->new($source) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 24 | $info; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # Helper method for _parse_model | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 192 | ▶ | sub _build_metadata { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_metadata: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 192 | my ($self, $model, $triple, $info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | my $iterator = $model->get_statements( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | $triple->{subject}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | $triple->{predicate}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | $triple->{object} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 192 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 192 | ▶ | while (my $triple = $iterator->next) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 621 | my $subject = $triple->subject->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 621 | my $predicate = $triple->predicate->uri_value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 621 | my $object = $triple->object->value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 621 | my $qname = join "_" , $self->sn->qname($predicate); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 621 | ▶ | if ($qname =~ /^(hydra_variable|hydra_property)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 144 | my $id= $triple->subject->value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 144 | $info->{"_$id"}->{$qname} = $object; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | elsif ($qname eq 'hydra_mapping') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 72 | my $id= $triple->subject->value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 72 | push @{$info->{"_$id"}->{$qname}} , $object; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | elsif ($qname =~ /^(void|hydra)_/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 237 | $info->{$qname} = $object; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 168 | push @{$info->{$qname}} , $object; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 192 | $info; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 46 | ▶ | sub _is_array_ref { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_array_ref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 46 | return ref($_[0]) eq 'ARRAY'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 777 | ▶ | sub _is_hash_ref { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_hash_ref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 777 | return ref($_[0]) eq 'HASH'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 89 | ▶ | sub _is_blessed { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_blessed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 89 | return ref($_[0]) =~ /\S/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 111 | ▶ | sub _is_string { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_string: called CC=4 SCAR=14.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 111 | ▶ | return defined($_[0]) && !ref($_[0]) && ref(\$_[0]) ne 'GLOB' && length($_[0]) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%6/9
defined $_[0] && !ref($_[0]) && ref \$_[0] ne 'GLOB' && length $_[0] > 0
defined $_[0] and not ref $_[0] and ref \$_[0] ne "GLOB"
defined $_[0] and not ref $_[0]
MC/DC25%1/4
defined $_[0] && !ref($_[0]) && ref \$_[0] ne 'GLOB' && length $_[0] > 0
defined $_[0]
not ref $_[0]
ref \$_[0] ne "GLOB"
length $_[0] > 0
Truth table40%2/5
A and not(B) and C && D
A= defined $_[0]B= not ref $_[0]C= ref \$_[0] ne "GLOB"D= length $_[0] > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||