Class: Wongi::Engine::JoinNode
Instance Attribute Summary collapse
Attributes inherited from BetaNode
#children, #parent, #rete
Instance Method Summary
collapse
Methods inherited from BetaNode
#assignment_node, #beta_deactivate_children, #depth, #empty?, #overlay, #refresh, #root?, #size, #tokens
Methods included from CoreExt
included
Constructor Details
#initialize(parent, tests, assignment) ⇒ JoinNode
Returns a new instance of JoinNode.
27
28
29
30
31
|
# File 'lib/wongi-engine/beta/join_node.rb', line 27
def initialize(parent, tests, assignment)
super(parent)
@tests = tests
@assignment_pattern = assignment
end
|
Instance Attribute Details
#alpha ⇒ Object
Returns the value of attribute alpha.
24
25
26
|
# File 'lib/wongi-engine/beta/join_node.rb', line 24
def alpha
@alpha
end
|
#assignment_pattern ⇒ Object
Returns the value of attribute assignment_pattern.
25
26
27
|
# File 'lib/wongi-engine/beta/join_node.rb', line 25
def assignment_pattern
@assignment_pattern
end
|
#tests ⇒ Object
Returns the value of attribute tests.
25
26
27
|
# File 'lib/wongi-engine/beta/join_node.rb', line 25
def tests
@tests
end
|
Instance Method Details
#alpha_activate(wme) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/wongi-engine/beta/join_node.rb', line 45
def alpha_activate(wme)
assignments = collect_assignments(wme)
tokens.each do |token|
next unless matches?(token, wme)
children.each do |beta|
beta.beta_activate Token.new(beta, token, wme, assignments)
end
end
end
|
#alpha_deactivate(wme) ⇒ Object
58
59
60
|
# File 'lib/wongi-engine/beta/join_node.rb', line 58
def alpha_deactivate(wme)
beta_deactivate_children(wme: wme)
end
|
#beta_activate(token) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/wongi-engine/beta/join_node.rb', line 62
def beta_activate(token)
return if tokens.find { |t| t.duplicate? token }
overlay.add_token(token)
template = specialize(alpha.template, tests, token)
select_wmes(template).each do |wme|
next unless matches?(token, wme)
assignments = collect_assignments(wme)
children.each do |beta|
beta.beta_activate Token.new(beta, token, wme, assignments)
end
end
end
|
#beta_deactivate(token) ⇒ Object
79
80
81
82
83
|
# File 'lib/wongi-engine/beta/join_node.rb', line 79
def beta_deactivate(token)
overlay.remove_token(token)
beta_deactivate_children(token: token)
end
|
#equivalent?(alpha, tests, assignment_pattern) ⇒ Boolean
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/wongi-engine/beta/join_node.rb', line 33
def equivalent?(alpha, tests, assignment_pattern)
return false unless self.alpha == alpha
return false unless self.assignment_pattern == assignment_pattern
return false unless (self.tests.empty? && tests.empty?) || (self.tests.length == tests.length && self.tests.all? { |my_test|
tests.any? { |new_test|
my_test.equivalent? new_test
}
})
true
end
|
#refresh_child(child) ⇒ Object
85
86
87
88
89
90
91
92
|
# File 'lib/wongi-engine/beta/join_node.rb', line 85
def refresh_child(child)
select_wmes(alpha.template).each do |wme|
assignments = collect_assignments(wme)
tokens.each do |token|
child.beta_activate Token.new(child, token, wme, assignments) if matches?(token, wme)
end
end
end
|