Class: Plumb::SemanticMatcher::FiniteSet

Inherits:
Node
  • Object
show all
Defined in:
lib/plumb/semantic_matcher.rb

Instance Attribute Summary

Attributes inherited from Node

#raw

Instance Method Summary collapse

Methods inherited from Node

#equivalent?, #error_message, #initialize, #intersect_with_range, #nominal?, #overlap_with_literal, #overlap_with_nominal, #overlap_with_numeric_literal, #overlap_with_opaque, #overlap_with_pattern, #overlap_with_range, #overlap_with_text_literal, #singleton?, #subset_from_nominal, #subset_from_opaque, #subset_from_pattern, #subset_from_range, #subset_from_text_literal, #value_domain

Constructor Details

This class inherits a constructor from Plumb::SemanticMatcher::Node

Instance Method Details

#intersect(other) ⇒ Object



228
# File 'lib/plumb/semantic_matcher.rb', line 228

def intersect(other) = other.intersect_with_finite_set(self)

#intersect_with_finite_set(other) ⇒ Object



230
231
232
233
# File 'lib/plumb/semantic_matcher.rb', line 230

def intersect_with_finite_set(other)
  merged = raw & other.raw
  merged.empty? ? Merge::EMPTY : Merge.merged(self.class.new(merged))
end

#kindObject



200
# File 'lib/plumb/semantic_matcher.rb', line 200

def kind = :finite_set

#matcher_domainObject



201
# File 'lib/plumb/semantic_matcher.rb', line 201

def matcher_domain = raw.map(&:class).uniq

#matches_value(candidate) ⇒ Object



202
# File 'lib/plumb/semantic_matcher.rb', line 202

def matches_value(candidate) = Relation.from(raw === candidate)

#members_match(other) ⇒ Object



214
215
216
# File 'lib/plumb/semantic_matcher.rb', line 214

def members_match(other)
  Relation.all(raw.map { |member| other.matches_value(member) })
end

#overlap(other) ⇒ Object



218
219
220
221
222
# File 'lib/plumb/semantic_matcher.rb', line 218

def overlap(other)
  return Relation::PROVEN if equivalent?(other)

  other.overlap_with_finite_set(self)
end

#overlap_with_finite_set(other) ⇒ Object



224
225
226
# File 'lib/plumb/semantic_matcher.rb', line 224

def overlap_with_finite_set(other)
  Relation.from(!(raw & other.raw).empty?)
end

#subset_from_finite_set(other) ⇒ Object



212
# File 'lib/plumb/semantic_matcher.rb', line 212

def subset_from_finite_set(other) = Relation.from(other.raw.subset?(raw))

#subset_from_literal(other) ⇒ Object



210
# File 'lib/plumb/semantic_matcher.rb', line 210

def subset_from_literal(other) = matches_value(other.raw)

#subset_from_numeric_literal(_other) ⇒ Object



211
# File 'lib/plumb/semantic_matcher.rb', line 211

def subset_from_numeric_literal(_other) = Relation::DISPROVEN

#subset_of(other) ⇒ Object



204
205
206
207
208
# File 'lib/plumb/semantic_matcher.rb', line 204

def subset_of(other)
  return Relation::PROVEN if equivalent?(other)

  other.subset_from_finite_set(self)
end