Class: Ruleby::Core::ParentNode

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

Overview

This is the base class for all nodes in the network that output to some other node (i.e. they are not at the bottom). It contains methods for propagating match results.

Instance Attribute Summary collapse

Attributes inherited from Printable

#parent_nodes

Instance Method Summary collapse

Methods inherited from Node

#resolve

Methods inherited from Printable

#print

Constructor Details

#initializeParentNode

Returns a new instance of ParentNode.



286
287
288
289
# File 'lib/core/nodes.rb', line 286

def initialize()
  super
  @out_nodes = []   
end

Instance Attribute Details

#child_nodesObject (readonly)

Returns the value of attribute child_nodes.



285
286
287
# File 'lib/core/nodes.rb', line 285

def child_nodes
  @child_nodes
end

Instance Method Details

#add_out_node(node, atom = nil) ⇒ Object



291
292
293
294
295
# File 'lib/core/nodes.rb', line 291

def add_out_node(node,atom=nil)
  unless @out_nodes.index node
    @out_nodes.push node
  end
end

#assert(assertable) ⇒ Object



314
315
316
# File 'lib/core/nodes.rb', line 314

def assert(assertable)
  propagate_assert(assertable)
end

#forks?(atom) ⇒ Boolean

returns true if this node is already being used for the same atom. That is, if it is used again it will fork the network (or the network may already be forked).

Returns:

  • (Boolean)


300
301
302
# File 'lib/core/nodes.rb', line 300

def forks?(atom)
  return !@out_nodes.empty?
end

#propagate_assert(assertable, out_nodes = @out_nodes) ⇒ Object



318
319
320
321
322
# File 'lib/core/nodes.rb', line 318

def propagate_assert(assertable,out_nodes=@out_nodes)
  out_nodes.each do |out_node|
    out_node.assert(assertable)
  end
end

#propagate_retract(fact, out_nodes = @out_nodes) ⇒ Object



308
309
310
311
312
# File 'lib/core/nodes.rb', line 308

def propagate_retract(fact,out_nodes=@out_nodes)
  out_nodes.each do |out_node|
    out_node.retract(fact)
  end
end

#retract(fact) ⇒ Object



304
305
306
# File 'lib/core/nodes.rb', line 304

def retract(fact)
  propagate_retract(fact)
end