mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
1. Added FeatureFunction::Setup(TranslationTask const&) const to allow FFs to set themselves up for specific input.
2. FeatureFunction::ChangeSource should not be allow to change the pointer to the source.
This commit is contained in:
parent
8ca11d941d
commit
ddf7bc3e23
@ -220,6 +220,11 @@ batch_run()
|
||||
boost::shared_ptr<TranslationTask>
|
||||
task = TranslationTask::create(source, ioWrapper);
|
||||
|
||||
// Allow for (sentence-)context-specific processing prior to
|
||||
// decoding. This can be used, for example, for context-sensitive
|
||||
// phrase lookup.
|
||||
FeatureFunction::SetupAll(*task);
|
||||
|
||||
// execute task
|
||||
#ifdef WITH_THREADS
|
||||
#ifdef PT_UG
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include "moses/Util.h"
|
||||
#include "moses/FF/DistortionScoreProducer.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses
|
||||
@ -35,7 +37,13 @@ void FeatureFunction::Destroy()
|
||||
RemoveAllInColl(s_staticColl);
|
||||
}
|
||||
|
||||
void FeatureFunction::CallChangeSource(InputType *&input)
|
||||
// The original declaration as
|
||||
// void FeatureFunction::CallChangeSource(InputType *&input)
|
||||
// had me a bit perplexed. Would you really want to allow
|
||||
// any feature function to replace the InputType behind the
|
||||
// back of the others? And change what the vector is pointing to?
|
||||
|
||||
void FeatureFunction::CallChangeSource(InputType * const&input)
|
||||
{
|
||||
for (size_t i = 0; i < s_staticColl.size(); ++i) {
|
||||
const FeatureFunction &ff = *s_staticColl[i];
|
||||
@ -43,6 +51,12 @@ void FeatureFunction::CallChangeSource(InputType *&input)
|
||||
}
|
||||
}
|
||||
|
||||
void FeatureFunction::SetupAll(TranslationTask const& ttask)
|
||||
{
|
||||
BOOST_FOREACH(FeatureFunction* ff, s_staticColl)
|
||||
ff->Setup(ttask);
|
||||
}
|
||||
|
||||
FeatureFunction::
|
||||
FeatureFunction(const std::string& line)
|
||||
: m_tuneable(true)
|
||||
|
@ -1,3 +1,4 @@
|
||||
// -*- c++ -*-
|
||||
#ifndef moses_FeatureFunction_h
|
||||
#define moses_FeatureFunction_h
|
||||
|
||||
@ -7,6 +8,8 @@
|
||||
#include "moses/FeatureVector.h"
|
||||
#include "moses/TypeDef.h"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
@ -24,6 +27,7 @@ class FactorMask;
|
||||
class InputPath;
|
||||
class StackVec;
|
||||
class DistortionScoreProducer;
|
||||
class TranslationTask;
|
||||
|
||||
/** base class for all feature functions.
|
||||
*/
|
||||
@ -55,7 +59,8 @@ public:
|
||||
static FeatureFunction &FindFeatureFunction(const std::string& name);
|
||||
static void Destroy();
|
||||
|
||||
static void CallChangeSource(InputType *&input);
|
||||
static void CallChangeSource(InputType * const&input);
|
||||
// see my note in FeatureFunction.cpp --- UG
|
||||
|
||||
FeatureFunction(const std::string &line);
|
||||
FeatureFunction(size_t numScoreComponents, const std::string &line);
|
||||
@ -135,8 +140,11 @@ public:
|
||||
, ScoreComponentCollection &estimatedFutureScore) const = 0;
|
||||
|
||||
// override this method if you want to change the input before decoding
|
||||
virtual void ChangeSource(InputType *&input) const {
|
||||
}
|
||||
virtual void ChangeSource(InputType * const&input) const { }
|
||||
|
||||
// for context-dependent processing
|
||||
static void SetupAll(TranslationTask const& task);
|
||||
virtual void Setup(TranslationTask const& task) const { };
|
||||
|
||||
// This method is called once all the translation options are retrieved from the phrase table, and
|
||||
// just before search.
|
||||
|
@ -59,7 +59,7 @@ void SkeletonChangeInput::EvaluateWhenApplied(const ChartHypothesis &hypo,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{}
|
||||
|
||||
void SkeletonChangeInput::ChangeSource(InputType *&input) const
|
||||
void SkeletonChangeInput::ChangeSource(InputType* const& input) const
|
||||
{
|
||||
// add factor[1] to each word. Created from first 4 letter of factor[0]
|
||||
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
, ScoreComponentCollection &scoreBreakdown
|
||||
, ScoreComponentCollection &estimatedFutureScore) const;
|
||||
|
||||
void ChangeSource(InputType *&input) const;
|
||||
void ChangeSource(InputType* const&input) const;
|
||||
|
||||
void EvaluateWithSourceContext(const InputType &input
|
||||
, const InputPath &inputPath
|
||||
|
@ -61,6 +61,10 @@ public:
|
||||
|
||||
virtual
|
||||
boost::shared_ptr<TranslationTask>
|
||||
self() { return m_self.lock(); }
|
||||
|
||||
virtual
|
||||
boost::shared_ptr<TranslationTask const>
|
||||
self() const { return m_self.lock(); }
|
||||
|
||||
// creator functions
|
||||
|
Loading…
Reference in New Issue
Block a user