2013-07-21 02:10:50 +04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2013-09-18 18:27:10 +04:00
|
|
|
#include <map>
|
2013-07-21 02:10:50 +04:00
|
|
|
#include "StatefulFeatureFunction.h"
|
2013-09-18 18:27:10 +04:00
|
|
|
#include "FFState.h"
|
|
|
|
#include "moses/Phrase.h"
|
2013-07-21 02:10:50 +04:00
|
|
|
|
2013-07-25 18:23:05 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2013-09-27 12:35:24 +04:00
|
|
|
enum ControlRecombinationType {
|
|
|
|
// when to recombine
|
2013-09-26 00:47:20 +04:00
|
|
|
SameOutput = 1,
|
|
|
|
Never = 2
|
2013-09-25 23:59:13 +04:00
|
|
|
};
|
2013-07-21 02:10:50 +04:00
|
|
|
|
2013-09-26 00:47:20 +04:00
|
|
|
class ControlRecombination;
|
|
|
|
|
2013-09-18 18:27:10 +04:00
|
|
|
class ControlRecombinationState : public FFState
|
2013-07-21 02:10:50 +04:00
|
|
|
{
|
|
|
|
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-18 18:27:10 +04:00
|
|
|
|
2013-09-27 12:35:24 +04:00
|
|
|
ControlRecombinationState(const Hypothesis &hypo, const ControlRecombination &ff);
|
|
|
|
ControlRecombinationState(const ChartHypothesis &hypo, const ControlRecombination &ff);
|
2013-09-18 18:27:10 +04:00
|
|
|
|
2015-10-08 19:14:08 +03:00
|
|
|
virtual size_t hash() const;
|
2015-10-13 19:12:10 +03:00
|
|
|
virtual bool operator==(const FFState& other) const;
|
2013-09-18 18:27:10 +04:00
|
|
|
|
2013-09-27 12:35:24 +04:00
|
|
|
const Phrase &GetPhrase() const {
|
|
|
|
return m_outputPhrase;
|
|
|
|
}
|
2013-09-18 18:27:10 +04:00
|
|
|
|
2013-07-21 02:41:49 +04:00
|
|
|
protected:
|
2013-09-27 12:35:24 +04:00
|
|
|
Phrase m_outputPhrase;
|
|
|
|
const ControlRecombination &m_ff;
|
|
|
|
const void *m_hypo;
|
2013-07-21 02:10:50 +04:00
|
|
|
};
|
|
|
|
|
2013-09-18 18:27:10 +04:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2013-07-21 02:10:50 +04:00
|
|
|
|
2013-09-18 19:27:18 +04:00
|
|
|
// only allow recombination for the same output
|
2013-09-18 18:27:10 +04:00
|
|
|
class ControlRecombination : public StatefulFeatureFunction
|
|
|
|
{
|
2013-07-21 02:10:50 +04:00
|
|
|
public:
|
2013-09-27 12:35:24 +04:00
|
|
|
ControlRecombination(const std::string &line)
|
2013-10-29 22:59:53 +04:00
|
|
|
: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;
|
|
|
|
}
|
|
|
|
|
2014-07-10 02:41:08 +04:00
|
|
|
FFState* EvaluateWhenApplied(
|
2013-09-27 12:35:24 +04:00
|
|
|
const Hypothesis& cur_hypo,
|
|
|
|
const FFState* prev_state,
|
|
|
|
ScoreComponentCollection* accumulator) const;
|
|
|
|
|
2014-07-10 02:54:16 +04:00
|
|
|
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;
|
|
|
|
}
|
2013-09-18 18:27:10 +04:00
|
|
|
protected:
|
2013-09-27 12:35:24 +04:00
|
|
|
ControlRecombinationType m_type;
|
2013-07-21 02:10:50 +04:00
|
|
|
};
|
|
|
|
|
2013-09-18 18:27:10 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|