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

Made tagparser work again

parent c557899b
Branches
No related tags found
No related merge requests found
...@@ -351,7 +351,7 @@ Action::BasicAction ActionBank::pushHead() ...@@ -351,7 +351,7 @@ Action::BasicAction ActionBank::pushHead()
auto undo = [](Config & c, Action::BasicAction &) auto undo = [](Config & c, Action::BasicAction &)
{c.stackPop();}; {c.stackPop();};
auto appliable = [](Config & c, Action::BasicAction &) auto appliable = [](Config & c, Action::BasicAction &)
{return !(c.stackSize() >= ProgramParameters::maxStackSize || (!c.stackEmpty() && c.stackTop() == c.getHead()));}; {return !(c.stackSize() >= ProgramParameters::maxStackSize || (!c.stackEmpty() && c.stackTop() == c.getHead()) || c.getHead() >= c.getTape(ProgramParameters::sequenceDelimiterTape).size());};
Action::BasicAction basicAction = Action::BasicAction basicAction =
{Action::BasicAction::Type::Push, "", apply, undo, appliable}; {Action::BasicAction::Type::Push, "", apply, undo, appliable};
...@@ -663,6 +663,8 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na ...@@ -663,6 +663,8 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na
}; };
auto appliable = [](Config & c, Action::BasicAction &) auto appliable = [](Config & c, Action::BasicAction &)
{ {
if (c.getHead() >= c.getTape(ProgramParameters::sequenceDelimiterTape).size())
return false;
if (c.stackEmpty() || c.endOfTapes()) if (c.stackEmpty() || c.endOfTapes())
return false; return false;
int b0 = c.getHead(); int b0 = c.getHead();
...@@ -728,6 +730,8 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na ...@@ -728,6 +730,8 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na
}; };
auto appliable = [](Config & c, Action::BasicAction &) auto appliable = [](Config & c, Action::BasicAction &)
{ {
if (c.getHead() >= c.getTape(ProgramParameters::sequenceDelimiterTape).size())
return false;
if (c.stackEmpty()) if (c.stackEmpty())
return false; return false;
if (util::split(c.getTape("ID").getRef(0), '-').size() > 1) if (util::split(c.getTape("ID").getRef(0), '-').size() > 1)
...@@ -786,7 +790,7 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na ...@@ -786,7 +790,7 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na
}; };
auto appliable = [](Config & c, Action::BasicAction &) auto appliable = [](Config & c, Action::BasicAction &)
{ {
return !c.isFinal() && !c.stackEmpty(); return !c.isFinal() && !c.stackEmpty() && c.getTape(ProgramParameters::sequenceDelimiterTape).getHyp(c.stackTop()-c.getHead()) != ProgramParameters::sequenceDelimiter;
}; };
Action::BasicAction basicAction = Action::BasicAction basicAction =
{Action::BasicAction::Type::Write, "", apply, undo, appliable}; {Action::BasicAction::Type::Write, "", apply, undo, appliable};
......
...@@ -943,6 +943,10 @@ void Config::updateIdsInSequence() ...@@ -943,6 +943,10 @@ void Config::updateIdsInSequence()
auto & ids = getTape("ID"); auto & ids = getTape("ID");
while (sentenceEnd >= 0 && eos.getHyp(sentenceEnd-getHead()) != ProgramParameters::sequenceDelimiter) while (sentenceEnd >= 0 && eos.getHyp(sentenceEnd-getHead()) != ProgramParameters::sequenceDelimiter)
sentenceEnd--; sentenceEnd--;
while (sentenceEnd >= ids.size())
sentenceEnd--;
int sentenceStart = std::max(0,sentenceEnd-1); int sentenceStart = std::max(0,sentenceEnd-1);
while (sentenceStart >= 0 && eos.getHyp(sentenceStart-getHead()) != ProgramParameters::sequenceDelimiter) while (sentenceStart >= 0 && eos.getHyp(sentenceStart-getHead()) != ProgramParameters::sequenceDelimiter)
sentenceStart--; sentenceStart--;
...@@ -964,6 +968,7 @@ void Config::updateIdsInSequence() ...@@ -964,6 +968,7 @@ void Config::updateIdsInSequence()
for (int i = sentenceStart; i <= sentenceEnd; i++) for (int i = sentenceStart; i <= sentenceEnd; i++)
{ {
auto splited = util::split(ids.getRef(i-getHead()), '-'); auto splited = util::split(ids.getRef(i-getHead()), '-');
if (splited.size() == 1) if (splited.size() == 1)
{ {
auto splited2 = util::split(ids.getRef(i-getHead()), '.'); auto splited2 = util::split(ids.getRef(i-getHead()), '.');
......
...@@ -584,6 +584,8 @@ void Oracle::createDatabase() ...@@ -584,6 +584,8 @@ void Oracle::createDatabase()
if (util::split(previousAction, ' ')[0] == "shift" || util::split(previousAction, ' ')[0] == "right") if (util::split(previousAction, ' ')[0] == "shift" || util::split(previousAction, ' ')[0] == "right")
{ {
newState = "signature"; newState = "signature";
if (c.endOfTapes())
newState = "parser";
movement = 1; movement = 1;
} }
else else
...@@ -772,6 +774,10 @@ void Oracle::createDatabase() ...@@ -772,6 +774,10 @@ void Oracle::createDatabase()
auto & eos = c.getTape(ProgramParameters::sequenceDelimiterTape); auto & eos = c.getTape(ProgramParameters::sequenceDelimiterTape);
int head = c.getHead(); int head = c.getHead();
if (head >= eos.size())
return action == "EOS" ? 0 : 1;
bool headIsMultiword = util::split(ids.getRef(0), '-').size() > 1; bool headIsMultiword = util::split(ids.getRef(0), '-').size() > 1;
bool headIsEmptyNode = util::split(ids.getRef(0), '.').size() > 1; bool headIsEmptyNode = util::split(ids.getRef(0), '.').size() > 1;
int headGov = -1; int headGov = -1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment