2015-09-24 12:57:36 +03:00
|
|
|
#include <vector>
|
|
|
|
#include "DeleteRules.h"
|
|
|
|
#include "moses/ScoreComponentCollection.h"
|
|
|
|
#include "moses/TargetPhrase.h"
|
|
|
|
#include "moses/InputFileStream.h"
|
|
|
|
#include "util/exception.hh"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
DeleteRules::DeleteRules(const std::string &line)
|
|
|
|
:StatelessFeatureFunction(1, line)
|
|
|
|
{
|
|
|
|
m_tuneable = false;
|
|
|
|
ReadParameters();
|
|
|
|
}
|
|
|
|
|
2015-12-10 06:17:36 +03:00
|
|
|
void DeleteRules::Load(AllOptions::ptr const& opts)
|
2015-09-24 12:57:36 +03:00
|
|
|
{
|
2015-12-10 06:17:36 +03:00
|
|
|
m_options = opts;
|
2015-09-25 02:01:00 +03:00
|
|
|
std::vector<FactorType> factorOrder;
|
|
|
|
factorOrder.push_back(0); // unfactored for now
|
|
|
|
|
|
|
|
InputFileStream strme(m_path);
|
|
|
|
|
|
|
|
string line;
|
|
|
|
while (getline(strme, line)) {
|
|
|
|
vector<string> toks = TokenizeMultiCharSeparator(line, "|||");
|
|
|
|
UTIL_THROW_IF2(toks.size() != 2, "Line must be source ||| target");
|
|
|
|
Phrase source, target;
|
|
|
|
source.CreateFromString(Input, factorOrder, toks[0], NULL);
|
|
|
|
target.CreateFromString(Output, factorOrder, toks[1], NULL);
|
|
|
|
|
|
|
|
size_t hash = 0;
|
|
|
|
boost::hash_combine(hash, source);
|
|
|
|
boost::hash_combine(hash, target);
|
|
|
|
m_ruleHashes.insert(hash);
|
|
|
|
}
|
2015-09-24 12:57:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteRules::EvaluateInIsolation(const Phrase &source
|
2015-09-25 02:01:00 +03:00
|
|
|
, const TargetPhrase &target
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
2015-11-04 18:10:45 +03:00
|
|
|
, ScoreComponentCollection &estimatedScores) const
|
2015-09-24 12:57:36 +03:00
|
|
|
{
|
|
|
|
// dense scores
|
|
|
|
size_t hash = 0;
|
|
|
|
boost::hash_combine(hash, source);
|
|
|
|
boost::hash_combine(hash, target);
|
|
|
|
|
|
|
|
boost::unordered_set<size_t>::const_iterator iter;
|
|
|
|
iter = m_ruleHashes.find(hash);
|
|
|
|
if (iter != m_ruleHashes.end()) {
|
2015-09-25 02:01:00 +03:00
|
|
|
scoreBreakdown.PlusEquals(this, -std::numeric_limits<float>::infinity());
|
2015-09-24 12:57:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteRules::EvaluateWithSourceContext(const InputType &input
|
|
|
|
, const InputPath &inputPath
|
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, const StackVec *stackVec
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
2015-11-04 18:10:45 +03:00
|
|
|
, ScoreComponentCollection *estimatedScores) const
|
2015-09-24 12:57:36 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
void DeleteRules::EvaluateTranslationOptionListWithSourceContext(const InputType &input
|
|
|
|
|
|
|
|
, const TranslationOptionList &translationOptionList) const
|
|
|
|
{}
|
|
|
|
|
|
|
|
void DeleteRules::EvaluateWhenApplied(const Hypothesis& hypo,
|
2015-09-25 02:01:00 +03:00
|
|
|
ScoreComponentCollection* accumulator) const
|
2015-09-24 12:57:36 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
void DeleteRules::EvaluateWhenApplied(const ChartHypothesis &hypo,
|
2015-09-25 02:01:00 +03:00
|
|
|
ScoreComponentCollection* accumulator) const
|
2015-09-24 12:57:36 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
void DeleteRules::SetParameter(const std::string& key, const std::string& value)
|
|
|
|
{
|
|
|
|
if (key == "path") {
|
2015-09-25 02:01:00 +03:00
|
|
|
m_path = value;
|
2015-09-24 12:57:36 +03:00
|
|
|
} else {
|
|
|
|
StatelessFeatureFunction::SetParameter(key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|