mosesdecoder/moses/FF/ControlRecombination.cpp

86 lines
2.3 KiB
C++
Raw Normal View History

#include "ControlRecombination.h"
#include "moses/Hypothesis.h"
#include "moses/Manager.h"
#include "moses/ChartHypothesis.h"
#include "moses/ChartManager.h"
#include "moses/StaticData.h"
#include "moses/InputFileStream.h"
#include "moses/Util.h"
#include "util/exception.hh"
using namespace std;
2013-07-25 18:23:05 +04:00
namespace Moses
{
ControlRecombinationState::ControlRecombinationState(const Hypothesis &hypo, const ControlRecombination &ff)
2013-09-27 12:35:24 +04:00
:m_ff(ff)
{
2013-09-27 12:35:24 +04:00
if (ff.GetType() == SameOutput) {
2014-04-09 12:59:52 +04:00
//UTIL_THROW(util::Exception, "Implemented not yet completed for phrase-based model. Need to take into account the coverage");
2013-09-27 12:35:24 +04:00
hypo.GetOutputPhrase(m_outputPhrase);
} else {
m_hypo = &hypo;
}
}
ControlRecombinationState::ControlRecombinationState(const ChartHypothesis &hypo, const ControlRecombination &ff)
2013-09-27 12:35:24 +04:00
:m_ff(ff)
{
2013-09-27 12:35:24 +04:00
if (ff.GetType() == SameOutput) {
hypo.GetOutputPhrase(m_outputPhrase);
} else {
m_hypo = &hypo;
}
}
int ControlRecombinationState::Compare(const FFState& other) const
{
2013-09-27 12:35:24 +04:00
const ControlRecombinationState &otherFF = static_cast<const ControlRecombinationState&>(other);
2014-04-09 12:59:52 +04:00
2013-09-27 12:35:24 +04:00
if (m_ff.GetType() == SameOutput) {
2014-04-09 12:59:52 +04:00
int ret = m_outputPhrase.Compare(otherFF.m_outputPhrase);
2013-09-27 12:35:24 +04:00
return ret;
} else {
// compare hypo address. Won't be equal unless they're actually the same hypo
if (m_hypo == otherFF.m_hypo)
return 0;
return (m_hypo < otherFF.m_hypo) ? -1 : +1;
}
}
std::vector<float> ControlRecombination::DefaultWeights() const
{
2013-11-23 00:27:46 +04:00
UTIL_THROW_IF2(m_numScoreComponents,
"ControlRecombination should not have any scores");
2013-09-27 12:35:24 +04:00
vector<float> ret(0);
return ret;
}
FFState* ControlRecombination::EvaluateWhenApplied(
const Hypothesis& hypo,
const FFState* prev_state,
ScoreComponentCollection* accumulator) const
{
2013-09-27 12:35:24 +04:00
return new ControlRecombinationState(hypo, *this);
}
FFState* ControlRecombination::EvaluateWhenApplied(
const ChartHypothesis &hypo,
int /* featureID - used to index the state in the previous hypotheses */,
ScoreComponentCollection* accumulator) const
{
2013-09-27 12:35:24 +04:00
return new ControlRecombinationState(hypo, *this);
}
void ControlRecombination::SetParameter(const std::string& key, const std::string& value)
{
2013-09-27 12:35:24 +04:00
if (key == "type") {
m_type = (ControlRecombinationType) Scan<int>(value);
} else {
StatefulFeatureFunction::SetParameter(key, value);
}
}
}