Class: Ruleby::Core::JoinNode
Overview
This class is a two-input node that is used to create a cross-product of the two network branches above it. It keeps a memory of the left and right inputs and compares new facts to each. These nodes make up what is called the Beta network.
Instance Attribute Summary collapse
Attributes inherited from ParentNode
#child_nodes
Attributes inherited from Printable
#parent_nodes
Instance Method Summary
collapse
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
Returns a new instance of JoinNode.
554
555
556
557
558
559
|
# File 'lib/core/nodes.rb', line 554
def initialize
super
@left_memory = {}
@right_memory = {}
@ref_nodes = []
end
|
Instance Attribute Details
#ref_nodes ⇒ Object
Returns the value of attribute ref_nodes.
552
553
554
|
# File 'lib/core/nodes.rb', line 552
def ref_nodes
@ref_nodes
end
|
Instance Method Details
#assert_left(context) ⇒ Object
571
572
573
574
575
576
577
578
579
580
|
# File 'lib/core/nodes.rb', line 571
def assert_left(context)
add_to_left_memory(context)
@right_memory.values.each do |right_context|
mr = match_ref_nodes(context,right_context)
if (mr.is_match)
new_context = MatchContext.new context.fact, mr
propagate_assert(new_context)
end
end
end
|
#assert_right(context) ⇒ Object
582
583
584
585
586
587
588
589
590
591
|
# File 'lib/core/nodes.rb', line 582
def assert_right(context)
@right_memory[context.fact.id] = context
@left_memory.values.flatten.each do |left_context|
mr = match_ref_nodes(left_context,context)
if (mr.is_match)
new_context = MatchContext.new context.fact, mr
propagate_assert(new_context)
end
end
end
|
#retract_left(fact) ⇒ Object
561
562
563
564
|
# File 'lib/core/nodes.rb', line 561
def retract_left(fact)
@left_memory.delete(fact.id)
propagate_retract(fact)
end
|
#retract_resolve(match) ⇒ Object
597
598
599
600
601
602
603
604
605
606
607
608
|
# File 'lib/core/nodes.rb', line 597
def retract_resolve(match)
@left_memory.each do |fact_id,contexts|
contexts.delete_if do |left_context|
resolve(left_context.match, match)
end
end
propagate_retract_resolve(match)
end
|
#retract_right(fact) ⇒ Object
566
567
568
569
|
# File 'lib/core/nodes.rb', line 566
def retract_right(fact)
@right_memory.delete(fact.id)
propagate_retract(fact)
end
|
#to_s ⇒ Object
593
594
595
|
# File 'lib/core/nodes.rb', line 593
def to_s
return "#{self.class}:#{object_id} | #{@left_memory.values} | #{@right_memory}"
end
|