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

Inherits:
Binary show all
Includes:
Query
Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/sparql-e0a915196943/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

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=, #boolean, #constant?, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #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, 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.4.0/bundler/gems/sparql-e0a915196943/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:

  • queryable (RDF::Queryable)

    the graph or repository to query

  • options (Hash{Symbol => Object}) (defaults to: {})

    any additional keyword options

Yields:

  • (solution)

    each matching solution

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Returns:

See Also:



67
68
69
70
71
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/sparql-e0a915196943/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, options.merge(graph_name: graph_name), &block)
end

#optimizeUnion, RDF::Query

Returns an optimized version of this query.

Return optimized query

Returns:



79
80
81
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/sparql-e0a915196943/lib/sparql/algebra/operator/graph.rb', line 79

def optimize
  operands = operands.map(&:optimize)
end

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

Don't do any more rewriting FIXME: if ooperator is JOIN, and rewritten sub-operators are queries, can do simple merge of sub-graphs

Returns:



87
88
89
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/sparql-e0a915196943/lib/sparql/algebra/operator/graph.rb', line 87

def rewrite(&block)
  self
end