Fix/rdf_ldf_statements.pm

filter: Statementstmt 57.5% 19 / 33 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 1 totaltotal 50.0% 23 / 46 CC 2 SCAR 7.6
CC
2
Cov
54%
_build_client
6.0
emit_value
2.0
__ANON__
1.1
CRAP 2.1
« Exporter/RDF.pm ↑ Summary Fix/aref_query.pm »
1 package Catmandu::Fix::rdf_ldf_statements;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use RDF::LDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 has path => (fix_arg => 1);
9 0 ▶has subject => (fix_opt => 1, default => sub { undef });
Subroutine __ANON__: not called CC=1 SCAR=1.2
10 0 ▶has predicate => (fix_opt => 1, default => sub { undef });
Subroutine __ANON__: not called CC=1 SCAR=1.2
11 0 ▶has url => (fix_opt => 1, default => sub { undef });
Subroutine __ANON__: not called CC=1 SCAR=1.2
12  
13 1 has client => (is => 'lazy');
14  
15 1 with 'Catmandu::Fix::SimpleGetValue';
16  
17 0 ▶sub _build_client {
Subroutine _build_client: not called CC=2 SCAR=17.9
18 0 my ($self) = @_;
19 0 ▶ my $url = $self->url // 'http://data.linkeddatafragments.org/viaf';
Condition0%0/2
$self->url // "http://data.linkeddatafragments.org/viaf"
l!l
00
MC/DC0%0/1
$self->url // "http://data.linkeddatafragments.org/viaf"
$self->url
Truth table0%0/2
A
A= $self->url
Aresult
11
00
20 0 RDF::LDF->new(url => $url);
21 }
22  
23 0 ▶sub emit_value {
Subroutine emit_value: not called CC=1 SCAR=6.9
Pod undocumented
24 0 my ($self,$var,$fixer) = @_;
25 0 my $subject_var = $fixer->capture($self->subject);
26 0 my $predicate_var = $fixer->capture($self->predicate);
27 0 my $client_var = $fixer->capture($self->client);
28 0 my $it = $fixer->generate_var;
29 0 my $st = $fixer->generate_var;
30  
31 0 my $perl = <<EOF;
32 if (is_value(${var})) {
33 my ${it} = ${client_var}->get_statements(${subject_var},${predicate_var},${var});
34 if (${it}) {
35 ${var} = [];
36 while (my ${st} = ${it}->()) {
37 push \@{${var}} , ${st}->subject->uri;
38 }
39 }
40 }
41 EOF
42 0 $perl;
43 }
44  
45 =head1 NAME
46  
47 Catmandu::Fix::rdf_ldf_statements - lookup an object into a LDF endpoint
48  
49 =head1 SYNOPSIS
50  
51 # Replace a name with an array of matching VIAF records
52 # name: "\"Einstein, Albert, 1879-1955\""
53 rdf_ldf_statements(name,url:"http://data.linkedatafragments.org/viaf",predicate:"http://schema.org/alternateName")
54  
55 # name:
56 # - http://viaf.org/viaf/75121530
57  
58 =head1 DESCRIPTION
59  
60 This L<Catmandu::Fix> can be used to find at a Linked Data Fragments endpoint
61 all subject URIs for which the object has a specific value found at a path. E.g.
62  
63 rdf_ldf_statements(name,url:"http://data.linkedatafragments.org/viaf")
64  
65 means, search at the endpoint http://data.linkedatafragments.org/viaf all the
66 subjects for which the object is the value found in 'name', and replace the name value
67 with all the found subjects.
68  
69 =head1 ARGUMENTS
70  
71 =over
72  
73 =item subject
74  
75 Optional subject URI to be used in the LDF query
76  
77 =item predicate
78  
79 Optional predicate URI to be used in the LDF query
80  
81 =item url
82  
83 Required URL to the Linked Data Fragments endpoint
84  
85 =back
86  
87 =head1 SEE ALSO
88  
89 L<Catmandu::Fix>
90  
91 =cut
92  
93 1 1;
« Exporter/RDF.pm ↑ Summary Fix/aref_query.pm »