2013-05-28 20:25:59 +04:00
|
|
|
#include <stdexcept>
|
|
|
|
#include "InputFeature.h"
|
2013-06-05 01:09:21 +04:00
|
|
|
#include "moses/Util.h"
|
2013-08-14 19:53:06 +04:00
|
|
|
#include "moses/ScoreComponentCollection.h"
|
|
|
|
#include "moses/InputPath.h"
|
2013-09-08 15:47:32 +04:00
|
|
|
#include "moses/StaticData.h"
|
|
|
|
#include "moses/TranslationModel/PhraseDictionaryTreeAdaptor.h"
|
2013-05-28 20:25:59 +04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
2013-12-07 04:21:06 +04:00
|
|
|
InputFeature *InputFeature::s_instance = NULL;
|
|
|
|
|
2013-05-28 20:25:59 +04:00
|
|
|
InputFeature::InputFeature(const std::string &line)
|
2015-04-29 22:16:52 +03:00
|
|
|
: StatelessFeatureFunction(line,true)
|
2014-03-11 17:56:40 +04:00
|
|
|
, m_numRealWordCount(0)
|
2013-05-28 20:25:59 +04:00
|
|
|
{
|
2014-03-24 14:53:29 +04:00
|
|
|
m_numInputScores = this->m_numScoreComponents;
|
2013-08-16 00:14:04 +04:00
|
|
|
ReadParameters();
|
2014-05-19 17:34:27 +04:00
|
|
|
|
2013-12-07 04:21:06 +04:00
|
|
|
UTIL_THROW_IF2(s_instance, "Can only have 1 input feature");
|
|
|
|
s_instance = this;
|
2013-08-14 19:53:06 +04:00
|
|
|
}
|
|
|
|
|
2015-12-10 06:17:36 +03:00
|
|
|
void InputFeature::Load(AllOptions::ptr const& opts)
|
2013-09-08 15:47:32 +04:00
|
|
|
{
|
2015-12-10 06:17:36 +03:00
|
|
|
m_options = opts;
|
2013-11-15 21:26:26 +04:00
|
|
|
const PhraseDictionary *pt = PhraseDictionary::GetColl()[0];
|
2013-09-27 12:35:24 +04:00
|
|
|
const PhraseDictionaryTreeAdaptor *ptBin = dynamic_cast<const PhraseDictionaryTreeAdaptor*>(pt);
|
2013-09-08 15:47:32 +04:00
|
|
|
|
2013-09-27 12:35:24 +04:00
|
|
|
m_legacy = (ptBin != NULL);
|
2013-09-08 15:47:32 +04:00
|
|
|
}
|
|
|
|
|
2013-08-14 19:53:06 +04:00
|
|
|
void InputFeature::SetParameter(const std::string& key, const std::string& value)
|
|
|
|
{
|
2013-08-16 00:14:04 +04:00
|
|
|
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);
|
|
|
|
}
|
2013-08-14 19:53:06 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-10 02:06:54 +04:00
|
|
|
void InputFeature::EvaluateWithSourceContext(const InputType &input
|
2015-01-14 14:07:42 +03:00
|
|
|
, const InputPath &inputPath
|
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, const StackVec *stackVec
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
2015-11-04 18:10:45 +03:00
|
|
|
, ScoreComponentCollection *estimatedScores) const
|
2013-08-14 19:53:06 +04:00
|
|
|
{
|
2013-09-27 12:35:24 +04:00
|
|
|
if (m_legacy) {
|
2015-02-19 15:27:23 +03:00
|
|
|
//binary phrase-table does input feature itself
|
|
|
|
return;
|
|
|
|
} else if (input.GetType() == WordLatticeInput) {
|
|
|
|
const ScorePair *scores = inputPath.GetInputScore();
|
|
|
|
if (scores) {
|
|
|
|
scoreBreakdown.PlusEquals(this, *scores);
|
|
|
|
}
|
2013-08-16 00:14:04 +04:00
|
|
|
}
|
2013-05-28 20:25:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-05 01:09:21 +04:00
|
|
|
} // namespace
|
2013-05-28 20:25:59 +04:00
|
|
|
|