Class: SPARQL::Algebra::Operator::BNode
- Inherits:
-
Unary
- Object
- SPARQL::Algebra::Operator
- Unary
- SPARQL::Algebra::Operator::BNode
- Includes:
- Evaluatable
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/bnode.rb
Overview
The SPARQL bnode
operator.
The BNODE function constructs a blank node that is distinct from all blank nodes in the dataset being queried and distinct from all blank nodes created by calls to this constructor for other query solutions. If the no argument form is used, every call results in a distinct blank node. If the form with a simple literal is used, every call results in distinct blank nodes for different simple literals, and the same blank node for calls with the same simple literal within expressions for one solution mapping.
[121] BuiltInCall ::= ... | 'BNODE' ( '(' Expression ')' | NIL )
Constant Summary collapse
- NAME =
:bnode
Constants inherited from Unary
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Constants included from RDF::Util::Logger
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#apply(literal, bindings, **options) ⇒ RDF::Node
The BNODE function constructs a blank node that is distinct from all blank nodes in the dataset being queried and distinct from all blank nodes created by calls to this constructor for other query solutions.
-
#evaluate(bindings, **options) ⇒ RDF::Term
Evaluates this operator using the given variable
bindings
. -
#initialize(literal = false, **options) ⇒ BNode
constructor
Initializes a new operator instance.
-
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
-
#to_sxp_bin ⇒ Array
Returns the SPARQL S-Expression (SSE) representation of this expression.
Methods included from Evaluatable
#memoize, #replace_aggregate!, #replace_vars!
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, #formulae, #inspect, #mergable?, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #validate!, #variable?, #variables, #vars
Methods included from Expression
cast, #constant?, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #valid?, #validate!, #variable?
Methods included from RDF::Util::Logger
#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger
Constructor Details
#initialize(literal = false, **options) ⇒ BNode
Initializes a new operator instance.
47 48 49 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/bnode.rb', line 47 def initialize(literal = false, **) super end |
Instance Method Details
#apply(literal, bindings, **options) ⇒ RDF::Node
The BNODE function constructs a blank node that is distinct from all blank nodes in the dataset being queried and distinct from all blank nodes created by calls to this constructor for other query solutions. If the no argument form is used, every call results in a distinct blank node. If the form with a simple literal is used, every call results in distinct blank nodes for different simple literals, and the same blank node for calls with the same simple literal within expressions for one solution mapping.
This functionality is compatible with the treatment of blank nodes in SPARQL CONSTRUCT templates.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/bnode.rb', line 74 def apply(literal, bindings, **) @@bnode_base ||= "b0" @@bindings ||= bindings @@bnodes ||= {} if literal == RDF::Literal::FALSE l, @@bnode_base = @@bnode_base, @@bnode_base.succ RDF::Node.new(l) else raise TypeError, "expected an simple literal, but got #{literal.inspect}" unless literal.literal? && literal.simple? # Return the same BNode if used with the same binding @@bnodes, @@bindings = {}, bindings unless @@bindings == bindings @@bnodes[literal.to_s.to_sym] ||= begin l, @@bnode_base = @@bnode_base, @@bnode_base.succ RDF::Node.new(l) end end end |
#evaluate(bindings, **options) ⇒ RDF::Term
Evaluates this operator using the given variable bindings
.
59 60 61 62 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/bnode.rb', line 59 def evaluate(bindings, **) args = operands.map { |operand| operand.evaluate(bindings, **.merge(depth: [:depth].to_i + 1)) } apply(args.first, bindings) end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
109 110 111 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/bnode.rb', line 109 def to_sparql(**) "BNODE(#{operands.last.to_sparql(**)})" end |
#to_sxp_bin ⇒ Array
Returns the SPARQL S-Expression (SSE) representation of this expression.
Remove the optional argument.
100 101 102 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/bnode.rb', line 100 def to_sxp_bin [NAME] + operands.reject {|o| o == false} end |