diff options
author | Ulrich Germann <ugermann@inf.ed.ac.uk> | 2015-03-21 20:09:41 +0300 |
---|---|---|
committer | Ulrich Germann <ugermann@inf.ed.ac.uk> | 2015-03-21 20:09:41 +0300 |
commit | ddf7bc3e234bdbdbe80f49e07ac4e4b7ba1e9bbc (patch) | |
tree | ebdf0c9a4a12e0a7c1c36af4b45daa4648e65158 | |
parent | 8ca11d941d99df42664b32c101020283cc83054e (diff) |
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.
-rw-r--r-- | moses/ExportInterface.cpp | 5 | ||||
-rw-r--r-- | moses/FF/FeatureFunction.cpp | 16 | ||||
-rw-r--r-- | moses/FF/FeatureFunction.h | 14 | ||||
-rw-r--r-- | moses/FF/SkeletonChangeInput.cpp | 2 | ||||
-rw-r--r-- | moses/FF/SkeletonChangeInput.h | 2 | ||||
-rw-r--r-- | moses/TranslationTask.h | 4 |
6 files changed, 37 insertions, 6 deletions
diff --git a/moses/ExportInterface.cpp b/moses/ExportInterface.cpp index 008878bf3..00850329e 100644 --- a/moses/ExportInterface.cpp +++ b/moses/ExportInterface.cpp @@ -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 diff --git a/moses/FF/FeatureFunction.cpp b/moses/FF/FeatureFunction.cpp index abe220161..5c4b65729 100644 --- a/moses/FF/FeatureFunction.cpp +++ b/moses/FF/FeatureFunction.cpp @@ -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) diff --git a/moses/FF/FeatureFunction.h b/moses/FF/FeatureFunction.h index b59998d9d..c8c78fb0f 100644 --- a/moses/FF/FeatureFunction.h +++ b/moses/FF/FeatureFunction.h @@ -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. diff --git a/moses/FF/SkeletonChangeInput.cpp b/moses/FF/SkeletonChangeInput.cpp index 7ab267d96..7937d7771 100644 --- a/moses/FF/SkeletonChangeInput.cpp +++ b/moses/FF/SkeletonChangeInput.cpp @@ -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] diff --git a/moses/FF/SkeletonChangeInput.h b/moses/FF/SkeletonChangeInput.h index 23ede5c97..f8d9010ce 100644 --- a/moses/FF/SkeletonChangeInput.h +++ b/moses/FF/SkeletonChangeInput.h @@ -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 diff --git a/moses/TranslationTask.h b/moses/TranslationTask.h index c9dccc0a5..acd446abe 100644 --- a/moses/TranslationTask.h +++ b/moses/TranslationTask.h @@ -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 |