Class: Predicate
- Inherits:
-
Object
show all
- Extended by:
- Factory
- Defined in:
- lib/predicate.rb,
lib/predicate/sequel.rb,
lib/predicate/factory.rb,
lib/predicate/grammar.rb,
lib/predicate/version.rb,
lib/predicate/nodes/eq.rb,
lib/predicate/nodes/gt.rb,
lib/predicate/nodes/in.rb,
lib/predicate/nodes/lt.rb,
lib/predicate/nodes/or.rb,
lib/predicate/nodes/and.rb,
lib/predicate/nodes/gte.rb,
lib/predicate/nodes/lte.rb,
lib/predicate/nodes/neq.rb,
lib/predicate/nodes/not.rb,
lib/predicate/nodes/expr.rb,
lib/predicate/nodes/match.rb,
lib/predicate/nodes/native.rb,
lib/predicate/nodes/opaque.rb,
lib/predicate/nodes/literal.rb,
lib/predicate/nodes/intersect.rb,
lib/predicate/nodes/tautology.rb,
lib/predicate/processors/to_s.rb,
lib/predicate/nodes/identifier.rb,
lib/predicate/nodes/nadic_bool.rb,
lib/predicate/sequel/to_sequel.rb,
lib/predicate/nodes/dyadic_comp.rb,
lib/predicate/processors/renamer.rb,
lib/predicate/nodes/contradiction.rb,
lib/predicate/processors/qualifier.rb,
lib/predicate/nodes/qualified_identifier.rb
Defined Under Namespace
Modules: And, Contradiction, DyadicComp, Eq, Expr, Factory, Grammar, Gt, Gte, Identifier, In, Intersect, Literal, Lt, Lte, Match, NadicBool, Native, Neq, Not, Opaque, Or, QualifiedIdentifier, Tautology, Version
Classes: NotSupportedError, Qualifier, Renamer, ToS, ToSequel
Constant Summary
collapse
- TupleLike =
->(t){ t.is_a?(Hash) }
- SexprLike =
->(x) { x.is_a?(Array) && x.first.is_a?(Symbol) }
- VERSION =
"#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
Instance Attribute Summary collapse
-
#sexpr ⇒ Object
(also: #expr)
readonly
Returns the value of attribute sexpr.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Factory
and, between, comp, contradiction, from_hash, identifier, in, intersect, literal, match, native, not, opaque, or, qualified_identifier, tautology
Constructor Details
#initialize(sexpr) ⇒ Predicate
Returns a new instance of Predicate.
14
15
16
|
# File 'lib/predicate.rb', line 14
def initialize(sexpr)
@sexpr = sexpr
end
|
Instance Attribute Details
#sexpr ⇒ Object
Also known as:
expr
Returns the value of attribute sexpr.
17
18
19
|
# File 'lib/predicate.rb', line 17
def sexpr
@sexpr
end
|
Class Method Details
.coerce(arg) ⇒ Object
Also known as:
parse
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/predicate.rb', line 23
def coerce(arg)
case arg
when Predicate then arg
when TrueClass then tautology
when FalseClass then contradiction
when Symbol then identifier(arg)
when Proc then native(arg)
when Hash then from_hash(arg)
else
raise ArgumentError, "Unable to coerce `#{arg}` to a predicate"
end
end
|
Instance Method Details
#! ⇒ Object
81
82
83
|
# File 'lib/predicate.rb', line 81
def !
Predicate.new(!expr)
end
|
#&(other) ⇒ Object
69
70
71
72
73
|
# File 'lib/predicate.rb', line 69
def &(other)
return self if other.tautology? or other==self
return other if tautology?
Predicate.new(expr & other.expr)
end
|
#==(other) ⇒ Object
Also known as:
eql?
122
123
124
|
# File 'lib/predicate.rb', line 122
def ==(other)
other.is_a?(Predicate) && (other.expr==expr)
end
|
#and_split(attr_list) ⇒ Object
Splits this predicate, say P, as too predicates P1 & P2 such that ‘P <=> P1 & P2` and P2 makes no reference to any attribute in `attr_list`.
104
105
106
|
# File 'lib/predicate.rb', line 104
def and_split(attr_list)
expr.and_split(attr_list).map{|e| Predicate.new(e)}
end
|
#attr_split ⇒ Object
Returns a hash ‘(attr -> Pattr)` associating attribute names to predicates, so that each predicate `Pattr` only makes reference to the corresponding attribute name `attr`, while the conjunction of `Pattr`s is still equivalent to the original predicate.
A ‘nil` key may map a predicate that still makes references to more than one attribute.
116
117
118
119
120
|
# File 'lib/predicate.rb', line 116
def attr_split
expr.attr_split.each_pair.each_with_object({}) do |(k,v),h|
h[k] = Predicate.new(v)
end
end
|
#call(tuple) ⇒ Object
97
98
99
|
# File 'lib/predicate.rb', line 97
def call(tuple)
expr.evaluate(tuple)
end
|
#constant_variables ⇒ Object
61
62
63
|
# File 'lib/predicate.rb', line 61
def constant_variables
expr.constant_variables
end
|
#constants ⇒ Object
65
66
67
|
# File 'lib/predicate.rb', line 65
def constants
expr.constants
end
|
#contradiction? ⇒ Boolean
53
54
55
|
# File 'lib/predicate.rb', line 53
def contradiction?
expr.contradiction?
end
|
#evaluate(tuple) ⇒ Object
93
94
95
|
# File 'lib/predicate.rb', line 93
def evaluate(tuple)
expr.evaluate(tuple)
end
|
#free_variables ⇒ Object
57
58
59
|
# File 'lib/predicate.rb', line 57
def free_variables
expr.free_variables
end
|
#hash ⇒ Object
127
128
129
|
# File 'lib/predicate.rb', line 127
def hash
expr.hash
end
|
#native? ⇒ Boolean
45
46
47
|
# File 'lib/predicate.rb', line 45
def native?
Native===expr
end
|
#qualify(qualifier) ⇒ Object
85
86
87
|
# File 'lib/predicate.rb', line 85
def qualify(qualifier)
Predicate.new(expr.qualify(qualifier))
end
|
#rename(renaming) ⇒ Object
89
90
91
|
# File 'lib/predicate.rb', line 89
def rename(renaming)
Predicate.new(expr.rename(renaming))
end
|
#tautology? ⇒ Boolean
49
50
51
|
# File 'lib/predicate.rb', line 49
def tautology?
expr.tautology?
end
|
#to_s(scope = nil) ⇒ Object
131
132
133
|
# File 'lib/predicate.rb', line 131
def to_s(scope = nil)
expr.to_s(scope)
end
|
#to_sequel ⇒ Object
11
12
13
|
# File 'lib/predicate/sequel.rb', line 11
def to_sequel
expr.to_sequel
end
|
#|(other) ⇒ Object
75
76
77
78
79
|
# File 'lib/predicate.rb', line 75
def |(other)
return self if other.contradiction? or other==self
return other if contradiction?
Predicate.new(expr | other.expr)
end
|