| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | AtteanX::Store::SimpleTripleStore - SimpleTripleStore, unindexed, in-memory RDF store | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 VERSION | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | This document describes AtteanX::Store::SimpleTripleStore version 0.040 | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | use AtteanX::Store::SimpleTripleStore; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | AtteanX::Store::SimpleTripleStore provides an in-memory triple-store. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use v5.14; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | package AtteanX::Store::SimpleTripleStore 0.040 { | |||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Type::Tiny::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Types::Standard qw(Int ArrayRef HashRef ConsumerOf InstanceOf); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Set::Scalar; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use Digest::SHA; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use Scalar::Util qw(refaddr reftype blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | with 'Attean::API::MutableTripleStore'; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | my @pos_names = Attean::API::Quad->variables; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head1 METHODS | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | Beyond the methods documented below, this class inherits methods from the | ||||||||||||||||||||||||||||
| 40 | L<Attean::API::QuadStore> class. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =over 4 | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =item C<< new ( triples => \@triples ) >> | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Returns a new memory-backed storage object. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 10 | ▶ | has triples => (is => 'rw', isa => ArrayRef[ConsumerOf['Attean::API::Triple']], default => sub { [] }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =item C<< get_triples ( $subject, $predicate, $object ) >> | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Returns a stream object of all statements matching the specified subject, | ||||||||||||||||||||||||||||
| 55 | predicate and objects. Any of the arguments may be undef to match any value. | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 49 | ▶ | sub get_triples { | ||||||||||||||||||||||||||
|
Subroutine
get_triples: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 49 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 49 | my @nodes = @_; | |||||||||||||||||||||||||||
| 62 | 49 | my %bound; | |||||||||||||||||||||||||||
| 63 | 49 | foreach my $pos (0 .. 2) { | |||||||||||||||||||||||||||
| 64 | 147 | my $n = $nodes[ $pos ]; | |||||||||||||||||||||||||||
| 65 | 147 | ▶ | if (blessed($n) and $n->does('Attean::API::Variable')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($n) and $n->does("Attean::API::Variable")
MC/DC100%2/2
builtin::blessed($n) and $n->does("Attean::API::Variable")
builtin::blessed($n)
$n->does("Attean::API::Variable")
Truth table100%3/3
A and B
A= builtin::blessed($n)B= $n->does("Attean::API::Variable")
| |||||||||||||||||||||||||||||
| 66 | 46 | $n = undef; | |||||||||||||||||||||||||||
| 67 | 46 | $nodes[$pos] = undef; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 147 | ▶ | if (blessed($n)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 46 | $bound{ $pos_names[$pos] } = $n; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 49 | my $triples = $self->triples; | |||||||||||||||||||||||||||
| 75 | 49 | my $iter = Attean::ListIterator->new( values => $triples, item_type => 'Attean::API::Triple' ); | |||||||||||||||||||||||||||
| 76 | return $iter->grep(sub { | ||||||||||||||||||||||||||||
| 77 | my $q = shift; | ||||||||||||||||||||||||||||
| 78 | foreach my $key (keys %bound) { | ||||||||||||||||||||||||||||
| 79 | my $term = $q->$key(); | ||||||||||||||||||||||||||||
| 80 | my $eq = eval { $term->equals( $bound{$key} ) } || 0; | ||||||||||||||||||||||||||||
| 81 | unless ($eq) { | ||||||||||||||||||||||||||||
| 82 | return 0; | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | return 1; | ||||||||||||||||||||||||||||
| 86 | 49 | }); | |||||||||||||||||||||||||||
| 87 | 0 | return $iter; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =item C<< add_triple( $t ) >> | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 16 | ▶ | sub add_triple { | ||||||||||||||||||||||||||
|
Subroutine
add_triple: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 96 | 16 | my $t = shift; | |||||||||||||||||||||||||||
| 97 | 16 | push(@{ $self->triples }, $t); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =item C<< remove_triple( $t ) >> | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | ▶ | sub remove_triple { | ||||||||||||||||||||||||||
|
Subroutine
remove_triple: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 106 | 1 | my $t = shift; | |||||||||||||||||||||||||||
| 107 | 1 | my @remove; | |||||||||||||||||||||||||||
| 108 | 1 | my $triples = $self->triples; | |||||||||||||||||||||||||||
| 109 | 1 | foreach my $i (0 .. $#{ $triples }) { | |||||||||||||||||||||||||||
| 110 | 4 | my $u = $triples->[$i]; | |||||||||||||||||||||||||||
| 111 | 4 | ▶ | if ($u->as_string eq $t->as_string) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 1 | push(@remove, $i); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 1 | ▶ | while (scalar(@remove)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 1 | my $i = pop(@remove); | |||||||||||||||||||||||||||
| 117 | 1 | splice(@$triples, $i, 1, ()); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 2 | 1; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | __END__ | ||||||||||||||||||||||||||||