RDF::Trine::Model::Union - Union models for joining multiple stores together


RDF-Trine documentation Contained in the RDF-Trine distribution.

Index


Code Index:

NAME

Top

RDF::Trine::Model::Union - Union models for joining multiple stores together

VERSION

Top

This document describes RDF::Trine::Model::Union version 0.135

METHODS

Top

Beyond the methods documented below, this class inherits methods from the RDF::Trine::Model class.

new ( @stores )

Returns a new union-model over the list of supplied rdf stores.

add_statement ( $statement [, $context] )

Adds the specified $statement to the first rdf store.

remove_statement ( $statement [, $context])

Removes the specified $statement from all of the rdf stores.

remove_statements ( $subject, $predicate, $object [, $context])

Removes all statements matching the supplied $statement pattern from all of the rdf stores.

count_statements ($subject, $predicate, $object)

Returns a count of all the statements matching the specified subject, predicate and objects. Any of the arguments may be undef to match any value.

get_statements ($subject, $predicate, $object [, $context] )

Returns a stream object of all statements matching the specified subject, predicate and objects from all of the rdf stores. Any of the arguments may be undef to match any value.

AUTHOR

Top

Gregory Todd Williams <gwilliams@cpan.org>

COPYRIGHT

Top


RDF-Trine documentation Contained in the RDF-Trine distribution.
# RDF::Trine::Model::Union
# -----------------------------------------------------------------------------

package RDF::Trine::Model::Union;

use strict;
use warnings;
no warnings 'redefine';
use base qw(RDF::Trine::Model);
use Scalar::Util qw(blessed);

use RDF::Trine::Node;
use RDF::Trine::Store::DBI;

our ($VERSION);
BEGIN {
	$VERSION	= '0.135';
}

################################################################################

sub new {
	my $class	= shift;
	my @stores	= @_;
	my $self	= bless({ stores => \@stores }, $class);
}

sub add_statement {
	my $self	= shift;
	my @iterators;
	my ($store)	= $self->_stores;
	$store->add_statement( @_ );
}

sub remove_statement {
	my $self	= shift;
	foreach my $store ($self->_stores) {
		$store->remove_statement( @_ );
	}
}

sub remove_statements {
	my $self	= shift;
	foreach my $store ($self->_stores) {
		$store->remove_statements( @_ );
	}
}

sub count_statements {
	my $self	= shift;
	my $count	= 0;
	foreach my $store ($self->_stores) {
		$count	+= $store->count_statements( @_ );
	}
	return $count;
}

sub get_statements {
	my $self	= shift;
	my @iterators;
	foreach my $store ($self->_stores) {
		my $i	= $store->get_statements( @_ );
		push(@iterators, $i);
# 		my @data;
# 		while (my $d = $i->next) {
# 			warn '++++++++++++++++++ ' . $d->as_string;
# 			
# 		}
# 		
# 		my $m	= $i->materialize;
# 		push(@iterators, $m);
	}
	while (@iterators > 1) {
		my $i	= shift(@iterators);
		my $j	= shift(@iterators);
		unshift(@iterators, $i->concat( $j ));
	}
	return $iterators[0]->unique;
}

# =item C<< get_pattern ( $bgp [, $context] ) >>
# 
# Returns a stream object of all bindings matching the specified graph pattern.
# 
# =cut
# 
# sub get_pattern {
# 	my $self	= shift;
# 	my @iterators;
# 	foreach my $store ($self->_stores) {
# 		push(@iterators, $store->get_pattern( @_ ));
# 	}
# 	while (@iterators > 1) {
# 		my $i	= shift(@iterators);
# 		my $j	= shift(@iterators);
# 		unshift(@iterators, $i->concat( $j ));
# 	}
# 	return $iterators[0];
# }

sub _stores {
	my $self	= shift;
	return @{ $self->{stores} };
}

sub _store {
	my $self	= shift;
	return;
}

1;

__END__