mosesdecoder/moses/FF/ConstrainedDecoding.h

92 lines
2.4 KiB
C
Raw Normal View History

2013-09-16 22:45:43 +04:00
#pragma once
#include <string>
#include <map>
2013-09-16 22:45:43 +04:00
#include "StatefulFeatureFunction.h"
#include "FFState.h"
#include "moses/Phrase.h"
namespace Moses
{
class ConstrainedDecodingState : public FFState
{
public:
2015-01-14 14:07:42 +03:00
ConstrainedDecodingState() {
}
2013-09-16 22:45:43 +04:00
2013-09-27 12:35:24 +04:00
ConstrainedDecodingState(const Hypothesis &hypo);
ConstrainedDecodingState(const ChartHypothesis &hypo);
2013-09-16 22:45:43 +04:00
2013-09-27 12:35:24 +04:00
int Compare(const FFState& other) const;
2013-09-16 22:45:43 +04:00
2013-09-27 12:35:24 +04:00
const Phrase &GetPhrase() const {
return m_outputPhrase;
}
2013-09-16 22:45:43 +04:00
protected:
2013-09-27 12:35:24 +04:00
Phrase m_outputPhrase;
2013-09-16 22:45:43 +04:00
};
//////////////////////////////////////////////////////////////////
2013-09-18 19:27:18 +04:00
// only allow hypotheses which match reference
2013-09-16 22:45:43 +04:00
class ConstrainedDecoding : public StatefulFeatureFunction
{
public:
ConstrainedDecoding(const std::string &line);
2013-09-27 12:35:24 +04:00
void Load();
bool IsUseable(const FactorMask &mask) const {
return true;
}
void EvaluateInIsolation(const Phrase &source
2015-01-14 14:07:42 +03:00
, const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown
, ScoreComponentCollection &estimatedFutureScore) const {
}
void EvaluateWithSourceContext(const InputType &input
2015-01-14 14:07:42 +03:00
, const InputPath &inputPath
, const TargetPhrase &targetPhrase
, const StackVec *stackVec
, ScoreComponentCollection &scoreBreakdown
, ScoreComponentCollection *estimatedFutureScore = NULL) const {
}
void EvaluateTranslationOptionListWithSourceContext(const InputType &input
2015-01-14 14:07:42 +03:00
, const TranslationOptionList &translationOptionList) const {
}
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 ConstrainedDecodingState();
}
std::vector<float> DefaultWeights() const;
void SetParameter(const std::string& key, const std::string& value);
protected:
std::vector<std::string> m_paths;
std::map<long, std::vector<Phrase> > m_constraints;
2013-09-27 12:35:24 +04:00
int m_maxUnknowns;
bool m_negate; // only keep translations which DON'T match the reference
bool m_soft;
2013-09-16 22:45:43 +04:00
};
}