| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# RDF::Trine::Parser::TriG |
|
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Trine::Parser::TriG - TriG RDF Parser |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Trine::Parser::TriG version 1.017 |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use RDF::Trine::Parser; |
|
15
|
|
|
|
|
|
|
my $parser = RDF::Trine::Parser->new( 'trig' ); |
|
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::TriG; |
|
32
|
|
|
|
|
|
|
|
|
33
|
68
|
|
|
68
|
|
1707
|
use 5.010; |
|
|
68
|
|
|
|
|
258
|
|
|
34
|
68
|
|
|
68
|
|
375
|
use strict; |
|
|
68
|
|
|
|
|
147
|
|
|
|
68
|
|
|
|
|
1478
|
|
|
35
|
68
|
|
|
68
|
|
337
|
use warnings; |
|
|
68
|
|
|
|
|
153
|
|
|
|
68
|
|
|
|
|
2082
|
|
|
36
|
68
|
|
|
68
|
|
328
|
no warnings 'redefine'; |
|
|
68
|
|
|
|
|
155
|
|
|
|
68
|
|
|
|
|
2384
|
|
|
37
|
68
|
|
|
68
|
|
332
|
no warnings 'once'; |
|
|
68
|
|
|
|
|
151
|
|
|
|
68
|
|
|
|
|
1788
|
|
|
38
|
68
|
|
|
68
|
|
378
|
use base qw(RDF::Trine::Parser::Turtle); |
|
|
68
|
|
|
|
|
172
|
|
|
|
68
|
|
|
|
|
6561
|
|
|
39
|
68
|
|
|
68
|
|
492
|
use RDF::Trine::Parser::Turtle::Constants; |
|
|
68
|
|
|
|
|
168
|
|
|
|
68
|
|
|
|
|
8943
|
|
|
40
|
68
|
|
|
68
|
|
477
|
use RDF::Trine qw(literal); |
|
|
68
|
|
|
|
|
151
|
|
|
|
68
|
|
|
|
|
5745
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
our ($VERSION); |
|
43
|
|
|
|
|
|
|
BEGIN { |
|
44
|
68
|
|
|
68
|
|
265
|
$VERSION = '1.017'; |
|
45
|
68
|
|
|
|
|
197
|
$RDF::Trine::Parser::parser_names{ 'trig' } = __PACKAGE__; |
|
46
|
68
|
|
|
|
|
184
|
foreach my $ext (qw(trig)) { |
|
47
|
68
|
|
|
|
|
57782
|
$RDF::Trine::Parser::file_extensions{ $ext } = __PACKAGE__; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
# foreach my $type (qw(application/x-turtle application/turtle text/turtle)) { |
|
50
|
|
|
|
|
|
|
# $RDF::Trine::Parser::media_types{ $type } = __PACKAGE__; |
|
51
|
|
|
|
|
|
|
# } |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _assert_triple { |
|
55
|
31
|
|
|
31
|
|
73
|
my $self = shift; |
|
56
|
31
|
|
|
|
|
68
|
my $subj = shift; |
|
57
|
31
|
|
|
|
|
44
|
my $pred = shift; |
|
58
|
31
|
|
|
|
|
48
|
my $obj = shift; |
|
59
|
31
|
|
|
|
|
58
|
my $graph = $self->{graph}; |
|
60
|
|
|
|
|
|
|
|
|
61
|
31
|
0
|
33
|
|
|
91
|
if ($self->{canonicalize} and blessed($obj) and $obj->isa('RDF::Trine::Node::Literal')) { |
|
|
|
|
33
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
$obj = $obj->canonicalize; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
31
|
|
|
|
|
121
|
my $st = RDF::Trine::Statement::Quad->new( $subj, $pred, $obj, $graph ); |
|
65
|
|
|
|
|
|
|
|
|
66
|
31
|
50
|
|
|
|
86
|
if (my $code = $self->{handle_triple}) { |
|
67
|
31
|
|
|
|
|
98
|
$code->( $st ); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
31
|
|
|
|
|
97
|
my $count = ++$self->{triple_count}; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _statement { |
|
74
|
23
|
|
|
23
|
|
39
|
my $self = shift; |
|
75
|
23
|
|
|
|
|
53
|
my $l = shift; |
|
76
|
23
|
|
|
|
|
33
|
my $t = shift; |
|
77
|
23
|
|
|
|
|
536
|
my $type = $t->type; |
|
78
|
|
|
|
|
|
|
# warn '--> ' . decrypt_constant($type); |
|
79
|
23
|
100
|
33
|
|
|
138
|
if ($type == LBRACE) { return $self->_graph($l, $t); } |
|
|
2
|
50
|
0
|
|
|
7
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
elsif ($type == LBRACKET) { return $self->_graph($l, $t); } |
|
81
|
0
|
|
|
|
|
0
|
elsif ($type == BNODE) { return $self->_graph($l, $t); } |
|
82
|
0
|
|
|
|
|
0
|
elsif ($type == EQUALS) { return $self->_graph($l, $t); } |
|
83
|
3
|
|
|
|
|
9
|
elsif ($type == IRI) { return $self->_graph($l, $t); } |
|
84
|
4
|
|
|
|
|
13
|
elsif ($type == PREFIXNAME) { return $self->_graph($l, $t); } |
|
85
|
|
|
|
|
|
|
elsif ($type == WS) {} |
|
86
|
|
|
|
|
|
|
elsif ($type == PREFIX or $type == SPARQLPREFIX) { |
|
87
|
14
|
|
|
|
|
47
|
$t = $self->_get_token_type($l, PREFIXNAME); |
|
88
|
14
|
|
|
|
|
43
|
my $name = $t->value; |
|
89
|
14
|
|
|
|
|
53
|
$name =~ s/:$//; |
|
90
|
14
|
|
|
|
|
50
|
$t = $self->_get_token_type($l, IRI); |
|
91
|
14
|
|
|
|
|
358
|
my $r = RDF::Trine::Node::Resource->new($t->value, $self->{baseURI}); |
|
92
|
14
|
|
|
|
|
46
|
my $iri = $r->uri_value; |
|
93
|
14
|
50
|
|
|
|
39
|
if ($type == PREFIX) { |
|
94
|
14
|
|
|
|
|
42
|
$t = $self->_get_token_type($l, DOT); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
14
|
|
|
|
|
356
|
$self->{map}->add_mapping( $name => $iri ); |
|
97
|
14
|
50
|
|
|
|
210
|
if (my $ns = $self->{namespaces}) { |
|
98
|
0
|
0
|
|
|
|
0
|
unless ($ns->namespace_uri($name)) { |
|
99
|
0
|
|
|
|
|
0
|
$ns->add_mapping( $name => $iri ); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
elsif ($type == BASE or $type == SPARQLBASE) { |
|
104
|
0
|
|
|
|
|
0
|
$t = $self->_get_token_type($l, IRI); |
|
105
|
0
|
|
|
|
|
0
|
my $r = RDF::Trine::Node::Resource->new($t->value, $self->{baseURI}); |
|
106
|
0
|
|
|
|
|
0
|
my $iri = $r->uri_value; |
|
107
|
0
|
0
|
|
|
|
0
|
if ($type == BASE) { |
|
108
|
0
|
|
|
|
|
0
|
$t = $self->_get_token_type($l, DOT); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
0
|
|
|
|
|
0
|
$self->{baseURI} = $iri; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
else { |
|
113
|
0
|
|
|
|
|
0
|
$self->_throw_error("Expecting statement but got " . decrypt_constant($type), $t, $l); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _graph { |
|
118
|
9
|
|
|
9
|
|
17
|
my $self = shift; |
|
119
|
9
|
|
|
|
|
16
|
my $l = shift; |
|
120
|
9
|
|
|
|
|
13
|
my $t = shift; |
|
121
|
9
|
|
|
|
|
208
|
my $type = $t->type; |
|
122
|
9
|
100
|
100
|
|
|
48
|
if ($type == IRI or $type == PREFIXNAME) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
123
|
7
|
|
|
|
|
23
|
$self->{graph} = $self->_token_to_node($t); |
|
124
|
7
|
|
|
|
|
15
|
my $old_token = $t; |
|
125
|
7
|
|
|
|
|
23
|
$t = $self->_next_nonws($l); |
|
126
|
7
|
50
|
|
|
|
21
|
unless (defined($t)) { |
|
127
|
0
|
|
|
|
|
0
|
$l->_throw_error("Unexpected EOF after graph"); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
} elsif ($type == BNODE) { |
|
130
|
0
|
|
|
|
|
0
|
$self->{graph} = $self->_token_to_node($t); |
|
131
|
0
|
|
|
|
|
0
|
$t = $self->_next_nonws($l); |
|
132
|
|
|
|
|
|
|
} elsif ($type == LBRACKET) { |
|
133
|
0
|
|
|
|
|
0
|
$t = $self->_get_token_type($l, RBRACKET); |
|
134
|
0
|
|
|
|
|
0
|
$t = $self->_next_nonws($l); |
|
135
|
0
|
|
|
|
|
0
|
$self->{graph} = RDF::Trine::Node::Blank->new(); |
|
136
|
|
|
|
|
|
|
} else { |
|
137
|
2
|
|
|
|
|
18
|
$self->{graph} = RDF::Trine::Node::Nil->new(); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
9
|
100
|
|
|
|
170
|
if ($t->type == EQUALS) { |
|
141
|
1
|
|
|
|
|
4
|
$t = $self->_next_nonws($l); |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
9
|
50
|
|
|
|
211
|
if ($t->type != LBRACE) { |
|
145
|
0
|
|
|
|
|
0
|
$self->_throw_error("Expecting LBRACE but got " . decrypt_constant($type), $t, $l); |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
9
|
|
|
|
|
31
|
$t = $self->_next_nonws($l); |
|
149
|
9
|
|
|
|
|
181
|
while (1) { |
|
150
|
32
|
|
|
|
|
741
|
my $type = $t->type; |
|
151
|
32
|
100
|
33
|
|
|
294
|
unless ($type == LBRACKET or $type == LPAREN or $type == IRI or $type == PREFIXNAME or $type == BNODE) { |
|
|
|
|
66
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
152
|
6
|
|
|
|
|
24
|
$self->_unget_token($t); |
|
153
|
6
|
|
|
|
|
13
|
last; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
26
|
|
|
|
|
90
|
$self->_triple($l, $t); |
|
156
|
26
|
|
|
|
|
71
|
$t = $self->_next_nonws($l); |
|
157
|
26
|
100
|
|
|
|
644
|
if ($t->type == RBRACE) { |
|
|
|
50
|
|
|
|
|
|
|
158
|
3
|
|
|
|
|
10
|
$self->_unget_token($t); |
|
159
|
3
|
|
|
|
|
5
|
last; |
|
160
|
|
|
|
|
|
|
} elsif ($t->type == DOT) { |
|
161
|
23
|
|
|
|
|
61
|
$t = $self->_next_nonws($l); |
|
162
|
23
|
|
|
|
|
577
|
next; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
9
|
|
|
|
|
24
|
$t = $self->_get_token_type($l, RBRACE); |
|
167
|
9
|
|
|
|
|
28
|
$t = $self->_next_nonws($l); |
|
168
|
9
|
100
|
|
|
|
235
|
return unless defined($t); |
|
169
|
6
|
100
|
|
|
|
141
|
unless ($t->type == DOT) { |
|
170
|
5
|
|
|
|
|
16
|
$self->_unget_token($t); |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub _triple { |
|
175
|
26
|
|
|
26
|
|
46
|
my $self = shift; |
|
176
|
26
|
|
|
|
|
32
|
my $l = shift; |
|
177
|
26
|
|
|
|
|
40
|
my $t = shift; |
|
178
|
26
|
|
|
|
|
606
|
my $type = $t->type; |
|
179
|
|
|
|
|
|
|
# subject |
|
180
|
26
|
|
|
|
|
43
|
my $subj; |
|
181
|
26
|
50
|
66
|
|
|
169
|
if ($type == LBRACKET) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
0
|
$subj = RDF::Trine::Node::Blank->new(); |
|
183
|
0
|
|
|
|
|
0
|
my $t = $self->_next_nonws($l); |
|
184
|
0
|
0
|
|
|
|
0
|
if ($t->type != RBRACKET) { |
|
185
|
0
|
|
|
|
|
0
|
$self->_unget_token($t); |
|
186
|
0
|
|
|
|
|
0
|
$self->_predicateObjectList( $l, $subj ); |
|
187
|
0
|
|
|
|
|
0
|
$t = $self->_get_token_type($l, RBRACKET); |
|
188
|
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
0
|
$t = $self->_next_nonws($l); |
|
190
|
0
|
0
|
|
|
|
0
|
return unless defined($t); |
|
191
|
0
|
|
|
|
|
0
|
$self->_unget_token($t); |
|
192
|
0
|
0
|
|
|
|
0
|
if ($t->type == DOT) { |
|
193
|
0
|
|
|
|
|
0
|
return; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
} elsif ($type == LPAREN) { |
|
197
|
0
|
|
|
|
|
0
|
my $t = $self->_next_nonws($l); |
|
198
|
0
|
0
|
|
|
|
0
|
if ($t->type == RPAREN) { |
|
199
|
0
|
|
|
|
|
0
|
$subj = RDF::Trine::Node::Resource->new('http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'); |
|
200
|
|
|
|
|
|
|
} else { |
|
201
|
0
|
|
|
|
|
0
|
$subj = RDF::Trine::Node::Blank->new(); |
|
202
|
0
|
|
|
|
|
0
|
my @objects = $self->_object($l, $t); |
|
203
|
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
0
|
while (1) { |
|
205
|
0
|
|
|
|
|
0
|
my $t = $self->_next_nonws($l); |
|
206
|
0
|
0
|
|
|
|
0
|
if ($t->type == RPAREN) { |
|
207
|
0
|
|
|
|
|
0
|
last; |
|
208
|
|
|
|
|
|
|
} else { |
|
209
|
0
|
|
|
|
|
0
|
push(@objects, $self->_object($l, $t)); |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
} |
|
212
|
0
|
|
|
|
|
0
|
$self->_assert_list($subj, @objects); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
} elsif (not($type==IRI or $type==PREFIXNAME or $type==BNODE)) { |
|
215
|
0
|
|
|
|
|
0
|
$self->_throw_error("Expecting resource or bnode but got " . decrypt_constant($type), $t, $l); |
|
216
|
|
|
|
|
|
|
} else { |
|
217
|
26
|
|
|
|
|
83
|
$subj = $self->_token_to_node($t); |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
# warn "Subject: $subj\n"; |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
#predicateObjectList |
|
222
|
26
|
|
|
|
|
85
|
$self->_predicateObjectList($l, $subj); |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
1; |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
__END__ |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=back |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 BUGS |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Please report any bugs or feature requests to through the GitHub web interface |
|
235
|
|
|
|
|
|
|
at L<https://github.com/kasei/perlrdf/issues>. |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
L<http://www4.wiwiss.fu-berlin.de/bizer/TriG/> |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 AUTHOR |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Gregory Todd Williams C<< <gwilliams@cpan.org> >> |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Copyright (c) 2006-2012 Gregory Todd Williams. This |
|
248
|
|
|
|
|
|
|
program is free software; you can redistribute it and/or modify it under |
|
249
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |