Class: KBS::ProductionNode
- Inherits:
-
Object
- Object
- KBS::ProductionNode
- Defined in:
- lib/kbs/production_node.rb
Instance Attribute Summary collapse
-
#rule ⇒ Object
Returns the value of attribute rule.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
Instance Method Summary collapse
- #activate(token) ⇒ Object
- #deactivate(token) ⇒ Object
- #fire_rule(token) ⇒ Object
-
#initialize(rule) ⇒ ProductionNode
constructor
A new instance of ProductionNode.
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
#rule ⇒ Object
Returns the value of attribute rule.
5 6 7 |
# File 'lib/kbs/production_node.rb', line 5 def rule @rule end |
#tokens ⇒ Object
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 |