line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
AtteanX::Store::LDF - Linked Data Fragment RDF store |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=begin markdown |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# STATUS |
8
|
|
|
|
|
|
|
[![Build Status](https://travis-ci.org/phochste/AtteanX-Store-LDF.svg)](https://travis-ci.org/phochste/AtteanX-Store-LDF) |
9
|
|
|
|
|
|
|
[![Coverage Status](https://coveralls.io/repos/phochste/AtteanX-Store-LDF/badge.svg)](https://coveralls.io/r/phochste/AtteanX-Store-LDF) |
10
|
|
|
|
|
|
|
[![Kwalitee Score](http://cpants.cpanauthors.org/dist/AtteanX-Store-LDF.png)](http://cpants.cpanauthors.org/dist/AtteanX-Store-LDF) |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=end markdown |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use v5.14; |
17
|
|
|
|
|
|
|
use Attean; |
18
|
|
|
|
|
|
|
use Attean::RDF qw(iri blank literal); |
19
|
|
|
|
|
|
|
use AtteanX::Store::LDF; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $uri = 'http://fragments.dbpedia.org/2014/en'; |
22
|
|
|
|
|
|
|
my $store = Attean->get_store('LDF')->new(endpoint_url => $uri); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $iter = $store->get_triples(undef,undef,literal("Albert Einstein")); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
while (my $triple = $iter->next) { |
27
|
|
|
|
|
|
|
say $triple->subject->ntriples_string . |
28
|
|
|
|
|
|
|
" " . |
29
|
|
|
|
|
|
|
$triple->predicate->ntriples_string . |
30
|
|
|
|
|
|
|
" " . |
31
|
|
|
|
|
|
|
$triple->object->ntriples_string . |
32
|
|
|
|
|
|
|
" ."; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
AtteanX::Store::LDF provides a triple-store connected to a Linked Data Fragment server. |
38
|
|
|
|
|
|
|
For more information on Triple Pattern Fragments consult L<http://linkeddatafragments.org/> |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
1
|
|
|
1
|
|
25131
|
use v5.14; |
|
1
|
|
|
|
|
4
|
|
42
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
70
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
package AtteanX::Store::LDF; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
1
|
|
787
|
use Moo; |
|
1
|
|
|
|
|
18195
|
|
|
1
|
|
|
|
|
9
|
|
49
|
1
|
|
|
1
|
|
2782
|
use Attean::API::Store; |
|
1
|
|
|
|
|
142574
|
|
|
1
|
|
|
|
|
129
|
|
50
|
1
|
|
|
1
|
|
12
|
use Type::Tiny::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
51
|
1
|
|
|
1
|
|
7453
|
use Types::Standard qw(Str); |
|
1
|
|
|
|
|
90814
|
|
|
1
|
|
|
|
|
17
|
|
52
|
1
|
|
|
1
|
|
5807
|
use RDF::LDF; |
|
1
|
|
|
|
|
68627892
|
|
|
1
|
|
|
|
|
49
|
|
53
|
1
|
|
|
1
|
|
742
|
use namespace::clean; |
|
1
|
|
|
|
|
14152
|
|
|
1
|
|
|
|
|
5
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
with 'Attean::API::TripleStore'; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 METHODS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
60
|
|
|
|
|
|
|
L<Attean::API::TripleStore> class. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=over 4 |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item new( endpoint_url => $endpoint_url ) |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Returns a new LDF-backed storage object. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
has endpoint_url => (is => 'ro', isa => Str, required => 1); |
71
|
|
|
|
|
|
|
has ldf => (is => 'ro', lazy => 1, builder => '_ldf'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _ldf { |
74
|
0
|
|
|
0
|
|
|
my $self = shift; |
75
|
0
|
|
|
|
|
|
RDF::LDF->new(url => $self->endpoint_url); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _term_as_string { |
79
|
0
|
|
|
0
|
|
|
my ($self,$term) = @_; |
80
|
0
|
0
|
|
|
|
|
if (!defined $term) { |
|
|
0
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return undef |
82
|
0
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
elsif ($term->does('Attean::API::Literal')) { |
84
|
0
|
|
|
|
|
|
return $term->as_string; # includes quotes and any language or datatype |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
0
|
|
|
|
|
|
return $term->value; # the raw IRI or blank node identifier value, without other syntax |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item count_triples_estimate( $subject, $predicate, $object ) |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Return the count of triples matching the specified subject, predicate and |
94
|
|
|
|
|
|
|
objects. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
sub count_triples_estimate { |
98
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
my ($s_pattern,$p_pattern,$o_pattern) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $ldf_iter = $self->ldf->get_statements( |
102
|
|
|
|
|
|
|
$self->_term_as_string($s_pattern), |
103
|
|
|
|
|
|
|
$self->_term_as_string($p_pattern), |
104
|
|
|
|
|
|
|
$self->_term_as_string($o_pattern) |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
return 0 unless defined $ldf_iter; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my ($statement,$info) = $ldf_iter->(); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $info->{'void_triples'}; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item get_triples( $subject, $predicate, $object) |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Returns a stream object of all statements matching the specified subject, |
117
|
|
|
|
|
|
|
predicate and objects. Any of the arguments may be undef to match any value. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
sub get_triples { |
121
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
122
|
0
|
|
|
|
|
|
my ($s_pattern,$p_pattern,$o_pattern) = @_; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $ldf_iter = $self->ldf->get_statements( |
125
|
|
|
|
|
|
|
$self->_term_as_string($s_pattern), |
126
|
|
|
|
|
|
|
$self->_term_as_string($p_pattern), |
127
|
|
|
|
|
|
|
$self->_term_as_string($o_pattern) |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
return Attean::ListIterator->new(values => [] , item_type => 'Attean::API::Triple') |
131
|
|
|
|
|
|
|
unless $ldf_iter; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
my $iter = Attean::CodeIterator->new( |
134
|
|
|
|
|
|
|
generator => sub { |
135
|
0
|
|
|
0
|
|
|
my $statement = $ldf_iter->(); |
136
|
0
|
0
|
|
|
|
|
return () unless defined($statement); |
137
|
0
|
|
|
|
|
|
my ($subject,$predicate,$object); |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
if ($statement->subject->is_resource) { |
140
|
0
|
|
|
|
|
|
$subject = Attean::IRI->new($statement->subject->value); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
else { |
143
|
0
|
|
|
|
|
|
$subject = Attean::Blank->new($statement->subject->value); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
$predicate = Attean::IRI->new($statement->predicate->value); |
147
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
if ($statement->object->is_resource) { |
|
|
0
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$object = Attean::IRI->new($statement->object->value); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
elsif ($statement->object->is_literal) { |
152
|
0
|
|
|
|
|
|
$object = Attean::Literal->new($statement->object->value); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
else { |
155
|
0
|
|
|
|
|
|
$object = Attean::Blank->new($statement->object->value); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my @res = ( |
159
|
|
|
|
|
|
|
Attean::Triple->new( |
160
|
|
|
|
|
|
|
subject => $subject , |
161
|
|
|
|
|
|
|
predicate => $predicate , |
162
|
|
|
|
|
|
|
object => $object |
163
|
|
|
|
|
|
|
) |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
@res; |
167
|
|
|
|
|
|
|
}, |
168
|
0
|
|
|
|
|
|
item_type => 'Attean::API::Triple', |
169
|
|
|
|
|
|
|
); |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
return $iter; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__END__ |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=back |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 SEE ALSO |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L<Attean> , L<Attean::API::TripleStore> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 BUGS |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Please report any bugs or feature requests to through the GitHub web interface |
187
|
|
|
|
|
|
|
at L<https://github.com/phochste/AtteanX-Store-LDF>. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 AUTHOR |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Patrick Hochstenbach C<< <patrick.hochstenbach@ugent.be> >> |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 COPYRIGHT |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Patrick Hochstenbach. |
196
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
197
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |