Class: SPARQL::Algebra::Operator::Construct
- Inherits:
-
Binary
- Object
- SPARQL::Algebra::Operator
- Binary
- SPARQL::Algebra::Operator::Construct
- Includes:
- Query
- Defined in:
- lib/sparql/algebra/operator/construct.rb
Overview
The SPARQL GraphPattern construct operator.
Constant Summary
- NAME =
[:construct]
Constants inherited from Binary
Constants inherited from SPARQL::Algebra::Operator
Instance Attribute Summary
Attributes included from Query
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary (collapse)
-
- (RDF::Query::Solutions) execute(queryable, options = {})
Executes this query on the given RDF::Queryable object.
-
- (Union, RDF::Query) optimize
Returns an optimized version of this query.
Methods included from Query
#context=, #each_solution, #failed?, #matched?, #unshift, #variables
Methods inherited from Binary
Methods inherited from SPARQL::Algebra::Operator
arity, base_uri, #base_uri, base_uri=, #boolean, #constant?, #eql?, #evaluatable?, evaluate, #executable?, for, #initialize, #inspect, #operand, prefixes, #prefixes, prefixes=, #to_sse, #to_sxp, #variable?
Methods included from Evaluatable
Methods included from Expression
cast, #constant?, #evaluate, for, new, open, parse, #to_sse, #variable?
Constructor Details
This class inherits a constructor from SPARQL::Algebra::Operator::Binary
Instance Method Details
- (RDF::Query::Solutions) execute(queryable, options = {})
Executes this query on the given RDF::Queryable object. Binds variables to the array of patterns in the first operand and returns the resulting RDF::Graph object
If any such instantiation produces a triple containing an unbound variable or an illegal RDF construct, such as an RDF::Literal in subject or predicate position, then that triple is not included in the output RDF graph. The graph template can contain triples with no variables (known as ground or explicit triples), and these also appear in the output RDF graph returned by the CONSTRUCT query form.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sparql/algebra/operator/construct.rb', line 35 def execute(queryable, = {}) debug("Construct #{operands.first}, #{.inspect}", ) graph = RDF::Graph.new patterns = operands.first query = operands.last query.execute(queryable, .merge(:depth => [:depth].to_i + 1)).each do |solution| debug("=> Apply #{solution.inspect} to BGP", ) # Create a mapping from BNodes within the pattern list to newly constructed BNodes nodes = {} patterns.each do |pattern| terms = {} [:subject, :predicate, :object].each do |r| terms[r] = case o = pattern.send(r) when RDF::Node then nodes[o] ||= RDF::Node.new when RDF::Query::Variable then solution[o] else o end end statement = RDF::Statement.from(terms) # Sanity checking on statement if statement.subject.nil? || statement.predicate.nil? || statement.object.nil? || statement.subject.literal? || statement.predicate.literal? debug("==> skip #{statement.inspect}", ) next end debug("==> add #{statement.inspect}", ) graph << statement end end debug("=> #{graph.dump(:n3)}", ) graph end |
- (Union, RDF::Query) optimize
Returns an optimized version of this query.
Return optimized query
80 81 82 |
# File 'lib/sparql/algebra/operator/construct.rb', line 80 def optimize operands = operands.map(&:optimize) end |