line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
42328
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
155
|
|
4
|
5
|
|
|
5
|
|
28
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
274
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Gwybodaeth::Triples; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Triples - Stores triples as hashes keyed by subject. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Triples; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $t = Triples->new(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$t->store_triple($subject,$predicate,$object); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This module provides a data structure which stores triples. The structure is a |
23
|
|
|
|
|
|
|
hash keyed by the $subject: |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$subject = { |
26
|
|
|
|
|
|
|
obj => [], |
27
|
|
|
|
|
|
|
predicate => [] |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=over |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
5
|
|
|
5
|
|
28
|
use Carp qw(croak); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
1345
|
|
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item new() |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Returns an instance of the class. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
44
|
8
|
|
|
8
|
1
|
83
|
my $class = shift; |
45
|
8
|
|
|
|
|
14
|
my $self = {}; |
46
|
8
|
|
|
|
|
24
|
bless $self, $class; |
47
|
8
|
|
|
|
|
68
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Stores the triple and returns a reference to itself |
51
|
|
|
|
|
|
|
# Expects ($sbject, $predicate, $object) as parameters |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item store_triple($subject,$prediate,$object) |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Stores $subject, $predicate and $object in the triples data structure. Returns |
56
|
|
|
|
|
|
|
a refenece the data structure. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub store_triple { |
61
|
10
|
50
|
|
10
|
1
|
885
|
ref(my $self = shift) or croak "instance variable needed"; |
62
|
|
|
|
|
|
|
|
63
|
10
|
100
|
|
|
|
55
|
defined(my $subject = shift) or croak "must pass a subject"; |
64
|
9
|
100
|
|
|
|
42
|
defined(my $predicate = shift) or croak "must pass a predicate"; |
65
|
8
|
100
|
|
|
|
34
|
defined(my $object = shift) or croak "must pass an object"; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# If this is the first time we've come accross $subject |
68
|
|
|
|
|
|
|
# we create a new hash key for it |
69
|
7
|
50
|
|
|
|
34
|
if (not defined($self->{$subject})) { |
70
|
7
|
|
|
|
|
53
|
$self->{$subject} = { |
71
|
|
|
|
|
|
|
'obj' => [], |
72
|
|
|
|
|
|
|
'predicate' => [], |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
7
|
|
|
|
|
14
|
push @{ $self->{$subject}{'obj'} }, $object; |
|
7
|
|
|
|
|
17
|
|
77
|
7
|
|
|
|
|
12
|
push @{ $self->{$subject}{'predicate'} }, $predicate; |
|
7
|
|
|
|
|
17
|
|
78
|
|
|
|
|
|
|
|
79
|
7
|
|
|
|
|
24
|
return $self; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |