Class: Wongi::Engine::NegNode
- Inherits:
-
BetaNode
show all
- Includes:
- TokenContainer
- Defined in:
- lib/wongi-engine/beta/neg_node.rb
Instance Attribute Summary collapse
Attributes inherited from BetaNode
#children, #parent, #rete
Instance Method Summary
collapse
Methods inherited from BetaNode
#assignment_node, #delete_token, #depth, #refresh, #root?
Methods included from CoreExt
included
Constructor Details
#initialize(parent, tests, alpha, unsafe) ⇒ NegNode
Returns a new instance of NegNode.
16
17
18
19
|
# File 'lib/wongi-engine/beta/neg_node.rb', line 16
def initialize parent, tests, alpha, unsafe
super(parent)
@tests, @alpha, @unsafe = tests, alpha, unsafe
end
|
Instance Attribute Details
#alpha ⇒ Object
Returns the value of attribute alpha.
14
15
16
|
# File 'lib/wongi-engine/beta/neg_node.rb', line 14
def alpha
@alpha
end
|
#tests ⇒ Object
Returns the value of attribute tests.
14
15
16
|
# File 'lib/wongi-engine/beta/neg_node.rb', line 14
def tests
@tests
end
|
Instance Method Details
#alpha_activate(wme) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/wongi-engine/beta/neg_node.rb', line 21
def alpha_activate wme
tokens.each do |token|
if matches?( token, wme ) && ( @unsafe || ! token.generated?( wme ) ) make_join_result(token, wme)
children.each do |child|
child.tokens.each do |t|
if t.parent == token
child.beta_deactivate t
end
end
end
end
end
end
|
#alpha_deactivate(wme) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/wongi-engine/beta/neg_node.rb', line 39
def alpha_deactivate wme
wme.neg_join_results.dup.each do |njr|
tokens.each do |token|
next unless token == njr.token
njr.unlink
if token.neg_join_results.empty?
children.each do |child|
child.beta_activate Token.new( child, token, nil, {} )
end
end
end
end
end
|
#beta_activate(token) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/wongi-engine/beta/neg_node.rb', line 53
def beta_activate token
return if tokens.find { |et| et.duplicate? token }
token.overlay.add_token(token, self)
alpha.wmes.each do |wme|
if matches?( token, wme )
make_join_result(token, wme)
end
end
if token.neg_join_results.empty?
children.each do |child|
child.beta_activate Token.new( child, token, nil, {} )
end
end
end
|
#beta_deactivate(token) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/wongi-engine/beta/neg_node.rb', line 68
def beta_deactivate token
return nil unless tokens.find token
token.overlay.remove_token(token, self)
token.deleted!
if token.parent
token.parent.children.delete token end
token.neg_join_results.each &:unlink
children.each do |child|
child.tokens.each do |t|
if t.parent == token
child.beta_deactivate t
end
end
end
token
end
|
#refresh_child(child) ⇒ Object
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/wongi-engine/beta/neg_node.rb', line 87
def refresh_child child
tokens.each do |token|
if token.neg_join_results.empty?
child.beta_activate Token.new( child, token, nil, {} )
end
end
alpha.wmes.each do |wme|
alpha_activate wme
end
end
|