Class: Wongi::Engine::ProductionNode

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

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(name, parent, actions) ⇒ ProductionNode

Returns a new instance of ProductionNode.



6
7
8
9
10
# File 'lib/wongi-engine/beta/production_node.rb', line 6

def initialize(name, parent, actions)
  super(parent)
  @actions = actions.each { |action| action.production = self }
  @name = name
end

Instance Attribute Details

#compilation_contextObject

Returns the value of attribute compilation_context.



4
5
6
# File 'lib/wongi-engine/beta/production_node.rb', line 4

def compilation_context
  @compilation_context
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/wongi-engine/beta/production_node.rb', line 4

def name
  @name
end

#tracerObject

Returns the value of attribute tracer.



4
5
6
# File 'lib/wongi-engine/beta/production_node.rb', line 4

def tracer
  @tracer
end

Instance Method Details

#beta_activate(token) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/wongi-engine/beta/production_node.rb', line 12

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)

  @actions.each do |action|
    action.execute token if action.respond_to? :execute
  end
end

#beta_deactivate(token) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/wongi-engine/beta/production_node.rb', line 23

def beta_deactivate(token)
  # p beta_deactivate: {class: self.class, object_id:, token:}

  # we should remove before the actions because otherwise the longer rule chains (like the infinite neg-gen cycle) don't work as expected
  overlay.remove_token(token)

  @actions.each do |action|
    action.deexecute token if action.respond_to? :deexecute
  end
end