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 ‘name` to the given `value`.
-
#bound?(name) ⇒ Boolean
Returns ‘true` if the variable `name` is bound in this solution.
-
#compatible?(other) ⇒ Boolean
Compatible Mappings.
-
#disjoint?(other) ⇒ Boolean
Disjoint mapping.
-
#dup ⇒ RDF::Statement
Duplicate solution, preserving patterns.
-
#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 ‘true` if this solution contains bindings for any of the given `variables`.
-
#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 u1 and u2 are isomorphic if, for every variable v in dom(u1) and in dom(u2), u1(v) = u2(v).
-
#merge(other) ⇒ RDF::Query::Solution
Merges the bindings from the given ‘other` query solution with a copy of this one.
-
#merge!(other) ⇒ void
Merges the bindings from the given ‘other` query 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 ‘true` if the variable `name` is unbound in this solution.
Methods included from Enumerable
#dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_term, #each_triple, #enum_for, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph_names, #has_graph?, #has_object?, #has_predicate?, #has_quad?, #has_statement?, #has_subject?, #has_term?, #has_triple?, #invalid?, #objects, #predicates, #project_graph, #quads, #statements, #subjects, #supports?, #terms, #to_set, #triples, #valid?, #validate!
Methods included from Util::Aliasing::LateBound
Methods included from Countable
Constructor Details
#initialize(bindings = {}) {|solution| ... } ⇒ Solution
Initializes the query solution.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rdf/query/solution.rb', line 38 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)
269 270 271 272 273 274 275 |
# File 'lib/rdf/query/solution.rb', line 269 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)
50 51 52 |
# File 'lib/rdf/query/solution.rb', line 50 def bindings @bindings end |
Instance Method Details
#[](name) ⇒ RDF::Term
Returns the value of the variable ‘name`.
135 136 137 |
# File 'lib/rdf/query/solution.rb', line 135 def [](name) @bindings[name.to_sym] end |
#[]=(name, value) ⇒ RDF::Term
Binds or rebinds the variable ‘name` to the given `value`.
147 148 149 |
# File 'lib/rdf/query/solution.rb', line 147 def []=(name, value) @bindings[name.to_sym] = value.is_a?(RDF::Term) ? value : RDF::Literal(value) end |
#bound?(name) ⇒ Boolean
Returns ‘true` if the variable `name` is bound in this solution.
115 116 117 |
# File 'lib/rdf/query/solution.rb', line 115 def bound?(name) !unbound?(name) end |
#compatible?(other) ⇒ Boolean
Compatible Mappings
Two solution mappings u1 and u2 are compatible if, for every variable v in dom(u1) and in dom(u2), u1(v) = u2(v).
192 193 194 195 196 |
# File 'lib/rdf/query/solution.rb', line 192 def compatible?(other) @bindings.all? do |k, v| !other.to_hash.has_key?(k) || other[k].eql?(v) end end |
#disjoint?(other) ⇒ Boolean
Disjoint mapping
A solution is disjoint with another solution if it shares no common variables in their domains.
206 207 208 209 210 |
# File 'lib/rdf/query/solution.rb', line 206 def disjoint?(other) @bindings.none? do |k, v| v && other.to_hash.has_key?(k) && other[k].eql?(v) end end |
#dup ⇒ RDF::Statement
Duplicate solution, preserving patterns
179 180 181 |
# File 'lib/rdf/query/solution.rb', line 179 def dup merge({}) end |
#each_binding {|name, value| ... } ⇒ Enumerator Also known as: each
Enumerates over every variable binding in this solution.
59 60 61 |
# File 'lib/rdf/query/solution.rb', line 59 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.
70 71 72 |
# File 'lib/rdf/query/solution.rb', line 70 def each_name(&block) @bindings.each_key(&block) end |
#each_value {|value| ... } ⇒ Enumerator
Enumerates over every variable value in this solution.
81 82 83 |
# File 'lib/rdf/query/solution.rb', line 81 def each_value(&block) @bindings.each_value(&block) end |
#each_variable {|variable| ... } ⇒ Enumerator
Enumerates over every variable in this solution.
103 104 105 106 107 |
# File 'lib/rdf/query/solution.rb', line 103 def each_variable @bindings.each do |name, value| yield Variable.new(name, value) end end |
#eql?(other) ⇒ Boolean Also known as: ==
Equivalence of solution
247 248 249 |
# File 'lib/rdf/query/solution.rb', line 247 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`.
93 94 95 |
# File 'lib/rdf/query/solution.rb', line 93 def has_variables?(variables) variables.any? { |variable| bound?(variable) } end |
#hash ⇒ Integer
Integer hash of this solution
241 242 243 |
# File 'lib/rdf/query/solution.rb', line 241 def hash @bindings.hash end |
#inspect ⇒ String
260 261 262 |
# File 'lib/rdf/query/solution.rb', line 260 def inspect sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, @bindings.inspect) end |
#isomorphic_with?(other) ⇒ Boolean
Isomorphic Mappings Two solution mappings u1 and u2 are isomorphic if, for every variable v in dom(u1) and in dom(u2), u1(v) = u2(v).
220 221 222 223 224 |
# File 'lib/rdf/query/solution.rb', line 220 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.
172 173 174 |
# File 'lib/rdf/query/solution.rb', line 172 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.
159 160 161 162 |
# File 'lib/rdf/query/solution.rb', line 159 def merge!(other) @bindings.merge!(other.to_hash) self end |
#to_a ⇒ Array<Array(Symbol, RDF::Term)>
228 229 230 |
# File 'lib/rdf/query/solution.rb', line 228 def to_a @bindings.to_a end |
#to_hash ⇒ Hash{Symbol => RDF::Term}
234 235 236 |
# File 'lib/rdf/query/solution.rb', line 234 def to_hash @bindings.dup end |
#unbound?(name) ⇒ Boolean
Returns ‘true` if the variable `name` is unbound in this solution.
125 126 127 |
# File 'lib/rdf/query/solution.rb', line 125 def unbound?(name) @bindings[name.to_sym].nil? end |