line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RDF::aREF::Encoder; |
2
|
7
|
|
|
7
|
|
15256
|
use strict; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
334
|
|
3
|
7
|
|
|
7
|
|
41
|
use warnings; |
|
7
|
|
|
|
|
127
|
|
|
7
|
|
|
|
|
251
|
|
4
|
7
|
|
|
7
|
|
87
|
use v5.10; |
|
7
|
|
|
|
|
25
|
|
|
7
|
|
|
|
|
685
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
459
|
use RDF::NS; |
|
7
|
|
|
|
|
8665
|
|
|
7
|
|
|
|
|
182
|
|
9
|
7
|
|
|
7
|
|
393
|
use RDF::aREF::Decoder qw(localName blankNodeIdentifier); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
435
|
|
10
|
7
|
|
|
7
|
|
36
|
use Scalar::Util qw(blessed reftype); |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
379
|
|
11
|
7
|
|
|
7
|
|
38
|
use Carp qw(croak); |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
10639
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
7
|
|
|
7
|
0
|
363
|
my ($class, %options) = @_; |
15
|
|
|
|
|
|
|
|
16
|
7
|
100
|
33
|
|
|
52
|
if (!defined $options{ns}) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
17
|
2
|
|
|
|
|
16
|
$options{ns} = RDF::NS->new; |
18
|
|
|
|
|
|
|
} elsif (!$options{ns}) { |
19
|
3
|
|
|
|
|
19
|
$options{ns} = bless { |
20
|
|
|
|
|
|
|
rdf => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
21
|
|
|
|
|
|
|
rdfs => 'http://www.w3.org/2000/01/rdf-schema#', |
22
|
|
|
|
|
|
|
owl => 'http://www.w3.org/2002/07/owl#', |
23
|
|
|
|
|
|
|
xsd => 'http://www.w3.org/2001/XMLSchema#', |
24
|
|
|
|
|
|
|
}, 'RDF::NS'; |
25
|
|
|
|
|
|
|
} elsif ( !blessed $options{ns} or !$options{ns}->isa('RDF::NS') ) { |
26
|
2
|
|
|
|
|
14
|
$options{ns} = RDF::NS->new($options{ns}); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
7
|
|
|
|
|
77187
|
$options{sn} = $options{ns}->REVERSE; |
30
|
7
|
|
|
|
|
20308
|
$options{subject_map} = !!$options{subject_map}; |
31
|
7
|
100
|
|
|
|
40
|
if ($options{NFC}) { |
32
|
1
|
|
|
|
|
4
|
eval { require Unicode::Normalize }; |
|
1
|
|
|
|
|
15291
|
|
33
|
1
|
50
|
|
|
|
3257
|
croak "Missing Unicode::Normalize: NFC normalization disabled!\n" if $@; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
7
|
|
|
|
|
43
|
bless \%options, $class; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub qname { |
40
|
20
|
|
|
20
|
1
|
1387
|
my ($self, $uri) = @_; |
41
|
20
|
50
|
|
|
|
75
|
return unless $self->{sn}; |
42
|
20
|
|
|
|
|
113
|
my @qname = $self->{sn}->qname($uri); |
43
|
20
|
50
|
|
|
|
4911
|
return $qname[0] if @qname == 1; |
44
|
20
|
100
|
100
|
|
|
152
|
return join('_',@qname) if @qname and $qname[1] =~ localName; |
45
|
8
|
|
|
|
|
25
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub uri { |
49
|
10
|
|
|
10
|
1
|
909
|
my ($self, $uri) = @_; |
50
|
|
|
|
|
|
|
|
51
|
10
|
100
|
|
|
|
17
|
if ( my $qname = $self->qname($uri) ) { |
52
|
7
|
|
|
|
|
33
|
return $qname; |
53
|
|
|
|
|
|
|
} else { |
54
|
3
|
|
|
|
|
13
|
return "<$uri>"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub subject { |
59
|
9
|
|
|
9
|
1
|
2474
|
my ($self, $subject) = @_; |
60
|
|
|
|
|
|
|
|
61
|
9
|
|
|
|
|
13
|
return do { |
62
|
9
|
100
|
|
|
|
65
|
if (!reftype $subject) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
63
|
|
|
|
|
|
|
undef |
64
|
|
|
|
|
|
|
# RDF/JSON |
65
|
1
|
|
|
|
|
4
|
} elsif (reftype $subject eq 'HASH') { |
66
|
2
|
50
|
66
|
|
|
14
|
if ($subject->{type} eq 'uri' or $subject->{type} eq 'bnode') { |
67
|
2
|
|
|
|
|
14
|
$subject->{value} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
# RDF::Trine::Node |
70
|
|
|
|
|
|
|
} elsif (reftype $subject eq 'ARRAY') { |
71
|
6
|
50
|
|
|
|
17
|
if (@$subject == 2 ) { |
72
|
6
|
100
|
|
|
|
16
|
if ($subject->[0] eq 'URI') { |
|
|
50
|
|
|
|
|
|
73
|
5
|
|
|
|
|
33
|
"".$subject->[1]; |
74
|
|
|
|
|
|
|
} elsif ($subject->[0] eq 'BLANK') { |
75
|
1
|
|
|
|
|
6
|
$self->bnode($subject->[1]) |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub predicate { |
83
|
11
|
|
|
11
|
1
|
2661
|
my ($self, $predicate) = @_; |
84
|
|
|
|
|
|
|
|
85
|
11
|
|
|
|
|
13
|
$predicate = do { |
86
|
11
|
100
|
66
|
|
|
81
|
if (!reftype $predicate) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
87
|
|
|
|
|
|
|
undef |
88
|
|
|
|
|
|
|
# RDF/JSON |
89
|
2
|
|
|
|
|
4
|
} elsif (reftype $predicate eq 'HASH' and $predicate->{type} eq 'uri') { |
90
|
2
|
|
|
|
|
5
|
$predicate->{value} |
91
|
|
|
|
|
|
|
# RDF::Trine::Node |
92
|
|
|
|
|
|
|
} elsif (reftype $predicate eq 'ARRAY') { |
93
|
7
|
100
|
66
|
|
|
45
|
(@$predicate == 2 and $predicate->[0] eq 'URI') |
94
|
|
|
|
|
|
|
? "".$predicate->[1] : undef; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
11
|
|
|
|
|
15
|
return do { |
99
|
11
|
100
|
|
|
|
39
|
if ( !defined $predicate ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
100
|
|
|
|
|
|
|
undef |
101
|
3
|
|
|
|
|
15
|
} elsif ( $predicate eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' ) { |
102
|
2
|
|
|
|
|
5
|
'a' |
103
|
|
|
|
|
|
|
} elsif ( my $qname = $self->qname($predicate) ) { |
104
|
2
|
|
|
|
|
10
|
$qname |
105
|
|
|
|
|
|
|
} else { |
106
|
4
|
|
|
|
|
12
|
$predicate |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub object { |
112
|
16
|
|
|
16
|
1
|
5188
|
my ($self, $object) = @_; |
113
|
|
|
|
|
|
|
|
114
|
16
|
|
|
|
|
17
|
return do { |
115
|
16
|
100
|
|
|
|
86
|
if (!reftype $object) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
116
|
|
|
|
|
|
|
undef |
117
|
|
|
|
|
|
|
# RDF/JSON |
118
|
1
|
|
|
|
|
6
|
} elsif (reftype $object eq 'HASH') { |
119
|
9
|
100
|
|
|
|
67
|
if ($object->{type} eq 'literal') { |
|
|
100
|
|
|
|
|
|
120
|
5
|
|
|
|
|
22
|
$self->literal( $object->{value}, $object->{lang}, $object->{datatype} ) |
121
|
|
|
|
|
|
|
} elsif ($object->{type} eq 'bnode') { |
122
|
1
|
|
|
|
|
4
|
$object->{value} |
123
|
|
|
|
|
|
|
} else { |
124
|
3
|
|
|
|
|
10
|
$self->uri($object->{value}) |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
# RDF::Trine::Node |
127
|
|
|
|
|
|
|
} elsif (reftype $object eq 'ARRAY') { |
128
|
6
|
100
|
|
|
|
19
|
if (@$object != 2 ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
129
|
3
|
|
|
|
|
8
|
$self->literal(@$object) |
130
|
|
|
|
|
|
|
} elsif ($object->[0] eq 'URI') { |
131
|
2
|
|
|
|
|
8
|
$self->uri("".$object->[1]) |
132
|
|
|
|
|
|
|
} elsif ($object->[0] eq 'BLANK') { |
133
|
1
|
|
|
|
|
4
|
$self->bnode($object->[1]) |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub literal { |
140
|
10
|
|
|
10
|
1
|
1410
|
my ($self, $value, $language, $datatype) = @_; |
141
|
10
|
50
|
|
|
|
30
|
if ($self->{NFC}) { |
142
|
0
|
|
|
|
|
0
|
$value = Unicode::Normalize::NFC($value); |
143
|
|
|
|
|
|
|
} |
144
|
10
|
100
|
|
|
|
21
|
if ($language) { |
|
|
100
|
|
|
|
|
|
145
|
5
|
|
|
|
|
57
|
$value.'@'.$language |
146
|
|
|
|
|
|
|
} elsif ($datatype) { |
147
|
3
|
|
|
|
|
11
|
$value.'^'.$self->uri($datatype) |
148
|
|
|
|
|
|
|
} else { |
149
|
2
|
|
|
|
|
10
|
$value.'@' |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub bnode { |
154
|
5
|
100
|
|
5
|
1
|
1427
|
$_[1] =~ blankNodeIdentifier ? '_:'.$_[1] : undef; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub triple { |
158
|
4
|
|
|
4
|
1
|
5
|
my ($self, $subject, $predicate, $object, $aref) = @_; |
159
|
|
|
|
|
|
|
|
160
|
4
|
|
50
|
|
|
12
|
$subject = $self->subject($subject) // return; |
161
|
4
|
|
50
|
|
|
10
|
$predicate = $self->predicate($predicate) // return; |
162
|
4
|
|
50
|
|
|
13
|
$object = $self->object($object) // return; |
163
|
4
|
|
50
|
|
|
13
|
$aref //= { }; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# empty |
166
|
4
|
100
|
100
|
|
|
22
|
if ( !keys %$aref and !$self->{subject_map} ) { |
|
|
100
|
|
|
|
|
|
167
|
2
|
|
|
|
|
5
|
$aref->{_id} = $subject; |
168
|
2
|
|
|
|
|
4
|
$aref->{$predicate} = $object; |
169
|
|
|
|
|
|
|
# predicate map |
170
|
|
|
|
|
|
|
} elsif ( $aref->{_id} ) { |
171
|
1
|
50
|
33
|
|
|
7
|
if ( $aref->{_id} eq $subject and !$self->{subject_map} ) { |
172
|
0
|
|
|
|
|
0
|
$self->_add_object_to_predicate_map( $aref, $predicate, $object ); |
173
|
|
|
|
|
|
|
} else { |
174
|
|
|
|
|
|
|
# convert predicate map to subject map |
175
|
1
|
|
|
|
|
4
|
my $s = delete $aref->{_id}; |
176
|
1
|
|
|
|
|
2
|
my $pm = { }; |
177
|
1
|
|
|
|
|
3
|
foreach (keys %$aref) { |
178
|
1
|
|
|
|
|
4
|
$pm->{$_} = delete $aref->{$_}; |
179
|
|
|
|
|
|
|
} |
180
|
1
|
50
|
|
|
|
3
|
if ($s eq $subject) { |
181
|
1
|
|
|
|
|
4
|
$self->_add_object_to_predicate_map( $pm, $predicate, $object ); |
182
|
|
|
|
|
|
|
} else { |
183
|
0
|
|
|
|
|
0
|
$aref->{$subject} = { $predicate => $object }; |
184
|
|
|
|
|
|
|
} |
185
|
1
|
|
|
|
|
3
|
$aref->{$s} = $pm; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} else { # subject map |
188
|
1
|
50
|
|
|
|
3
|
if ( $aref->{$subject} ) { |
189
|
0
|
|
|
|
|
0
|
$self->_add_object_to_predicate_map( $aref->{$subject}, $predicate, $object ); |
190
|
|
|
|
|
|
|
} else { |
191
|
1
|
|
|
|
|
4
|
$aref->{$subject} = { $predicate => $object }; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
4
|
|
|
|
|
29
|
return $aref; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub _add_object_to_predicate_map { |
199
|
1
|
|
|
1
|
|
2
|
my ($self, $map, $predicate, $object) = @_; |
200
|
|
|
|
|
|
|
|
201
|
1
|
50
|
|
|
|
6
|
if (ref $map->{$predicate}) { |
|
|
50
|
|
|
|
|
|
202
|
0
|
|
|
|
|
0
|
push @{$map->{$predicate}}, $object; |
|
0
|
|
|
|
|
0
|
|
203
|
|
|
|
|
|
|
} elsif (defined $map->{$predicate}) { |
204
|
0
|
|
|
|
|
0
|
$map->{$predicate} = [ $map->{$predicate}, $object ]; |
205
|
|
|
|
|
|
|
} else { |
206
|
1
|
|
|
|
|
2
|
$map->{$predicate} = $object; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub add_iterator { |
211
|
0
|
|
|
0
|
1
|
0
|
my ($self, $iterator, $aref) = @_; |
212
|
0
|
|
|
|
|
0
|
while (my $s = $iterator->next) { |
213
|
0
|
|
|
|
|
0
|
$self->triple($s->subject, $s->predicate, $s->object, $aref); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub add_hashref { |
218
|
4
|
|
|
4
|
1
|
6
|
my ($self, $hashref, $aref) = @_; |
219
|
|
|
|
|
|
|
|
220
|
4
|
|
|
|
|
16
|
while (my ($s,$ps) = each %$hashref) { |
221
|
4
|
50
|
|
|
|
19
|
my $subject = $s =~ /^_:/ ? ['BLANK',substr($s, 2)] : ['URI',$s]; |
222
|
4
|
|
|
|
|
15
|
foreach my $p (keys %$ps) { |
223
|
4
|
|
|
|
|
7
|
my $predicate = ['URI',$p]; |
224
|
4
|
|
|
|
|
6
|
foreach my $object (@{ $hashref->{$s}->{$p} }) { |
|
4
|
|
|
|
|
10
|
|
225
|
4
|
|
|
|
|
9
|
$self->triple($subject, $predicate, $object, $aref); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
1; |
233
|
|
|
|
|
|
|
__END__ |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 NAME |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
RDF::aREF::Encoder - encode RDF to another RDF Encoding Form |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 SYNOPSIS |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
use RDF::aREF::Encoder; |
242
|
|
|
|
|
|
|
my $encoder = RDF::aREF::Encoder->new; |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
# encode parts of aREF |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
my $qname = $encoder->qname('http://schema.org/Review'); # 'schema_Review' |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
my $predicate = $encoder->predicate({ |
250
|
|
|
|
|
|
|
type => 'uri', |
251
|
|
|
|
|
|
|
value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' |
252
|
|
|
|
|
|
|
}); # 'a' |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
my $object = $encoder->object({ |
255
|
|
|
|
|
|
|
type => 'literal', |
256
|
|
|
|
|
|
|
value => 'hello, world!', |
257
|
|
|
|
|
|
|
lang => 'en' |
258
|
|
|
|
|
|
|
}); # 'hello, world!@en' |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
# method also accepts RDF::Trine::Node instances |
261
|
|
|
|
|
|
|
my $object = $encoder->object( RDF::Trine::Resource->new($iri) ); |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
# encode RDF graphs (see also function 'encode_aref' in RDF::aREF) |
264
|
|
|
|
|
|
|
use RDF::Trine::Parser; |
265
|
|
|
|
|
|
|
my $aref = { }; |
266
|
|
|
|
|
|
|
RDF::Trine::Parser->parse_file ( $base_uri, $fh, sub { |
267
|
|
|
|
|
|
|
my $s = shift; |
268
|
|
|
|
|
|
|
$encoder->triple( $s->subject, $s->predicate, $s->object, $aref ); |
269
|
|
|
|
|
|
|
} ); |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 DESCRIPTION |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
This module provides methods to encode RDF data in another RDF Encoding Form |
274
|
|
|
|
|
|
|
(aREF). As aREF was designed to facilitate creation of RDF data, it may be |
275
|
|
|
|
|
|
|
easier to create aREF "by hand" instead of using this module! |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head1 OPTIONS |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head2 ns |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
A default namespace map, given as version string of module L<RDF::NS> for |
282
|
|
|
|
|
|
|
stable qNames or as instance of L<RDF::NS>. The most recent installed version |
283
|
|
|
|
|
|
|
of L<RDF::NS> is used by default. The value C<0> can be used to only use |
284
|
|
|
|
|
|
|
required namespace mappings (rdf, rdfs, owl and xsd). |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=head2 subject_map |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
By default RDF graphs with common subject are encoded as aREF predicate map: |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
{ |
291
|
|
|
|
|
|
|
_id => $subject, $predicate => $object |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Enable this option to always encode as aREF subject map: |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
{ |
297
|
|
|
|
|
|
|
$subject => { $predicate => $object } |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=head1 METHODS |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
Note that no syntax checking is applied, e.g. whether a given URI is a valid |
303
|
|
|
|
|
|
|
URI or whether a given language is a valid language tag! |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head2 qname( $uri ) |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
Abbreviate an URI as qName or return C<undef>. For instance |
308
|
|
|
|
|
|
|
C<http://purl.org/dc/terms/title> is abbreviated to "C<dct_title>". |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head2 uri( $uri ) |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Abbreviate an URI or as qName or enclose it in angular brackets. |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=head2 literal( $value, $language_tag, $datatype_uri ) |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
Encode a literal RDF node by either appending "C<@>" and an optional |
317
|
|
|
|
|
|
|
language tag, or "C<^>" and an datatype URI. |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=head2 bnode( $identifier ) |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
Encode a blank node by prepending "C<_:>" to its identifier. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=head2 subject( $subject ) |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=head2 predicate( $predicate ) |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=head2 object( $object ) |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
Encode an RDF subject, predicate, or object respectively. The argument must |
330
|
|
|
|
|
|
|
either be given as hash reference, as defined in |
331
|
|
|
|
|
|
|
L<RDF/JSON|http://www.w3.org/TR/rdf-json/> format (see also method |
332
|
|
|
|
|
|
|
C<as_hashref> of L<RDF::Trine::Model>), or as array reference as internally |
333
|
|
|
|
|
|
|
used by L<RDF::Trine>. |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
A hash reference is expected to have the following fields: |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=over |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=item type |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
one of C<uri>, C<literal> or C<bnode> (required) |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
=item value |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
the URI of the object, its lexical value or a blank node label depending on |
346
|
|
|
|
|
|
|
whether the object is a uri, literal or bnode |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
=item lang |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
the language of a literal value (optional but if supplied it must not be empty) |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=item datatype |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
the datatype URI of the literal value (optional) |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
=back |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
An array reference is expected to consists of |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=over |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
=item |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
three elements (value, language tag, and datatype uri) for literal nodes, |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
=item |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
two elements "C<URI>" and the URI for URI nodes, |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
=item |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
two elements "C<BLANK>" and the blank node identifier for blank nodes. |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
=back |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
=head2 triple( $subject, $predicate, $object, [, $aref ] ) |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
Encode an RDF triple, its elements given as explained for method C<subject>, |
379
|
|
|
|
|
|
|
C<predicate>, and C<object>. If an aREF data structure is given as fourth |
380
|
|
|
|
|
|
|
argument, the triple is added to this structure, possibly changing an aREF |
381
|
|
|
|
|
|
|
predicate map to an aRef subject map. Returns C<undef> on failure. |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
=head2 add_hashref( $aref, $rdf ) |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
Add RDF given in L<RDF/JSON|http://www.w3.org/TR/rdf-json/> format (as returned |
386
|
|
|
|
|
|
|
by method C<as_hashref> in L<RDF::Trine::Model>). |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
=head2 add_iterator( $aref, $iterator ) |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
Add a L<RDF::Trine::Iterator> to an aREF subject map. |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
I<experimental> |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
=head1 SEE ALSO |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
L<RDF::aREF::Decoder>, L<RDF::Trine::Node> |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
=cut |