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

BACK now return to back state

parent f76a0bb7
No related branches found
No related tags found
No related merge requests found
...@@ -81,7 +81,7 @@ class Transition : ...@@ -81,7 +81,7 @@ class Transition :
if self.name == "NOBACK" : if self.name == "NOBACK" :
return True return True
if "BACK" in self.name : if "BACK" in self.name :
if len(config.historyPop) < self.size : if len([h[0].name for h in config.historyPop if "NOBACK" in h[0].name]) < self.size :
return False return False
return str([t[0].name for t in config.historyPop]) not in config.historyHistory return str([t[0].name for t in config.historyPop]) not in config.historyHistory
...@@ -180,7 +180,8 @@ def scoreOracleReduce(config, ml) : ...@@ -180,7 +180,8 @@ def scoreOracleReduce(config, ml) :
################################################################################ ################################################################################
def applyBack(config, strategy, size) : def applyBack(config, strategy, size) :
for i in range(size) : i = 0
while True :
trans, data, movement, _, state = config.historyPop.pop() trans, data, movement, _, state = config.historyPop.pop()
config.moveWordIndex(-movement) config.moveWordIndex(-movement)
if trans.name == "RIGHT" : if trans.name == "RIGHT" :
...@@ -193,10 +194,13 @@ def applyBack(config, strategy, size) : ...@@ -193,10 +194,13 @@ def applyBack(config, strategy, size) :
applyBackReduce(config, data) applyBackReduce(config, data)
elif trans.name == "TAG" : elif trans.name == "TAG" :
applyBackTag(config, trans.colName) applyBackTag(config, trans.colName)
elif trans.name != "NOBACK" : elif trans.name == "NOBACK" :
i += 1
else :
print("ERROR : trying to apply BACK to '%s'"%trans.name, file=sys.stderr) print("ERROR : trying to apply BACK to '%s'"%trans.name, file=sys.stderr)
exit(1) exit(1)
config.state = state if i == size :
break
################################################################################ ################################################################################
################################################################################ ################################################################################
......
...@@ -93,7 +93,7 @@ if __name__ == "__main__" : ...@@ -93,7 +93,7 @@ if __name__ == "__main__" :
tmpDicts = Dicts() tmpDicts = Dicts()
tmpDicts.readConllu(args.corpus, ["UPOS"], 0) tmpDicts.readConllu(args.corpus, ["UPOS"], 0)
tagActions = ["TAG UPOS %s"%p for p in tmpDicts.getElementsOf("UPOS") if "__" not in p and not isEmpty(p)] tagActions = ["TAG UPOS %s"%p for p in tmpDicts.getElementsOf("UPOS") if "__" not in p and not isEmpty(p)]
transitionSets = [[Transition(elem) for elem in (tagActions+args.ts.split(',')) if len(elem) > 0], [Transition("NOBACK"), Transition("BACK 3")]] transitionSets = [[Transition(elem) for elem in (tagActions+args.ts.split(',')) if len(elem) > 0], [Transition("NOBACK"), Transition("BACK 2")]]
args.predictedStr = "UPOS" args.predictedStr = "UPOS"
args.states = ["tagger", "backer"] args.states = ["tagger", "backer"]
strategy = {"TAG" : (1,1), "NOBACK" : (0,0)} strategy = {"TAG" : (1,1), "NOBACK" : (0,0)}
...@@ -115,7 +115,7 @@ if __name__ == "__main__" : ...@@ -115,7 +115,7 @@ if __name__ == "__main__" :
tmpDicts = Dicts() tmpDicts = Dicts()
tmpDicts.readConllu(args.corpus, ["UPOS"], 0) tmpDicts.readConllu(args.corpus, ["UPOS"], 0)
tagActions = ["TAG UPOS %s"%p for p in tmpDicts.getElementsOf("UPOS") if "__" not in p and not isEmpty(p)] tagActions = ["TAG UPOS %s"%p for p in tmpDicts.getElementsOf("UPOS") if "__" not in p and not isEmpty(p)]
transitionSets = [[Transition(elem) for elem in tagActions if len(elem) > 0], [Transition(elem) for elem in ["SHIFT","REDUCE","LEFT","RIGHT"] if len(elem) > 0], [Transition("NOBACK"),Transition("BACK 4")]] transitionSets = [[Transition(elem) for elem in tagActions if len(elem) > 0], [Transition(elem) for elem in ["SHIFT","REDUCE","LEFT","RIGHT"] if len(elem) > 0], [Transition("NOBACK"),Transition("BACK 2")]]
args.predictedStr = "HEAD,UPOS" args.predictedStr = "HEAD,UPOS"
args.states = ["tagger", "parser", "backer"] args.states = ["tagger", "parser", "backer"]
strategy = {"RIGHT" : (1,2), "SHIFT" : (1,2), "LEFT" : (0,1), "REDUCE" : (0,1), "TAG" : (0,1), "NOBACK" : (0,0)} strategy = {"RIGHT" : (1,2), "SHIFT" : (1,2), "LEFT" : (0,1), "REDUCE" : (0,1), "TAG" : (0,1), "NOBACK" : (0,0)}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment