Skip to content
Snippets Groups Projects
Commit bc57dbba authored by Franck Dary's avatar Franck Dary
Browse files

Added strucutre containing predicted dependents in Config

parent 436a97bc
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
################################################################################
################################################################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment