line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dallycot::Value::TripleStore; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JSMITH'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Manages a memory-based triple store of linked data |
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
13234
|
use strict; |
|
23
|
|
|
|
|
39
|
|
|
23
|
|
|
|
|
735
|
|
7
|
23
|
|
|
23
|
|
165
|
use warnings; |
|
23
|
|
|
|
|
35
|
|
|
23
|
|
|
|
|
494
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
86
|
use utf8; |
|
23
|
|
|
|
|
34
|
|
|
23
|
|
|
|
|
103
|
|
10
|
23
|
|
|
23
|
|
431
|
use parent 'Dallycot::Value::Any'; |
|
23
|
|
|
|
|
39
|
|
|
23
|
|
|
|
|
102
|
|
11
|
|
|
|
|
|
|
|
12
|
23
|
|
|
23
|
|
1321
|
use experimental qw(switch); |
|
23
|
|
|
|
|
43
|
|
|
23
|
|
|
|
|
152
|
|
13
|
|
|
|
|
|
|
|
14
|
23
|
|
|
23
|
|
2786
|
use Promises qw(deferred); |
|
23
|
|
|
|
|
34
|
|
|
23
|
|
|
|
|
118
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub as_text { |
17
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $base_url = $self->[0]; |
20
|
0
|
|
|
|
|
|
my $subject = $self->[1]; |
21
|
0
|
|
|
|
|
|
my $size = $self->[2]->size(); |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return "Graph($subject in $base_url with $size triples)"; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub to_rdf { |
27
|
0
|
|
|
0
|
0
|
|
my( $self, $model ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return RDF::Trine::Node::Resource->new($self->[1]->as_string); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
0
|
0
|
|
sub is_defined { return 1 } |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub is_empty { |
35
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return 0 == $self->[2]->count_statements( $self->[1], undef, undef ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub calculate_length { |
41
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return Dallycot::Value::Numeric->new( $self->[2]->size() ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub id { |
47
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return "<" . $self->[1]->as_string .">"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub type { |
53
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my @types = map { $_->[1] } $self->_fetch_property('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'); |
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return Dallycot::Value::Set->new(@types); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _fetch_property { |
60
|
0
|
|
|
0
|
|
|
my ( $self, $prop ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my ( $base, $subject, $graph ) = @$self; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $pred_node = RDF::Trine::Node::Resource->new($prop); |
65
|
0
|
|
|
|
|
|
my @nodes = $graph->objects( $subject, $pred_node ); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my @results; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
for my $node (@nodes) { |
70
|
0
|
0
|
|
|
|
|
if ( $node->is_resource ) { |
|
|
0
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
push @results, bless [ $base, $node, $graph ] => __PACKAGE__; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
elsif ( $node->is_literal ) { |
74
|
0
|
|
|
|
|
|
my $datatype = "String"; |
75
|
0
|
|
|
|
|
|
given ($datatype) { |
76
|
0
|
|
|
|
|
|
when ("String") { |
77
|
0
|
0
|
|
|
|
|
if ( $node->has_language ) { |
78
|
0
|
|
|
|
|
|
push @results, |
79
|
|
|
|
|
|
|
Dallycot::Value::String->new( $node->literal_value, $node->literal_value_language ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
0
|
|
|
|
|
|
push @results, Dallycot::Value::String->new( $node->literal_value ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
when ("Numeric") { |
86
|
0
|
|
|
|
|
|
push @results, Dallycot::Value::Numeric->new( $node->literal_value ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return @results; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub fetch_property { |
96
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $prop ) = @_; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $d = deferred; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $worked = eval { |
101
|
0
|
|
|
|
|
|
$d->resolve( $self->_fetch_property($prop) ); |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
if ($@) { |
|
|
0
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
$d->reject($@); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif ( !$worked ) { |
110
|
0
|
|
|
|
|
|
$d->reject("Unable to fetch $prop."); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return $d->promise; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |