def addLink(self, inlink, outlink, relation): node1 = inlink.begin node2 = outlink.end # find link from begin to end existingLink = self.findLink(node1, relation, node2) if existingLink: #print "CLOSURE, existing link", existingLink # existingLink either has < or =, check whether it is the same as # the new link, if not, give inconsistency warning and return if existingLink.relation != relation: self.isConsistent = 0 #self.printMessage2(existingLink,relation,inlink,outlink) return # find reversed link from end to begin existingLink = self.findLink(node2, relation, node1) if existingLink: #print "CLOSURE, existing reversed link", existingLink # existing link can be < or =, < will clash with new relation, # so only allowed combination is to have two ='s if existingLink.relation == '<' or relation == '<': self.isConsistent = 0 #self.printMessage2(existingLink,relation,inlink,outlink) return # Use stored link type so code can abstract away from # node versus point distinction newLink = self.linkType(self.environment, node1, relation, node2) # BUT, that didn't work in PythonWin 2.2.3, it did not allow using # __init__ on the superclass, therefore, if self.closureType == 'xpoints': newLink = PLink(self.environment, node1, relation, node2) if self.closureType == 'xnodes': newLink = Link(self.environment, node1, relation, node2) #print "CLOSURE, adding link", newLink newLink.history = "closure"
def test1(): """Just three nodes and two links, should derive one new link, uncomment link3 and an inconsistency should be created.""" ENV = Environment() AXIOMS.add(Axiom("before","before","before")) AXIOMS.add(Axiom("before","includes","before")) node1 = EventNode(ENV,'crashed','OCCURRENCE') node2 = EventNode(ENV,'flying','STATE') node3 = EventNode(ENV,'saw','PERCEPTION') node4 = EventNode(ENV,'heard','PERCEPTION') link1 = Link(ENV,node1,'before',node2) link2 = Link(ENV,node2,'includes',node3) link3 = Link(ENV,node1,'after',node3) clos = Closure(ENV,"nodes") clos.computeClosure() print(ENV)