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) ⇒ 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
29
30
31
32
33
34
35
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 29
def rete
@rete ||= if parent
parent.rete
else
@rete
end
end
|
Instance Method Details
#assignment_node(variable, body) ⇒ Object
74
75
76
77
78
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 74
def assignment_node variable, body
node = AssignmentNode.new self, variable, body
node.refresh
node
end
|
#beta_memory ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 37
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
121
122
123
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 121
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
65
66
67
68
69
70
71
72
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 65
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
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 47
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 87
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) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 80
def neg_node alpha, tests, alpha_deaf
node = NegNode.new self, tests, alpha
alpha.betas << node unless alpha_deaf
node.refresh
node
end
|
#network(conditions, earlier, parameters, alpha_deaf) ⇒ Object
106
107
108
109
110
111
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 106
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
58
59
60
61
62
63
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 58
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
113
114
115
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 113
def refresh
parent.refresh_child self
end
|
#refresh_child(node) ⇒ Object
117
118
119
|
# File 'lib/wongi-engine/beta/beta_node.rb', line 117
def refresh_child node
raise "#{self.class} must implement refresh_child"
end
|