def createEnvironment(self,relationCombination,name1,name2,envID=0): """Create an environment consisting solely of two nodes and the relations between the four points as specified in the given relation combination. Give the nodes names as specified. Uses EventNodes with class OCCURRENCE (which is totally arbitrary). NewPLink is a wrapper around PLink creation. Need to make sure that when a link with '=' as the relation is created, the reverse link is put in as well. I don't want to make this a responsibility of the PLink.__init__, but of the environment in which PLinks are created.""" def NewPLink(env,p1,rel,p2): PLink(env,p1,rel,p2) if rel == '=': PLink(env,p2,rel,p1) ENV = Environment(envID) r1 = relationCombination[0] r2 = relationCombination[1] r3 = relationCombination[2] r4 = relationCombination[3] nodeX = EventNode(ENV,name1,'OCCURRENCE') nodeY = EventNode(ENV,name2,'OCCURRENCE') NewPLink(ENV,nodeX.begin, r1, nodeY.begin) NewPLink(ENV,nodeX.begin, r2, nodeY.end) NewPLink(ENV,nodeX.end, r3, nodeY.begin) NewPLink(ENV,nodeX.end, r4, nodeY.end) return ENV
def mergeEnvironments(self, env1, env2, nodeName): """Returns a new environment which is the union of env1 and env2. Assumes that all nodes are events. Also assumes that all names are unique and that both env1 and env2 contain a node with name nodeName. Only merges the Nodes (and Points) and the PLinks, no merging of Links. Only really usefull for axiom compilation.""" def addPLink(env, plink): name1 = plink.begin.string name2 = plink.end.string node1 = env.findPointWithName(name1) node2 = env.findPointWithName(name2) rel = plink.relation PLink(env, node1, rel, node2) mergedEnv = Environment() for node in env1.NODES: EventNode(mergedEnv, node.string, node.eventClass) for node in env2.NODES: if not node.string == nodeName: EventNode(mergedEnv, node.string, node.eventClass) for plink in env1.PLINKS: addPLink(mergedEnv, plink) for plink in env2.PLINKS: addPLink(mergedEnv, plink) return mergedEnv
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)