2011-05-11 02:02:25 +04:00
|
|
|
#ifndef moses_PhraseBoundaryFeature_h
|
|
|
|
#define moses_PhraseBoundaryFeature_h
|
|
|
|
|
2013-05-24 16:04:39 +04:00
|
|
|
#include <stdexcept>
|
2011-05-11 02:02:25 +04:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
2013-05-24 22:11:15 +04:00
|
|
|
#include "StatefulFeatureFunction.h"
|
2013-05-24 21:02:49 +04:00
|
|
|
#include "moses/FF/FFState.h"
|
|
|
|
#include "moses/Word.h"
|
2011-05-11 02:02:25 +04:00
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
class PhraseBoundaryState : public FFState
|
|
|
|
{
|
2011-05-11 02:02:25 +04:00
|
|
|
public:
|
2011-06-24 17:06:58 +04:00
|
|
|
PhraseBoundaryState(const Word* sourceWord, const Word* targetWord) :
|
2013-05-29 21:16:15 +04:00
|
|
|
m_sourceWord(sourceWord), m_targetWord(targetWord) {}
|
|
|
|
const Word* GetSourceWord() const {
|
|
|
|
return m_sourceWord;
|
|
|
|
}
|
|
|
|
const Word* GetTargetWord() const {
|
|
|
|
return m_targetWord;
|
|
|
|
}
|
2011-05-11 02:02:25 +04:00
|
|
|
virtual int Compare(const FFState& other) const;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2011-06-24 17:06:58 +04:00
|
|
|
const Word* m_sourceWord;
|
|
|
|
const Word* m_targetWord;
|
2011-05-11 02:02:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concatenations of factors on boundaries of phrases.
|
|
|
|
**/
|
2013-05-29 21:16:15 +04:00
|
|
|
class PhraseBoundaryFeature : public StatefulFeatureFunction
|
|
|
|
{
|
2011-05-11 02:02:25 +04:00
|
|
|
public:
|
2013-01-02 20:06:22 +04:00
|
|
|
PhraseBoundaryFeature(const std::string &line);
|
2011-05-11 02:02:25 +04:00
|
|
|
|
2013-05-30 15:41:08 +04:00
|
|
|
bool IsUseable(const FactorMask &mask) const;
|
2011-05-11 02:02:25 +04:00
|
|
|
|
2011-08-22 17:52:02 +04:00
|
|
|
virtual const FFState* EmptyHypothesisState(const InputType &) const;
|
2011-05-11 02:02:25 +04:00
|
|
|
|
|
|
|
virtual FFState* Evaluate(const Hypothesis& cur_hypo, const FFState* prev_state,
|
2013-05-29 21:16:15 +04:00
|
|
|
ScoreComponentCollection* accumulator) const;
|
2011-05-11 02:02:25 +04:00
|
|
|
|
2011-08-22 17:52:02 +04:00
|
|
|
virtual FFState* EvaluateChart( const ChartHypothesis& /* cur_hypo */,
|
|
|
|
int /* featureID */,
|
2013-05-24 16:04:39 +04:00
|
|
|
ScoreComponentCollection* ) const {
|
|
|
|
throw std::logic_error("PhraseBoundaryState not supported in chart decoder, yet");
|
|
|
|
}
|
2013-08-30 18:49:00 +04:00
|
|
|
|
|
|
|
void Evaluate(const InputType &input
|
2013-09-27 12:35:24 +04:00
|
|
|
, const InputPath &inputPath
|
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown) const
|
2013-08-30 18:49:00 +04:00
|
|
|
{}
|
|
|
|
void Evaluate(const Phrase &source
|
2013-09-27 12:35:24 +04:00
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
|
|
|
, ScoreComponentCollection &estimatedFutureScore) const
|
2013-08-30 18:49:00 +04:00
|
|
|
{}
|
|
|
|
|
2013-06-20 16:25:02 +04:00
|
|
|
void SetParameter(const std::string& key, const std::string& value);
|
2013-05-24 16:04:39 +04:00
|
|
|
|
2011-05-11 02:02:25 +04:00
|
|
|
private:
|
|
|
|
void AddFeatures(
|
2013-05-29 21:16:15 +04:00
|
|
|
const Word* leftWord, const Word* rightWord, const FactorList& factors,
|
2011-05-11 02:02:25 +04:00
|
|
|
const std::string& side, ScoreComponentCollection* scores) const ;
|
|
|
|
FactorList m_sourceFactors;
|
|
|
|
FactorList m_targetFactors;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|