def addCor(ds): newdeps = [] for d in ds: newdeps.append(d) for d in ds: if d.label == "cor" or d.label == "conj": c1 = d.head c2 = d.child for i in ds: if c1 == i.head: newD = dependency.Dependency() newD.label = i.label newD.head = c2 newD.child = i.child newdeps.append(newD) elif c2 == i.head: newD = dependency.Dependency() newD.label = i.label newD.head = c1 newD.child = i.child newdeps.append(newD) elif c1 == i.child: newD = dependency.Dependency() newD.label = i.label newD.head = i.head newD.child = c2 newdeps.append(newD) elif c2 == i.child: newD = dependency.Dependency() newD.label = i.label newD.head = i.head newD.child = c1 newdeps.append(newD) return newdeps
def readDepsFromFile(f): fdeps = [] sDeps = [] for line in f: # print(line) if line != "\n": d = dependency.Dependency() d.read(line.strip()) #print(d.label) sDeps.append(d) else: fdeps.append(sDeps) sDeps = [] return fdeps
def setupPartsGeneral(self): # set part properties: part number, rhythmic species for num, part in enumerate(self.parts): # part number part.partNum = num part.name = 'Part ' + str(num + 1) part.errors = [] # part rhythmic species part.species = assignSpecies(part) # set up note consecution relations, from consecutions.py consecutions.getConsecutions(part) # set up note properties used in parsing for idx, note in enumerate(part.recurse().notes): # get the order position of the note in the line note.index = idx # assigns a Rule object to each Note note.rule = rule.Rule() # assigns a Dependency object to each Note note.dependency = dependency.Dependency()
def decreaseWordIdx(d): # print(d) m = re.match("(^.*)-(.*)", d.head) if m.group() != None: headW = m.group(1) headIdx = int(m.group(2)) - 1 # print("head", headW, headIdx) newHead = headW + "-" + str(headIdx) n = re.match("(^.*)-(.*)", d.child) if n.group() != None: childW = n.group(1) childIdx = int(n.group(2)) - 1 # print("child", childW, childIdx) newChild = childW + "-" + str(childIdx) newD = dependency.Dependency() newD.label = d.label newD.head = newHead newD.child = newChild # print(newD) return (newD)
# print(newD) return (newD) ##Match sd deps to gcg deps sdF = open(sys.argv[1], 'r', encoding="utf8") sdDeps = DepsTools.readDepsFromFile(sdF) depList = [] sdeps = [] for s in sdDeps: for dp in s: d = decreaseWordIdx(dp) if d.label == "nsubj": newD = dependency.Dependency() newD.label = "1" newD.head = d.head newD.child = d.child sdeps.append(newD) elif d.label == "dobj": newD = dependency.Dependency() newD.label = "2" newD.head = d.head newD.child = d.child sdeps.append(newD) elif d.label == "rcmod": verb = d.child noun = d.head rcty = DepsTools.TypeRcmod(dp, s) # only subject --> object rel