Class: Wongi::Engine::AssignmentNode

Inherits:
BetaNode
  • Object
show all
Defined in:
lib/wongi-engine/beta/assignment_node.rb

Instance Attribute Summary

Attributes inherited from BetaNode

#children, #context, #parent, #rete

Instance Method Summary collapse

Methods inherited from BetaNode

#assignment_node, #beta_memory, #delete_token, #depth, #empty?, #filter_node, #join_node, #ncc_node, #neg_node, #network, #optional_node, #refresh, #size, #tokens

Methods included from CoreExt

included

Constructor Details

#initialize(parent, variable, body) ⇒ AssignmentNode

Returns a new instance of AssignmentNode.



20
21
22
23
# File 'lib/wongi-engine/beta/assignment_node.rb', line 20

def initialize parent, variable, body
  super parent
  @variable, @body = variable, body
end

Instance Method Details

#beta_activate(token, wme = nil, assignments = { }) ⇒ Object



25
26
27
28
29
# File 'lib/wongi-engine/beta/assignment_node.rb', line 25

def beta_activate token, wme = nil, assignments = { }
  children.each do |child|
    child.beta_activate Token.new( child, token, nil, { @variable => @body.respond_to?(:call) ? @body.call(token) : @body } )
  end
end

#beta_deactivate(token) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/wongi-engine/beta/assignment_node.rb', line 31

def beta_deactivate token
  children.each do |child|
    child.tokens.each do |t|
      if t.parent == token
        child.beta_deactivate t
        #token.destroy
      end
    end
  end
end

#refresh_child(child) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/wongi-engine/beta/assignment_node.rb', line 42

def refresh_child child
  tmp = children
  self.children = [ child ]
  parent.tokens.each do |token|
    children.each do |child|
      child.beta_activate Token.new( child, token, nil, { @variable => @body.respond_to?(:call) ? @body.call(token) : @body } )
    end
  end
  self.children = tmp
end