Class: SPARQL::Algebra::Operator::Table
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::Table
- Includes:
- Query
- Defined in:
- lib/sparql/algebra/operator/table.rb
Overview
The SPARQL Table operator.
This is used to provide inline values. Each row becomes a solution.
[28] ValuesClause ::= ( ‘VALUES’ DataBlock )?
[61] InlineData ::= ‘VALUES’ DataBlock
Constant Summary collapse
- NAME =
[:table]
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Instance Attribute Summary
Attributes included from Query
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#execute(queryable, **options) {|solution| ... } ⇒ RDF::Query::Solutions
Returns solutions for each row.
-
#to_sparql(top_level: true, **options) ⇒ String
Returns a partial SPARQL grammar for this operator.
-
#variables ⇒ Hash{Symbol => RDF::Query::Variable}
In-scope variables for a table are the variables operand.
Methods included from Query
#each_solution, #empty?, #failed?, #graph_name=, #matched?, #query_yields_boolean?, #query_yields_solutions?, #query_yields_statements?, #unshift
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=, #rewrite, #to_binary, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars
Methods included from Expression
cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?
Constructor Details
This class inherits a constructor from SPARQL::Algebra::Operator
Instance Method Details
#execute(queryable, **options) {|solution| ... } ⇒ RDF::Query::Solutions
Returns solutions for each row
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/sparql/algebra/operator/table.rb', line 82 def execute(queryable, **, &block) @solutions = RDF::Query::Solutions() Array(operands[1..-1]).each do |row| next unless row.is_a?(Array) bindings = row[1..-1].inject({}) do |memo, (var, value)| memo[var.to_sym] = value unless value == :undef memo end @solutions << RDF::Query::Solution.new(bindings) end @solutions.variable_names = self.variables.keys @solutions.each(&block) if block_given? @solutions end |
#to_sparql(top_level: true, **options) ⇒ String
Returns a partial SPARQL grammar for this operator.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/sparql/algebra/operator/table.rb', line 113 def to_sparql(top_level: true, **) str = "VALUES (#{Array(operands.first)[1..-1].map { |e| e.to_sparql(**) }.join(' ')}) {\n" operands[1..-1].each do |row| line = '(' row[1..-1].each do |col| v = col[1].to_sparql(**) line << v + ' ' end line = line.chomp(' ') line << ")\n" str << line end str << "}\n" top_level ? Operator.to_sparql(str, **) : str end |
#variables ⇒ Hash{Symbol => RDF::Query::Variable}
In-scope variables for a table are the variables operand
101 102 103 104 |
# File 'lib/sparql/algebra/operator/table.rb', line 101 def variables in_scope = operands.first.is_a?(Array) ? operands.first[1..-1] : [] in_scope.inject({}) {|memo, v| memo.merge(v.variables)} end |