Class: KBS::ProductionNode

Inherits:
Object
  • Object
show all
Defined in:
lib/kbs/production_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule) ⇒ ProductionNode

Returns a new instance of ProductionNode.



7
8
9
10
# File 'lib/kbs/production_node.rb', line 7

def initialize(rule)
  @rule = rule
  @tokens = []
end

Instance Attribute Details

#ruleObject

Returns the value of attribute rule.



5
6
7
# File 'lib/kbs/production_node.rb', line 5

def rule
  @rule
end

#tokensObject

Returns the value of attribute tokens.



5
6
7
# File 'lib/kbs/production_node.rb', line 5

def tokens
  @tokens
end

Instance Method Details

#activate(token) ⇒ Object



12
13
14
15
16
# File 'lib/kbs/production_node.rb', line 12

def activate(token)
  @tokens << token
  # Don't fire immediately - wait for run() to fire rules
  # This allows negation nodes to deactivate tokens before they fire
end

#deactivate(token) ⇒ Object



24
25
26
# File 'lib/kbs/production_node.rb', line 24

def deactivate(token)
  @tokens.delete(token)
end

#fire_rule(token) ⇒ Object



18
19
20
21
22
# File 'lib/kbs/production_node.rb', line 18

def fire_rule(token)
  return if token.fired?
  @rule.fire(token.facts)
  token.mark_fired!
end