diff --git a/Config.py b/Config.py index a9f785ecb9a8ea841c6c89f01b37adbe59252844..b3f3e6cf39a4c698812a81d8c6bb7d4ef52b7c58 100644 --- a/Config.py +++ b/Config.py @@ -5,7 +5,8 @@ import sys class Config : def __init__(self, col2index, index2col) : self.lines = [] - self.childs = [] + self.goldChilds = [] + self.predChilds = [] self.col2index = col2index self.index2col = index2col self.predicted = set({"HEAD", "DEPREL"}) @@ -15,7 +16,8 @@ class Config : def addLine(self, cols) : self.lines.append([[val,""] for val in cols]) - self.childs.append([]) + self.goldChilds.append([]) + self.predChilds.append([]) def get(self, lineIndex, colname, predicted) : if lineIndex not in range(len(self.lines)) : @@ -131,7 +133,7 @@ def readConllu(filename) : if head == "0" : continue configs[-1].set(index, "HEAD", id2index[head], False) - configs[-1].childs[int(id2index[head])].append(index) + configs[-1].goldChilds[int(id2index[head])].append(index) configs[-1].comments = comments diff --git a/Transition.py b/Transition.py index af1324aa88940a4aa438de51168f34bc2268e99f..61e1c115c2d0badfdbd7f9e2c14813bc3ef75271 100644 --- a/Transition.py +++ b/Transition.py @@ -74,7 +74,7 @@ def getMissingLinks(config) : # Number of missing links between wordIndex and the right of the sentence def nbLinksBufferRight(config) : head = 1 if int(config.getGold(config.wordIndex, "HEAD")) > config.wordIndex else 0 - return head + len([c for c in config.childs[config.wordIndex] if c > config.wordIndex]) + return head + len([c for c in config.goldChilds[config.wordIndex] if c > config.wordIndex]) ################################################################################ ################################################################################ @@ -89,7 +89,7 @@ def nbLinksStackRight(config) : if len(config.stack) == 0 : return 0 head = 1 if int(config.getGold(config.stack[-1], "HEAD")) >= config.wordIndex else 0 - return head + len([c for c in config.childs[config.stack[-1]] if c >= config.wordIndex]) + return head + len([c for c in config.goldChilds[config.stack[-1]] if c >= config.wordIndex]) ################################################################################ ################################################################################ @@ -97,7 +97,7 @@ def nbLinksStackRight(config) : def nbLinksBufferStack(config) : if len(config.stack) == 0 : return 0 - return len([s for s in config.stack if config.getGold(s, "HEAD") == config.wordIndex or config.wordIndex in config.childs[s]]) + return len([s for s in config.stack if config.getGold(s, "HEAD") == config.wordIndex or config.wordIndex in config.goldChilds[s]]) ################################################################################ ################################################################################ @@ -133,12 +133,14 @@ def scoreOracleReduce(config, ml) : ################################################################################ def applyRight(config) : config.set(config.wordIndex, "HEAD", config.stack[-1]) + config.predChilds[config.stack[-1]].append(config.wordIndex) config.addWordIndexToStack() ################################################################################ ################################################################################ def applyLeft(config) : config.set(config.stack[-1], "HEAD", config.wordIndex) + config.predChilds[config.wordIndex].append(config.stack[-1]) config.popStack() ################################################################################ @@ -171,6 +173,7 @@ def applyEOS(config) : if config.isMultiword(index) or not isEmpty(config.getAsFeature(index, "HEAD")) : continue config.set(index, "HEAD", str(rootIndex)) + config.predChilds[rootIndex].append(index) ################################################################################ ################################################################################