line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OWL::DirectSemantics; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
2
|
|
|
2
|
|
46795
|
$OWL::DirectSemantics::AUTHORITY = 'cpan:TOBYINK'; |
5
|
2
|
|
|
|
|
40
|
$OWL::DirectSemantics::VERSION = '0.001'; |
6
|
|
|
|
|
|
|
}; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
51
|
use 5.008; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
72
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
2453
|
use RDF::Trine '0.133'; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use RDF::Trine::Serializer::OwlFn; |
12
|
|
|
|
|
|
|
use OWL::DirectSemantics::Element; |
13
|
|
|
|
|
|
|
use OWL::DirectSemantics::Translator; |
14
|
|
|
|
|
|
|
use OWL::DirectSemantics::Writer; |
15
|
|
|
|
|
|
|
use Module::Pluggable |
16
|
|
|
|
|
|
|
search_path => 'OWL::DirectSemantics::Element', |
17
|
|
|
|
|
|
|
sub_name => 'element_modules', |
18
|
|
|
|
|
|
|
require => 1, |
19
|
|
|
|
|
|
|
; |
20
|
|
|
|
|
|
|
use Module::Pluggable |
21
|
|
|
|
|
|
|
search_path => 'OWL::DirectSemantics::TraitFor::Element', |
22
|
|
|
|
|
|
|
sub_name => 'element_traits', |
23
|
|
|
|
|
|
|
require => 1, |
24
|
|
|
|
|
|
|
; |
25
|
|
|
|
|
|
|
use Scalar::Util qw[]; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
BEGIN |
28
|
|
|
|
|
|
|
{ |
29
|
|
|
|
|
|
|
OWL::DirectSemantics->element_traits; |
30
|
|
|
|
|
|
|
OWL::DirectSemantics->element_modules; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
unless(RDF::Trine::Model->can('remove_list')) |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
# Patch current versions of Trine with remove_list |
36
|
|
|
|
|
|
|
*{'RDF::Trine::Model::remove_list'} = sub |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
my $head = shift; |
40
|
|
|
|
|
|
|
my $rdf = RDF::Trine::Namespace->new('http://www.w3.org/1999/02/22-rdf-syntax-ns#'); |
41
|
|
|
|
|
|
|
my %args = @_; |
42
|
|
|
|
|
|
|
my %seen; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
while (Scalar::Util::blessed($head) and not($head->isa('RDF::Trine::Node::Resource') and $head->uri_value eq $rdf->nil->uri_value)) { |
45
|
|
|
|
|
|
|
if ($seen{ $head->as_string }++) { |
46
|
|
|
|
|
|
|
throw RDF::Trine::Error -text => "Loop found during rdf:List traversal"; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
my $stream = $self->get_statements($head, undef, undef); |
49
|
|
|
|
|
|
|
my %statements; |
50
|
|
|
|
|
|
|
while (my $st = $stream->next) { |
51
|
|
|
|
|
|
|
my $statement_type = { |
52
|
|
|
|
|
|
|
$rdf->first->uri => 'rdf:first', |
53
|
|
|
|
|
|
|
$rdf->rest->uri => 'rdf:rest', |
54
|
|
|
|
|
|
|
$rdf->type->uri => 'rdf:type', |
55
|
|
|
|
|
|
|
}->{$st->predicate->uri} || 'other'; |
56
|
|
|
|
|
|
|
$statement_type = 'other' |
57
|
|
|
|
|
|
|
if $statement_type eq 'rdf:type' && !$st->object->equal($rdf->List); |
58
|
|
|
|
|
|
|
push @{$statements{$statement_type}}, $st; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
if ($args{orphan_check}) { |
61
|
|
|
|
|
|
|
return $head if defined $statements{other} && scalar(@{ $statements{other} }) > 0; |
62
|
|
|
|
|
|
|
return $head if $self->count_statements(undef, undef, $head) > 0; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
unless (scalar(@{ $statements{'rdf:first'} })==1 and scalar(@{ $statements{'rdf:rest'} })==1) { |
65
|
|
|
|
|
|
|
throw RDF::Trine::Error -text => "Invalid structure found during rdf:List traversal"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
$self->remove_statement($_) |
68
|
|
|
|
|
|
|
foreach (@{$statements{'rdf:first'}}, @{$statements{'rdf:rest'}}, @{$statements{'rdf:type'}}); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$head = $statements{'rdf:rest'}->[0]->object; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
OWL::DirectSemantics - representation of the direct semantics of OWL2 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SYNOPSIS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
use RDF::Trine; |
86
|
|
|
|
|
|
|
my $model = RDF::Trine::Model->temporary_model; |
87
|
|
|
|
|
|
|
RDF::Trine::Mode->parse_url_into_model($url, $model); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
use OWL::DirectSemantics; |
90
|
|
|
|
|
|
|
my $translator = OWL::DirectSemantics::Translator->new; |
91
|
|
|
|
|
|
|
my $ontology = $translator->translate($model); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
foreach my $ax ($ontology->axioms) |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
if ($ax->element_name eq 'ClassAssertion') |
96
|
|
|
|
|
|
|
{ |
97
|
|
|
|
|
|
|
printf("%s is of type %s.\n", $ax->node, $ax->class); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
print "The following data couldn't be translated to OWL:\n"; |
102
|
|
|
|
|
|
|
print RDF::Trine::Serializer |
103
|
|
|
|
|
|
|
->new('ntriples') |
104
|
|
|
|
|
|
|
->serialize_model_to_string($model); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 DESCRIPTION |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This distribution provides a basic framework for representing the OWL 2 direct semantics |
109
|
|
|
|
|
|
|
model, and a translator to build that model from an RDF-based model. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SEE ALSO |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
L<OWL::DirectSemantics::Translator>, |
114
|
|
|
|
|
|
|
L<OWL::DirectSemantics::Element>, |
115
|
|
|
|
|
|
|
L<RDF::Trine::Serializer::OwlFn>. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L<RDF::Closure>, |
118
|
|
|
|
|
|
|
L<RDF::Trine::Parser::OwlFn>. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L<RDF::Trine>, |
121
|
|
|
|
|
|
|
L<RDF::Query>, |
122
|
|
|
|
|
|
|
L<http://www.perlrdf.org/>. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 COPYRIGHT |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Copyright 2011-2012 Toby Inkster |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
133
|
|
|
|
|
|
|
under the same terms as Perl itself. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
138
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
139
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
140
|
|
|
|
|
|
|
|