mosesdecoder/moses/FF/ControlRecombination.h

89 lines
1.9 KiB
C
Raw Permalink Normal View History

#pragma once
#include <string>
#include <map>
#include "StatefulFeatureFunction.h"
#include "FFState.h"
#include "moses/Phrase.h"
2013-07-25 18:23:05 +04:00
namespace Moses
{
2013-09-27 12:35:24 +04:00
enum ControlRecombinationType {
// when to recombine
SameOutput = 1,
Never = 2
2013-09-25 23:59:13 +04:00
};
class ControlRecombination;
class ControlRecombinationState : public FFState
{
public:
2013-09-27 12:35:24 +04:00
ControlRecombinationState(const ControlRecombination &ff)
2015-01-14 14:07:42 +03:00
:m_ff(ff) {
}
2013-09-27 12:35:24 +04:00
ControlRecombinationState(const Hypothesis &hypo, const ControlRecombination &ff);
ControlRecombinationState(const ChartHypothesis &hypo, const ControlRecombination &ff);
virtual size_t hash() const;
2015-10-13 19:12:10 +03:00
virtual bool operator==(const FFState& other) const;
2013-09-27 12:35:24 +04:00
const Phrase &GetPhrase() const {
return m_outputPhrase;
}
protected:
2013-09-27 12:35:24 +04:00
Phrase m_outputPhrase;
const ControlRecombination &m_ff;
const void *m_hypo;
};
//////////////////////////////////////////////////////////////////
2013-09-18 19:27:18 +04:00
// only allow recombination for the same output
class ControlRecombination : public StatefulFeatureFunction
{
public:
2013-09-27 12:35:24 +04:00
ControlRecombination(const std::string &line)
:StatefulFeatureFunction(0, line)
2013-09-27 12:35:24 +04:00
,m_type(SameOutput)
{
m_tuneable = false;
ReadParameters();
}
bool IsUseable(const FactorMask &mask) const {
return true;
}
FFState* EvaluateWhenApplied(
2013-09-27 12:35:24 +04:00
const Hypothesis& cur_hypo,
const FFState* prev_state,
ScoreComponentCollection* accumulator) const;
FFState* EvaluateWhenApplied(
2013-09-27 12:35:24 +04:00
const ChartHypothesis& /* cur_hypo */,
int /* featureID - used to index the state in the previous hypotheses */,
ScoreComponentCollection* accumulator) const;
virtual const FFState* EmptyHypothesisState(const InputType &input) const {
return new ControlRecombinationState(*this);
}
std::vector<float> DefaultWeights() const;
void SetParameter(const std::string& key, const std::string& value);
ControlRecombinationType GetType() const {
return m_type;
}
protected:
2013-09-27 12:35:24 +04:00
ControlRecombinationType m_type;
};
}