line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Copyright (c) 2004-2006 IBM Corporation. |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# All rights reserved. This program and the accompanying materials |
5
|
|
|
|
|
|
|
# are made available under the terms of the Eclipse Public License v1.0 |
6
|
|
|
|
|
|
|
# which accompanies this distribution, and is available at |
7
|
|
|
|
|
|
|
# http://www.eclipse.org/legal/epl-v10.html |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# File: $Source: /var/lib/cvs/ODO/lib/ODO/Jena/Node/Parser.pm,v $ |
10
|
|
|
|
|
|
|
# Created by: Stephen Evanchik( evanchik@us.ibm.com ) |
11
|
|
|
|
|
|
|
# Created on: 11/05/2004 |
12
|
|
|
|
|
|
|
# Revision: $Id: Parser.pm,v 1.2 2009-11-25 17:58:26 ubuntu Exp $ |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# Contributors: |
15
|
|
|
|
|
|
|
# IBM Corporation - initial API and implementation |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
package ODO::Jena::Node::Parser; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
1255
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
20
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
5
|
use base qw/ODO/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
95
|
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
6
|
use vars qw /$VERSION/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
76
|
|
25
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /: (\d+)\.(\d+)/; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
5
|
use ODO::Jena::Node; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
935
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 NAME |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
ODO::Jena::Node::Parser - Package of functions used to parse encoded database statements |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SYNOPSIS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Synopsis |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 DESCRIPTION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
The functions provided by this package parse statemen strings returned from a database that |
41
|
|
|
|
|
|
|
was created by Jena L. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=over |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item parse( $node_string ) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub parse { |
52
|
3
|
|
|
3
|
1
|
1962
|
my ($self, $node_string) = @_; |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
|
|
8
|
foreach my $node_type (qw/literal resource blank variable/) { |
55
|
5
|
|
|
|
|
10
|
my $fn = "__parse_${node_type}_node"; |
56
|
5
|
|
|
|
|
17
|
my $node = ODO::Jena::Node::Parser->$fn($node_string); |
57
|
|
|
|
|
|
|
|
58
|
5
|
100
|
|
|
|
38
|
return $node |
59
|
|
|
|
|
|
|
if(defined($node)); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# my ( $r_ref_header, $r_long_uri) = ODO::Jena::Node::Parser::isResourceReference($node); |
63
|
|
|
|
|
|
|
# my ($br_header, $br_long_uri) = ODO::Jena::Node::Parser::isBlankReference($node); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
return undef; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item __parse_literal_node( $string ) |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Determines whether or not the given string is a Jena literal value. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Parameters: |
73
|
|
|
|
|
|
|
$string - The string to examine. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Returns: |
76
|
|
|
|
|
|
|
undef if it is not a literal value; an ODO::Jena::Node::Literal otherwise |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub __parse_literal_node { |
81
|
3
|
|
|
3
|
|
7
|
my ($self, $string) = @_; |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
6
|
my $header = |
84
|
|
|
|
|
|
|
${ODO::Jena::Node::Constants::LITERAL_HEADER} |
85
|
|
|
|
|
|
|
. ${ODO::Jena::Node::Constants::VALUE_DELIMITER}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return undef |
88
|
3
|
100
|
|
|
|
40
|
unless($string =~ /^$header/); |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
30
|
my ($p_header, $lang_len, $datatype_len, $p_value) = ($string =~ /^($header):(\d+):(\d*):(.*):$/); |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
3
|
my $language = ''; |
93
|
1
|
50
|
33
|
|
|
14
|
if(defined($lang_len) && $lang_len ne '' && $lang_len > 0) { |
|
|
|
33
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
$language = substr($p_value, 0, $lang_len); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else { |
97
|
1
|
|
|
|
|
2
|
$lang_len = 0; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
2
|
my $datatype = ''; |
101
|
1
|
50
|
33
|
|
|
8
|
if(defined($datatype_len) && $datatype_len ne '' && $datatype_len > 0) { |
|
|
|
33
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
$datatype = substr($p_value, $lang_len, $datatype_len); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
1
|
|
|
|
|
2
|
$datatype_len = 0; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
4
|
$p_value = substr($p_value, $lang_len + $datatype_len, length($p_value) - ($lang_len + $datatype_len)); |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
15
|
return ODO::Jena::Node::Literal->new(-value=> $p_value, -datatype=> $datatype, -language=> $language); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item __parse_literal_reference( $string) |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Determines whether or not the given string is a literal reference. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Parameters: |
119
|
|
|
|
|
|
|
$literal - Required. The string to examine. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Returns: |
122
|
|
|
|
|
|
|
undef if the string is not a literal reference |
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub __parse_literal_reference { |
126
|
0
|
|
|
0
|
|
0
|
my ($self, $string) = @_; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
0
|
my $header = |
129
|
|
|
|
|
|
|
$ODO::Jena::Node::Constants::LITERAL_HEADER |
130
|
|
|
|
|
|
|
. ${ODO::Jena::Node::Constants::VALUE_DELIMITER}; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
0
|
my ($p_header, $long_id) = $string =~ /^($header):(\d+)/; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
return undef |
135
|
0
|
0
|
0
|
|
|
0
|
unless($p_header && $long_id); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# TODO: Literal reference? |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item __parse_resource_node( $string ) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Determines whether or not the given string is a resource value. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Parameters: |
146
|
|
|
|
|
|
|
$string - The string to examine. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Returns: |
149
|
|
|
|
|
|
|
undef if the given string is not a resource value; an ODO::Jena::Node::Resource otherwise |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub __parse_resource_node { |
154
|
2
|
|
|
2
|
|
5
|
my ($self, $string) = @_; |
155
|
|
|
|
|
|
|
|
156
|
2
|
|
|
|
|
6
|
my $header = |
157
|
|
|
|
|
|
|
${ODO::Jena::Node::Constants::RESOURCE_HEADER} |
158
|
|
|
|
|
|
|
. ${ODO::Jena::Node::Constants::VALUE_DELIMITER}; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
return undef |
161
|
2
|
50
|
|
|
|
19
|
unless($string =~ /^$header/); |
162
|
|
|
|
|
|
|
|
163
|
2
|
|
|
|
|
12
|
my ($p_header, $prefix_id, $uri, @rest) = split(/:/, $string); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# URLs may have :'s in them which throws the split off |
166
|
2
|
|
|
|
|
8
|
$uri = join( ':', ($uri, @rest)); |
167
|
|
|
|
|
|
|
|
168
|
2
|
|
50
|
|
|
34
|
return ODO::Jena::Node::Resource->new(-value=> $uri, -prefix_id=> ($prefix_id || '') ); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item __parse_resource_reference( $string ) |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Determines whether or not the given string is a resource reference. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Parameters: |
177
|
|
|
|
|
|
|
$resource - Required. The string to examine. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Returns: |
180
|
|
|
|
|
|
|
undef if the given string is not a resource reference. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub __parse_resource_reference { |
185
|
0
|
|
|
0
|
|
|
my ($self, $string) = @_; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
my $header = |
188
|
|
|
|
|
|
|
${ODO::Jena::Node::Constants::RESOURCE_HEADER} |
189
|
|
|
|
|
|
|
. ${ODO::Jena::Node::Constants::REFERENCE_DELIMITER}; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
my ($p_header, $long_id) = $string =~ /^($header):(\d+)/; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
return undef |
194
|
0
|
0
|
0
|
|
|
|
unless($p_header && $long_id); |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# TODO: Return something useful here |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item __parse_variable_node( $string ) |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Determines whether or not the given string is a variable node. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Parameters: |
205
|
|
|
|
|
|
|
$string - The string to examine. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Returns: |
208
|
|
|
|
|
|
|
undef if it is not a variable node; an ODO::Jena::Node::Variable otherwise |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub __parse_variable_node { |
213
|
0
|
|
|
0
|
|
|
my ($self, $string) = @_; |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $header = |
216
|
|
|
|
|
|
|
${ODO::Jena::Node::Constants::VARIABLE_HEADER} |
217
|
|
|
|
|
|
|
. ${ODO::Jena::Node::Constants::VALUE_DELIMITER}; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
return undef |
220
|
0
|
0
|
|
|
|
|
unless($string =~ /^$header/); |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
my ($p_header, $p_value) = split(/:/, $string); |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
return ODO::Jena::Node::Variable->new(-value=> $p_value); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item __parse_blank_node( $string ) |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Determines whether or not the given string is a blank node. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Parameters: |
233
|
|
|
|
|
|
|
$string - The string to examine. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Returns: |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
undef if the given string is not a blank node; an ODO::Jena::Node::Blank otherwise |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub __parse_blank_node { |
242
|
0
|
|
|
0
|
|
|
my ($self, $string) = @_; |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
my $header = |
245
|
|
|
|
|
|
|
${ODO::Jena::Node::Constants::BLANK_HEADER} |
246
|
|
|
|
|
|
|
. ${ODO::Jena::Node::Constants::VALUE_DELIMITER}; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
return undef |
249
|
0
|
0
|
|
|
|
|
unless($string =~ /^$header/); |
250
|
|
|
|
|
|
|
|
251
|
0
|
|
|
|
|
|
my ($p_header, $prefix_id, $blankID, @rest) = split(/:/, $string); |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# There may be :'s in the ID itself which throws the split off |
254
|
0
|
|
|
|
|
|
$blankID = join(':', ($blankID, @rest)); |
255
|
|
|
|
|
|
|
|
256
|
0
|
|
0
|
|
|
|
return ODO::Jena::Node::Blank->new(-value=> $string, -prefix_id=> ($prefix_id || '')); |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=item __parse_blank_reference( $string ) |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Determines whether or not the given string is a blank node reference. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Parameters: |
265
|
|
|
|
|
|
|
$blankID - Required. The string to examine. |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Returns: |
268
|
|
|
|
|
|
|
undef if the given string is not a blank node reference. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=cut |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub __parse_blank_reference { |
273
|
0
|
|
|
0
|
|
|
my ($self, $string) = @_; |
274
|
|
|
|
|
|
|
|
275
|
0
|
|
|
|
|
|
my $header = |
276
|
|
|
|
|
|
|
${ODO::Jena::Node::Constants::BLANK_HEADER} |
277
|
|
|
|
|
|
|
. ${ODO::Jena::Node::Constants::REFERENCE_DELIMITER}; |
278
|
|
|
|
|
|
|
|
279
|
0
|
|
|
|
|
|
my ($p_header, $prefix_id, $long_id) = $string =~ /^($header):(\d*):(\d+)/; |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
return undef |
282
|
0
|
0
|
0
|
|
|
|
unless($p_header && $long_id); |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
# TODO: Return something useful here |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=back |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head1 AUTHOR |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
IBM Corporation |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=head1 SEE ALSO |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
L, L, L |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=head1 COPYRIGHT |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
Copyright (c) 2004-2006 IBM Corporation. |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
All rights reserved. This program and the accompanying materials |
303
|
|
|
|
|
|
|
are made available under the terms of the Eclipse Public License v1.0 |
304
|
|
|
|
|
|
|
which accompanies this distribution, and is available at |
305
|
|
|
|
|
|
|
http://www.eclipse.org/legal/epl-v10.html |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=cut |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
1; |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
__END__ |