| RDF-Query documentation | Contained in the RDF-Query distribution. |
RDF::Query::Algebra::GroupGraphPattern - Algebra class for GroupGraphPattern patterns
This document describes RDF::Query::Algebra::GroupGraphPattern version 2.907.
Beyond the methods documented below, this class inherits methods from the RDF::Query::Algebra class.
new ( @graph_patterns )Returns a new GroupGraphPattern structure.
construct_argsReturns a list of arguments that, passed to this class' constructor, will produce a clone of this algebra pattern.
patternsReturns a list of the graph patterns in this GGP.
add_patternAppends a new child pattern to the GGP.
quadsReturns a list of the quads belonging to this GGP.
sseReturns the SSE string for this algebra expression.
explainReturns a string serialization of the algebra appropriate for display on the command line.
as_sparqlReturns the SPARQL string for this algebra expression.
as_hashReturns the query as a nested set of plain data structures (no objects).
as_spin ( $model )Adds statements to the given model to represent this algebra object in the SPARQL Inferencing Notation (http://www.spinrdf.org/).
typeReturns the type of this algebra expression.
referenced_variablesReturns a list of the variable names used in this algebra expression.
potentially_boundReturns a list of the variable names used in this algebra expression that will bind values during execution.
definite_variablesReturns a list of the variable names that will be bound after evaluating this algebra expression.
Gregory Todd Williams <gwilliams@cpan.org>
| RDF-Query documentation | Contained in the RDF-Query distribution. |
# RDF::Query::Algebra::GroupGraphPattern # -----------------------------------------------------------------------------
package RDF::Query::Algebra::GroupGraphPattern; use strict; use warnings; no warnings 'redefine'; use base qw(RDF::Query::Algebra); use Log::Log4perl; use Scalar::Util qw(blessed refaddr); use Data::Dumper; use List::Util qw(first); use Carp qw(carp croak confess); use RDF::Query::Error qw(:try); use Time::HiRes qw(gettimeofday tv_interval); use RDF::Trine::Iterator qw(sgrep smap swatch); ###################################################################### our ($VERSION, $debug); BEGIN { $debug = 0; $VERSION = '2.907'; our %SERVICE_BLOOM_IGNORE = ('http://dbpedia.org/sparql' => 1); # by default, assume dbpedia doesn't implement k:bloom(). } ######################################################################
sub new { my $class = shift; my @patterns = @_; my $self = bless( \@patterns, $class ); foreach my $p (@patterns) { unless (blessed($p)) { Carp::cluck; throw RDF::Query::Error::MethodInvocationError -text => "GroupGraphPattern constructor called with unblessed value"; } } return $self; }
sub construct_args { my $self = shift; return ($self->patterns); }
sub patterns { my $self = shift; return @{ $self }; }
sub add_pattern { my $self = shift; my $pattern = shift; push( @{ $self }, $pattern ); }
sub quads { my $self = shift; my @quads; my %bgps; foreach my $p ($self->subpatterns_of_type('RDF::Query::Algebra::NamedGraph')) { push(@quads, $p->quads); foreach my $bgp ($p->subpatterns_of_type('RDF::Query::Algebra::BasicGraphPattern')) { $bgps{ refaddr($bgp) }++; } } foreach my $p ($self->subpatterns_of_type('RDF::Query::Algebra::BasicGraphPattern')) { next if ($bgps{ refaddr($p) }); push(@quads, $p->quads); } return @quads; }
sub sse { my $self = shift; my $context = shift; my $prefix = shift || ''; my $indent = ($context->{indent} ||= "\t"); my @patterns = $self->patterns; if (scalar(@patterns) == 1) { return $patterns[0]->sse( $context, $prefix ); } else { return sprintf( "(join\n${prefix}${indent}%s)", join("\n${prefix}${indent}", map { $_->sse( $context, "${prefix}${indent}" ) } @patterns) ); } }
sub explain { my $self = shift; my $s = shift; my $count = shift; my $indent = $s x $count; my $string = "${indent}group graph pattern\n"; my @patterns = $self->patterns; if (scalar(@patterns) == 1) { $string .= $patterns[0]->explain( $s, $count+1 ); } else { foreach my $p (@patterns) { $string .= $p->explain( $s, $count+1 ); } } return $string; }
sub as_sparql { my $self = shift; my $context = shift || {}; my $indent = shift || ''; my $force = $context->{force_ggp_braces}; $force = 0 unless (defined($force)); if ($force) { $context->{force_ggp_braces}--; } my @patterns; my @p = $self->patterns; if (scalar(@p) == 0) { return "{}"; } elsif (scalar(@p) == 1 and not($force)) { return $p[0]->as_sparql($context, $indent); } else { foreach my $p (@p) { push(@patterns, $p->as_sparql( $context, "$indent\t" )); } my $patterns = join("\n${indent}\t", @patterns); my $string = sprintf("{\n${indent}\t%s\n${indent}}", $patterns); return $string; } }
sub as_hash { my $self = shift; my $context = shift; return { type => lc($self->type), patterns => [ map { $_->as_hash } $self->patterns ], }; }
sub as_spin { my $self = shift; my $model = shift; return map { $_->as_spin($model) } $self->patterns; }
sub type { return 'GGP'; }
sub referenced_variables { my $self = shift; return RDF::Query::_uniq(map { $_->referenced_variables } $self->patterns); }
sub potentially_bound { my $self = shift; return RDF::Query::_uniq(map { $_->potentially_bound } $self->patterns); }
sub definite_variables { my $self = shift; return RDF::Query::_uniq(map { $_->definite_variables } $self->patterns); } 1; __END__