line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Exporter::RDF; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
43012
|
use namespace::clean; |
|
4
|
|
|
|
|
34188
|
|
|
4
|
|
|
|
|
18
|
|
4
|
4
|
|
|
4
|
|
1577
|
use Catmandu::Sane; |
|
4
|
|
|
|
|
310885
|
|
|
4
|
|
|
|
|
37
|
|
5
|
4
|
|
|
4
|
|
932
|
use Moo; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
20
|
|
6
|
4
|
|
|
4
|
|
3805
|
use RDF::Trine::Serializer; |
|
4
|
|
|
|
|
2479273
|
|
|
4
|
|
|
|
|
89
|
|
7
|
4
|
|
|
4
|
|
24
|
use RDF::Trine::Model; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
69
|
|
8
|
4
|
|
|
4
|
|
1074
|
use RDF::aREF; |
|
4
|
|
|
|
|
41221
|
|
|
4
|
|
|
|
|
1539
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.30'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::RDF'; |
13
|
|
|
|
|
|
|
with 'Catmandu::Exporter'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# internal attributes |
16
|
|
|
|
|
|
|
has decoder => ( |
17
|
|
|
|
|
|
|
is => 'lazy' |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has serializer => ( |
21
|
|
|
|
|
|
|
is => 'lazy' |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has model => ( |
25
|
|
|
|
|
|
|
is => 'lazy' |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _build_decoder { |
29
|
12
|
0
|
33
|
12
|
|
1961
|
RDF::aREF::Decoder->new( |
30
|
|
|
|
|
|
|
ns => $_[0]->ns // ($_[0]->ns eq 0 ? { } : RDF::NS->new), |
31
|
|
|
|
|
|
|
callback => $_[0]->model |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _build_serializer { |
36
|
12
|
|
100
|
12
|
|
5020
|
RDF::Trine::Serializer->new($_[0]->type // 'ntriples'); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _build_model { |
40
|
12
|
|
|
12
|
|
1198
|
my $self = shift; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Streaming output when we have type => NTriples |
43
|
12
|
100
|
100
|
|
|
73
|
if (lc($self->type // 'ntriples') eq 'ntriples') { |
44
|
|
|
|
|
|
|
sub { |
45
|
8
|
|
|
8
|
|
4953
|
require RDF::Trine::Statement; |
46
|
8
|
|
|
|
|
13
|
eval { |
47
|
8
|
|
|
|
|
22
|
my $st = RDF::aREF::Decoder::trine_statement(@_); |
48
|
8
|
|
|
|
|
577
|
$self->fh->print($self->serializer->statement_as_string($st)); |
49
|
|
|
|
|
|
|
}; |
50
|
8
|
50
|
|
|
|
4713
|
$self->decoder->error($@) if $@; |
51
|
2
|
|
|
|
|
32
|
}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
10
|
|
|
|
|
78
|
RDF::Trine::Model->new; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add { |
59
|
|
|
|
|
|
|
my ($self, $aref) = @_; |
60
|
|
|
|
|
|
|
$self->decoder->decode($aref, keep_bnode_map => 1); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub commit { |
64
|
|
|
|
|
|
|
my ($self) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
if (ref $self->model eq 'RDF::Trine::Model') { |
67
|
|
|
|
|
|
|
$self->model->end_bulk_ops; |
68
|
|
|
|
|
|
|
$self->decoder->clean_bnodes; |
69
|
|
|
|
|
|
|
$self->serializer->serialize_model_to_file( $self->fh, $self->model ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NAME |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Catmandu::Exporter::RDF - serialize RDF data |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
In Perl code: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use Catmandu -all; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $exporter = exporter('RDF', |
87
|
|
|
|
|
|
|
file => 'export.rdf', |
88
|
|
|
|
|
|
|
type => 'XML', |
89
|
|
|
|
|
|
|
fix => 'rdf.fix' |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$exporter->add( $aref ); # pass RDF data in aREF encoding |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$exporter->commit; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 DESCRIPTION |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This L<Catmandu::Exporter> exports RDF data in different RDF serializations. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 CONFIGURATION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item file |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item fh |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item encoding |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item fix |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Default configuration options of L<Catmandu::Exporter>. The option C<fix> is |
113
|
|
|
|
|
|
|
supported as derived from L<Catmandu::Fixable>. For every C<add> or for every |
114
|
|
|
|
|
|
|
item in C<add_many> the given fixes will be applied first. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item type |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
A serialization form can be set with option C<type> with default value |
119
|
|
|
|
|
|
|
C<NTriples>. The option must refer to a subclass of L<RDF::Trine::Serializer>, |
120
|
|
|
|
|
|
|
for instance C<Turtle> for RDF/Turtle with L<RDF::Trine::Serializer::Turtle>. |
121
|
|
|
|
|
|
|
The first letter is transformed uppercase, so C<< format => 'turtle' >> will |
122
|
|
|
|
|
|
|
work as well. In addition there are aliases C<ttl> for C<Turtle>, C<n3> for |
123
|
|
|
|
|
|
|
C<Notation3>, C<xml> and C<XML> for C<RDFXML>, C<json> for C<RDFJSON>. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
When the option C<type> is set to 'NTriples' the export can be streamed in all |
126
|
|
|
|
|
|
|
other cases the results are exported in bulk after C<commit()>. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item ns |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
The option C<ns> can refer to an instance of or to a constructor argument of |
131
|
|
|
|
|
|
|
L<RDF::NS>. Use a fixed date, such as "C<20130816>" to make sure your URI |
132
|
|
|
|
|
|
|
namespace prefixes are stable. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=back |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 METHODS |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
See also L<Catmandu::Exporter>. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 add( ... ) |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
RDF data is added given in B<another RDF Encoding Form (aREF)> as |
143
|
|
|
|
|
|
|
implemented with L<RDF::aREF> and defined at L<http://github.com/gbv/aref>. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 count |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Returns the number of times C<add> has been called. In contrast to other |
148
|
|
|
|
|
|
|
Catmandu exporters, this does not reflect the number of exporter records |
149
|
|
|
|
|
|
|
because RDF data is always merged to one RDF graph. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 uri( $uri ) |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Expand and abbreviated with L<RDF::NS>. For instance "C<dc:title>" is expanded |
154
|
|
|
|
|
|
|
to "C<http://purl.org/dc/elements/1.1/title>". |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Serialization is based on L<RDF::Trine::Serializer>. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=encoding utf8 |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |