class Wongi::Engine::NegNode
Attributes
alpha[R]
tests[R]
Public Class Methods
new(parent, tests, alpha)
click to toggle source
Calls superclass method
Wongi::Engine::BetaNode::new
# File lib/wongi-engine/beta/neg_node.rb, line 8 def initialize(parent, tests, alpha) super(parent) @tests = tests @alpha = alpha end
Public Instance Methods
alpha_activate(wme, children: self.children)
click to toggle source
# File lib/wongi-engine/beta/neg_node.rb, line 14 def alpha_activate(wme, children: self.children) # p alpha_activate: {class: self.class, object_id:, wme:} tokens.each do |token| next unless matches?(token, wme) # order matters for proper invalidation overlay.add_neg_join_result(NegJoinResult.new(token, wme)) beta_deactivate_children(token: token, children: children) end end
alpha_deactivate(wme)
click to toggle source
# File lib/wongi-engine/beta/neg_node.rb, line 25 def alpha_deactivate(wme) # p alpha_deactivate: {class: self.class, object_id:, wme:} overlay.neg_join_results_for(wme: wme).each do |njr| tokens.each do |token| next unless token == njr.token overlay.remove_neg_join_result(njr) next unless overlay.neg_join_results_for(token: token).empty? children.each do |child| child.beta_activate(Token.new(child, token, nil)) end end end end
beta_activate(token)
click to toggle source
# File lib/wongi-engine/beta/neg_node.rb, line 41 def beta_activate(token) # p beta_activate: {class: self.class, object_id:, 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| overlay.add_neg_join_result(NegJoinResult.new(token, wme)) if matches?(token, wme) end return if overlay.neg_join_results_for(token: token).any? children.each do |child| child.beta_activate(Token.new(child, token, nil, {})) end end
beta_deactivate(token)
click to toggle source
# File lib/wongi-engine/beta/neg_node.rb, line 58 def beta_deactivate(token) # p beta_deactivate: {class: self.class, object_id:, token:} overlay.remove_token(token) beta_deactivate_children(token: token) end
matches?(token, wme)
click to toggle source
# File lib/wongi-engine/beta/neg_node.rb, line 73 def matches?(token, wme) puts "matching #{wme} against #{token}" if debug? @tests.each do |test| return false unless test.matches?(token, wme) end true end
refresh_child(child)
click to toggle source
# File lib/wongi-engine/beta/neg_node.rb, line 64 def refresh_child(child) tokens.each do |token| child.beta_activate(Token.new(child, token, nil, {})) if overlay.neg_join_results_for(token: token).empty? end select_wmes(alpha.template).each do |wme| alpha_activate wme, children: [child] end end