| 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 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 37 | require Exporter; | ||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | 1 | ▶ | use Carp; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 40 | require RDF::Core::Parser; | ||||||||||||||||||||||
| 41 | require RDF::Core::Statement; | ||||||||||||||||||||||
| 42 | require RDF::Core::NodeFactory; | ||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | 0 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 45 | 0 | my ($pkg,%options) = @_; | |||||||||||||||||||||
| 46 | 0 | ▶ | $pkg = ref $pkg || $pkg; | ||||||||||||||||||||
|
Condition0%0/3
ref $pkg || $pkg
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg
$pkg
Truth table0%0/3
A || B
A= ref $pkgB= $pkg
| |||||||||||||||||||||||
| 47 | 0 | my $self = {}; | |||||||||||||||||||||
| 48 | 0 | $self->{_options} = \%options; | |||||||||||||||||||||
| 49 | 0 | bless $self, $pkg; | |||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||
| 51 | 0 | ▶ | sub setOptions { | ||||||||||||||||||||
|
Subroutine
setOptions: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 52 | 0 | my ($self,$options) = @_; | |||||||||||||||||||||
| 53 | 0 | $self->{_options} = $options; | |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||
| 55 | 0 | ▶ | sub getOptions { | ||||||||||||||||||||
|
Subroutine
getOptions: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 56 | 0 | my $self = shift; | |||||||||||||||||||||
| 57 | 0 | return $self->{_options}; | |||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||
| 59 | 0 | ▶ | sub parse { | ||||||||||||||||||||
|
Subroutine
parse: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||
| 61 | 0 | ▶ | if (@_ > 0) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 62 | #set options if passed | ||||||||||||||||||||||
| 63 | 0 | $self->{_options} = $_[0]; | |||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||
| 65 | # make copy of options for parser | ||||||||||||||||||||||
| 66 | 0 | my %parserOptions = %{$self->getOptions}; | |||||||||||||||||||||
| 67 | 0 | delete $parserOptions{Model}; | |||||||||||||||||||||
| 68 | 0 | delete $parserOptions{Source}; | |||||||||||||||||||||
| 69 | 0 | delete $parserOptions{SourceType}; | |||||||||||||||||||||
| 70 | $parserOptions{Assert} = | ||||||||||||||||||||||
| 71 | 0 | ▶ | sub {my %params = @_; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||
| 72 | 0 | my $params = \%params; | |||||||||||||||||||||
| 73 | 0 | my $factory = new RDF::Core::NodeFactory(); | |||||||||||||||||||||
| 74 | 0 | my ($subject,$object,$predicate); | |||||||||||||||||||||
| 75 | 0 | ▶ | if (exists $params->{subject_ns}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 76 | $subject = $factory->newResource($params->{subject_ns}, | ||||||||||||||||||||||
| 77 | 0 | $params->{subject_name}); | |||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||
| 79 | 0 | $subject = $factory->newResource($params->{subject_uri}); | |||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||
| 81 | 0 | ▶ | if (exists $params->{predicate_ns}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 82 | $predicate = $factory->newResource($params->{predicate_ns}, | ||||||||||||||||||||||
| 83 | 0 | $params->{predicate_name}); | |||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||
| 85 | 0 | $predicate = $factory->newResource($params->{predicate_uri}); | |||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||
| 87 | 0 | ▶ | if (exists $params->{object_literal}) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 88 | $object = $factory->newLiteral($params->{object_literal}, | ||||||||||||||||||||||
| 89 | $params->{object_lang} || undef, | ||||||||||||||||||||||
| 90 | $params->{object_datatype}||undef | ||||||||||||||||||||||
| 91 | 0 | ▶ | ); | ||||||||||||||||||||
|
Condition0%0/4
$params->{'object_lang'} || undef
$params->{'object_datatype'} || undef
MC/DC0%0/1
$params->{'object_lang'} || undef
$params->{'object_lang'}
MC/DC0%0/1
$params->{'object_datatype'} || undef
$params->{'object_datatype'}
Truth table0%0/2
A
A= $params->{'object_lang'}
Truth table0%0/2
A
A= $params->{'object_datatype'}
| |||||||||||||||||||||||
| 92 | } elsif (exists $params->{object_ns}) { | ||||||||||||||||||||||
| 93 | $object = $factory->newResource($params->{object_ns}, | ||||||||||||||||||||||
| 94 | 0 | $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 | ▶ | unless defined $parserOptions{Assert}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 102 | 0 | my $parser = new RDF::Core::Parser(%parserOptions); | |||||||||||||||||||||
| 103 | return $parser->parse($self->getOptions->{Source}) | ||||||||||||||||||||||
| 104 | 0 | ▶ | if $self->getOptions->{SourceType} eq 'string'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 105 | return $parser->parseFile($self->getOptions->{Source}) | ||||||||||||||||||||||
| 106 | 0 | ▶ | if $self->getOptions->{SourceType} eq 'file'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||
| 108 | 1; | ||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||