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

Fixed oracle for systematic backtracking

parent 8353c4cc
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment