Class: Wongi::Engine::BetaNode
- Inherits:
-
Object
- Object
- Wongi::Engine::BetaNode
show all
- Includes:
- CoreExt
- Defined in:
- lib/wongi-engine/beta/beta_node.rb
Defined Under Namespace
Classes: CompilationContext
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#assignment_node(variable, body) ⇒ Object
-
#beta_memory ⇒ Object
-
#delete_token(token) ⇒ Object
-
#depth ⇒ Object
-
#filter_node(test) ⇒ Object
-
#initialize(parent = nil) ⇒ BetaNode
constructor
A new instance of BetaNode.
-
#join_node(alpha, tests, assignment, filters, alpha_deaf) ⇒ Object
-
#ncc_node(condition, earlier, parameters, alpha_deaf) ⇒ Object
-
#neg_node(alpha, tests, alpha_deaf, unsafe) ⇒ Object
-
#network(conditions, earlier, parameters, alpha_deaf) ⇒ Object
-
#optional_node(alpha, tests, assignment, alpha_deaf) ⇒ Object
-
#refresh ⇒ Object
-
#refresh_child(node) ⇒ Object
Methods included from CoreExt
included
Constructor Details
#initialize(parent = nil) ⇒ BetaNode
Returns a new instance of BetaNode.
12
13
14
15
16
17
18
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 12
def initialize parent = nil
@parent = parent
@children = []
if parent
parent.children << self
end
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
9
10
11
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 9
def children
@children
end
|
#parent ⇒ Object
Returns the value of attribute parent.
8
9
10
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 8
def parent
@parent
end
|
#rete ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 28
def rete
@rete ||= if parent
parent.rete
else
@rete
end
end
|
Instance Method Details
#assignment_node(variable, body) ⇒ Object
73
74
75
76
77
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 73
def assignment_node variable, body
node = AssignmentNode.new self, variable, body
node.refresh
node
end
|
#beta_memory ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 36
def beta_memory
return self if BetaMemory === self beta = children.find { |node| BetaMemory === node }
if beta.nil?
beta = BetaMemory.new self
beta.refresh
end
beta
end
|
#delete_token(token) ⇒ Object
120
121
122
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 120
def delete_token token
end
|
#depth ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 20
def depth
@depth ||= if parent.nil?
0
else
parent.depth + 1
end
end
|
#filter_node(test) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 64
def filter_node test
existing = children.find{ |node| FilterNode === node && node.equivalent?( test ) }
return existing if existing
node = FilterNode.new self, test
node.refresh
node
end
|
#join_node(alpha, tests, assignment, filters, alpha_deaf) ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 46
def join_node alpha, tests, assignment, filters, alpha_deaf
existing = children.find{ |node| JoinNode === node && node.equivalent?( alpha, tests, assignment, filters ) }
return existing if existing
node = JoinNode.new self, tests, assignment, filters
node.alpha = alpha
alpha.betas << node unless alpha_deaf
node
end
|
#ncc_node(condition, earlier, parameters, alpha_deaf) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 86
def ncc_node condition, earlier, parameters, alpha_deaf
bottom = network condition.children, earlier, parameters, alpha_deaf
self.children.each do |node|
if node.kind_of?( NccNode ) and node.partner.parent == bottom
return node
end
end
ncc = NccNode.new self
partner = NccPartner.new bottom.beta_memory
ncc.partner = partner
partner.ncc = ncc
partner.divergent = self
ncc.refresh
partner.refresh
ncc
end
|
#neg_node(alpha, tests, alpha_deaf, unsafe) ⇒ Object
79
80
81
82
83
84
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 79
def neg_node alpha, tests, alpha_deaf, unsafe
node = NegNode.new self, tests, alpha, unsafe
alpha.betas << node unless alpha_deaf
node.refresh
node
end
|
#network(conditions, earlier, parameters, alpha_deaf) ⇒ Object
105
106
107
108
109
110
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 105
def network conditions, earlier, parameters, alpha_deaf
conditions.inject(CompilationContext.new self, self.rete, earlier, parameters, alpha_deaf) do |context, condition|
condition.compile context
end.node
end
|
#optional_node(alpha, tests, assignment, alpha_deaf) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 57
def optional_node alpha, tests, assignment, alpha_deaf
node = OptionalNode.new self, tests, assignment
node.alpha = alpha
alpha.betas << node unless alpha_deaf
node
end
|
#refresh ⇒ Object
112
113
114
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 112
def refresh
parent.refresh_child self
end
|
#refresh_child(node) ⇒ Object
116
117
118
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 116
def refresh_child node
raise "#{self.class} must implement refresh_child"
end
|