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/Ontology.pm,v $ |
10
|
|
|
|
|
|
|
# Created by: Stephen Evanchik( evanchik@us.ibm.com ) |
11
|
|
|
|
|
|
|
# Created on: 12/21/2004 |
12
|
|
|
|
|
|
|
# Revision: $Id: Ontology.pm,v 1.6 2009-11-25 17:46:52 ubuntu Exp $ |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# Contributors: |
15
|
|
|
|
|
|
|
# IBM Corporation - initial API and implementation |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
package ODO::Ontology; |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
3
|
|
33544
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
111
|
|
20
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
200
|
|
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
3
|
|
823
|
use ODO::Exception; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
144
|
|
23
|
3
|
|
|
3
|
|
947
|
use ODO::Query::Simple; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
133
|
|
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
3
|
|
3311
|
use URI; |
|
3
|
|
|
|
|
43757
|
|
|
3
|
|
|
|
|
931
|
|
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
3
|
|
38
|
use base qw/ODO/; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
487
|
|
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
3
|
|
18
|
use vars qw /$VERSION/; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
5516
|
|
30
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /: (\d+)\.(\d+)/; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our @METHODS = qw/graph schema_graph schema_name base_namespace base_class/; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(@METHODS); |
35
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors(qw/symbol_table_list/); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our $PERL_IDENTIFIER = "/^[A-Za-z_][A-Za-z_0-9]*$/"; |
38
|
|
|
|
|
|
|
our $PERL_VARIABLE = "/^(:${PERL_IDENTIFIER}::)+$/"; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
ODO::Ontology |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SYNOPSIS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 DESCRIPTION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 METHODS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=over |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item add_symtab_entry( $hashref, $uri, $name) |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub add_symtab_entry { |
58
|
0
|
|
|
0
|
1
|
|
my ($self, $table_ref, $uri, $label) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $symtab = $self->__declare_symbol_table($table_ref); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$symtab->{'labels'}->{ $label } = $uri; |
63
|
0
|
|
|
|
|
|
$symtab->{'uris'}->{ $uri } = $label; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return 1; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item get_symtab_entry( $hashref, $uri ) |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub get_symtab_entry { |
74
|
0
|
|
|
0
|
1
|
|
my ($self, $table_ref, $uri) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $symtab = $self->__declare_symbol_table($table_ref); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return undef |
79
|
0
|
0
|
0
|
|
|
|
unless(exists($symtab->{'uris'}->{ $uri }) && defined($symtab->{'uris'}->{ $uri } )); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return $symtab->{'uris'}->{ $uri }; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub get_symbol_table { |
85
|
0
|
|
|
0
|
0
|
|
my ($self, $table_ref) = @_; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $self->__declare_symbol_table($table_ref); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item make_perl_package_name( $base, ( $name | [ name1, name2, name3 ] ) ) |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub make_perl_package_name { |
96
|
0
|
|
|
0
|
1
|
|
my ($self, $base, $name) = @_; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my @name_list; |
99
|
0
|
0
|
|
|
|
|
if(UNIVERSAL::isa($name, 'ARRAY')) { |
100
|
0
|
|
|
|
|
|
@name_list = @{ $name }; |
|
0
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
0
|
|
|
|
|
|
@name_list = ($name); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
0
|
|
|
|
unshift @name_list, $base |
107
|
|
|
|
|
|
|
if(defined($base) && $base ne ''); |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return join('::', @name_list); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub __declare_symbol_table { |
114
|
0
|
|
|
0
|
|
|
my ($self, $table_ref) = @_; |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
0
|
|
|
|
return $self->{'symbol_table_list'}->{ $table_ref } |
117
|
|
|
|
|
|
|
if( exists($self->{'symbol_table_list'}->{ $table_ref }) |
118
|
|
|
|
|
|
|
&& UNIVERSAL::isa($self->{'symbol_table_list'}->{ $table_ref }, 'HASH')); |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$self->{'symbol_table_list'}->{ $table_ref } = { |
121
|
|
|
|
|
|
|
labels=> {}, |
122
|
|
|
|
|
|
|
uris=> {}, |
123
|
|
|
|
|
|
|
}; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return $self->{'symbol_table_list'}->{ $table_ref }; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub __parse_uri_for_name { |
130
|
0
|
|
|
0
|
|
|
my ($self, $uri) = @_; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
$uri = URI->new($uri); |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $name = $uri->fragment(); |
135
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
return $name |
137
|
|
|
|
|
|
|
if($name); |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
($name) = $uri->as_string() =~ /(?:[\#\/\:])([^\#\/\:]+)$/; |
140
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
return $name |
142
|
|
|
|
|
|
|
if($name); |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
return $uri->as_string(); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# FIXME: Figure out what to do here |
147
|
|
|
|
|
|
|
# return ($uri->fragment() || $uri->as_string()); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub __is_perl_package { |
152
|
0
|
|
|
0
|
|
|
my ($self, $perl_test_structure) = @_; |
153
|
|
|
|
|
|
|
|
154
|
0
|
0
|
|
|
|
|
return 1 |
155
|
|
|
|
|
|
|
if(UNIVERSAL::can($perl_test_structure, 'new')); |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
return 0; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub __make_perl_identifier { |
162
|
0
|
|
|
0
|
|
|
my ($self, $name) = @_; |
163
|
0
|
|
|
|
|
|
$name =~ s/\ |#|\:|\\|\/|\-|\.//g; |
164
|
0
|
|
|
|
|
|
return $name |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub __make_perl_string { |
169
|
0
|
|
|
0
|
|
|
my ($self, $string) = @_; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
$string =~ s/ +/ /g; |
172
|
0
|
|
|
|
|
|
$string =~ s/\n|\r//g; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
return $string; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub init { |
178
|
0
|
|
|
0
|
1
|
|
my ($self, $config) = @_; |
179
|
0
|
|
|
|
|
|
$self->params($config, @METHODS); |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
$self->{'symbol_table_list'} = {} |
182
|
|
|
|
|
|
|
unless(UNIVERSAL::isa($self->{'symbol_table_list'}, 'HASH')); |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
return $self; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 COPYRIGHT |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Copyright (c) 2005-2006 IBM Corporation. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
All rights reserved. This program and the accompanying materials |
194
|
|
|
|
|
|
|
are made available under the terms of the Eclipse Public License v1.0 |
195
|
|
|
|
|
|
|
which accompanies this distribution, and is available at |
196
|
|
|
|
|
|
|
http://www.eclipse.org/legal/epl-v10.html |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
1; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
__END__ |