mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
target context feature base class
This commit is contained in:
parent
4b5e49aff9
commit
91541f0b83
@ -8,6 +8,7 @@
|
||||
#include "moses/TranslationTask.h"
|
||||
#include "moses/Util.h"
|
||||
#include "moses/FF/StatelessFeatureFunction.h"
|
||||
#include "moses/FF/FFState.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -104,6 +105,13 @@ public:
|
||||
, const TargetPhrase &targetPhrase
|
||||
, Discriminative::Classifier &classifier) const = 0;
|
||||
|
||||
// Overload to process target-context dependent features, these features are
|
||||
// evaluated during decoding. For efficiency, features are not fed directly into
|
||||
// the classifier object but instead output in the vector "features" and managed
|
||||
// separately in VW.h.
|
||||
virtual FFState *operator()(const Hypothesis &hypo
|
||||
, std::vector<StringPiece> &features) const = 0;
|
||||
|
||||
protected:
|
||||
std::vector<FactorType> m_sourceFactors, m_targetFactors;
|
||||
|
||||
|
49
moses/FF/VW/VWFeatureContext.h
Normal file
49
moses/FF/VW/VWFeatureContext.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "VWFeatureBase.h"
|
||||
#include "moses/InputType.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
// Inherit from this for source-dependent classifier features. They will
|
||||
// automatically register with the classifier class named VW0 or one or more
|
||||
// names specified by the used-by=name1,name2,... parameter.
|
||||
//
|
||||
// The classifier gets a full list by calling
|
||||
// VWFeatureBase::GetTargetContextFeatures(GetScoreProducerDescription())
|
||||
|
||||
|
||||
class VWFeatureContext : public VWFeatureBase
|
||||
{
|
||||
public:
|
||||
VWFeatureContext(const std::string &line)
|
||||
: VWFeatureBase(line, vwft_targetContext) {
|
||||
}
|
||||
|
||||
// Gets its pure virtual functions from VWFeatureBase
|
||||
|
||||
virtual void operator()(const InputType &input
|
||||
, const InputPath &inputPath
|
||||
, const TargetPhrase &targetPhrase
|
||||
, Discriminative::Classifier &classifier) const {
|
||||
}
|
||||
|
||||
virtual void operator()(const InputType &input
|
||||
, const InputPath &inputPath
|
||||
, const Range &sourceRange
|
||||
, Discriminative::Classifier &classifier) const {
|
||||
}
|
||||
|
||||
virtual void SetParameter(const std::string& key, const std::string& value) {
|
||||
VWFeatureBase::SetParameter(key, value);
|
||||
}
|
||||
|
||||
protected:
|
||||
inline std::string GetWord(const InputType &input, size_t pos) const {
|
||||
return input.GetWord(pos).GetString(m_sourceFactors, false);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -30,6 +30,11 @@ public:
|
||||
, Discriminative::Classifier &classifier) const {
|
||||
}
|
||||
|
||||
virtual FFState *operator()(const Hypothesis &hypo
|
||||
, std::vector<StringPiece> &features) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual void SetParameter(const std::string& key, const std::string& value) {
|
||||
VWFeatureBase::SetParameter(key, value);
|
||||
}
|
||||
|
@ -28,6 +28,11 @@ public:
|
||||
, Discriminative::Classifier &classifier) const {
|
||||
}
|
||||
|
||||
virtual FFState *operator()(const Hypothesis &hypo
|
||||
, std::vector<StringPiece> &features) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual void SetParameter(const std::string& key, const std::string& value) {
|
||||
VWFeatureBase::SetParameter(key, value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user