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. NOTE it has not clear how this will work if the NotPattern is declared as the first pattern in a rule.

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

#retract_resolve, #to_s

Methods inherited from ParentNode

#add_out_node, #assert, #forks?, #propagate_assert, #propagate_retract, #retract

Methods inherited from Node

#resolve

Methods inherited from Printable

#print

Constructor Details

#initializeNotNode

Returns a new instance of NotNode.



658
659
660
# File 'lib/core/nodes.rb', line 658

def initialize
  super
end

Instance Method Details

#assert_left(context) ⇒ Object



686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/core/nodes.rb', line 686

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



702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'lib/core/nodes.rb', line 702

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

#retract_left(fact) ⇒ Object



662
663
664
665
# File 'lib/core/nodes.rb', line 662

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

#retract_right(fact) ⇒ Object



667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
# File 'lib/core/nodes.rb', line 667

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