line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# The contents of this file are subject to the Mozilla Public |
3
|
|
|
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file |
4
|
|
|
|
|
|
|
# except in compliance with the License. You may obtain a copy of |
5
|
|
|
|
|
|
|
# the License at http://www.mozilla.org/MPL/ |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Software distributed under the License is distributed on an "AS |
8
|
|
|
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
9
|
|
|
|
|
|
|
# implied. See the License for the specific language governing |
10
|
|
|
|
|
|
|
# rights and limitations under the License. |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# The Original Code is the RDF::Core module |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# The Initial Developer of the Original Code is Ginger Alliance Ltd. |
15
|
|
|
|
|
|
|
# Portions created by Ginger Alliance are |
16
|
|
|
|
|
|
|
# Copyright (C) 2001 Ginger Alliance Ltd. |
17
|
|
|
|
|
|
|
# All Rights Reserved. |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# Contributor(s): |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# Alternatively, the contents of this file may be used under the |
22
|
|
|
|
|
|
|
# terms of the GNU General Public License Version 2 or later (the |
23
|
|
|
|
|
|
|
# "GPL"), in which case the provisions of the GPL are applicable |
24
|
|
|
|
|
|
|
# instead of those above. If you wish to allow use of your |
25
|
|
|
|
|
|
|
# version of this file only under the terms of the GPL and not to |
26
|
|
|
|
|
|
|
# allow others to use your version of this file under the MPL, |
27
|
|
|
|
|
|
|
# indicate your decision by deleting the provisions above and |
28
|
|
|
|
|
|
|
# replace them with the notice and other provisions required by |
29
|
|
|
|
|
|
|
# the GPL. If you do not delete the provisions above, a recipient |
30
|
|
|
|
|
|
|
# may use your version of this file under either the MPL or the |
31
|
|
|
|
|
|
|
# GPL. |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
package RDF::Core::Model::Parser; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
546
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
37
|
|
|
|
|
|
|
require Exporter; |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
531
|
|
40
|
|
|
|
|
|
|
require RDF::Core::Parser; |
41
|
|
|
|
|
|
|
require RDF::Core::Statement; |
42
|
|
|
|
|
|
|
require RDF::Core::NodeFactory; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
0
|
|
|
0
|
|
|
my ($pkg,%options) = @_; |
46
|
0
|
|
0
|
|
|
|
$pkg = ref $pkg || $pkg; |
47
|
0
|
|
|
|
|
|
my $self = {}; |
48
|
0
|
|
|
|
|
|
$self->{_options} = \%options; |
49
|
0
|
|
|
|
|
|
bless $self, $pkg; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
sub setOptions { |
52
|
0
|
|
|
0
|
|
|
my ($self,$options) = @_; |
53
|
0
|
|
|
|
|
|
$self->{_options} = $options; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
sub getOptions { |
56
|
0
|
|
|
0
|
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
return $self->{_options}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
sub parse { |
60
|
0
|
|
|
0
|
|
|
my $self = shift; |
61
|
0
|
0
|
|
|
|
|
if (@_ > 0) { |
62
|
|
|
|
|
|
|
#set options if passed |
63
|
0
|
|
|
|
|
|
$self->{_options} = $_[0]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
# make copy of options for parser |
66
|
0
|
|
|
|
|
|
my %parserOptions = %{$self->getOptions}; |
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
delete $parserOptions{Model}; |
68
|
0
|
|
|
|
|
|
delete $parserOptions{Source}; |
69
|
0
|
|
|
|
|
|
delete $parserOptions{SourceType}; |
70
|
0
|
|
|
0
|
|
|
$parserOptions{Assert} = |
71
|
|
|
|
|
|
|
sub {my %params = @_; |
72
|
0
|
|
|
|
|
|
my $params = \%params; |
73
|
0
|
|
|
|
|
|
my $factory = new RDF::Core::NodeFactory(); |
74
|
0
|
|
|
|
|
|
my ($subject,$object,$predicate); |
75
|
0
|
0
|
|
|
|
|
if (exists $params->{subject_ns}) { |
76
|
0
|
|
|
|
|
|
$subject = $factory->newResource($params->{subject_ns}, |
77
|
|
|
|
|
|
|
$params->{subject_name}); |
78
|
|
|
|
|
|
|
} else { |
79
|
0
|
|
|
|
|
|
$subject = $factory->newResource($params->{subject_uri}); |
80
|
|
|
|
|
|
|
} |
81
|
0
|
0
|
|
|
|
|
if (exists $params->{predicate_ns}) { |
82
|
0
|
|
|
|
|
|
$predicate = $factory->newResource($params->{predicate_ns}, |
83
|
|
|
|
|
|
|
$params->{predicate_name}); |
84
|
|
|
|
|
|
|
} else { |
85
|
0
|
|
|
|
|
|
$predicate = $factory->newResource($params->{predicate_uri}); |
86
|
|
|
|
|
|
|
} |
87
|
0
|
0
|
|
|
|
|
if (exists $params->{object_literal}) { |
|
|
0
|
|
|
|
|
|
88
|
0
|
|
0
|
|
|
|
$object = $factory->newLiteral($params->{object_literal}, |
|
|
|
0
|
|
|
|
|
89
|
|
|
|
|
|
|
$params->{object_lang} || undef, |
90
|
|
|
|
|
|
|
$params->{object_datatype}||undef |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
} elsif (exists $params->{object_ns}) { |
93
|
0
|
|
|
|
|
|
$object = $factory->newResource($params->{object_ns}, |
94
|
|
|
|
|
|
|
$params->{object_name}); |
95
|
|
|
|
|
|
|
} else { |
96
|
0
|
|
|
|
|
|
$object = $factory->newResource($params->{object_uri}); |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
my $st = new RDF::Core::Statement($subject,$predicate,$object); |
99
|
0
|
|
|
|
|
|
$self->getOptions->{Model}->addStmt($st); |
100
|
|
|
|
|
|
|
} |
101
|
0
|
0
|
|
|
|
|
unless defined $parserOptions{Assert}; |
102
|
0
|
|
|
|
|
|
my $parser = new RDF::Core::Parser(%parserOptions); |
103
|
0
|
0
|
|
|
|
|
return $parser->parse($self->getOptions->{Source}) |
104
|
|
|
|
|
|
|
if $self->getOptions->{SourceType} eq 'string'; |
105
|
0
|
0
|
|
|
|
|
return $parser->parseFile($self->getOptions->{Source}) |
106
|
|
|
|
|
|
|
if $self->getOptions->{SourceType} eq 'file'; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |