def translateEnvironment(self,name1,name2): """Take the PLinks and translate them into a disjunction of TimeML relations.""" timemlRels = [] for reltype in LINK2PLINK.keys(): consistent = 1 env = self.copy() for plink in LINK2PLINK[reltype]: rel = plink[2] p1Name = translateBoundaries(name1,name2,plink[0],plink[1]) p2Name = translateBoundaries(name1,name2,plink[3],plink[4]) p1 = env.findPointWithName(p1Name) p2 = env.findPointWithName(p2Name) if env.hasConflictingLink(p1,rel,p2): consistent = 0 continue if env.findPLink(p1,rel,p2): continue PLink(env,p1,rel,p2) if rel == '=': PLink(env,p2,rel,p1) if consistent: closedEnv = env.close("points") if closedEnv.isConsistent: timemlRels.append(reltype) relstring = '' for rel in sort(timemlRels): relstring = relstring + rel + ' ' return relstring
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 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 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)
def createEnvironmentFromPLinks(self,plinks,node1,node2): env = Environment() points = [node1.begin,node1.end,node2.begin,node2.end] for point in points: point.copy(env) for plink in plinks: rel = plink.relation p1Name = plink.begin.string p2Name = plink.end.string p1 = env.findPointWithName(p1Name) p2 = env.findPointWithName(p2Name) PLink(env,p1,rel,p2) return env
def copy(self): newEnv = Environment() newEnv.id = self.id newEnv.isConsistent = self.isConsistent for node in self.NODES: newEnv.NODES.add(node) for link in self.LINKS: newEnv.LINKS.add(link) for point in self.POINTS: newPoint = point.copy(newEnv) for plink in self.PLINKS: p1Name = plink.begin.string p2Name = plink.end.string p1 = newEnv.findPointWithName(p1Name) p2 = newEnv.findPointWithName(p2Name) PLink(newEnv,p1,plink.relation,p2) return newEnv
def NewPLink(env,p1,rel,p2): PLink(env,p1,rel,p2) if rel == '=': PLink(env,p2,rel,p1)