line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Trine::Parser::NQuads |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Trine::Parser::NQuads - N-Quads Parser |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Trine::Parser::NQuads version 1.018 |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use RDF::Trine::Parser; |
15
|
|
|
|
|
|
|
my $parser = RDF::Trine::Parser->new( 'nquads' ); |
16
|
|
|
|
|
|
|
$parser->parse_into_model( $base_uri, $data, $model ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
... |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 METHODS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
25
|
|
|
|
|
|
|
L<RDF::Trine::Parser> class. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over 4 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package RDF::Trine::Parser::NQuads; |
32
|
|
|
|
|
|
|
|
33
|
68
|
|
|
68
|
|
434
|
use strict; |
|
68
|
|
|
|
|
161
|
|
|
68
|
|
|
|
|
1743
|
|
34
|
68
|
|
|
68
|
|
320
|
use warnings; |
|
68
|
|
|
|
|
153
|
|
|
68
|
|
|
|
|
1744
|
|
35
|
68
|
|
|
68
|
|
328
|
use utf8; |
|
68
|
|
|
|
|
147
|
|
|
68
|
|
|
|
|
339
|
|
36
|
|
|
|
|
|
|
|
37
|
68
|
|
|
68
|
|
1491
|
use base qw(RDF::Trine::Parser::NTriples); |
|
68
|
|
|
|
|
160
|
|
|
68
|
|
|
|
|
4216
|
|
38
|
|
|
|
|
|
|
|
39
|
68
|
|
|
68
|
|
406
|
use Carp; |
|
68
|
|
|
|
|
153
|
|
|
68
|
|
|
|
|
3434
|
|
40
|
68
|
|
|
68
|
|
454
|
use Encode qw(decode); |
|
68
|
|
|
|
|
183
|
|
|
68
|
|
|
|
|
2450
|
|
41
|
68
|
|
|
68
|
|
382
|
use Data::Dumper; |
|
68
|
|
|
|
|
155
|
|
|
68
|
|
|
|
|
2679
|
|
42
|
68
|
|
|
68
|
|
386
|
use Log::Log4perl; |
|
68
|
|
|
|
|
158
|
|
|
68
|
|
|
|
|
433
|
|
43
|
68
|
|
|
68
|
|
3822
|
use Scalar::Util qw(blessed reftype); |
|
68
|
|
|
|
|
168
|
|
|
68
|
|
|
|
|
2972
|
|
44
|
|
|
|
|
|
|
|
45
|
68
|
|
|
68
|
|
380
|
use RDF::Trine qw(literal); |
|
68
|
|
|
|
|
162
|
|
|
68
|
|
|
|
|
2287
|
|
46
|
68
|
|
|
68
|
|
372
|
use RDF::Trine::Node; |
|
68
|
|
|
|
|
155
|
|
|
68
|
|
|
|
|
1819
|
|
47
|
68
|
|
|
68
|
|
348
|
use RDF::Trine::Statement; |
|
68
|
|
|
|
|
154
|
|
|
68
|
|
|
|
|
1527
|
|
48
|
68
|
|
|
68
|
|
332
|
use RDF::Trine::Error qw(:try); |
|
68
|
|
|
|
|
156
|
|
|
68
|
|
|
|
|
435
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
###################################################################### |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
our ($VERSION); |
53
|
|
|
|
|
|
|
BEGIN { |
54
|
68
|
|
|
68
|
|
13324
|
$VERSION = '1.018'; |
55
|
68
|
|
|
|
|
188
|
$RDF::Trine::Parser::parser_names{ 'nquads' } = __PACKAGE__; |
56
|
68
|
|
|
|
|
158
|
$RDF::Trine::Parser::format_uris{ 'http://sw.deri.org/2008/07/n-quads/#n-quads' } = __PACKAGE__; |
57
|
68
|
|
|
|
|
177
|
foreach my $ext (qw(nq)) { |
58
|
68
|
|
|
|
|
199
|
$RDF::Trine::Parser::file_extensions{ $ext } = __PACKAGE__; |
59
|
|
|
|
|
|
|
} |
60
|
68
|
|
|
|
|
162
|
my $class = __PACKAGE__; |
61
|
68
|
|
|
|
|
167
|
$RDF::Trine::Parser::canonical_media_types{ $class } = 'text/x-nquads'; |
62
|
68
|
|
|
|
|
156
|
foreach my $type (qw(text/x-nquads)) { |
63
|
68
|
|
|
|
|
20420
|
$RDF::Trine::Parser::media_types{ $type } = __PACKAGE__; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
###################################################################### |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item C<< parse_into_model ( $base_uri, $data, $model ) >> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Parses the bytes in C<< $data >>, using the given C<< $base_uri >>. For each RDF triple |
72
|
|
|
|
|
|
|
or quad parsed, will call C<< $model->add_statement( $statement ) >>. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub parse_into_model { |
77
|
6
|
|
|
6
|
1
|
50
|
my $proto = shift; |
78
|
6
|
50
|
|
|
|
28
|
my $self = blessed($proto) ? $proto : $proto->new(); |
79
|
6
|
|
|
|
|
14
|
my $uri = shift; |
80
|
6
|
50
|
33
|
|
|
33
|
if (blessed($uri) and $uri->isa('RDF::Trine::Node::Resource')) { |
81
|
0
|
|
|
|
|
0
|
$uri = $uri->uri_value; |
82
|
|
|
|
|
|
|
} |
83
|
6
|
|
|
|
|
14
|
my $input = shift; |
84
|
6
|
|
|
|
|
17
|
my $model = shift; |
85
|
6
|
|
|
|
|
18
|
my %args = @_; |
86
|
|
|
|
|
|
|
|
87
|
6
|
50
|
|
|
|
23
|
if (my $context = $args{'context'}) { |
88
|
0
|
|
|
|
|
0
|
throw RDF::Trine::Error::ParserError -text => "Cannot pass a context node to N-Quads parse_into_model method"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $handler = sub { |
92
|
8
|
|
|
8
|
|
21
|
my $st = shift; |
93
|
8
|
|
|
|
|
35
|
$model->add_statement( $st ); |
94
|
6
|
|
|
|
|
27
|
}; |
95
|
6
|
|
|
|
|
38
|
return $self->parse( $uri, $input, $handler ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _emit_statement { |
99
|
8
|
|
|
8
|
|
22
|
my $self = shift; |
100
|
8
|
|
|
|
|
18
|
my $handler = shift; |
101
|
8
|
|
|
|
|
18
|
my $nodes = shift; |
102
|
8
|
|
|
|
|
19
|
my $lineno = shift; |
103
|
8
|
|
|
|
|
16
|
my $st; |
104
|
|
|
|
|
|
|
|
105
|
8
|
100
|
|
|
|
39
|
if ($self->{canonicalize}) { |
106
|
5
|
50
|
33
|
|
|
51
|
if ($nodes->[2]->isa('RDF::Trine::Node::Literal') and $nodes->[2]->has_datatype) { |
107
|
5
|
|
|
|
|
19
|
my $value = $nodes->[2]->literal_value; |
108
|
5
|
|
|
|
|
20
|
my $dt = $nodes->[2]->literal_datatype; |
109
|
5
|
|
|
|
|
29
|
my $canon = RDF::Trine::Node::Literal->canonicalize_literal_value( $value, $dt, 1 ); |
110
|
5
|
|
|
|
|
36
|
$nodes->[2] = literal( $canon, undef, $dt ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
8
|
100
|
|
|
|
47
|
if (scalar(@$nodes) == 3) { |
|
|
50
|
|
|
|
|
|
115
|
1
|
|
|
|
|
12
|
$st = RDF::Trine::Statement->new( @$nodes ); |
116
|
|
|
|
|
|
|
} elsif (scalar(@$nodes) == 4) { |
117
|
7
|
|
|
|
|
57
|
$st = RDF::Trine::Statement::Quad->new( @$nodes ); |
118
|
|
|
|
|
|
|
} else { |
119
|
|
|
|
|
|
|
# warn Dumper($nodes); |
120
|
0
|
|
|
|
|
0
|
throw RDF::Trine::Error::ParserError -text => qq[Not valid N-Quads data at line $lineno]; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
8
|
|
|
|
|
25
|
$handler->( $st ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 BUGS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Please report any bugs or feature requests to through the GitHub web interface |
136
|
|
|
|
|
|
|
at L<https://github.com/kasei/perlrdf/issues>. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 AUTHOR |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Gregory Todd Williams C<< <gwilliams@cpan.org> >> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 COPYRIGHT |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Copyright (c) 2006-2012 Gregory Todd Williams. This |
145
|
|
|
|
|
|
|
program is free software; you can redistribute it and/or modify it under |
146
|
|
|
|
|
|
|
the same terms as Perl itself. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |