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