Class: Ruleby::Core::TerminalNode
- Defined in:
- lib/core/nodes.rb
Overview
This class represents the bottom node in the network. There is a one to one relation between TerminalNodes and Rules. A terminal node acts as a wrapper for a rule. The class is responsible for keeping a memory of the activations that have been generated by the network.
Constant Summary collapse
- @@counter =
0
Instance Attribute Summary collapse
-
#activations ⇒ Object
readonly
Returns the value of attribute activations.
Attributes inherited from Printable
Class Method Summary collapse
Instance Method Summary collapse
- #assert(context) ⇒ Object
-
#initialize(rule) ⇒ TerminalNode
constructor
A new instance of TerminalNode.
- #retract(fact) ⇒ Object
- #retract_resolve(match) ⇒ Object
- #satisfied? ⇒ Boolean
- #to_s ⇒ Object
Methods inherited from Node
Methods inherited from Printable
Constructor Details
#initialize(rule) ⇒ TerminalNode
Returns a new instance of TerminalNode.
731 732 733 734 735 |
# File 'lib/core/nodes.rb', line 731 def initialize(rule) super() @rule = rule @activations = MultiHash.new end |
Instance Attribute Details
#activations ⇒ Object (readonly)
Returns the value of attribute activations.
736 737 738 |
# File 'lib/core/nodes.rb', line 736 def activations @activations end |
Class Method Details
.increment_counter ⇒ Object
766 767 768 |
# File 'lib/core/nodes.rb', line 766 def self.increment_counter @@counter = @@counter + 1 end |
.reset_counter ⇒ Object
770 771 772 |
# File 'lib/core/nodes.rb', line 770 def self.reset_counter @@counter = 0 end |
Instance Method Details
#assert(context) ⇒ Object
738 739 740 741 742 |
# File 'lib/core/nodes.rb', line 738 def assert(context) match = context.match a = Activation.new(@rule.action, match, @@counter) @activations.add match.fact_ids, a end |
#retract(fact) ⇒ Object
744 745 746 |
# File 'lib/core/nodes.rb', line 744 def retract(fact) @activations.remove fact.id end |
#retract_resolve(match) ⇒ Object
756 757 758 759 760 761 762 763 764 |
# File 'lib/core/nodes.rb', line 756 def retract_resolve(match) # in this method we retract an existing activation from memory if its # match resolves with the match given. It would probably be better to # check if it resolves with a list of facts. But the system is not set up # for that yet. @activations.delete_if do |activation| resolve(activation.match, match) end end |
#satisfied? ⇒ Boolean
748 749 750 |
# File 'lib/core/nodes.rb', line 748 def satisfied? return !@activations.values.empty? end |
#to_s ⇒ Object
752 753 754 |
# File 'lib/core/nodes.rb', line 752 def to_s return "TerminalNode:#{object_id} | #{@activations.values}" end |