line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Trine |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Trine - An RDF Framework for Perl |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Trine version 1.017_01 |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use RDF::Trine; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $store = RDF::Trine::Store::Memory->new(); |
17
|
|
|
|
|
|
|
my $model = RDF::Trine::Model->new($store); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# parse some web data into the model, and print the count of resulting RDF statements |
20
|
|
|
|
|
|
|
RDF::Trine::Parser->parse_url_into_model( 'http://kasei.us/about/foaf.xrdf', $model ); |
21
|
|
|
|
|
|
|
print $model->size . " RDF statements parsed\n"; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Create a namespace object for the foaf vocabulary |
24
|
|
|
|
|
|
|
my $foaf = RDF::Trine::Namespace->new( 'http://xmlns.com/foaf/0.1/' ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Create a node object for the FOAF name property |
27
|
|
|
|
|
|
|
my $pred = $foaf->name; |
28
|
|
|
|
|
|
|
# alternatively: |
29
|
|
|
|
|
|
|
# my $pred = RDF::Trine::Node::Resource->new('http://xmlns.com/foaf/0.1/name'); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Create an iterator for all the statements in the model with foaf:name as the predicate |
32
|
|
|
|
|
|
|
my $iter = $model->get_statements(undef, $pred, undef); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Now print the results |
35
|
|
|
|
|
|
|
print "Names of things:\n"; |
36
|
|
|
|
|
|
|
while (my $st = $iter->next) { |
37
|
|
|
|
|
|
|
my $s = $st->subject; |
38
|
|
|
|
|
|
|
my $name = $st->object; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# $s and $name have string overloading, so will print correctly |
41
|
|
|
|
|
|
|
print "The name of $s is $name\n"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
RDF::Trine provides an Resource Descriptive Framework (RDF) with an emphasis on |
47
|
|
|
|
|
|
|
extensibility, API stability, and the presence of a test suite. The package |
48
|
|
|
|
|
|
|
consists of several components: |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=over 4 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
L<RDF::Trine::Model> - RDF model providing access to a triple store. This module would typically be used to access an existing store by a developer looking to "Just get stuff done." |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
L<RDF::Trine::Parser> - RDF parsers for various serialization formats including RDF/XML, Turtle, RDFa, and RDF/JSON. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
L<RDF::Trine::Store::Memory> - An in-memory, non-persistant triple store. Typically used for temporary data. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
L<RDF::Trine::Store::DBI> - A triple store for MySQL, PostgreSQL, and SQLite, based on the relational schema used by Redland. Typically used to for large, persistent data. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
L<RDF::Trine::Iterator> - Iterator classes for variable bindings and RDF statements, used by RDF::Trine::Store, RDF::Trine::Model, and RDF::Query. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
L<RDF::Trine::Namespace> - A convenience class for easily constructing RDF::Trine::Node::Resource objects from URI namespaces. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
package RDF::Trine; |
81
|
|
|
|
|
|
|
|
82
|
68
|
|
|
68
|
|
1385247
|
use 5.010; |
|
68
|
|
|
|
|
249
|
|
83
|
68
|
|
|
68
|
|
350
|
use strict; |
|
68
|
|
|
|
|
127
|
|
|
68
|
|
|
|
|
1305
|
|
84
|
68
|
|
|
68
|
|
309
|
use warnings; |
|
68
|
|
|
|
|
149
|
|
|
68
|
|
|
|
|
1794
|
|
85
|
68
|
|
|
68
|
|
348
|
no warnings 'redefine'; |
|
68
|
|
|
|
|
134
|
|
|
68
|
|
|
|
|
2224
|
|
86
|
68
|
|
|
68
|
|
29328
|
use Module::Load::Conditional qw[can_load]; |
|
68
|
|
|
|
|
1406707
|
|
|
68
|
|
|
|
|
4094
|
|
87
|
68
|
|
|
68
|
|
39843
|
use LWP::UserAgent; |
|
68
|
|
|
|
|
2385819
|
|
|
68
|
|
|
|
|
7360
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
our ($debug, @ISA, $VERSION, @EXPORT_OK); |
90
|
|
|
|
|
|
|
BEGIN { |
91
|
68
|
|
|
68
|
|
261
|
$debug = 0; |
92
|
68
|
|
|
|
|
157
|
$VERSION = '1.017_01'; |
93
|
|
|
|
|
|
|
|
94
|
68
|
|
|
|
|
542
|
require Exporter; |
95
|
68
|
|
|
|
|
747
|
@ISA = qw(Exporter); |
96
|
68
|
|
|
|
|
244
|
@EXPORT_OK = qw(iri blank literal variable statement store UNION_GRAPH NIL_GRAPH); |
97
|
|
|
|
|
|
|
|
98
|
68
|
50
|
|
|
|
383
|
unless ($ENV{RDFTRINE_NO_REDLAND}) { |
99
|
68
|
|
|
|
|
528
|
can_load( modules => { |
100
|
|
|
|
|
|
|
'RDF::Redland' => undef, |
101
|
|
|
|
|
|
|
'RDF::Trine::Store::Redland' => undef, |
102
|
|
|
|
|
|
|
'RDF::Trine::Parser::Redland' => undef, |
103
|
|
|
|
|
|
|
} ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
68
|
|
|
68
|
|
560954
|
use constant UNION_GRAPH => 'tag:gwilliams@cpan.org,2010-01-01:RT:ALL'; |
|
68
|
|
|
|
|
166
|
|
|
68
|
|
|
|
|
4329
|
|
108
|
68
|
|
|
68
|
|
391
|
use constant NIL_GRAPH => 'tag:gwilliams@cpan.org,2010-01-01:RT:NIL'; |
|
68
|
|
|
|
|
142
|
|
|
68
|
|
|
|
|
3058
|
|
109
|
|
|
|
|
|
|
|
110
|
68
|
|
|
68
|
|
46201
|
use Log::Log4perl qw(:easy); |
|
68
|
|
|
|
|
2349571
|
|
|
68
|
|
|
|
|
404
|
|
111
|
|
|
|
|
|
|
if (! Log::Log4perl::initialized() ) { |
112
|
|
|
|
|
|
|
Log::Log4perl->easy_init($ERROR); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
68
|
|
|
68
|
|
78724
|
use RDF::Trine::Graph; |
|
68
|
|
|
|
|
231
|
|
|
68
|
|
|
|
|
2284
|
|
116
|
68
|
|
|
68
|
|
28387
|
use RDF::Trine::Parser; |
|
68
|
|
|
|
|
249
|
|
|
68
|
|
|
|
|
2202
|
|
117
|
68
|
|
|
68
|
|
538
|
use RDF::Trine::Serializer; |
|
68
|
|
|
|
|
147
|
|
|
68
|
|
|
|
|
1683
|
|
118
|
68
|
|
|
68
|
|
362
|
use RDF::Trine::Node; |
|
68
|
|
|
|
|
188
|
|
|
68
|
|
|
|
|
2383
|
|
119
|
68
|
|
|
68
|
|
380
|
use RDF::Trine::Statement; |
|
68
|
|
|
|
|
141
|
|
|
68
|
|
|
|
|
1063
|
|
120
|
68
|
|
|
68
|
|
312
|
use RDF::Trine::Namespace; |
|
68
|
|
|
|
|
157
|
|
|
68
|
|
|
|
|
454
|
|
121
|
68
|
|
|
68
|
|
25029
|
use RDF::Trine::NamespaceMap; |
|
68
|
|
|
|
|
194
|
|
|
68
|
|
|
|
|
1857
|
|
122
|
68
|
|
|
68
|
|
462
|
use RDF::Trine::Iterator; |
|
68
|
|
|
|
|
154
|
|
|
68
|
|
|
|
|
2377
|
|
123
|
68
|
|
|
68
|
|
374
|
use RDF::Trine::Store; |
|
68
|
|
|
|
|
156
|
|
|
68
|
|
|
|
|
1179
|
|
124
|
68
|
|
|
68
|
|
298
|
use RDF::Trine::Error; |
|
68
|
|
|
|
|
143
|
|
|
68
|
|
|
|
|
387
|
|
125
|
68
|
|
|
68
|
|
30322
|
use RDF::Trine::Model; |
|
68
|
|
|
|
|
270
|
|
|
68
|
|
|
|
|
1881
|
|
126
|
|
|
|
|
|
|
|
127
|
68
|
|
|
68
|
|
29348
|
use RDF::Trine::Parser::Turtle; |
|
68
|
|
|
|
|
376
|
|
|
68
|
|
|
|
|
3210
|
|
128
|
68
|
|
|
68
|
|
34448
|
use RDF::Trine::Parser::TriG; |
|
68
|
|
|
|
|
200
|
|
|
68
|
|
|
|
|
18940
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _uniq { |
132
|
762
|
|
|
762
|
|
1473
|
my %seen; |
133
|
|
|
|
|
|
|
my @data; |
134
|
762
|
|
|
|
|
1565
|
foreach (@_) { |
135
|
2045
|
100
|
|
|
|
6309
|
push(@data, $_) unless ($seen{ $_ }++); |
136
|
|
|
|
|
|
|
} |
137
|
762
|
|
|
|
|
4138
|
return @data; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 FUNCTIONS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item C<< iri ( $iri ) >> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Returns a L<RDF::Trine::Node::Resource> object with the given IRI value. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub iri { |
151
|
114
|
|
|
114
|
1
|
2223
|
my $iri = shift; |
152
|
114
|
|
|
|
|
532
|
return RDF::Trine::Node::Resource->new( $iri ); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item C<< blank ( $id ) >> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns a L<RDF::Trine::Node::Blank> object with the given identifier. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub blank { |
162
|
10
|
|
|
10
|
1
|
35
|
my $id = shift; |
163
|
10
|
|
|
|
|
57
|
return RDF::Trine::Node::Blank->new( $id ); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item C<< literal ( $value, $lang, $dt ) >> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns a L<RDF::Trine::Node::Literal> object with the given value and optional |
169
|
|
|
|
|
|
|
language/datatype. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub literal { |
174
|
115
|
|
|
115
|
1
|
2549
|
return RDF::Trine::Node::Literal->new( @_ ); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item C<< variable ( $name ) >> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Returns a L<RDF::Trine::Node::Variable> object with the given variable name. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub variable { |
184
|
3497
|
|
|
3497
|
1
|
9230
|
my $name = shift; |
185
|
3497
|
|
|
|
|
11307
|
return RDF::Trine::Node::Variable->new( $name ); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item C<< statement ( @nodes ) >> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Returns a L<RDF::Trine::Statement> object with the supplied node objects. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub statement { |
195
|
46
|
|
|
46
|
1
|
132
|
my @nodes = @_; |
196
|
46
|
100
|
|
|
|
141
|
if (scalar(@nodes) == 4) { |
197
|
23
|
|
|
|
|
102
|
return RDF::Trine::Statement::Quad->new( @nodes ); |
198
|
|
|
|
|
|
|
} else { |
199
|
23
|
|
|
|
|
96
|
return RDF::Trine::Statement->new( @nodes ); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item C<< store ( $config ) >> |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Returns a L<RDF::Trine::Store> object based on the supplied configuration string. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub store { |
210
|
1
|
|
|
1
|
1
|
7
|
my $config = shift; |
211
|
1
|
|
|
|
|
9
|
return RDF::Trine::Store->new_with_string( $config ); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item C<< default_useragent ( [ $ua ] ) >> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Returns the L<LWP::UserAgent> object used by default for any operation requiring network |
217
|
|
|
|
|
|
|
requests. Ordinarily, the calling code will obtain the default user agent, and clone it |
218
|
|
|
|
|
|
|
before further configuring it for a specific request, thus leaving the default object |
219
|
|
|
|
|
|
|
untouched. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
If C<< $ua >> is passed as an argument, sets the global default user agent to this object. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
{ my $_useragent; |
226
|
|
|
|
|
|
|
sub default_useragent { |
227
|
2
|
|
|
2
|
1
|
6
|
my $class = shift; |
228
|
2
|
|
33
|
|
|
13
|
my $ua = shift || $_useragent; |
229
|
2
|
50
|
|
|
|
8
|
unless (defined($ua)) { |
230
|
2
|
|
|
|
|
20
|
$ua = LWP::UserAgent->new( agent => "RDF::Trine/$RDF::Trine::VERSION" ); |
231
|
|
|
|
|
|
|
} |
232
|
2
|
|
|
|
|
4276
|
$_useragent = $ua; |
233
|
2
|
|
|
|
|
11
|
return $ua; |
234
|
|
|
|
|
|
|
}} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
237
|
|
|
|
|
|
|
__END__ |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=back |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 BUGS |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Please report any bugs or feature requests to through the GitHub web interface |
244
|
|
|
|
|
|
|
at L<https://github.com/kasei/perlrdf/issues>. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 SEE ALSO |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
L<http://www.perlrdf.org/> |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 AUTHOR |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Gregory Todd Williams C<< <gwilliams@cpan.org> >> |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 COPYRIGHT |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Copyright (c) 2006-2012 Gregory Todd Williams. This |
257
|
|
|
|
|
|
|
program is free software; you can redistribute it and/or modify it under |
258
|
|
|
|
|
|
|
the same terms as Perl itself. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=cut |