Class: SPARQL::Algebra::Operator::Graph
- Inherits:
-
Binary
- Object
- SPARQL::Algebra::Operator
- Binary
- SPARQL::Algebra::Operator::Graph
- Includes:
- Query
- Defined in:
- 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.
[58] GraphGraphPattern ::= ‘GRAPH’ VarOrIri GroupGraphPattern
Constant Summary collapse
- NAME =
[:graph]
Constants inherited from Binary
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Instance Attribute Summary
Attributes included from Query
Attributes inherited from SPARQL::Algebra::Operator
Class Method Summary collapse
-
.new(name, patterns, **options, &block) ⇒ RDF::Query
A
graph
is an RDF::Query with a graph_name.
Instance Method Summary collapse
-
#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. -
#rewrite(&block) ⇒ SPARQL::Algebra::Expression
Don’t do any more rewriting.
-
#to_sparql(top_level: true, **options) ⇒ String
Returns a partial SPARQL grammar for this operator.
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
Methods inherited from SPARQL::Algebra::Operator
#aggregate?, arity, #base_uri, base_uri, base_uri=, #bind, #boolean, #constant?, #deep_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_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars
Methods included from Expression
cast, #constant?, #evaluate, extension, 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)
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/sparql/algebra/operator/graph.rb', line 87 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
.
115 116 117 118 119 |
# File 'lib/sparql/algebra/operator/graph.rb', line 115 def execute(queryable, **, &block) debug() {"Graph #{operands.first}"} graph_name, query = operands.first, operands.last @solutions = queryable.query(query, graph_name: graph_name, **, &block) end |
#rewrite(&block) ⇒ SPARQL::Algebra::Expression
Don’t do any more rewriting
124 125 126 |
# File 'lib/sparql/algebra/operator/graph.rb', line 124 def rewrite(&block) self end |
#to_sparql(top_level: true, **options) ⇒ String
Returns a partial SPARQL grammar for this operator.
135 136 137 138 139 140 141 |
# File 'lib/sparql/algebra/operator/graph.rb', line 135 def to_sparql(top_level: true, **) query = operands.last.to_sparql(top_level: false, **) # Paths don't automatically get braces. query = "{\n#{query}\n}" unless query.start_with?('{') str = "GRAPH #{operands.first.to_sparql(**)} " + query top_level ? Operator.to_sparql(str, **) : str end |