def _shareNode_JoinNode(self, lastCircuitNode, alphaMemory, tests): # check if i can share looking at beta network first if lastCircuitNode is not None: for child in lastCircuitNode.children: # i can't use isinstance, child must be exactly a JoinNode # otherwise negative node could be shared and this is a problem if (child.__class__ == JoinNode # is a join node and child.rightParent == alphaMemory # alpha memory is the same and child.tests == tests): # tests are the same too # i can share the node self.eventsManager.fire(EventsManager.E_NODE_SHARED, child) return child else: # try to share node looking at the alphaMemory # this could allow to share dummy join nodes for child in alphaMemory.children: # i can't use isinstance, child must be exactly a JoinNode # otherwise negative node could be shared and this is a problem if (child.__class__ == JoinNode # is a join node and child.isLeftRoot() # like the node i will create, this one is left dummy and child.tests == tests): # tests are the same too # i can share the node self.eventsManager.fire(EventsManager.E_NODE_SHARED, child) return child # i can't share an old node # it's time to create a new one newChild = JoinNode(rightParent=alphaMemory, leftParent=lastCircuitNode, tests=tests) # link the new join to the right alpha memory alphaMemory.prependChild(newChild) if lastCircuitNode is not None: # link the join node to the parent lastCircuitNode.prependChild(newChild) # it's useless to update a leaf join node # even if it find matches # it has no children to propage the activation #myclips.logger.info("New node: %s", newChild) #myclips.logger.info("Right-linked node: %s to %s", newChild, alphaMemory) #myclips.logger.info("Left-linked node: %s to %s", newChild, lastCircuitNode) self.eventsManager.fire(EventsManager.E_NODE_ADDED, newChild) self.eventsManager.fire(EventsManager.E_NODE_LINKED, lastCircuitNode, newChild, -1) self.eventsManager.fire(EventsManager.E_NODE_LINKED, alphaMemory, newChild, 1) return newChild