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.
542
543
544
545
546
547
|
# File 'lib/core/nodes.rb', line 542
def initialize
super
@left_memory = {}
@right_memory = {}
@ref_nodes = []
end
|
Instance Attribute Details
#ref_nodes ⇒ Object
Returns the value of attribute ref_nodes.
540
541
542
|
# File 'lib/core/nodes.rb', line 540
def ref_nodes
@ref_nodes
end
|
Instance Method Details
#assert_left(context) ⇒ Object
559
560
561
562
563
564
565
566
567
568
|
# File 'lib/core/nodes.rb', line 559
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
570
571
572
573
574
575
576
577
578
579
|
# File 'lib/core/nodes.rb', line 570
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
549
550
551
552
|
# File 'lib/core/nodes.rb', line 549
def retract_left(fact)
@left_memory.delete(fact.id)
propagate_retract(fact)
end
|
#retract_right(fact) ⇒ Object
554
555
556
557
|
# File 'lib/core/nodes.rb', line 554
def retract_right(fact)
@right_memory.delete(fact.id)
propagate_retract(fact)
end
|
#to_s ⇒ Object
581
582
583
|
# File 'lib/core/nodes.rb', line 581
def to_s
return "#{self.class}:#{object_id} | #{@left_memory.values} | #{@right_memory}"
end
|