| 1 | # RDF::Trine::Model::Union | ||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||
| 3 | |||||||||||
| 4 | =head1 NAME | ||||||||||
| 5 | |||||||||||
| 6 | RDF::Trine::Model::Union - Union models for joining multiple stores together | ||||||||||
| 7 | |||||||||||
| 8 | =head1 VERSION | ||||||||||
| 9 | |||||||||||
| 10 | This document describes RDF::Trine::Model::Union version 1.019 | ||||||||||
| 11 | |||||||||||
| 12 | =head1 METHODS | ||||||||||
| 13 | |||||||||||
| 14 | Beyond the methods documented below, this class inherits methods from the | ||||||||||
| 15 | L<RDF::Trine::Model> class. | ||||||||||
| 16 | |||||||||||
| 17 | =over 4 | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | package RDF::Trine::Model::Union; | ||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 1 | ▶ | no warnings 'redefine'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 1 | ▶ | use base qw(RDF::Trine::Model); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | use RDF::Trine::Node; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 1 | ▶ | use RDF::Trine::Store; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | 1 | our ($VERSION); | |||||||||
| 33 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 1 | $VERSION = '1.019'; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | ################################################################################ | ||||||||||
| 38 | |||||||||||
| 39 | =item C<< new ( @stores ) >> | ||||||||||
| 40 | |||||||||||
| 41 | Returns a new union-model over the list of supplied rdf stores. | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 46 | 1 | my $class = shift; | |||||||||
| 47 | 1 | my @stores = @_; | |||||||||
| 48 | 1 | my $self = bless({ stores => \@stores }, $class); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | =item C<< add_statement ( $statement [, $context] ) >> | ||||||||||
| 52 | |||||||||||
| 53 | Adds the specified C<$statement> to the first rdf store. | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub add_statement { | ||||||||
|
Subroutine
add_statement: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 58 | 1 | my $self = shift; | |||||||||
| 59 | 1 | my @iterators; | |||||||||
| 60 | 1 | my ($store) = $self->_stores; | |||||||||
| 61 | 1 | $store->add_statement( @_ ); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | =item C<< remove_statement ( $statement [, $context]) >> | ||||||||||
| 65 | |||||||||||
| 66 | Removes the specified C<$statement> from all of the rdf stores. | ||||||||||
| 67 | |||||||||||
| 68 | =cut | ||||||||||
| 69 | |||||||||||
| 70 | 1 | ▶ | sub remove_statement { | ||||||||
|
Subroutine
remove_statement: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 71 | 1 | my $self = shift; | |||||||||
| 72 | 1 | foreach my $store ($self->_stores) { | |||||||||
| 73 | 2 | $store->remove_statement( @_ ); | |||||||||
| 74 | } | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | =item C<< remove_statements ( $subject, $predicate, $object [, $context]) >> | ||||||||||
| 78 | |||||||||||
| 79 | Removes all statements matching the supplied C<$statement> pattern from all of the rdf stores. | ||||||||||
| 80 | |||||||||||
| 81 | =cut | ||||||||||
| 82 | |||||||||||
| 83 | 1 | ▶ | sub remove_statements { | ||||||||
|
Subroutine
remove_statements: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 84 | 1 | my $self = shift; | |||||||||
| 85 | 1 | foreach my $store ($self->_stores) { | |||||||||
| 86 | 2 | $store->remove_statements( @_ ); | |||||||||
| 87 | } | ||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | =item C<< count_statements ($subject, $predicate, $object) >> | ||||||||||
| 91 | |||||||||||
| 92 | Returns a count of all the statements matching the specified subject, | ||||||||||
| 93 | predicate and objects. Any of the arguments may be undef to match any value. | ||||||||||
| 94 | |||||||||||
| 95 | =cut | ||||||||||
| 96 | |||||||||||
| 97 | 1 | ▶ | sub count_statements { | ||||||||
|
Subroutine
count_statements: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 98 | 1 | my $self = shift; | |||||||||
| 99 | 1 | my $count = 0; | |||||||||
| 100 | 1 | foreach my $store ($self->_stores) { | |||||||||
| 101 | 2 | $count += $store->count_statements( @_ ); | |||||||||
| 102 | } | ||||||||||
| 103 | 1 | return $count; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | =item C<< get_statements ($subject, $predicate, $object [, $context] ) >> | ||||||||||
| 107 | |||||||||||
| 108 | Returns a stream object of all statements matching the specified subject, | ||||||||||
| 109 | predicate and objects from all of the rdf stores. Any of the arguments may be | ||||||||||
| 110 | undef to match any value. | ||||||||||
| 111 | |||||||||||
| 112 | =cut | ||||||||||
| 113 | |||||||||||
| 114 | 5 | ▶ | sub get_statements { | ||||||||
|
Subroutine
get_statements: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 115 | 5 | my $self = shift; | |||||||||
| 116 | 5 | my @iterators; | |||||||||
| 117 | 5 | foreach my $store ($self->_stores) { | |||||||||
| 118 | 10 | my $i = $store->get_statements( @_ ); | |||||||||
| 119 | 10 | push(@iterators, $i); | |||||||||
| 120 | # my @data; | ||||||||||
| 121 | # while (my $d = $i->next) { | ||||||||||
| 122 | # warn '++++++++++++++++++ ' . $d->as_string; | ||||||||||
| 123 | # | ||||||||||
| 124 | # } | ||||||||||
| 125 | # | ||||||||||
| 126 | # my $m = $i->materialize; | ||||||||||
| 127 | # push(@iterators, $m); | ||||||||||
| 128 | } | ||||||||||
| 129 | 5 | ▶ | while (@iterators > 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | 5 | my $i = shift(@iterators); | |||||||||
| 131 | 5 | my $j = shift(@iterators); | |||||||||
| 132 | 5 | unshift(@iterators, $i->concat( $j )); | |||||||||
| 133 | } | ||||||||||
| 134 | 5 | return $iterators[0]->unique; | |||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | # =item C<< get_pattern ( $bgp [, $context] ) >> | ||||||||||
| 138 | # | ||||||||||
| 139 | # Returns a stream object of all bindings matching the specified graph pattern. | ||||||||||
| 140 | # | ||||||||||
| 141 | # =cut | ||||||||||
| 142 | # | ||||||||||
| 143 | # sub get_pattern { | ||||||||||
| 144 | # my $self = shift; | ||||||||||
| 145 | # my @iterators; | ||||||||||
| 146 | # foreach my $store ($self->_stores) { | ||||||||||
| 147 | # push(@iterators, $store->get_pattern( @_ )); | ||||||||||
| 148 | # } | ||||||||||
| 149 | # while (@iterators > 1) { | ||||||||||
| 150 | # my $i = shift(@iterators); | ||||||||||
| 151 | # my $j = shift(@iterators); | ||||||||||
| 152 | # unshift(@iterators, $i->concat( $j )); | ||||||||||
| 153 | # } | ||||||||||
| 154 | # return $iterators[0]; | ||||||||||
| 155 | # } | ||||||||||
| 156 | |||||||||||
| 157 | 9 | ▶ | sub _stores { | ||||||||
|
Subroutine
_stores: called CC=1 SCAR=0.0
| |||||||||||
| 158 | 9 | my $self = shift; | |||||||||
| 159 | 9 | return @{ $self->{stores} }; | |||||||||
| 160 | } | ||||||||||
| 161 | |||||||||||
| 162 | 7 | ▶ | sub _store { | ||||||||
|
Subroutine
_store: called CC=1 SCAR=0.0
| |||||||||||
| 163 | 7 | my $self = shift; | |||||||||
| 164 | 7 | return; | |||||||||
| 165 | } | ||||||||||
| 166 | |||||||||||
| 167 | 1 | 1; | |||||||||
| 168 | |||||||||||
| 169 | __END__ | ||||||||||