Module: Predicate::In
- Includes:
- Expr
- Defined in:
- lib/predicate/nodes/in.rb
Constant Summary
Constants included
from Expr
Expr::OP_NEGATIONS
Instance Method Summary
collapse
Methods included from Expr
#!, #and_split, #attr_split, #contradiction?, #identifier?, #literal?, #opaque?, #qualify, #rename, #sexpr, #tautology?, #to_s, #to_sequel, #|
Methods included from Factory
#and, #between, #comp, #contradiction, #from_hash, #in, #intersect, #literal, #match, #native, #not, #opaque, #or, #qualified_identifier, #tautology
Instance Method Details
#&(other) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/predicate/nodes/in.rb', line 18
def &(other)
return super unless other.is_a?(In)
fv = free_variables
return super unless fv.size == 1 && fv == other.free_variables
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
|
#constant_variables ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/predicate/nodes/in.rb', line 43
def constant_variables
if right.literal? and right.value.size == 1
free_variables
else
[]
end
end
|
#constants ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/predicate/nodes/in.rb', line 51
def constants
if right.literal? and right.value.size == 1
{ identifier.name => right.value.first }
else
{}
end
end
|
#dyadic_priority ⇒ Object
59
60
61
|
# File 'lib/predicate/nodes/in.rb', line 59
def dyadic_priority
800
end
|
#evaluate(tuple) ⇒ Object
63
64
65
66
|
# File 'lib/predicate/nodes/in.rb', line 63
def evaluate(tuple)
values = right.evaluate(tuple)
values.include?(identifier.evaluate(tuple))
end
|
#free_variables ⇒ Object
39
40
41
|
# File 'lib/predicate/nodes/in.rb', line 39
def free_variables
@free_variables ||= identifier.free_variables
end
|
#left ⇒ Object
Also known as:
identifier
9
10
11
|
# File 'lib/predicate/nodes/in.rb', line 9
def left
self[1]
end
|
#priority ⇒ Object
5
6
7
|
# File 'lib/predicate/nodes/in.rb', line 5
def priority
80
end
|
#right ⇒ Object
14
15
16
|
# File 'lib/predicate/nodes/in.rb', line 14
def right
self[2]
end
|