Class: Ruleby::Core::NotNode

Inherits:
JoinNode show all
Defined in:
lib/core/nodes.rb

Overview

This node class is used when a rule is looking for a fact that does not exist. It is a two-input node, and thus has some of the properties of the JoinNode.

Instance Attribute Summary

Attributes inherited from JoinNode

#ref_nodes

Attributes inherited from ParentNode

#child_nodes

Attributes inherited from Printable

#parent_nodes

Instance Method Summary collapse

Methods inherited from JoinNode

#modify_right, #retract_resolve, #to_s

Methods inherited from ParentNode

#add_out_node, #assert, #modify, #propagate, #propagate_assert, #propagate_modify, #propagate_retract, #retract

Methods inherited from Node

#resolve

Methods inherited from Printable

#print

Constructor Details

#initialize(bucket) ⇒ NotNode



827
828
829
# File 'lib/core/nodes.rb', line 827

def initialize(bucket)
  super
end

Instance Method Details

#assert_left(context) ⇒ Object



855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
# File 'lib/core/nodes.rb', line 855

def assert_left(context)    
  add_to_left_memory(context)      
  if @ref_nodes.empty? && @right_memory.empty?
    propagate_assert(context)
  else
    propagate = true
    @right_memory.values.each do |right_context|
      if match_ref_nodes(context,right_context)     
        propagate = false
        break
      end
    end
    propagate_assert(context) if propagate
  end
end

#assert_right(context) ⇒ Object



871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
# File 'lib/core/nodes.rb', line 871

def assert_right(context)
  @right_memory[context.fact.id] = context
  if @ref_nodes.empty?
    @left_memory.values.flatten.each do |left_context|
      propagate_retract_resolve(left_context.match)
    end
  else
    @left_memory.values.flatten.each do |left_context|
      if match_ref_nodes(left_context,context)
        # QUESTION is there a more efficient way to retract here?
        propagate_retract_resolve(left_context.match)
      end
    end
  end
end

#modify_left(context) ⇒ Object



887
888
889
890
891
# File 'lib/core/nodes.rb', line 887

def modify_left(context)
  @left_memory[context.fact.id] = context

  # TODO something needs to happen here - but i'm not sure what!
end

#retract_left(fact) ⇒ Object



831
832
833
834
# File 'lib/core/nodes.rb', line 831

def retract_left(fact)
  @left_memory.delete(fact.id)
  propagate_retract(fact)
end

#retract_right(fact) ⇒ Object



836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/core/nodes.rb', line 836

def retract_right(fact)
  right_context = @right_memory.delete(fact.id)  
  unless right_context == @right_memory.default
    unless @ref_nodes.empty? && !@right_memory.empty?
      @left_memory.values.each do |lm|
        lm.each do |left_context|
          # TODO we should cache the matches on the left that were unmatched 
          # by a result from a NotPattern.  We could hash them by the right 
          # match that caused this.  That we way we would not have to 
          # re-compare the the left and right matches.
          if match_ref_nodes(left_context,right_context)      
            propagate_assert(left_context)
          end
        end
      end   
    end
  end
end