diff --git a/transition_machine/src/Oracle.cpp b/transition_machine/src/Oracle.cpp index f7b84c32c3988e76fb127a5b0813e5cdfbaa6ae2..d3af24d7f833ff620aa0f65480d4262d7e43151a 100644 --- a/transition_machine/src/Oracle.cpp +++ b/transition_machine/src/Oracle.cpp @@ -94,6 +94,19 @@ void Oracle::createDatabase() return 1; }))); + auto backSys = [](Config & c, Oracle * oracle) + { + if (oracle->data.count("systematic")) + { + if (Action("BACK " + oracle->data["systematic"]).appliable(c)) + return std::string("BACK " + oracle->data["systematic"]); + + return std::string("EPSILON"); + } + + return std::string("EPSILON"); + }; + str2oracle.emplace("error_tagger", std::unique_ptr<Oracle>(new Oracle( [](Oracle * oracle) { @@ -113,40 +126,7 @@ void Oracle::createDatabase() } } }, - [](Config & c, Oracle * oracle) - { - int stateHistorySize = c.getStateHistory("tagger").size(); - - if (c.getCurrentStateHistory().size() >= 2 && (c.getCurrentStateHistory().top() == "BACK" || c.getCurrentStateHistory().getElem(1) == "BACK")) - return std::string("EPSILON"); - - if (c.hashHistory.contains(c.computeHash())) - return std::string("EPSILON"); - - if (oracle->data.count("systematic")) - { - if (stateHistorySize > std::stoi(oracle->data["systematic"])) - return std::string("BACK " + oracle->data["systematic"]); - - return std::string("EPSILON"); - } - - auto & pos = c.getTape("POS"); - - if (c.getHead() > 0 && pos[-1] != pos.getRef(-1) && pos[-1] == "det" && pos[0] == "prorel") - return std::string("BACK 1"); - - if (c.getHead() > 0 && pos[-1] != pos.getRef(-1) && pos[-1] == "det" && pos[0] == "prep") - return std::string("BACK 1"); - - if (c.getHead() > 0 && pos[-1] != pos.getRef(-1) && pos[-1] == "nc" && pos[0] == "nc") - return std::string("BACK 1"); - - if (c.getHead() > 0 && pos[-1] != pos.getRef(-1) && pos[-1] == "nc" && pos[0] == "prep") - return std::string("BACK 1"); - - return std::string("EPSILON"); - }, + backSys, [](Config &, Oracle *, const std::string &) { return 0; @@ -171,47 +151,7 @@ void Oracle::createDatabase() } } }, - [](Config & c, Oracle * oracle) - { - int stateHistorySize = c.getStateHistory("morpho").size(); - - if (c.getCurrentStateHistory().size() >= 2 && (c.getCurrentStateHistory().top() == "BACK" || c.getCurrentStateHistory().getElem(1) == "BACK")) - return std::string("EPSILON"); - - if (c.hashHistory.contains(c.computeHash())) - return std::string("EPSILON"); - - if (oracle->data.count("systematic")) - { - if (stateHistorySize > std::stoi(oracle->data["systematic"])) - return std::string("BACK " + oracle->data["systematic"]); - - return std::string("EPSILON"); - } - - auto & morpho = c.getTape("MORPHO"); - - if (c.getHead() <= 0) - return std::string("EPSILON"); - - auto & morphoRef = morpho.getRef(-1); - auto & morpho0 = morpho[-1]; - auto & morpho1 = morpho[0]; - - if (morpho0 == morphoRef) - return std::string("EPSILON"); - - auto genre0 = split(morpho0, '|')[0]; - auto genre1 = split(morpho1, '|')[0]; - - if (genre0 == "g=f" && genre1 == "g=m") - return std::string("BACK 1"); - - if (genre0 == "g=m" && genre1 == "g=f") - return std::string("BACK 1"); - - return std::string("EPSILON"); - }, + backSys, [](Config &, Oracle *, const std::string &) { return 0; @@ -236,26 +176,7 @@ void Oracle::createDatabase() } } }, - [](Config & c, Oracle * oracle) - { - int stateHistorySize = c.getStateHistory("parser").size(); - - if (c.getCurrentStateHistory().size() >= 2 && (c.getCurrentStateHistory().top() == "BACK" || c.getCurrentStateHistory().getElem(1) == "BACK")) - return std::string("EPSILON"); - - if (c.hashHistory.contains(c.computeHash())) - return std::string("EPSILON"); - - if (oracle->data.count("systematic")) - { - if (stateHistorySize > std::stoi(oracle->data["systematic"])) - return std::string("BACK " + oracle->data["systematic"]); - - return std::string("EPSILON"); - } - - return std::string("EPSILON"); - }, + backSys, [](Config &, Oracle *, const std::string &) { return 0;