Sha256: 9cfc9df24c2abb7b19c748752b5aafb2cbdd14b3f4b31e622c3e6dfbdd406dea
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
class Predicate module In include Expr def priority 80 end def left self[1] end alias :identifier :left def right self[2] end def &(other) # we only optimize with another In return super unless other.is_a?(In) # we only optimize is same free variables fv = free_variables return super unless fv.size == 1 && fv == other.free_variables # we only optimize if both right terms are literals return super unless right.literal? and other.right.literal? intersection = right.value & other.right.value if intersection.empty? Factory.contradiction elsif intersection.size == 1 Factory.eq(fv.first, [:literal, intersection.first]) else Factory.in(fv.first, intersection) end end def free_variables @free_variables ||= identifier.free_variables end def constant_variables if right.literal? and right.value.size == 1 free_variables else [] end end def constants if right.literal? and right.value.size == 1 { identifier.name => right.value.first } else {} end end def dyadic_priority 800 end def evaluate(tuple) values = right.evaluate(tuple) values.include?(identifier.evaluate(tuple)) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
predicate-2.2.0 | lib/predicate/nodes/in.rb |
predicate-2.1.0 | lib/predicate/nodes/in.rb |