mosesdecoder/moses/FF/ControlRecombination.cpp

97 lines
2.5 KiB
C++
Raw Permalink 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;
}
}
size_t ControlRecombinationState::hash() const
{
size_t ret;
if (m_ff.GetType() == SameOutput) {
2015-10-16 15:53:33 +03:00
ret = hash_value(m_outputPhrase);
} else {
// compare hypo address. Won't be equal unless they're actually the same hypo
2015-10-16 15:53:33 +03:00
ret = (size_t) m_hypo;
}
return ret;
}
2015-10-13 19:12:10 +03:00
bool ControlRecombinationState::operator==(const FFState& other) const
{
const ControlRecombinationState &otherFF = static_cast<const ControlRecombinationState&>(other);
if (m_ff.GetType() == SameOutput) {
return m_outputPhrase == otherFF.m_outputPhrase;
2015-10-13 19:12:10 +03:00
} else {
2015-10-16 15:53:33 +03:00
// compare hypo address. Won't be equal unless they're actually the same hypo
if (m_hypo == otherFF.m_hypo)
return true;
return (m_hypo == otherFF.m_hypo);
2015-10-13 19:12:10 +03:00
}
}
std::vector<float> ControlRecombination::DefaultWeights() const
{
2013-11-23 00:27:46 +04:00
UTIL_THROW_IF2(m_numScoreComponents,
2014-01-15 19:42:02 +04:00
"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);
}
}
}