line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Copyright (c) 2005-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/Graph.pm,v $ |
10
|
|
|
|
|
|
|
# Created by: Stephen Evanchik( evanchik@us.ibm.com ) |
11
|
|
|
|
|
|
|
# Created on: 01/18/2005 |
12
|
|
|
|
|
|
|
# Revision: $Id: Graph.pm,v 1.3 2010-05-20 17:29:00 ubuntu Exp $ |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# Contributors: |
15
|
|
|
|
|
|
|
# IBM Corporation - initial API and implementation |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
package ODO::Graph; |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
|
6
|
|
54184
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
227
|
|
20
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
158
|
|
21
|
|
|
|
|
|
|
|
22
|
6
|
|
|
6
|
|
27
|
use base qw/ODO/; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
1739
|
|
23
|
|
|
|
|
|
|
|
24
|
6
|
|
|
6
|
|
2521
|
use ODO::Exception; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
343
|
|
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
6
|
|
358323
|
use Module::Load::Conditional qw/can_load/; |
|
6
|
|
|
|
|
236565
|
|
|
6
|
|
|
|
|
531
|
|
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
6
|
|
64
|
use vars qw /$VERSION/; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
543
|
|
29
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /: (\d+)\.(\d+)/; |
30
|
|
|
|
|
|
|
|
31
|
6
|
|
|
|
|
63
|
use Class::Interfaces('ODO::Graph'=> |
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
'isa'=> 'ODO', |
34
|
|
|
|
|
|
|
'methods'=> [ 'add', 'remove', 'query', 'contains', 'size', 'clear', 'intersection', 'union' ], |
35
|
|
|
|
|
|
|
} |
36
|
6
|
|
|
6
|
|
5891
|
); |
|
6
|
|
|
|
|
4737
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/name/); |
39
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors(qw/storage storage_package/); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub AUTOLOAD { |
43
|
8
|
|
|
8
|
|
1072
|
our $AUTOLOAD; |
44
|
|
|
|
|
|
|
|
45
|
8
|
|
|
|
|
24
|
my $caller_package = shift @_; |
46
|
8
|
|
|
|
|
18
|
my $storage_type = $AUTOLOAD; |
47
|
|
|
|
|
|
|
|
48
|
8
|
|
|
|
|
165
|
$storage_type =~ s/^${caller_package}:://; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return undef |
51
|
8
|
50
|
|
|
|
43
|
if($storage_type =~ /::DESTROY$/); |
52
|
|
|
|
|
|
|
|
53
|
8
|
|
|
|
|
64
|
my $backend_loaded = can_load( modules => {"ODO::Graph::Storage::$storage_type"=> undef} ); |
54
|
|
|
|
|
|
|
|
55
|
8
|
50
|
33
|
|
|
616
|
throw ODO::Exception::Module(error=> "Could not load graph storage module: 'ODO::Graph::Storage::$storage_type'\n==> $@") |
56
|
|
|
|
|
|
|
if(!defined($backend_loaded) || !UNIVERSAL::can("ODO::Graph::Storage::$storage_type", 'new')); |
57
|
|
|
|
|
|
|
|
58
|
8
|
50
|
|
|
|
77
|
throw ODO::Exception::Module(error=> "Can not load $caller_package") |
59
|
|
|
|
|
|
|
if(!UNIVERSAL::can($caller_package, 'new_from_autoload')); |
60
|
|
|
|
|
|
|
|
61
|
8
|
|
|
|
|
17
|
shift; # Get rid of the package |
62
|
|
|
|
|
|
|
|
63
|
8
|
|
|
|
|
426
|
return $caller_package->new_from_autoload(storage_package=> "ODO::Graph::Storage::$storage_type", @_); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
ODO::Graph - Base methods for a graph object |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use ODO::Graph::Simple; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Create an ODO::Graph::Simple object backed by memory |
75
|
|
|
|
|
|
|
my $graph = ODO::Graph::Simple->Memory(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Base graph object that defines the graph interface. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Constructor. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTOLOAD |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Autoload. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 METHODS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=over |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item add( $statement ) |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item add( \@statements ) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item add( @statements ) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Add statement(s). |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item remove( $statement ) |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item remove( \@statements ) |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item remove( @statements ) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Remove statement(s). |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item size( ) |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Returns the number of statements in the graph. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item query( $query ) |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Query the graph based on the query parameter which must be a subclass of L. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item clear( ) |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Remove all statements from the graph. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item contains( $query ) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns a boolean value of the graph contains results that match the query. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item storage( ) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Returns the underlying graph storage object. See L for more information. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item storage_package( ) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Returns the name of the package for the underlying graph storage object. |
132
|
|
|
|
|
|
|
See L for more information. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub new_from_autoload { |
137
|
8
|
|
|
8
|
0
|
16
|
my $self = shift; |
138
|
8
|
|
|
|
|
61
|
return $self->new(@_); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub init { |
142
|
8
|
|
|
8
|
1
|
251
|
my ($self, $config) = @_; |
143
|
|
|
|
|
|
|
|
144
|
8
|
|
|
|
|
62
|
$self->params($config, qw/name storage_package/); |
145
|
|
|
|
|
|
|
|
146
|
8
|
|
|
|
|
402
|
my $backend_loaded = can_load( modules => {$self->{'storage_package'}=> undef} ); |
147
|
8
|
50
|
|
|
|
954
|
throw ODO::Exception::Module(error=> "Could not load graph storage module: '". $self->{'storage_package'} ."'\n==> $@") |
148
|
|
|
|
|
|
|
if(!defined($backend_loaded)); |
149
|
|
|
|
|
|
|
|
150
|
8
|
|
|
|
|
19
|
$self->{'storage'} = $self->{'storage_package'}->new( %{ $config }, parent_graph=> $self ); |
|
8
|
|
|
|
|
50
|
|
151
|
|
|
|
|
|
|
|
152
|
8
|
|
|
|
|
76
|
return $self; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=back |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SEE ALSO |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L, L, L |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 COPYRIGHT |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Copyright (c) 2005-2006 IBM Corporation. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
All rights reserved. This program and the accompanying materials |
166
|
|
|
|
|
|
|
are made available under the terms of the Eclipse Public License v1.0 |
167
|
|
|
|
|
|
|
which accompanies this distribution, and is available at |
168
|
|
|
|
|
|
|
http://www.eclipse.org/legal/epl-v10.html |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
__END__ |