| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package RDF::aREF::Encoder; |
|
2
|
8
|
|
|
8
|
|
45953
|
use strict; |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
252
|
|
|
3
|
8
|
|
|
8
|
|
42
|
use warnings; |
|
|
8
|
|
|
|
|
13
|
|
|
|
8
|
|
|
|
|
184
|
|
|
4
|
8
|
|
|
8
|
|
83
|
use v5.10; |
|
|
8
|
|
|
|
|
25
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.27'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
279
|
use RDF::NS; |
|
|
8
|
|
|
|
|
7383
|
|
|
|
8
|
|
|
|
|
192
|
|
|
9
|
8
|
|
|
8
|
|
289
|
use RDF::aREF::Decoder qw(localName blankNodeIdentifier); |
|
|
8
|
|
|
|
|
14
|
|
|
|
8
|
|
|
|
|
396
|
|
|
10
|
8
|
|
|
8
|
|
46
|
use Scalar::Util qw(blessed reftype); |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
397
|
|
|
11
|
8
|
|
|
8
|
|
45
|
use Carp qw(croak); |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
8815
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
|
14
|
12
|
|
|
12
|
0
|
2238
|
my ($class, %options) = @_; |
|
15
|
|
|
|
|
|
|
|
|
16
|
12
|
100
|
33
|
|
|
72
|
if (!defined $options{ns}) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
17
|
3
|
|
|
|
|
16
|
$options{ns} = RDF::NS->new; |
|
18
|
|
|
|
|
|
|
} elsif (!$options{ns}) { |
|
19
|
3
|
|
|
|
|
17
|
$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
|
6
|
|
|
|
|
35
|
$options{ns} = RDF::NS->new($options{ns}); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
12
|
|
|
|
|
212329
|
$options{sn} = $options{ns}->REVERSE; |
|
30
|
12
|
|
|
|
|
54420
|
$options{subject_map} = !!$options{subject_map}; |
|
31
|
12
|
100
|
|
|
|
47
|
if ($options{NFC}) { |
|
32
|
1
|
|
|
|
|
3
|
eval { require Unicode::Normalize }; |
|
|
1
|
|
|
|
|
523
|
|
|
33
|
1
|
50
|
|
|
|
1525
|
croak "Missing Unicode::Normalize: NFC normalization disabled!\n" if $@; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
12
|
|
|
|
|
265
|
bless \%options, $class; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub qname { |
|
40
|
33
|
|
|
33
|
1
|
1483
|
my ($self, $uri) = @_; |
|
41
|
33
|
50
|
|
|
|
86
|
return unless $self->{sn}; |
|
42
|
33
|
|
|
|
|
90
|
my @qname = $self->{sn}->qname($uri); |
|
43
|
33
|
50
|
|
|
|
6413
|
return $qname[0] if @qname == 1; |
|
44
|
33
|
100
|
100
|
|
|
254
|
return join('_',@qname) if @qname and $qname[1] =~ localName; |
|
45
|
10
|
|
|
|
|
26
|
return; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub uri { |
|
49
|
16
|
|
|
16
|
1
|
1011
|
my ($self, $uri) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
16
|
100
|
|
|
|
31
|
if ( my $qname = $self->qname($uri) ) { |
|
52
|
11
|
|
|
|
|
48
|
return $qname; |
|
53
|
|
|
|
|
|
|
} else { |
|
54
|
5
|
|
|
|
|
24
|
return "<$uri>"; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub subject { |
|
59
|
20
|
|
|
20
|
1
|
2435
|
my ($self, $subject) = @_; |
|
60
|
|
|
|
|
|
|
|
|
61
|
20
|
|
|
|
|
30
|
return do { |
|
62
|
20
|
100
|
|
|
|
124
|
if (!reftype $subject) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
undef |
|
64
|
|
|
|
|
|
|
# RDF/JSON |
|
65
|
1
|
|
|
|
|
3
|
} elsif (reftype $subject eq 'HASH') { |
|
66
|
2
|
50
|
66
|
|
|
16
|
if ($subject->{type} eq 'uri' or $subject->{type} eq 'bnode') { |
|
67
|
|
|
|
|
|
|
$subject->{value} |
|
68
|
2
|
|
|
|
|
10
|
} |
|
69
|
|
|
|
|
|
|
# RDF::Trine::Node |
|
70
|
|
|
|
|
|
|
} elsif (reftype $subject eq 'ARRAY') { |
|
71
|
17
|
50
|
|
|
|
43
|
if (@$subject == 2 ) { |
|
72
|
17
|
100
|
|
|
|
59
|
if ($subject->[0] eq 'URI') { |
|
|
|
50
|
|
|
|
|
|
|
73
|
16
|
|
|
|
|
85
|
"".$subject->[1]; |
|
74
|
|
|
|
|
|
|
} elsif ($subject->[0] eq 'BLANK') { |
|
75
|
1
|
|
|
|
|
3
|
$self->bnode($subject->[1]) |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
}; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub predicate { |
|
83
|
22
|
|
|
22
|
1
|
2640
|
my ($self, $predicate) = @_; |
|
84
|
|
|
|
|
|
|
|
|
85
|
22
|
|
|
|
|
28
|
$predicate = do { |
|
86
|
22
|
100
|
66
|
|
|
123
|
if (!reftype $predicate) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
undef |
|
88
|
|
|
|
|
|
|
# RDF/JSON |
|
89
|
2
|
|
|
|
|
4
|
} elsif (reftype $predicate eq 'HASH' and $predicate->{type} eq 'uri') { |
|
90
|
|
|
|
|
|
|
$predicate->{value} |
|
91
|
|
|
|
|
|
|
# RDF::Trine::Node |
|
92
|
2
|
|
|
|
|
4
|
} elsif (reftype $predicate eq 'ARRAY') { |
|
93
|
18
|
100
|
66
|
|
|
104
|
(@$predicate == 2 and $predicate->[0] eq 'URI') |
|
94
|
|
|
|
|
|
|
? "".$predicate->[1] : undef; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
}; |
|
97
|
|
|
|
|
|
|
|
|
98
|
22
|
|
|
|
|
32
|
return do { |
|
99
|
22
|
100
|
|
|
|
69
|
if ( !defined $predicate ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
undef |
|
101
|
3
|
|
|
|
|
13
|
} elsif ( $predicate eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' ) { |
|
102
|
6
|
|
|
|
|
19
|
'a' |
|
103
|
|
|
|
|
|
|
} elsif ( my $qname = $self->qname($predicate) ) { |
|
104
|
9
|
|
|
|
|
31
|
$qname |
|
105
|
|
|
|
|
|
|
} else { |
|
106
|
4
|
|
|
|
|
12
|
$predicate |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
}; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub object { |
|
112
|
27
|
|
|
27
|
1
|
5981
|
my ($self, $object) = @_; |
|
113
|
|
|
|
|
|
|
|
|
114
|
27
|
|
|
|
|
35
|
return do { |
|
115
|
27
|
100
|
|
|
|
136
|
if (!reftype $object) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
undef |
|
117
|
|
|
|
|
|
|
# RDF/JSON |
|
118
|
1
|
|
|
|
|
3
|
} elsif (reftype $object eq 'HASH') { |
|
119
|
9
|
100
|
|
|
|
30
|
if ($object->{type} eq 'literal') { |
|
|
|
100
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$self->literal( $object->{value}, $object->{lang}, $object->{datatype} ) |
|
121
|
5
|
|
|
|
|
19
|
} elsif ($object->{type} eq 'bnode') { |
|
122
|
|
|
|
|
|
|
$object->{value} |
|
123
|
1
|
|
|
|
|
4
|
} else { |
|
124
|
|
|
|
|
|
|
$self->uri($object->{value}) |
|
125
|
3
|
|
|
|
|
11
|
} |
|
126
|
|
|
|
|
|
|
# RDF::Trine::Node |
|
127
|
|
|
|
|
|
|
} elsif (reftype $object eq 'ARRAY') { |
|
128
|
17
|
100
|
|
|
|
46
|
if (@$object != 2 ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
129
|
8
|
|
|
|
|
22
|
$self->literal(@$object) |
|
130
|
|
|
|
|
|
|
} elsif ($object->[0] eq 'URI') { |
|
131
|
8
|
|
|
|
|
25
|
$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
|
16
|
|
|
16
|
1
|
919
|
my ($self, $value, $language, $datatype) = @_; |
|
141
|
16
|
100
|
|
|
|
41
|
if ($self->{NFC}) { |
|
142
|
2
|
|
|
|
|
33
|
$value = Unicode::Normalize::NFC($value); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
16
|
100
|
100
|
|
|
58
|
if ($language) { |
|
|
|
100
|
|
|
|
|
|
|
145
|
6
|
|
|
|
|
26
|
$value.'@'.$language |
|
146
|
|
|
|
|
|
|
} elsif ($datatype and $datatype ne 'http://www.w3.org/2001/XMLSchema#string') { |
|
147
|
3
|
|
|
|
|
10
|
$value.'^'.$self->uri($datatype) |
|
148
|
|
|
|
|
|
|
} else { |
|
149
|
7
|
|
|
|
|
39
|
$value.'@' |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub bnode { |
|
154
|
5
|
100
|
|
5
|
1
|
1566
|
$_[1] =~ blankNodeIdentifier ? '_:'.$_[1] : undef; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub triple { |
|
158
|
15
|
|
|
15
|
1
|
279
|
my ($self, $subject, $predicate, $object, $aref) = @_; |
|
159
|
|
|
|
|
|
|
|
|
160
|
15
|
|
50
|
|
|
37
|
$subject = $self->subject($subject) // return; |
|
161
|
15
|
|
50
|
|
|
37
|
$predicate = $self->predicate($predicate) // return; |
|
162
|
15
|
|
50
|
|
|
37
|
$object = $self->object($object) // return; |
|
163
|
15
|
|
100
|
|
|
39
|
$aref //= { }; |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# empty |
|
166
|
15
|
100
|
100
|
|
|
67
|
if ( !keys %$aref and !$self->{subject_map} ) { |
|
|
|
100
|
|
|
|
|
|
|
167
|
8
|
|
|
|
|
39
|
$aref->{_id} = $subject; |
|
168
|
8
|
|
|
|
|
19
|
$aref->{$predicate} = $object; |
|
169
|
|
|
|
|
|
|
# predicate map |
|
170
|
|
|
|
|
|
|
} elsif ( $aref->{_id} ) { |
|
171
|
6
|
100
|
100
|
|
|
28
|
if ( $aref->{_id} eq $subject and !$self->{subject_map} ) { |
|
172
|
4
|
|
|
|
|
11
|
$self->_add_object_to_predicate_map( $aref, $predicate, $object ); |
|
173
|
|
|
|
|
|
|
} else { |
|
174
|
|
|
|
|
|
|
# convert predicate map to subject map |
|
175
|
2
|
|
|
|
|
6
|
my $s = delete $aref->{_id}; |
|
176
|
2
|
|
|
|
|
5
|
my $pm = { }; |
|
177
|
2
|
|
|
|
|
7
|
foreach (keys %$aref) { |
|
178
|
3
|
|
|
|
|
10
|
$pm->{$_} = delete $aref->{$_}; |
|
179
|
|
|
|
|
|
|
} |
|
180
|
2
|
100
|
|
|
|
6
|
if ($s eq $subject) { |
|
181
|
1
|
|
|
|
|
3
|
$self->_add_object_to_predicate_map( $pm, $predicate, $object ); |
|
182
|
|
|
|
|
|
|
} else { |
|
183
|
1
|
|
|
|
|
4
|
$aref->{$subject} = { $predicate => $object }; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
2
|
|
|
|
|
5
|
$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
|
15
|
|
|
|
|
67
|
return $aref; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub _add_object_to_predicate_map { |
|
199
|
5
|
|
|
5
|
|
14
|
my ($self, $map, $predicate, $object) = @_; |
|
200
|
|
|
|
|
|
|
|
|
201
|
5
|
50
|
|
|
|
25
|
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
|
5
|
|
|
|
|
14
|
$map->{$predicate} = $object; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub add_iterator { |
|
211
|
4
|
|
|
4
|
1
|
4973
|
my ($self, $iterator, $aref) = @_; |
|
212
|
4
|
|
|
|
|
14
|
while (my $s = $iterator->next) { |
|
213
|
9
|
|
|
|
|
553
|
$self->triple($s->subject, $s->predicate, $s->object, $aref); |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub add_hashref { |
|
218
|
4
|
|
|
4
|
1
|
9
|
my ($self, $hashref, $aref) = @_; |
|
219
|
|
|
|
|
|
|
|
|
220
|
4
|
|
|
|
|
20
|
while (my ($s,$ps) = each %$hashref) { |
|
221
|
4
|
50
|
|
|
|
16
|
my $subject = $s =~ /^_:/ ? ['BLANK',substr($s, 2)] : ['URI',$s]; |
|
222
|
4
|
|
|
|
|
12
|
foreach my $p (keys %$ps) { |
|
223
|
4
|
|
|
|
|
7
|
my $predicate = ['URI',$p]; |
|
224
|
4
|
|
|
|
|
5
|
foreach my $object (@{ $hashref->{$s}->{$p} }) { |
|
|
4
|
|
|
|
|
9
|
|
|
225
|
4
|
|
|
|
|
11
|
$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 |