lib/OWL2Perl.pm

filter: Statementstmt 59.6% 245 / 411 Branchbran 35.9% 74 / 206 Conditioncond 30.0% 39 / 130 MC/DCmcdc 8.8% 7 / 79 Subroutinesub 96.5% 28 / 29 Podpod 100% 3 / 3 totaltotal 46.1% 396 / 858 CC 166 SCAR 77.8
CC
166
Cov
48%
_process_classes
3974.6
_process_datatype_properties
30.6
_process_object_properties
27.3
CRAP 2383.1
↑ Summary lib/OWL/Base.pm »
1 #-----------------------------------------------------------------
2 # OWL2Perl
3 # Author: Edward Kawas
4 # For copyright and disclaimer see below.
5 #
6 # $Id: OWL2Perl.pm,v 1.36 2010-03-09 18:04:43 ubuntu Exp $
7 #-----------------------------------------------------------------
8 package OWL2Perl;
9 2 ▶use strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 # add versioning to this module
12 2 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
13
14 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶ use vars qw{@ISA @EXPORT @EXPORT_OK};
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 $VERSION = 1.00;
17 2 *OWL2Perl::VERSION = *VERSION;
18 }
19
20 2 ▶use FindBin qw( $Bin );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use lib $Bin;
Subroutine BEGIN: called CC=1 SCAR=0.0
22
23 2 ▶use OWL::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use base qw/OWL::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25
26 2 ▶use OWL::Data::Def::ObjectProperty;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use OWL::Data::Def::DatatypeProperty;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use OWL::Data::Def::OWLClass;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use OWL::Generators::GenOWL;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶use OWL::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
31
32 2 ▶use ODO::Parser::XML;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use ODO::Graph::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use ODO::Ontology::OWL::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use ODO::Graph::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶use ODO::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use ODO::Ontology::OWL::Lite::Restriction;
Subroutine BEGIN: called CC=1 SCAR=0.0
38
39 #-----------------------------------------------------------------
40 # A list of allowed attribute names. See OWL::Base for details.
41 #-----------------------------------------------------------------
42 {
43 my %_allowed = (
44 outdir => { type => OWL::Base->STRING,
45 7 ▶ post=> sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
46 7 my $self = shift;
47 # if $dir is undefined, make it the default
48 7 my $dir = $self->{outdir};
49 7 ▶ $self->{outdir} = $OWLCFG::GENERATORS_OUTDIR ||
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir 1 6 7
Condition33%1/3
$OWLCFG::GENERATORS_OUTDIR || 'OWL::Utils'->find_file($OWL2Perl::Bin, 'generated')
l!l&&r!l&&!r
100
MC/DC0%0/2
$OWLCFG::GENERATORS_OUTDIR || 'OWL::Utils'->find_file($OWL2Perl::Bin, 'generated')
$OWLCFG::GENERATORS_OUTDIR 'OWL::Utils'->find_file($OWL2Perl::Bin, 'generated')
Truth table33%1/3
A || B
A= $OWLCFG::GENERATORS_OUTDIRB= 'OWL::Utils'->find_file($OWL2Perl::Bin, 'generated')
ABresult
1X1
011
000
50 OWL::Utils->find_file( $Bin, 'generated')
51 unless defined $dir;
52 }},
53 2 force => { type => OWL::Base->BOOLEAN },
54 follow_imports => { type => OWL::Base->BOOLEAN },
55
56 # private
57 _imports_added => undef,
58 );
59
60 6 ▶ sub _accessible {
Subroutine _accessible: called CC=2 SCAR=7.2
61 6 my ( $self, $attr ) = @_;
62 6 ▶ exists $_allowed{$attr} or $self->SUPER::_accessible($attr);
Branch: 1 branch
BranchTrueFalseTotal
exists $_allowed{$attr} or $self->SUPER::_accessible($attr) 6 0 6
63 }
64
65 24 ▶ sub _attr_prop {
Subroutine _attr_prop: called CC=3 SCAR=12.5
66 24 my ( $self, $attr_name, $prop_name ) = @_;
67 24 my $attr = $_allowed{$attr_name};
68 24 ▶ return ref($attr) ? $attr->{$prop_name} : $attr if $attr;
Branch: 2 branches
BranchTrueFalseTotal
if $attr 24 0 24
ref $attr ? : 24 0 24
69 0 return $self->SUPER::_attr_prop( $attr_name, $prop_name );
70 }
71 }
72
73 #-----------------------------------------------------------------
74 # init
75 #-----------------------------------------------------------------
76 2 ▶sub init {
Subroutine init: called CC=2 SCAR=7.0
Pod documented
77 3 my ($self) = shift;
78 3 $self->SUPER::init();
79
80 # defaults for some variables ...
81 3 $self->force(0);
82 3 ▶ $self->outdir($OWLCFG::GENERATORS_OUTDIR || OWL::Utils->find_file( $Bin, 'generated'));
Condition66%2/3
$OWLCFG::GENERATORS_OUTDIR || 'OWL::Utils'->find_file($OWL2Perl::Bin, 'generated')
l!l&&r!l&&!r
120
MC/DC0%0/2
$OWLCFG::GENERATORS_OUTDIR || 'OWL::Utils'->find_file($OWL2Perl::Bin, 'generated')
$OWLCFG::GENERATORS_OUTDIR 'OWL::Utils'->find_file($OWL2Perl::Bin, 'generated')
Truth table66%2/3
A || B
A= $OWLCFG::GENERATORS_OUTDIRB= 'OWL::Utils'->find_file($OWL2Perl::Bin, 'generated')
ABresult
1X1
011
000
83 3 $self->follow_imports(0);
84 3 $self->{_imports_added} = ();
85 }
86
87 ###################################################################
88 # consumes an OWL::Ontology::Lite object and an optional scalar ref
89 # If $code given, no code written to output directory, otherwise
90 # code written to scalar.
91 ###################################################################
92 3 ▶sub generate_datatypes {
Subroutine generate_datatypes: called CC=1 SCAR=0.0
Pod documented
93 3 my ( $self, $lite, $code ) = @_;
94
95 # process the object properties
96 3 $LOG->info("\tProcessing object properties");
97 3 my $oProps = $self->_process_object_properties( $lite, $code );
98
99 # process the datatype properties
100 3 $LOG->info("\tProcessing datatype properties");
101 3 my $dProps = $self->_process_datatype_properties( $lite, $code );
102
103 # process the owl classes
104 3 $LOG->info("\tProcessing owl classes");
105 3 $self->_process_classes( $lite->classMap, $oProps, $dProps, $code );
106 }
107
108 # private sub
109 3 ▶sub _process_object_properties {
Subroutine _process_object_properties: called CC=16 SCAR=33.1
110 3 my ( $self, $lite, $code ) = @_;
111 3 my %objectProperties = %{ $lite->objectPropertyMap };
112 3 my %oProperties;
113 3 foreach my $key ( keys %objectProperties ) {
114 26 my $object = $objectProperties{$key};
115 next
116 unless defined $object->{'object'}
117 26 ▶ and UNIVERSAL::isa( $object->{'object'}, 'ODO::Node::Resource' );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object->{"object"} and UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource") 20 6 26
Condition66%2/3
defined $object->{"object"} and UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
!ll&&!rl&&r
2006
MC/DC50%1/2
defined $object->{"object"} and UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
defined $object->{"object"} UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
Truth table66%2/3
A and B
A= defined $object->{"object"}B= UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
ABresult
0X0
100
111
118 6 my $property = new OWL::Data::Def::ObjectProperty;
119
120 # set the uri / uri sets the name too
121 6 $property->uri($key);
122 6 ▶ if ( defined $object->{'domain'} and @{ $object->{'domain'} } > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"domain"} and @{$object->{"domain"};} > 0) 0 6 6
Condition33%1/3
defined $object->{"domain"} and @{$object->{"domain"};} > 0
!ll&&!rl&&r
060
MC/DC0%0/2
defined $object->{"domain"} and @{$object->{"domain"};} > 0
defined $object->{"domain"} @{$object->{"domain"};} > 0
Truth table33%1/3
A and B
A= defined $object->{"domain"}B= @{$object->{"domain"};} > 0
ABresult
0X0
100
111
123 0 my $range = shift @{ $object->{'domain'} };
124 0 $property->domain($range);
125 }
126 6 ▶ if ( defined $object->{'range'} and @{ $object->{'range'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"range"} and @{$object->{"range"};}) 0 6 6
Condition33%1/3
defined $object->{"range"} and @{$object->{"range"};}
!ll&&!rl&&r
060
MC/DC0%0/2
defined $object->{"range"} and @{$object->{"range"};}
defined $object->{"range"} @{$object->{"range"};}
Truth table33%1/3
A and B
A= defined $object->{"range"}B= @{$object->{"range"};}
ABresult
0X0
100
111
127 0 my $range = shift @{ $object->{'range'} };
128 0 $property->range($range);
129 }
130 6 ▶ if ( defined $object->{'inheritance'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"inheritance"} and @{$object->{"inheritance"};} > 0) 6 0 6
Condition33%1/3
defined $object->{"inheritance"} and @{$object->{"inheritance"};} > 0
!ll&&!rl&&r
006
MC/DC0%0/2
defined $object->{"inheritance"} and @{$object->{"inheritance"};} > 0
defined $object->{"inheritance"} @{$object->{"inheritance"};} > 0
Truth table33%1/3
A and B
A= defined $object->{"inheritance"}B= @{$object->{"inheritance"};} > 0
ABresult
0X0
100
111
131 6 and @{ $object->{'inheritance'} } > 0 )
132 {
133 6 ▶ my $parent = $object->{'inheritance'}->[0] || '';
Condition50%1/2
$object->{'inheritance'}[0] || ''
l!l
60
MC/DC0%0/1
$object->{'inheritance'}[0] || ''
$object->{'inheritance'}[0]
Truth table50%1/2
A
A= $object->{'inheritance'}[0]
Aresult
11
00
134 6 ▶ if ( UNIVERSAL::isa( $parent, 'ODO::Node::Resource' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($parent, "ODO::Node::Resource")) 6 0 6
135 6 $parent = $parent->value;
136 }
137 6 ▶ $parent = 'OWL::Data::OWL::ObjectProperty'
Branch: 1 branch
BranchTrueFalseTotal
if $parent eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property" 6 0 6
138 if $parent eq
139 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property';
140 6 $property->parent($parent);
141 }
142 6 my $generator = OWL::Generators::GenOWL->new();
143 6 ▶ if ( defined $code ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code) { } 0 6 6
144 0 $generator->generate_object_property(
145 property => $property,
146 outcode => $code,
147 force_over => $self->force(),
148 );
149 } else {
150 6 ▶ $generator->generate_object_property(
Branch: 1 branch
BranchTrueFalseTotal
if $self->outdir 6 0 6
151 property => $property,
152 force_over => $self->force(),
153 impl_outdir => $self->outdir()
154 ) if $self->outdir();
155 6 ▶ $generator->generate_object_property(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->outdir 0 6 6
156 property => $property,
157 force_over => $self->force(),
158 ) unless $self->outdir();
159 }
160 6 $oProperties{$key} = $property;
161 }
162 3 return \%oProperties;
163 }
164
165 #private sub
166 3 ▶sub _process_datatype_properties {
Subroutine _process_datatype_properties: called CC=16 SCAR=34.2
167 3 my ( $self, $lite, $code ) = @_;
168 3 my %objectProperties = %{ $lite->datatypePropertyMap };
169 3 my %dProperties;
170 3 foreach my $key ( keys %objectProperties ) {
171 10 my $object = $objectProperties{$key};
172 next
173 unless defined $object->{'object'}
174 10 ▶ and UNIVERSAL::isa( $object->{'object'}, 'ODO::Node::Resource' );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object->{"object"} and UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource") 0 10 10
Condition33%1/3
defined $object->{"object"} and UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $object->{"object"} and UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
defined $object->{"object"} UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
Truth table33%1/3
A and B
A= defined $object->{"object"}B= UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
ABresult
0X0
100
111
175 10 my $property = new OWL::Data::Def::DatatypeProperty;
176
177 # set the uri / uri sets the name automatically
178 10 $property->uri($key);
179 10 ▶ if ( defined $object->{'domain'} and @{ $object->{'domain'} } > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"domain"} and @{$object->{"domain"};} > 0) 0 10 10
Condition33%1/3
defined $object->{"domain"} and @{$object->{"domain"};} > 0
!ll&&!rl&&r
0100
MC/DC0%0/2
defined $object->{"domain"} and @{$object->{"domain"};} > 0
defined $object->{"domain"} @{$object->{"domain"};} > 0
Truth table33%1/3
A and B
A= defined $object->{"domain"}B= @{$object->{"domain"};} > 0
ABresult
0X0
100
111
180 0 my $range = shift @{ $object->{'domain'} };
181 0 $property->domain($range);
182 }
183 10 ▶ if ( defined $object->{'range'} and @{ $object->{'range'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"range"} and @{$object->{"range"};}) 0 10 10
Condition33%1/3
defined $object->{"range"} and @{$object->{"range"};}
!ll&&!rl&&r
0100
MC/DC0%0/2
defined $object->{"range"} and @{$object->{"range"};}
defined $object->{"range"} @{$object->{"range"};}
Truth table33%1/3
A and B
A= defined $object->{"range"}B= @{$object->{"range"};}
ABresult
0X0
100
111
184 0 my $range = shift @{ $object->{'range'} };
185 0 $property->range($range);
186 }
187 10 ▶ if ( defined $object->{'inheritance'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"inheritance"} and @{$object->{"inheritance"};} > 0) 10 0 10
Condition33%1/3
defined $object->{"inheritance"} and @{$object->{"inheritance"};} > 0
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $object->{"inheritance"} and @{$object->{"inheritance"};} > 0
defined $object->{"inheritance"} @{$object->{"inheritance"};} > 0
Truth table33%1/3
A and B
A= defined $object->{"inheritance"}B= @{$object->{"inheritance"};} > 0
ABresult
0X0
100
111
188 10 and @{ $object->{'inheritance'} } > 0 )
189 {
190 10 ▶ my $parent = $object->{'inheritance'}->[0] || '';
Condition50%1/2
$object->{'inheritance'}[0] || ''
l!l
100
MC/DC0%0/1
$object->{'inheritance'}[0] || ''
$object->{'inheritance'}[0]
Truth table50%1/2
A
A= $object->{'inheritance'}[0]
Aresult
11
00
191 10 ▶ if ( UNIVERSAL::isa( $parent, 'ODO::Node::Resource' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($parent, "ODO::Node::Resource")) 10 0 10
192 10 $parent = $parent->value;
193 }
194 10 ▶ $parent = 'OWL::Data::OWL::DatatypeProperty'
Branch: 1 branch
BranchTrueFalseTotal
if $parent eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property" 10 0 10
195 if $parent eq
196 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property';
197 10 $property->parent($parent);
198 }
199 10 my $generator = OWL::Generators::GenOWL->new();
200 10 ▶ if ( defined $code ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code) { } 0 10 10
201 0 $generator->generate_datatype_property(
202 property => $property,
203 outcode => $code,
204 force_over => $self->force(),
205 );
206 } else {
207 10 ▶ $generator->generate_datatype_property(
Branch: 1 branch
BranchTrueFalseTotal
if $self->outdir 10 0 10
208 property => $property,
209 force_over => $self->force(),
210 impl_outdir => $self->outdir()
211 ) if $self->outdir();
212 10 ▶ $generator->generate_datatype_property(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->outdir 0 10 10
213 property => $property,
214 force_over => $self->force(),
215 ) unless $self->outdir();
216 }
217 10 $dProperties{$key} = $property;
218 }
219 3 return \%dProperties;
220 }
221
222 # private sub
223 3 ▶sub _process_classes {
Subroutine _process_classes: called CC=116 SCAR=82.9
224 3 my ( $self, $lite, $oProps, $dProps, $code ) = @_;
225
226 # $lite, oProps and dProps are hash refs ...
227 3 my %classes = %{ $lite };
228 #my %classes = %{ $lite->classMap };
229 3 my %dProperties;
230 3 foreach my $key ( keys %classes ) {
231 20 my $object = $classes{$key};
232 # we only process ODO Nodes
233 next
234 unless defined $object->{'object'}
235 20 ▶ and UNIVERSAL::isa( $object->{'object'}, 'ODO::Node::Resource' );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object->{"object"} and UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource") 0 20 20
Condition33%1/3
defined $object->{"object"} and UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
!ll&&!rl&&r
0020
MC/DC0%0/2
defined $object->{"object"} and UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
defined $object->{"object"} UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
Truth table33%1/3
A and B
A= defined $object->{"object"}B= UNIVERSAL::isa($object->{"object"}, "ODO::Node::Resource")
ABresult
0X0
100
111
236 20 my $class = new OWL::Data::Def::OWLClass;
237 # dont want to add the same property multiple times for a class
238 20 my %added_properties;
239
240 # set the uri / this also sets the name
241 20 $class->type($key);
242
243 # process inheritance
244 20 ▶ if ( defined $object->{'inheritance'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"inheritance"} and @{$object->{"inheritance"};} > 0) 4 16 20
Condition66%2/3
defined $object->{"inheritance"} and @{$object->{"inheritance"};} > 0
!ll&&!rl&&r
0164
MC/DC50%1/2
defined $object->{"inheritance"} and @{$object->{"inheritance"};} > 0
defined $object->{"inheritance"} @{$object->{"inheritance"};} > 0
Truth table66%2/3
A and B
A= defined $object->{"inheritance"}B= @{$object->{"inheritance"};} > 0
ABresult
0X0
100
111
245 20 and @{ $object->{'inheritance'} } > 0 )
246 {
247 4 foreach my $parent ( @{ $object->{'inheritance'} } ) {
248 6 $class->add_parent($parent);
249 }
250 }
251
252 # process equivalent classes - either string or ODO::EquivalentClass
253 20 ▶ if ( defined $object->{'equivalent'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"equivalent"} and @{$object->{"equivalent"};} > 0) 2 18 20
Condition66%2/3
defined $object->{"equivalent"} and @{$object->{"equivalent"};} > 0
!ll&&!rl&&r
0182
MC/DC50%1/2
defined $object->{"equivalent"} and @{$object->{"equivalent"};} > 0
defined $object->{"equivalent"} @{$object->{"equivalent"};} > 0
Truth table66%2/3
A and B
A= defined $object->{"equivalent"}B= @{$object->{"equivalent"};} > 0
ABresult
0X0
100
111
254 20 and @{ $object->{'equivalent'} } > 0 )
255 {
256 2 foreach my $equivalent ( @{ $object->{'equivalent'} } ) {
257 2 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($equivalent, 'ODO::Ontology::OWL::Lite::Fragments::EquivalentClass')) { } 0 2 2
258 UNIVERSAL::isa(
259 $equivalent,
260 'ODO::Ontology::OWL::Lite::Fragments::EquivalentClass'
261 )
262 )
263 {
264
265 # perl object
266 0 my $key = $equivalent->{'restrictionURI'};
267 0 ▶ if ( defined $classes{$key}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $classes{$key} and defined $classes{$key}{'object'}) { } 0 0 0
Condition0%0/3
defined $classes{$key} and defined $classes{$key}{"object"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $classes{$key} and defined $classes{$key}{"object"}
defined $classes{$key} defined $classes{$key}{"object"}
Truth table0%0/3
A and B
A= defined $classes{$key}B= defined $classes{$key}{"object"}
ABresult
0X0
100
111
268 and defined $classes{$key}->{'object'} )
269 {
270
271 # add to parents ... this $key will be auto generated
272 0 $class->add_parent($key);
273 } else {
274
275 # suck in the restrictions
276 0 ▶ if ( $dProps->{ $equivalent->{'onProperty'} } ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$dProps{$equivalent->{'onProperty'}}) { } 0 0 0
elsif ($$oProps{$equivalent->{'onProperty'}}) { } 0 0 0
277 0 my $dp = $dProps->{ $equivalent->{'onProperty'} };
278 # FIXME
279 0 $class->add_datatype_properties($dp);
280 } elsif ( $oProps->{ $equivalent->{'onProperty'} } ) {
281 0 my $op = $oProps->{ $equivalent->{'onProperty'} };
282 # FIXME
283 0 $class->add_object_properties($op);
284 } else {
285 # is this a Bnode with a someValuesFrom clause in it?
286 # construct a new bnode object and add a restriction to
287 # then add this bnode class to $class parent
288
289 # check for some things first
290 0 ▶ next unless defined $equivalent->{'restrictionURI'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $equivalent->{"restrictionURI"} 0 0 0
291 next unless defined $equivalent->{'someValuesFrom'}
292 0 ▶ and ( defined $classes{$equivalent->{'someValuesFrom'}} and defined $classes{$equivalent->{'someValuesFrom'}}->{'object'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $equivalent->{"someValuesFrom"} and (defined $classes{$equivalent->{"someValuesFrom"}} and defined $classes{$equivalent->{"someValuesFrom"}}{"object"}) 0 0 0
Condition0%0/6
defined $equivalent->{"someValuesFrom"} and (defined $classes{$equivalent->{"someValuesFrom"}} and defined $classes{$equivalent->{"someValuesFrom"}}{"object"})
!ll&&!rl&&r
000
defined $classes{$equivalent->{"someValuesFrom"}} and defined $classes{$equivalent->{"someValuesFrom"}}{"object"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $equivalent->{"someValuesFrom"} and (defined $classes{$equivalent->{"someValuesFrom"}} and defined $classes{$equivalent->{"someValuesFrom"}}{"object"})
defined $equivalent->{"someValuesFrom"} defined $classes{$equivalent->{"someValuesFrom"}} defined $classes{$equivalent->{"someValuesFrom"}}{"object"}
Truth table0%0/4
A and B and C
A= defined $equivalent->{"someValuesFrom"}B= defined $classes{$equivalent->{"someValuesFrom"}}C= defined $classes{$equivalent->{"someValuesFrom"}}{"object"}
ABCresult
0XX0
10X0
1100
1111
293 # should do the following, but sometimes the item is a url ...
294 # next unless $oProps->{ $equivalent->{'onProperty'} } or $dProps->{ $equivalent->{'onProperty'} };
295
296 # construct our hash
297 0 my $bnode_hash;
298 0 $bnode_hash->{object} = new ODO::Node::Blank($equivalent->{'restrictionURI'});
299 0 $bnode_hash->{equivalent} = [];
300 0 $bnode_hash->{restrictions} = [];
301 0 $bnode_hash->{inheritance} = [];
302 0 my %bnode_intersection;
303 0 $bnode_intersection{classes} = [];
304 0 my $propertyName = $equivalent->{'onProperty'};
305 0 ▶ $propertyName = $1 if $propertyName =~ m/\w+[#\/]+(\w+)$/ or $propertyName =~ m/\w+[#\/]+(\w+)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $propertyName =~ m[\w+[#/]+(\w+)$] or $propertyName =~ m[\w+[#/]+(\w+)$] 0 0 0
Condition0%0/3
$propertyName =~ m[\w+[#/]+(\w+)$] or $propertyName =~ m[\w+[#/]+(\w+)$]
l!l&&r!l&&!r
000
MC/DC0%0/2
$propertyName =~ m[\w+[#/]+(\w+)$] or $propertyName =~ m[\w+[#/]+(\w+)$]
$propertyName =~ m[\w+[#/]+(\w+)$] $propertyName =~ m[\w+[#/]+(\w+)$]
Truth table0%0/3
A or B
A= $propertyName =~ m[\w+[#/]+(\w+)$]B= $propertyName =~ m[\w+[#/]+(\w+)$]
ABresult
1X1
011
000
306 $bnode_intersection{restrictions} = [
307 ODO::Ontology::OWL::Lite::Restriction->new(
308 onProperty=>$equivalent->{'onProperty'},
309 0 restrictionURI=>$equivalent->{'someValuesFrom'},
310 propertyName=> $propertyName,
311 )
312 ];
313 0 $bnode_hash->{intersections} = \%bnode_intersection;
314 # generate an impl for this bnode
315 0 $self->_process_classes({$equivalent->{'restrictionURI'} => $bnode_hash}, $oProps, $dProps, $code);
316 0 $class->add_parent($equivalent->{'restrictionURI'});
317 }
318 }
319 } else {
320
321 # string
322 2 my $key = $equivalent;
323 2 ▶ if ( defined $classes{$key}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $classes{$key} and defined $classes{$key}{'object'}) { } 2 0 2
Condition33%1/3
defined $classes{$key} and defined $classes{$key}{"object"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $classes{$key} and defined $classes{$key}{"object"}
defined $classes{$key} defined $classes{$key}{"object"}
Truth table33%1/3
A and B
A= defined $classes{$key}B= defined $classes{$key}{"object"}
ABresult
0X0
100
111
324 and defined $classes{$key}->{'object'} )
325 {
326
327 # add to parents ... this $key will be auto generated
328 2 $class->add_parent($key);
329 } else {
330
331 # suck in the restrictions
332 0 $LOG->warn("equivalent(else->else):->$key\n");
333 0 foreach my $restrict ( @{ $object->{'restrictions'} } )
334 {
335 0 ▶ next if defined $added_properties{$restrict->{'onProperty'}};
Branch: 1 branch
BranchTrueFalseTotal
if defined $added_properties{$restrict->{"onProperty"}} 0 0 0
336 0 $added_properties{$restrict->{'onProperty'}} = 1;
337 0 ▶ if ( $dProps->{ $restrict->{'onProperty'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dProps{$restrict->{'onProperty'}}) { } 0 0 0
338 0 my $dp = $dProps->{ $restrict->{'onProperty'} };
339 0 $class->add_datatype_properties($dp);
340 } else {
341 0 my $op = $oProps->{ $restrict->{'onProperty'} };
342 0 $class->add_object_properties($op);
343 }
344 }
345 }
346 }
347 }
348 }
349
350 # process intersections - read in the equivalent classes and suck out their attributes ... put them on this class
351 20 ▶ if ( defined $object->{'intersections'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"intersections"} and @{$object->{"intersections"}{"classes"};} > 0 or @{$object->{"intersections"}{"restrictions"};} > 0) 4 16 20
Condition83%5/6
defined $object->{"intersections"} and @{$object->{"intersections"}{"classes"};} > 0 or @{$object->{"intersections"}{"restrictions"};} > 0
l!l&&r!l&&!r
2216
defined $object->{"intersections"} and @{$object->{"intersections"}{"classes"};} > 0
!ll&&!rl&&r
0182
MC/DC66%2/3
defined $object->{"intersections"} and @{$object->{"intersections"}{"classes"};} > 0 or @{$object->{"intersections"}{"restrictions"};} > 0
defined $object->{"intersections"} @{$object->{"intersections"}{"classes"};} > 0 @{$object->{"intersections"}{"restrictions"};} > 0
Truth table60%3/5
A and B or C
A= defined $object->{"intersections"}B= @{$object->{"intersections"}{"classes"};} > 0C= @{$object->{"intersections"}{"restrictions"};} > 0
ABCresult
11X1
0X11
1011
0X00
1000
352 20 and @{ $object->{'intersections'}->{'classes'} } > 0
353 18 or @{ $object->{'intersections'}->{'restrictions'} } > 0 )
354 {
355 4 foreach
356 4 my $restrict ( @{ $object->{'intersections'}->{'restrictions'} } )
357 {
358 # TODO if the restriction is a someValuesFrom, then:
359 # add the onProperty to object/datatype_properties
360 # stop processing
361 16 ▶ if (defined $restrict->{'onProperty'} ){ #and not defined $added_properties{$restrict->{'onProperty'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{'onProperty'}) { } 16 0 16
362 # check if $restrict->{'hasValue'} ? add the hasValue to class : process restriction
363 16 ▶ if (defined $restrict->{'hasValue'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"hasValue"}) 8 8 16
364 # add hasValue: extract the value,
365 8 my $o = OWL::Utils->trim($restrict->{'hasValue'});
366 8 my $p = $restrict->{'onProperty'};
367 8 my $range = $restrict->{'range'};
368 8 my %hv_hash;
369 8 $hv_hash{object} = $o;
370 8 $hv_hash{range} = $range;
371 8 $hv_hash{name} = $restrict->{'propertyName'};
372 8 ▶ if ( $dProps->{ $restrict->{'onProperty'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dProps{$restrict->{'onProperty'}}) { } 4 4 8
373 4 $hv_hash{module} = $self->oProperty2module( $self->uri2package( $p ) );
374 } else {
375 4 ▶ $hv_hash{module} = $self->oProperty2module( $self->uri2package( $range ) ) if $range;
Branch: 1 branch
BranchTrueFalseTotal
if $range 2 2 4
376 4 ▶ $hv_hash{module} = 'OWL::Data::OWL::Class' unless $range;
Branch: 1 branch
BranchTrueFalseTotal
unless $range 2 2 4
377 }
378 8 $class->add_has_value_property(\%hv_hash);
379 # no next, because we use the has_value stuff to init our stuff
380 }
381 16 ▶ if ( $dProps->{ $restrict->{'onProperty'} } ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$dProps{$restrict->{'onProperty'}}) { } 12 4 16
elsif ($$oProps{$restrict->{'onProperty'}}) { } 4 0 4
382 12 my $dp = $dProps->{ $restrict->{'onProperty'} };
383 # extract any cardinality constraints
384 12 ▶ if ( defined $restrict->{'minCardinality'} or defined $restrict->{'maxCardinality'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}) 8 4 12
Condition66%2/3
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
l!l&&r!l&&!r
804
MC/DC50%1/2
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
defined $restrict->{"minCardinality"} defined $restrict->{"maxCardinality"}
Truth table66%2/3
A or B
A= defined $restrict->{"minCardinality"}B= defined $restrict->{"maxCardinality"}
ABresult
1X1
011
000
385 8 ▶ my $min = $restrict->{'minCardinality'} || '0';
Condition50%1/2
$restrict->{'minCardinality'} || '0'
l!l
08
MC/DC0%0/1
$restrict->{'minCardinality'} || '0'
$restrict->{'minCardinality'}
Truth table50%1/2
A
A= $restrict->{'minCardinality'}
Aresult
11
00
386 8 ▶ my $max = $restrict->{'maxCardinality'} || undef;
Condition50%1/2
$restrict->{'maxCardinality'} || undef
l!l
08
MC/DC0%0/1
$restrict->{'maxCardinality'} || undef
$restrict->{'maxCardinality'}
Truth table50%1/2
A
A= $restrict->{'maxCardinality'}
Aresult
11
00
387 8 my $hash;
388 8 ▶ $hash->{min} = $min if defined $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min 8 0 8
389 8 ▶ $hash->{max} = $max if defined $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max 0 8 8
390 8 $hash->{name} = $restrict->{'propertyName'};
391 8 my $hoh = $class->cardinality_constraints();
392 8 $hoh->{$restrict->{'propertyName'}} = $hash;
393 8 $class->cardinality_constraints($hoh);
394 }
395
396 # add someValuesFrom, allValuesFrom to inheritance
397 12 ▶ $class->add_datatype_properties($dp) unless defined $added_properties{$restrict->{'onProperty'}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $added_properties{$restrict->{"onProperty"}} 12 0 12
398 } elsif ($oProps->{ $restrict->{'onProperty'} }) {
399 4 my $op = $oProps->{ $restrict->{'onProperty'} };
400 # extract any cardinality constraints
401 4 ▶ if (defined $restrict->{'minCardinality'} or defined $restrict->{'maxCardinality'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}) 0 4 4
Condition33%1/3
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
l!l&&r!l&&!r
004
MC/DC0%0/2
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
defined $restrict->{"minCardinality"} defined $restrict->{"maxCardinality"}
Truth table33%1/3
A or B
A= defined $restrict->{"minCardinality"}B= defined $restrict->{"maxCardinality"}
ABresult
1X1
011
000
402 0 ▶ my $min = $restrict->{'minCardinality'} || '0';
Condition0%0/2
$restrict->{'minCardinality'} || '0'
l!l
00
MC/DC0%0/1
$restrict->{'minCardinality'} || '0'
$restrict->{'minCardinality'}
Truth table0%0/2
A
A= $restrict->{'minCardinality'}
Aresult
11
00
403 0 ▶ my $max =$restrict->{'maxCardinality'} || undef;
Condition0%0/2
$restrict->{'maxCardinality'} || undef
l!l
00
MC/DC0%0/1
$restrict->{'maxCardinality'} || undef
$restrict->{'maxCardinality'}
Truth table0%0/2
A
A= $restrict->{'maxCardinality'}
Aresult
11
00
404 0 my $hash;
405 0 ▶ $hash->{min} = $min if defined $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min 0 0 0
406 0 ▶ $hash->{max} = $max if defined $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max 0 0 0
407 0 $hash->{name} = $restrict->{'propertyName'};
408 0 my $hoh = $class->cardinality_constraints();
409 0 $hoh->{$restrict->{'propertyName'}} = $hash;
410 0 $class->cardinality_constraints($hoh);
411 }
412 # add the valuesFrom to values_from_properties
413 4 ▶ if (defined $restrict->{'someValuesFrom'} and defined $restrict->{'propertyName'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"someValuesFrom"} and defined $restrict->{"propertyName"}) 0 4 4
Condition33%1/3
defined $restrict->{"someValuesFrom"} and defined $restrict->{"propertyName"}
!ll&&!rl&&r
400
MC/DC0%0/2
defined $restrict->{"someValuesFrom"} and defined $restrict->{"propertyName"}
defined $restrict->{"someValuesFrom"} defined $restrict->{"propertyName"}
Truth table33%1/3
A and B
A= defined $restrict->{"someValuesFrom"}B= defined $restrict->{"propertyName"}
ABresult
0X0
100
111
414 0 my $pname = $restrict->{'propertyName'};
415 0 my $svf = $self->owlClass2module( $self->uri2package($restrict->{'someValuesFrom'}) );
416 0 ▶ my $vfp_hash = $class->values_from_property() || ();
Condition0%0/3
$class->values_from_property || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$class->values_from_property || ()
$class->values_from_property ()
Truth table0%0/3
A || B
A= $class->values_from_propertyB= ()
ABresult
1X1
011
000
417 0 ▶ if (exists $vfp_hash->{$pname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $vfp_hash->{$pname}) { } 0 0 0
418 0 $vfp_hash->{$pname} = {%{$vfp_hash->{$pname}}, "$svf" => 1};
419 0 $class->values_from_property($vfp_hash);
420 } else {
421 0 $vfp_hash->{$pname} = {$svf => 1};
422 0 $class->values_from_property($vfp_hash);
423 }
424 }
425 4 ▶ $class->add_object_properties($op) unless defined $added_properties{$restrict->{'onProperty'}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $added_properties{$restrict->{"onProperty"}} 4 0 4
426 } else {
427 0 $LOG->warn(sprintf("Trying to use property, '%s', but it was not imported in your ontology!", $restrict->{'onProperty'}));
428 }
429 16 $added_properties{$restrict->{'onProperty'}} = 1;
430 } else {
431 # just a bnode? check if it exists
432 0 ▶ $class->add_parent($restrict->{restrictionURI}) if defined $classes{$restrict->{restrictionURI}};
Branch: 1 branch
BranchTrueFalseTotal
if defined $classes{$restrict->{"restrictionURI"}} 0 0 0
433 }
434
435 }
436 4 foreach my $iClass ( @{ $object->{'intersections'}->{'classes'} } )
437 {
438 2 $class->add_parent($iClass);
439 }
440 }
441
442 # process unions - read in the equivalent classes and suck out their attributes ... put them on this class
443 20 ▶ if ( defined $object->{'unions'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"unions"} and @{$object->{"unions"}{"classes"};} > 0 or @{$object->{"unions"}{"restrictions"};} > 0) 0 20 20
Condition33%2/6
defined $object->{"unions"} and @{$object->{"unions"}{"classes"};} > 0 or @{$object->{"unions"}{"restrictions"};} > 0
l!l&&r!l&&!r
0020
defined $object->{"unions"} and @{$object->{"unions"}{"classes"};} > 0
!ll&&!rl&&r
0200
MC/DC0%0/3
defined $object->{"unions"} and @{$object->{"unions"}{"classes"};} > 0 or @{$object->{"unions"}{"restrictions"};} > 0
defined $object->{"unions"} @{$object->{"unions"}{"classes"};} > 0 @{$object->{"unions"}{"restrictions"};} > 0
Truth table20%1/5
A and B or C
A= defined $object->{"unions"}B= @{$object->{"unions"}{"classes"};} > 0C= @{$object->{"unions"}{"restrictions"};} > 0
ABCresult
11X1
0X11
1011
0X00
1000
444 20 and @{ $object->{'unions'}->{'classes'} } > 0
445 20 or @{ $object->{'unions'}->{'restrictions'} } > 0 )
446 {
447 0 foreach
448 0 my $restrict ( @{ $object->{'unions'}->{'restrictions'} } )
449 {
450 # TODO if the restriction is a someValuesFrom, then:
451 # add the onProperty to object/datatype_properties
452 # stop processing
453 0 ▶ next unless defined $restrict->{'onProperty'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $restrict->{"onProperty"} 0 0 0
454 # next if defined $added_properties{$restrict->{'onProperty'}};
455
456 # check if $restrict->{'hasValue'} ? add the hasValue to class : process restriction
457 0 ▶ if (defined $restrict->{'hasValue'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"hasValue"}) 0 0 0
458 # add hasValue: extract the value,
459 0 my $o = OWL::Utils->trim($restrict->{'hasValue'});
460 0 my $p = $restrict->{'onProperty'};
461 0 my $range = $restrict->{'range'};
462 0 my %hv_hash;
463 0 $hv_hash{object} = $o;
464 0 $hv_hash{range} = $range;
465 0 $hv_hash{name} = $restrict->{'propertyName'};
466 0 ▶ if ( $dProps->{ $restrict->{'onProperty'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dProps{$restrict->{'onProperty'}}) { } 0 0 0
467 0 $hv_hash{module} = $self->oProperty2module( $self->uri2package( $p ) );
468 } else {
469 0 ▶ $hv_hash{module} = $self->oProperty2module( $self->uri2package( $range ) ) if $range;
Branch: 1 branch
BranchTrueFalseTotal
if $range 0 0 0
470 0 ▶ $hv_hash{module} = 'OWL::Data::OWL::Class' unless $range;
Branch: 1 branch
BranchTrueFalseTotal
unless $range 0 0 0
471 }
472
473 0 $class->add_has_value_property(\%hv_hash);
474 # no next, because we use the has_value stuff to init our stuff
475 }
476 0 ▶ if ( $dProps->{ $restrict->{'onProperty'} } ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$dProps{$restrict->{'onProperty'}}) { } 0 0 0
elsif ($$oProps{$restrict->{'onProperty'}}) { } 0 0 0
477 0 my $dp = $dProps->{ $restrict->{'onProperty'} };
478 # extract any cardinality constraints
479 0 ▶ if ( defined $restrict->{'minCardinality'} or defined $restrict->{'maxCardinality'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}) 0 0 0
Condition0%0/3
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
defined $restrict->{"minCardinality"} defined $restrict->{"maxCardinality"}
Truth table0%0/3
A or B
A= defined $restrict->{"minCardinality"}B= defined $restrict->{"maxCardinality"}
ABresult
1X1
011
000
480 0 ▶ my $min = $restrict->{'minCardinality'} || '0';
Condition0%0/2
$restrict->{'minCardinality'} || '0'
l!l
00
MC/DC0%0/1
$restrict->{'minCardinality'} || '0'
$restrict->{'minCardinality'}
Truth table0%0/2
A
A= $restrict->{'minCardinality'}
Aresult
11
00
481 0 ▶ my $max = $restrict->{'maxCardinality'} || undef;
Condition0%0/2
$restrict->{'maxCardinality'} || undef
l!l
00
MC/DC0%0/1
$restrict->{'maxCardinality'} || undef
$restrict->{'maxCardinality'}
Truth table0%0/2
A
A= $restrict->{'maxCardinality'}
Aresult
11
00
482 0 my $hash;
483 0 ▶ $hash->{min} = $min if defined $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min 0 0 0
484 0 ▶ $hash->{max} = $max if defined $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max 0 0 0
485 0 $hash->{name} = $restrict->{'propertyName'};
486 0 my $hoh = $class->cardinality_constraints();
487 0 $hoh->{$restrict->{'propertyName'}} = $hash;
488 0 $class->cardinality_constraints($hoh);
489 }
490
491 0 ▶ $class->add_datatype_properties($dp) unless defined $added_properties{$restrict->{'onProperty'}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $added_properties{$restrict->{"onProperty"}} 0 0 0
492 } elsif ($oProps->{ $restrict->{'onProperty'} }) {
493 0 my $op = $oProps->{ $restrict->{'onProperty'} };
494 # extract any cardinality constraints
495 0 ▶ if (defined $restrict->{'minCardinality'} or defined $restrict->{'maxCardinality'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}) 0 0 0
Condition0%0/3
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
defined $restrict->{"minCardinality"} defined $restrict->{"maxCardinality"}
Truth table0%0/3
A or B
A= defined $restrict->{"minCardinality"}B= defined $restrict->{"maxCardinality"}
ABresult
1X1
011
000
496 0 ▶ my $min = $restrict->{'minCardinality'} || '0';
Condition0%0/2
$restrict->{'minCardinality'} || '0'
l!l
00
MC/DC0%0/1
$restrict->{'minCardinality'} || '0'
$restrict->{'minCardinality'}
Truth table0%0/2
A
A= $restrict->{'minCardinality'}
Aresult
11
00
497 0 ▶ my $max =$restrict->{'maxCardinality'} || undef;
Condition0%0/2
$restrict->{'maxCardinality'} || undef
l!l
00
MC/DC0%0/1
$restrict->{'maxCardinality'} || undef
$restrict->{'maxCardinality'}
Truth table0%0/2
A
A= $restrict->{'maxCardinality'}
Aresult
11
00
498 0 my $hash;
499 0 ▶ $hash->{min} = $min if defined $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min 0 0 0
500 0 ▶ $hash->{max} = $max if defined $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max 0 0 0
501 0 $hash->{name} = $restrict->{'propertyName'};
502 0 my $hoh = $class->cardinality_constraints();
503 0 $hoh->{$restrict->{'propertyName'}} = $hash;
504 0 $class->cardinality_constraints($hoh);
505 }
506 # add the valuesFrom to values_from_properties
507 0 ▶ if (defined $restrict->{'someValuesFrom'} and defined $restrict->{'propertyName'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"someValuesFrom"} and defined $restrict->{"propertyName"}) 0 0 0
Condition0%0/3
defined $restrict->{"someValuesFrom"} and defined $restrict->{"propertyName"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $restrict->{"someValuesFrom"} and defined $restrict->{"propertyName"}
defined $restrict->{"someValuesFrom"} defined $restrict->{"propertyName"}
Truth table0%0/3
A and B
A= defined $restrict->{"someValuesFrom"}B= defined $restrict->{"propertyName"}
ABresult
0X0
100
111
508 0 my $pname = $restrict->{'propertyName'};
509 0 my $svf = $self->owlClass2module( $self->uri2package($restrict->{'someValuesFrom'}) );
510 0 ▶ my $vfp_hash = $class->values_from_property() || ();
Condition0%0/3
$class->values_from_property || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$class->values_from_property || ()
$class->values_from_property ()
Truth table0%0/3
A || B
A= $class->values_from_propertyB= ()
ABresult
1X1
011
000
511 0 ▶ if (exists $vfp_hash->{$pname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $vfp_hash->{$pname}) { } 0 0 0
512 0 $vfp_hash->{$pname} = {%{$vfp_hash->{$pname}}, "$svf" => 1};
513 0 $class->values_from_property($vfp_hash);
514 } else {
515 0 $vfp_hash->{$pname} = {$svf => 1};
516 0 $class->values_from_property($vfp_hash);
517 }
518 }
519 0 ▶ $class->add_object_properties($op) unless defined $added_properties{$restrict->{'onProperty'}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $added_properties{$restrict->{"onProperty"}} 0 0 0
520 } else {
521 0 $LOG->warn(sprintf("Trying to use property, '%s', but it was not imported in your ontology!", $restrict->{'onProperty'}));
522 }
523 0 $added_properties{$restrict->{'onProperty'}} = 1;
524 }
525 0 foreach my $iClass ( @{ $object->{'unions'}->{'classes'} } )
526 {
527 0 $class->add_parent($iClass);
528 }
529 }
530
531 # process the restriction
532 20 ▶ if ( defined $object->{'restrictions'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"restrictions"} and @{$object->{"restrictions"};}) 2 18 20
Condition66%2/3
defined $object->{"restrictions"} and @{$object->{"restrictions"};}
!ll&&!rl&&r
0182
MC/DC50%1/2
defined $object->{"restrictions"} and @{$object->{"restrictions"};}
defined $object->{"restrictions"} @{$object->{"restrictions"};}
Truth table66%2/3
A and B
A= defined $object->{"restrictions"}B= @{$object->{"restrictions"};}
ABresult
0X0
100
111
533 20 and @{ $object->{'restrictions'} } )
534 {
535 2 foreach my $restrict ( @{ $object->{'restrictions'} } ) {
536 2 ▶ next unless defined $restrict->{'onProperty'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $restrict->{"onProperty"} 0 2 2
537 #next if defined $added_properties{$restrict->{'onProperty'}};
538 # check if $restrict->{'hasValue'} ? add the hasValue to class : process restriction
539 2 ▶ if (defined $restrict->{'hasValue'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"hasValue"}) 0 2 2
540 # add hasValue: extract the value,
541 0 my $o = OWL::Utils->trim($restrict->{'hasValue'});
542 0 my $p = $restrict->{'onProperty'};
543 0 my $range = $restrict->{'range'};
544 0 my %hv_hash;
545 0 $hv_hash{object} = $o;
546 0 $hv_hash{range} = $range;
547 0 $hv_hash{name} = $restrict->{'propertyName'};
548 0 ▶ if ( $dProps->{ $restrict->{'onProperty'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dProps{$restrict->{'onProperty'}}) { } 0 0 0
549 0 $hv_hash{module} = $self->oProperty2module( $self->uri2package( $p ) );
550 } else {
551 0 ▶ $hv_hash{module} = $self->oProperty2module( $self->uri2package( $range ) ) if $range;
Branch: 1 branch
BranchTrueFalseTotal
if $range 0 0 0
552 0 ▶ $hv_hash{module} = 'OWL::Data::OWL::Class' unless $range;
Branch: 1 branch
BranchTrueFalseTotal
unless $range 0 0 0
553 }
554
555 0 $class->add_has_value_property(\%hv_hash);
556 # no next, because we use the has_value stuff to init our stuff
557 }
558 2 ▶ if ( $dProps->{ $restrict->{'onProperty'} } ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($$dProps{$restrict->{'onProperty'}}) { } 0 2 2
elsif ($$oProps{$restrict->{'onProperty'}}) { } 2 0 2
elsif ($$oProps{$restrict->{'restrictionURI'}}) { } 0 0 0
559 0 my $dp = $dProps->{ $restrict->{'onProperty'} };
560 # FIXME
561 # extract any cardinality constraints
562 0 ▶ if ( defined $restrict->{'minCardinality'} or defined $restrict->{'maxCardinality'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}) 0 0 0
Condition0%0/3
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
defined $restrict->{"minCardinality"} defined $restrict->{"maxCardinality"}
Truth table0%0/3
A or B
A= defined $restrict->{"minCardinality"}B= defined $restrict->{"maxCardinality"}
ABresult
1X1
011
000
563 0 ▶ my $min = $restrict->{'minCardinality'} || '0';
Condition0%0/2
$restrict->{'minCardinality'} || '0'
l!l
00
MC/DC0%0/1
$restrict->{'minCardinality'} || '0'
$restrict->{'minCardinality'}
Truth table0%0/2
A
A= $restrict->{'minCardinality'}
Aresult
11
00
564 0 ▶ my $max = $restrict->{'maxCardinality'} || undef;
Condition0%0/2
$restrict->{'maxCardinality'} || undef
l!l
00
MC/DC0%0/1
$restrict->{'maxCardinality'} || undef
$restrict->{'maxCardinality'}
Truth table0%0/2
A
A= $restrict->{'maxCardinality'}
Aresult
11
00
565 0 my $hash;
566 0 ▶ $hash->{min} = $min if defined $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min 0 0 0
567 0 ▶ $hash->{max} = $max if defined $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max 0 0 0
568 0 $hash->{name} = $restrict->{'propertyName'};
569 0 my $hoh = $class->cardinality_constraints();
570 0 $hoh->{$restrict->{'propertyName'}} = $hash;
571 0 $class->cardinality_constraints($hoh);
572 }
573 0 ▶ $class->add_datatype_properties($dp) unless defined $added_properties{$restrict->{'onProperty'}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $added_properties{$restrict->{"onProperty"}} 0 0 0
574 } elsif ( $oProps->{ $restrict->{'onProperty'} } ) {
575 2 my $op = $oProps->{ $restrict->{'onProperty'} };
576 # FIXME
577 # extract any cardinality constraints
578 2 ▶ if (defined $restrict->{'minCardinality'} or defined $restrict->{'maxCardinality'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}) 2 0 2
Condition33%1/3
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
l!l&&r!l&&!r
200
MC/DC0%0/2
defined $restrict->{"minCardinality"} or defined $restrict->{"maxCardinality"}
defined $restrict->{"minCardinality"} defined $restrict->{"maxCardinality"}
Truth table33%1/3
A or B
A= defined $restrict->{"minCardinality"}B= defined $restrict->{"maxCardinality"}
ABresult
1X1
011
000
579 2 ▶ my $min = $restrict->{'minCardinality'} || '0';
Condition50%1/2
$restrict->{'minCardinality'} || '0'
l!l
20
MC/DC0%0/1
$restrict->{'minCardinality'} || '0'
$restrict->{'minCardinality'}
Truth table50%1/2
A
A= $restrict->{'minCardinality'}
Aresult
11
00
580 2 ▶ my $max = $restrict->{'maxCardinality'} || undef;
Condition50%1/2
$restrict->{'maxCardinality'} || undef
l!l
02
MC/DC0%0/1
$restrict->{'maxCardinality'} || undef
$restrict->{'maxCardinality'}
Truth table50%1/2
A
A= $restrict->{'maxCardinality'}
Aresult
11
00
581 2 my $hash;
582 2 ▶ $hash->{min} = $min if defined $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min 2 0 2
583 2 ▶ $hash->{max} = $max if defined $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max 0 2 2
584 2 $hash->{name} = $restrict->{'propertyName'};
585 2 my $hoh = $class->cardinality_constraints();
586 2 $hoh->{$restrict->{'propertyName'}} = $hash;
587 2 $class->cardinality_constraints($hoh);
588 }
589 2 ▶ $class->add_object_properties($op) unless defined $added_properties{$restrict->{'onProperty'}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $added_properties{$restrict->{"onProperty"}} 2 0 2
590 } elsif ( $oProps->{ $restrict->{'restrictionURI'} } ) {
591
592 # FIXME hack ...
593 0 my $op = $oProps->{ $restrict->{'restrictionURI'} };
594 $class->add_parent($op)
595 0 ▶ if defined $classes{ $restrict->{'restrictionURI'} };
Branch: 1 branch
BranchTrueFalseTotal
if defined $classes{$restrict->{"restrictionURI"}} 0 0 0
596 }
597 2 $added_properties{$restrict->{'onProperty'}} = 1;
598 }
599 }
600
601 #use Data::Dumper; $LOG->info(Dumper($class)) if defined $class->values_from_property();
602
603 20 my $generator = OWL::Generators::GenOWL->new();
604 20 ▶ if ( defined $code ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code) { } 0 20 20
605 0 $generator->generate_class(
606 class => $class,
607 outcode => $code,
608 force_over => $self->force(),
609 );
610 } else {
611 20 ▶ $generator->generate_class(
Branch: 1 branch
BranchTrueFalseTotal
if $self->outdir 20 0 20
612 class => $class,
613 force_over => $self->force(),
614 impl_outdir => $self->outdir()
615 ) if $self->outdir();
616 20 ▶ $generator->generate_class(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->outdir 0 20 20
617 class => $class,
618 force_over => $self->force(),
619 ) unless $self->outdir();
620 }
621 }
622 }
623
624 ############################################################
625 # consumes an array ref of URLs and a base_uri (optional; #
626 # defaults to the currently processed URL) and returns the #
627 # ODO::Ontology::OWL::Lite object #
628 ############################################################
629
630 1 ▶sub process_owl {
Subroutine process_owl: called CC=12 SCAR=28.3
Pod documented
631 1 my ( $self, $urls, $base_uris ) = @_;
632 # initialize $base_uris if it is not already
633 1 ▶ $base_uris = [] unless defined $base_uris;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base_uris 0 1 1
634 1 my $counter = -1;
635 1 my $GRAPH_schema = ODO::Graph::Simple->Memory();
636 1 my $GRAPH_source_data = ODO::Graph::Simple->Memory();
637 1 for my $url (@$urls) {
638 2 $counter++;
639 2 ▶ next unless defined $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 0 2 2
640 2 $LOG->info( 'Obtaining OWL ontology from: ' . $url );
641
642 # if passed a file, make it a file url
643 2 ▶ if (-e $url and -f $url) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $url and -f $url) 2 0 2
Condition33%1/3
-e $url and -f $url
!ll&&!rl&&r
002
MC/DC0%0/2
-e $url and -f $url
-e $url -f $url
Truth table33%1/3
A and B
A= -e $urlB= -f $url
ABresult
0X0
100
111
644 2 $url = "file://$url";
645 }
646
647 2 my $owl;
648 2 eval {
649 2 $LOG->info('Downloading OWL file');
650 2 $owl = OWL::Utils::getHttpRequestByURL($url);
651 };
652 2 ▶ $self->throw("Error obtaining ontology ('$url'): $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
653 # parse the owl document
654 2 ▶ my ( $statements, $imports ) =
Branch: 2 branches
BranchTrueFalseTotal
defined $base_uris->[$counter] ? : 2 0 2
defined $OWLCFG::XML_PARSER ? : 0 2 2
655 ODO::Parser::XML->parse(
656 $owl,
657 base_uri => defined $base_uris->[$counter]? $base_uris->[$counter] : $url,
658 sax_parser => defined $OWLCFG::XML_PARSER ? $OWLCFG::XML_PARSER : undef
659 );
660
661 2 $GRAPH_schema->add($statements);
662 2 $self->{_imports_added}{$url} = 1;
663
664 # process imports
665 2 ▶ if ( $self->follow_imports() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->follow_imports) 0 2 2
666 0 foreach my $i (@$imports) {
667 0 $i =~ s/#*$//gi;
668
669 # skip imports we have already processed
670 0 ▶ next if $self->{_imports_added}{$i};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_imports_added"}{$i} 0 0 0
671 0 $self->_process_import( $GRAPH_schema, $i );
672 }
673 }
674 }
675
676 # create the 'stuff'
677 1 $LOG->info('Aggregating ontologies ...');
678 1 my $SCHEMA =
679 ODO::Ontology::OWL::Lite->new(
680 graph => $GRAPH_source_data,
681 schema_graph => $GRAPH_schema,
682 schemaName => '',
683 verbose => $LOG->is_info()
684 );
685 1 return $SCHEMA;
686 }
687
688 # private sub
689 0 ▶sub _process_import {
Subroutine _process_import: not called CC=4 SCAR=30.0
690 0 my ( $self, $GRAPH_schema, $import ) = @_;
691 0 $import =~ s/#*$//gi;
692 0 $LOG->info("\tProcessing import $import");
693 0 my $owl = OWL::Utils::getHttpRequestByURL($import);
694 0 ▶ my ( $statements, $imports ) =
Branch: 1 branch
BranchTrueFalseTotal
defined $OWLCFG::XML_PARSER ? : 0 0 0
695 ODO::Parser::XML->parse(
696 $owl,
697 base_uri => $import,
698 sax_parser => defined $OWLCFG::XML_PARSER ? $OWLCFG::XML_PARSER : undef
699 );
700 0 $GRAPH_schema->add($statements);
701 0 foreach my $i (@$imports) {
702 0 $i =~ s/#*$//gi;
703
704 # skip imports we have already processed
705 0 ▶ next if $self->{_imports_added}{$i};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_imports_added"}{$i} 0 0 0
706 0 $self->{_imports_added}{$i} = 1;
707 0 $self->_process_import( $GRAPH_schema, $i );
708 }
709 }
710 2 1;
711
712 __END__
↑ Summary lib/OWL/Base.pm »