mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-11-10 10:59:21 +03:00
64 lines
1.6 KiB
C++
64 lines
1.6 KiB
C++
#include <stdexcept>
|
|
#include "InputFeature.h"
|
|
#include "moses/Util.h"
|
|
#include "moses/ScoreComponentCollection.h"
|
|
#include "moses/InputPath.h"
|
|
#include "moses/StaticData.h"
|
|
#include "moses/TranslationModel/PhraseDictionaryTreeAdaptor.h"
|
|
|
|
using namespace std;
|
|
|
|
namespace Moses
|
|
{
|
|
InputFeature *InputFeature::s_instance = NULL;
|
|
|
|
InputFeature::InputFeature(const std::string &line)
|
|
:StatelessFeatureFunction(line)
|
|
{
|
|
ReadParameters();
|
|
|
|
UTIL_THROW_IF2(s_instance, "Can only have 1 input feature");
|
|
s_instance = this;
|
|
}
|
|
|
|
void InputFeature::Load()
|
|
{
|
|
const PhraseDictionary *pt = PhraseDictionary::GetColl()[0];
|
|
const PhraseDictionaryTreeAdaptor *ptBin = dynamic_cast<const PhraseDictionaryTreeAdaptor*>(pt);
|
|
|
|
m_legacy = (ptBin != NULL);
|
|
}
|
|
|
|
void InputFeature::SetParameter(const std::string& key, const std::string& value)
|
|
{
|
|
if (key == "num-input-features") {
|
|
m_numInputScores = Scan<size_t>(value);
|
|
} else if (key == "real-word-count") {
|
|
m_numRealWordCount = Scan<size_t>(value);
|
|
} else {
|
|
StatelessFeatureFunction::SetParameter(key, value);
|
|
}
|
|
|
|
}
|
|
|
|
void InputFeature::Evaluate(const InputType &input
|
|
, const InputPath &inputPath
|
|
, const TargetPhrase &targetPhrase
|
|
, ScoreComponentCollection &scoreBreakdown
|
|
, ScoreComponentCollection *estimatedFutureScore) const
|
|
{
|
|
if (m_legacy) {
|
|
//binary phrase-table does input feature itself
|
|
return;
|
|
}
|
|
/*
|
|
const ScorePair *scores = inputPath.GetInputScore();
|
|
if (scores) {
|
|
scoreBreakdown.PlusEquals(this, *scores);
|
|
}
|
|
*/
|
|
}
|
|
|
|
} // namespace
|
|
|