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

Corrected a bug where RULE action was always considered appliable

parent ddbbd352
Branches
No related tags found
No related merge requests found
......@@ -316,6 +316,7 @@ void Trainer::printScoresAndSave(FILE * output)
savedStr.emplace_back(saved[it.first] ? "SAVED" : "");
}
if (ProgramParameters::interactive)
fprintf(stderr, " \r");
fprintf(output, "Iteration %d/%d :\n", curIter+1, ProgramParameters::nbIter);
......
......@@ -49,6 +49,18 @@ class ActionBank
static bool simpleBufferWriteAppliable(Config & config,
const std::string & tapeName, int relativeIndex);
/// @brief Whether or not the transform rule is appliable.
///
/// This is a helper function that helps construct BasicAction.
/// @param config The current Config.
/// @param tapeName The name of the tape the rule would be applied on.
/// @param relativeIndex The relative index of the cell of the tape.
/// @param rule The rule.
///
/// @return Whether or not rule can be applied to the cell of tapeName.
static bool isRuleAppliable(Config & config,
const std::string & tapeName, int relativeIndex, const std::string & rule);
/// @brief Apply a transformation rule to a copy of a multi-tapes buffer cell, and write the result in another cell.
///
/// A rule is in the form '\@er\@w' which in this case means 'remove er suffix and add w suffix'
......
......@@ -126,8 +126,8 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na
{writeRuleResult(c, fromTapeName, targetTapeName, rule, 0);};
auto undo = [targetTapeName](Config & c, Action::BasicAction &)
{simpleBufferWrite(c, targetTapeName, "", 0);};
auto appliable = [targetTapeName](Config & c, Action::BasicAction &)
{return simpleBufferWriteAppliable(c, targetTapeName, 0);};
auto appliable = [fromTapeName,rule](Config & c, Action::BasicAction &)
{return isRuleAppliable(c, fromTapeName, 0, rule);};
Action::BasicAction basicAction =
{Action::BasicAction::Type::Write, rule, apply, undo, appliable};
......@@ -457,6 +457,14 @@ bool ActionBank::simpleBufferWriteAppliable(Config & config,
return (!(index < 0 || index >= (int)tape.hyp.size())) && tape.hyp[index].empty();
}
bool ActionBank::isRuleAppliable(Config & config,
const std::string & tapeName, int relativeIndex, const std::string & rule)
{
if (!simpleBufferWriteAppliable(config, tapeName, relativeIndex))
return false;
return ruleIsAppliable(config.getTape(tapeName)[config.head+relativeIndex], rule);
}
void ActionBank::writeRuleResult(Config & config, const std::string & fromTapeName, const std::string & targetTapeName, const std::string & rule, int relativeIndex)
{
auto & fromTape = config.getTape(fromTapeName);
......
......@@ -188,14 +188,14 @@ void Classifier::printWeightedActions(FILE * output, WeightedActions & wa, int t
auto & it = wa[i];
bool thisActionIsPossible = it.first ? true : false;
oneActionWasPossible = oneActionWasPossible || thisActionIsPossible;
fprintf(output, "%s %.2f\t%s\n", thisActionIsPossible ? "*" : " ", it.second.first, it.second.second.c_str());
fprintf(output, "%s %6.2f %s\n", thisActionIsPossible ? "*" : " ", it.second.first, it.second.second.c_str());
}
if(!oneActionWasPossible)
for(unsigned int i = threshhold; i < wa.size() ;i++)
if(wa[i].first)
{
fprintf(output, "%s %.2f\t%s\n", "*", wa[i].second.first, wa[i].second.second.c_str());
fprintf(output, "%s %6.2f %s\n", "*", wa[i].second.first, wa[i].second.second.c_str());
break;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment