diff --git a/decoder/src/Decoder.cpp b/decoder/src/Decoder.cpp index 934252b718bc813b638f1dbbc8a363399b45b111..3ca314a85f0af9ece9db339ca5cb0a785e43bdcb 100644 --- a/decoder/src/Decoder.cpp +++ b/decoder/src/Decoder.cpp @@ -175,7 +175,7 @@ void applyActionAndTakeTransition(TransitionMachine & tm, const std::string & ac Action * action = tm.getCurrentClassifier()->getAction(actionName); TransitionMachine::Transition * transition = tm.getTransition(actionName); action->setInfos(transition->headMvt, tm.getCurrentState()); - config.addToActionsHistory(config.getCurrentStateName(), actionName, tm.getCurrentClassifier()->getActionCost(config, actionName)); + config.addToActionsHistory(config.getCurrentStateName(), actionName, 0); action->apply(config); tm.takeTransition(transition); } diff --git a/transition_machine/src/Oracle.cpp b/transition_machine/src/Oracle.cpp index d3af24d7f833ff620aa0f65480d4262d7e43151a..1c7b7a0567ac80c36cc1da23e4e1fd179382bbd7 100644 --- a/transition_machine/src/Oracle.cpp +++ b/transition_machine/src/Oracle.cpp @@ -377,8 +377,12 @@ void Oracle::createDatabase() int head = c.getHead(); int stackHead = c.stackEmpty() ? 0 : c.stackTop(); - int stackGov = stackHead + std::stoi(govs.getRef(stackHead-head)); - int headGov = head + std::stoi(govs.getRef(0)); + int stackGov = 0; + try {stackGov = stackHead + std::stoi(govs.getRef(stackHead-head));} + catch (std::exception &){fprintf(stderr, "ERROR (%s) : aborting.\n", ERRINFO); exit(1);} + int headGov = 0; + try {headGov = head + std::stoi(govs.getRef(0));} + catch (std::exception &){fprintf(stderr, "ERROR (%s) : aborting.\n", ERRINFO); exit(1);} int sentenceStart = c.getHead()-1 < 0 ? 0 : c.getHead()-1; int sentenceEnd = c.getHead(); @@ -405,7 +409,9 @@ void Oracle::createDatabase() exit(1); } - int otherGov = i + std::stoi(govs.getRef(i-head)); + int otherGov = 0; + try {otherGov = i + std::stoi(govs.getRef(i-head));} + catch (std::exception &){fprintf(stderr, "ERROR (%s) : aborting.\n", ERRINFO); exit(1);} for (int j = 0; j < c.stackSize(); j++) { @@ -443,7 +449,9 @@ void Oracle::createDatabase() { for (int i = head; i <= sentenceEnd; i++) { - int otherGov = i + std::stoi(govs.getRef(i-head)); + int otherGov = 0; + try {otherGov = i + std::stoi(govs.getRef(i-head));} + catch (std::exception &){fprintf(stderr, "ERROR (%s) : aborting.\n", ERRINFO); exit(1);} if (otherGov == stackHead) cost++; } @@ -457,7 +465,9 @@ void Oracle::createDatabase() for (int i = head+1; i <= sentenceEnd; i++) { - int otherGov = i + std::stoi(govs.getRef(i-head)); + int otherGov = 0; + try {otherGov = i + std::stoi(govs.getRef(i-head));} + catch (std::exception &){fprintf(stderr, "ERROR (%s) : aborting.\n", ERRINFO); exit(1);} if (otherGov == stackHead || stackGov == i) cost++; } @@ -476,7 +486,9 @@ void Oracle::createDatabase() if (s == c.stackTop()) continue; - int otherGov = s + std::stoi(govs.getRef(s-head)); + int otherGov = 0; + try {otherGov = s + std::stoi(govs.getRef(s-head));} + catch (std::exception &){fprintf(stderr, "ERROR (%s) : aborting.\n", ERRINFO); exit(1);} if (otherGov == head || headGov == s) cost++; } @@ -551,12 +563,16 @@ void Oracle::explainCostOfAction(FILE * output, Config & c, const std::string & if (object[0] == "b") { - int index = c.getHead() + std::stoi(object[1]); + int index = 0; + try {index = c.getHead() + std::stoi(object[1]);} + catch (std::exception &){fprintf(stderr, "ERROR (%s) : aborting.\n", ERRINFO); exit(1);} expected = c.getTape(tape).getRef(index-c.getHead()); } else if (object[0] == "s") { - int stackIndex = std::stoi(object[1]); + int stackIndex = 0; + try {stackIndex = std::stoi(object[1]);} + catch (std::exception &){fprintf(stderr, "ERROR (%s) : aborting.\n", ERRINFO); exit(1);} int bufferIndex = c.stackGetElem(stackIndex) + c.getHead(); expected = c.getTape(tape).getRef(bufferIndex-c.getHead()); }