Class: RDF::Query::Solution
- Inherits:
-
Object
- Object
- RDF::Query::Solution
- Includes:
- Enumerable
- Defined in:
- lib/rdf/query/solution.rb
Overview
An RDF query solution.
Instance Attribute Summary collapse
- #bindings ⇒ Object readonly
Instance Method Summary collapse
-
#[](name) ⇒ RDF::Term
Returns the value of the variable
name. -
#[]=(name, value) ⇒ RDF::Term
Binds or rebinds the variable
nameto the givenvalue. -
#bound?(name) ⇒ Boolean
Returns
trueif the variablenameis bound in this solution. -
#compatible?(other) ⇒ Boolean
Compatible Mappings Two solution mappings μ1 and μ2 are compatible if, for every variable v in dom(μ1) and in dom(μ2), μ1(v) = μ2(v).
-
#each_binding {|name, value| ... } ⇒ Enumerator
(also: #each)
Enumerates over every variable binding in this solution.
-
#each_name {|name| ... } ⇒ Enumerator
(also: #each_key)
Enumerates over every variable name in this solution.
-
#each_value {|value| ... } ⇒ Enumerator
Enumerates over every variable value in this solution.
-
#each_variable {|variable| ... } ⇒ Enumerator
Enumerates over every variable in this solution.
-
#eql?(other) ⇒ Boolean
(also: #==)
Equivalence of solution.
-
#has_variables?(variables) ⇒ Boolean
Returns
trueif this solution contains bindings for any of the givenvariables. -
#hash ⇒ Integer
Integer hash of this solution.
-
#initialize(bindings = {}) {|solution| ... } ⇒ Solution
constructor
Initializes the query solution.
- #inspect ⇒ String
-
#isomorphic_with?(other) ⇒ Boolean
Isomorphic Mappings Two solution mappings μ1 and μ2 are isomorphic if, for every variable v in dom(μ1) and in dom(μ2), μ1(v) = μ2(v).
-
#merge(other) ⇒ RDF::Query::Solution
Merges the bindings from the given
otherquery solution with a copy of this one. -
#merge!(other) ⇒ void
Merges the bindings from the given
otherquery solution into this one, overwriting any existing ones having the same name. - #to_a ⇒ Array<Array(Symbol, RDF::Term)>
- #to_hash ⇒ Hash{Symbol => RDF::Term}
-
#unbound?(name) ⇒ Boolean
Returns
trueif the variablenameis unbound in this solution.
Methods included from Enumerable
#contexts, #dump, #each_context, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_triple, #enum_context, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_triple, #has_context?, #has_object?, #has_predicate?, #has_quad?, #has_statement?, #has_subject?, #has_triple?, #objects, #predicates, #quads, #statements, #subjects, #supports?, #to_set, #triples
Methods included from Util::Aliasing::LateBound
Methods included from Countable
Constructor Details
#initialize(bindings = {}) {|solution| ... } ⇒ Solution
Initializes the query solution.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rdf/query/solution.rb', line 36 def initialize(bindings = {}, &block) @bindings = bindings.to_hash if block_given? case block.arity when 1 then block.call(self) else instance_eval(&block) end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ RDF::Term (protected)
244 245 246 247 248 249 250 |
# File 'lib/rdf/query/solution.rb', line 244 def method_missing(name, *args, &block) if args.empty? && @bindings.has_key?(name.to_sym) @bindings[name.to_sym] else super # raises NoMethodError end end |
Instance Attribute Details
#bindings ⇒ Object (readonly)
48 49 50 |
# File 'lib/rdf/query/solution.rb', line 48 def bindings @bindings end |
Instance Method Details
#[](name) ⇒ RDF::Term
Returns the value of the variable name.
133 134 135 |
# File 'lib/rdf/query/solution.rb', line 133 def [](name) @bindings[name.to_sym] end |
#[]=(name, value) ⇒ RDF::Term
Binds or rebinds the variable name to the given value.
145 146 147 |
# File 'lib/rdf/query/solution.rb', line 145 def []=(name, value) @bindings[name.to_sym] = value end |
#bound?(name) ⇒ Boolean
Returns true if the variable name is bound in this solution.
113 114 115 |
# File 'lib/rdf/query/solution.rb', line 113 def bound?(name) !unbound?(name) end |
#compatible?(other) ⇒ Boolean
Compatible Mappings Two solution mappings μ1 and μ2 are compatible if, for every variable v in dom(μ1) and in dom(μ2), μ1(v) = μ2(v).
181 182 183 184 185 |
# File 'lib/rdf/query/solution.rb', line 181 def compatible?(other) @bindings.all? do |k, v| !other.to_hash.has_key?(k) || other[k].eql?(v) end end |
#each_binding {|name, value| ... } ⇒ Enumerator Also known as: each
Enumerates over every variable binding in this solution.
57 58 59 |
# File 'lib/rdf/query/solution.rb', line 57 def each_binding(&block) @bindings.each(&block) end |
#each_name {|name| ... } ⇒ Enumerator Also known as: each_key
Enumerates over every variable name in this solution.
68 69 70 |
# File 'lib/rdf/query/solution.rb', line 68 def each_name(&block) @bindings.each_key(&block) end |
#each_value {|value| ... } ⇒ Enumerator
Enumerates over every variable value in this solution.
79 80 81 |
# File 'lib/rdf/query/solution.rb', line 79 def each_value(&block) @bindings.each_value(&block) end |
#each_variable {|variable| ... } ⇒ Enumerator
Enumerates over every variable in this solution.
101 102 103 104 105 |
# File 'lib/rdf/query/solution.rb', line 101 def each_variable(&block) @bindings.each do |name, value| block.call(Variable.new(name, value)) end end |
#eql?(other) ⇒ Boolean Also known as: ==
Equivalence of solution
222 223 224 |
# File 'lib/rdf/query/solution.rb', line 222 def eql?(other) other.is_a?(Solution) && @bindings.eql?(other.bindings) end |
#has_variables?(variables) ⇒ Boolean
Returns true if this solution contains bindings for any of the given
variables.
91 92 93 |
# File 'lib/rdf/query/solution.rb', line 91 def has_variables?(variables) variables.any? { |variable| bound?(variable) } end |
#hash ⇒ Integer
Integer hash of this solution
216 217 218 |
# File 'lib/rdf/query/solution.rb', line 216 def hash @bindings.hash end |
#inspect ⇒ String
235 236 237 |
# File 'lib/rdf/query/solution.rb', line 235 def inspect sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, @bindings.inspect) end |
#isomorphic_with?(other) ⇒ Boolean
Isomorphic Mappings Two solution mappings μ1 and μ2 are isomorphic if, for every variable v in dom(μ1) and in dom(μ2), μ1(v) = μ2(v).
195 196 197 198 199 |
# File 'lib/rdf/query/solution.rb', line 195 def isomorphic_with?(other) @bindings.all? do |k, v| !other.to_hash.has_key?(k) || other[k].eql?(v) end end |
#merge(other) ⇒ RDF::Query::Solution
Merges the bindings from the given other query solution with a copy
of this one.
170 171 172 |
# File 'lib/rdf/query/solution.rb', line 170 def merge(other) self.class.new(@bindings.dup).merge!(other) end |
#merge!(other) ⇒ void
This method returns an undefined value.
Merges the bindings from the given other query solution into this
one, overwriting any existing ones having the same name.
157 158 159 160 |
# File 'lib/rdf/query/solution.rb', line 157 def merge!(other) @bindings.merge!(other.to_hash) self end |
#to_a ⇒ Array<Array(Symbol, RDF::Term)>
203 204 205 |
# File 'lib/rdf/query/solution.rb', line 203 def to_a @bindings.to_a end |
#to_hash ⇒ Hash{Symbol => RDF::Term}
209 210 211 |
# File 'lib/rdf/query/solution.rb', line 209 def to_hash @bindings.dup end |
#unbound?(name) ⇒ Boolean
Returns true if the variable name is unbound in this solution.
123 124 125 |
# File 'lib/rdf/query/solution.rb', line 123 def unbound?(name) @bindings[name.to_sym].nil? end |