From bc57dbba2549ce0f1ff0daad859567a151f4b6d5 Mon Sep 17 00:00:00 2001 From: Franck Dary <franck.dary@lis-lab.fr> Date: Sat, 24 Apr 2021 12:31:49 +0200 Subject: [PATCH] Added strucutre containing predicted dependents in Config --- Config.py | 8 +++++--- Transition.py | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Config.py b/Config.py index a9f785e..b3f3e6c 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 af1324a..61e1c11 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) ################################################################################ ################################################################################ -- GitLab