Class: SPARQL::Algebra::Operator::Graph

Inherits:
Binary show all
Includes:
Query
Defined in:
vendor/bundler/ruby/2.7.0/bundler/gems/sparql-cd4915d97d78/lib/sparql/algebra/operator/graph.rb

Overview

The SPARQL GraphPattern graph operator.

This is a wrapper to add a graph_name to the query, or an array of statements.

Examples:

of a query

(prefix ((: <http://example/>))
  (graph ?g
    (bgp (triple ?s ?p ?o))))

named set of statements

(prefix ((: <http://example/>))
  (graph :g
    ((triple :s :p :o))))

See Also:

Constant Summary collapse

NAME =
[:graph]

Constants inherited from Binary

Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Instance Attribute Summary

Attributes included from Query

#solutions

Attributes inherited from SPARQL::Algebra::Operator

#operands

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Query

#each_solution, #empty?, #failed?, #graph_name=, #matched?, #query_yields_boolean?, #query_yields_solutions?, #query_yields_statements?, #unshift, #variables

Methods inherited from Binary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, #base_uri, base_uri, base_uri=, #bind, #boolean, #constant?, #dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, prefixes, #prefixes, prefixes=, #to_binary, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Binary

Class Method Details

.self.new(name, bgp) ⇒ RDF::Query .self.new(name, bgp) ⇒ RDF::Query .self.new(name, patterns) ⇒ RDF::Query

A graph is an RDF::Query with a graph_name. It can also be used as a container of statements or patterns, or other queryable operators (see GraphGraphPattern)

Overloads:

Returns:



39
40
41
42
43
44
45
46
47
48
49
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/sparql-cd4915d97d78/lib/sparql/algebra/operator/graph.rb', line 39

def self.new(name, patterns, &block)
  case patterns
  when RDF::Query
    # Record that the argument as a (bgp) for re-serialization back to SSE
    RDF::Query.new(*patterns.patterns, graph_name: name, &block)
  when Operator
    super
  else
    RDF::Query.new(*patterns, graph_name: name, as_container: true, &block)
  end
end

Instance Method Details

#execute(queryable, **options) {|solution| ... } ⇒ RDF::Query::Solutions

If the second operand is a Query operator: Executes this query on the given queryable graph or repository. Applies the given graph_name to the query, limiting the scope of the query to the specified graph, which may be an RDF::URI or RDF::Query::Variable.

Parameters:

Yields:

  • (solution)

    each matching solution

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Returns:

See Also:



67
68
69
70
71
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/sparql-cd4915d97d78/lib/sparql/algebra/operator/graph.rb', line 67

def execute(queryable, **options, &block)
  debug(options) {"Graph #{operands.first}"}
  graph_name, query = operands.first, operands.last
  @solutions = queryable.query(query, graph_name: graph_name, **options, &block)
end

#rewrite(&block) ⇒ SPARQL::Algebra::Expression

Don't do any more rewriting

Returns:



76
77
78
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/sparql-cd4915d97d78/lib/sparql/algebra/operator/graph.rb', line 76

def rewrite(&block)
  self
end