From 912e1d1eaf4e35261a3dc00ec121d921d8c49556 Mon Sep 17 00:00:00 2001 From: Franck Dary <franck.dary@lis-lab.fr> Date: Fri, 15 Mar 2019 16:23:13 +0100 Subject: [PATCH] Added Back x actions but there is still a bug --- transition_machine/src/Action.cpp | 5 +++ transition_machine/src/Oracle.cpp | 69 ++++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/transition_machine/src/Action.cpp b/transition_machine/src/Action.cpp index 1f838e5..32dcce8 100644 --- a/transition_machine/src/Action.cpp +++ b/transition_machine/src/Action.cpp @@ -1,6 +1,7 @@ #include "Action.hpp" #include "ActionBank.hpp" #include "util.hpp" +#include "ProgramParameters.hpp" void Action::apply(Config & config) { @@ -46,6 +47,10 @@ void Action::undoOnlyStack(Config & config) sequence[i].undo(config, sequence[i]); } + + if (ProgramParameters::debug) + fprintf(stderr, "Undoing action <%s>, history size = %d\n", name.c_str(), config.getStateHistory(stateName).size()); + config.getStateHistory(stateName).pop(); } Action::Action(const std::string & name) diff --git a/transition_machine/src/Oracle.cpp b/transition_machine/src/Oracle.cpp index b660cbc..a208dda 100644 --- a/transition_machine/src/Oracle.cpp +++ b/transition_machine/src/Oracle.cpp @@ -102,21 +102,34 @@ void Oracle::createDatabase() char b1[1024]; while (fscanf(fd, "%[^\n]\n", b1) == 1) - oracle->data[b1] = b1; + { + auto line = split(b1); + if (line.size() == 2) + oracle->data[line[0]] = line[1]; + else + { + fprintf(stderr, "ERROR (%s) : Invalid line \'%s\'. Aborting.\n", ERRINFO, b1); + exit(1); + } + } }, [](Config & c, Oracle * oracle) { - if (c.getCurrentStateHistory().size() >= 2 && (c.getCurrentStateHistory().top() == "BACK" || c.getCurrentStateHistory().getElem(1) == "BACK")) - return std::string("EPSILON"); + int stateHistorySize = c.getStateHistory("tagger").size(); - if (c.getCurrentStateHistory().size() < 2) + 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")) - return std::string("BACK 1"); + { + if (stateHistorySize > std::stoi(oracle->data["systematic"])) + return std::string("BACK " + oracle->data["systematic"]); + + return std::string("EPSILON"); + } auto & pos = c.getTape("POS"); @@ -147,21 +160,34 @@ void Oracle::createDatabase() char b1[1024]; while (fscanf(fd, "%[^\n]\n", b1) == 1) - oracle->data[b1] = b1; + { + auto line = split(b1); + if (line.size() == 2) + oracle->data[line[0]] = line[1]; + else + { + fprintf(stderr, "ERROR (%s) : Invalid line \'%s\'. Aborting.\n", ERRINFO, b1); + exit(1); + } + } }, [](Config & c, Oracle * oracle) { - if (c.getCurrentStateHistory().size() >= 2 && (c.getCurrentStateHistory().top() == "BACK" || c.getCurrentStateHistory().getElem(1) == "BACK")) - return std::string("EPSILON"); + int stateHistorySize = c.getStateHistory("morpho").size(); - if (c.getCurrentStateHistory().size() < 2) + 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")) - return std::string("BACK 1"); + { + if (stateHistorySize > std::stoi(oracle->data["systematic"])) + return std::string("BACK " + oracle->data["systematic"]); + + return std::string("EPSILON"); + } auto & morpho = c.getTape("MORPHO"); @@ -199,21 +225,34 @@ void Oracle::createDatabase() char b1[1024]; while (fscanf(fd, "%[^\n]\n", b1) == 1) - oracle->data[b1] = b1; + { + auto line = split(b1); + if (line.size() == 2) + oracle->data[line[0]] = line[1]; + else + { + fprintf(stderr, "ERROR (%s) : Invalid line \'%s\'. Aborting.\n", ERRINFO, b1); + exit(1); + } + } }, [](Config & c, Oracle * oracle) { - if (c.getCurrentStateHistory().size() >= 2 && (c.getCurrentStateHistory().top() == "BACK" || c.getCurrentStateHistory().getElem(1) == "BACK")) - return std::string("EPSILON"); + int stateHistorySize = c.getStateHistory("parser").size(); - if (c.getCurrentStateHistory().size() < 2) + 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")) - return std::string("BACK 1"); + { + if (stateHistorySize > std::stoi(oracle->data["systematic"])) + return std::string("BACK " + oracle->data["systematic"]); + + return std::string("EPSILON"); + } return std::string("EPSILON"); }, -- GitLab