diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2013-08-13 15:12:58 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2013-08-13 15:12:58 +0400 |
commit | f6761003285ef52c4c21ddc9a2650f42ea867212 (patch) | |
tree | 1155cf39b1c6ba472cde75674a6cf18bcc615e88 | |
parent | af74ee1968e96360ee92fde098a02c79b94e0024 (diff) |
implement Evaluate(inputpath, input) for chart translation options. Plumbing for lattice input
-rw-r--r-- | moses/ChartParserCallback.h | 4 | ||||
-rw-r--r-- | moses/ChartTranslationOption.cpp | 11 | ||||
-rw-r--r-- | moses/ChartTranslationOption.h | 3 | ||||
-rw-r--r-- | moses/ChartTranslationOptionList.cpp | 9 | ||||
-rw-r--r-- | moses/ChartTranslationOptionList.h | 1 | ||||
-rw-r--r-- | moses/ChartTranslationOptions.cpp | 12 | ||||
-rw-r--r-- | moses/ChartTranslationOptions.h | 8 | ||||
-rw-r--r-- | moses/Incremental.cpp | 4 |
8 files changed, 49 insertions, 3 deletions
diff --git a/moses/ChartParserCallback.h b/moses/ChartParserCallback.h index 84ddb8b75..b68346c5f 100644 --- a/moses/ChartParserCallback.h +++ b/moses/ChartParserCallback.h @@ -10,6 +10,8 @@ namespace Moses class TargetPhraseCollection; class WordsRange; class TargetPhrase; +class InputPath; +class InputType; class ChartParserCallback { @@ -21,6 +23,8 @@ public: virtual bool Empty() const = 0; virtual void AddPhraseOOV(TargetPhrase &phrase, std::list<TargetPhraseCollection*> &waste_memory, const WordsRange &range) = 0; + + virtual void Evaluate(const InputPath &inputPath, const InputType &input) = 0; }; } // namespace Moses diff --git a/moses/ChartTranslationOption.cpp b/moses/ChartTranslationOption.cpp index 225b575e0..74b8fb80b 100644 --- a/moses/ChartTranslationOption.cpp +++ b/moses/ChartTranslationOption.cpp @@ -1,4 +1,6 @@ #include "ChartTranslationOptions.h" +#include "InputType.h" +#include "InputPath.h" namespace Moses { @@ -8,5 +10,14 @@ ChartTranslationOption::ChartTranslationOption(const TargetPhrase &targetPhrase) { } +void ChartTranslationOption::Evaluate(const InputPath &inputPath, const InputType &input) +{ + const std::vector<FeatureFunction*> &ffs = FeatureFunction::GetFeatureFunctions(); + + for (size_t i = 0; i < ffs.size(); ++i) { + const FeatureFunction &ff = *ffs[i]; + ff.Evaluate(input, inputPath.GetPhrase(), m_scoreBreakdown); + } +} } diff --git a/moses/ChartTranslationOption.h b/moses/ChartTranslationOption.h index e66655acd..46e59e84d 100644 --- a/moses/ChartTranslationOption.h +++ b/moses/ChartTranslationOption.h @@ -5,6 +5,8 @@ namespace Moses { class TargetPhrase; +class InputPath; +class InputType; class ChartTranslationOption { @@ -23,6 +25,7 @@ public: return m_scoreBreakdown; } + void Evaluate(const InputPath &inputPath, const InputType &input); }; } diff --git a/moses/ChartTranslationOptionList.cpp b/moses/ChartTranslationOptionList.cpp index 27d24c65c..19b272d2a 100644 --- a/moses/ChartTranslationOptionList.cpp +++ b/moses/ChartTranslationOptionList.cpp @@ -147,4 +147,13 @@ void ChartTranslationOptionList::ApplyThreshold() m_size = std::distance(m_collection.begin(), bound); } +void ChartTranslationOptionList::Evaluate(const InputPath &inputPath, const InputType &input) +{ + CollType::iterator iter; + for (iter = m_collection.begin(); iter != m_collection.end(); ++iter) { + ChartTranslationOptions &transOpts = **iter; + transOpts.Evaluate(inputPath, input); + } +} + } diff --git a/moses/ChartTranslationOptionList.h b/moses/ChartTranslationOptionList.h index bec13e644..5f51f8d2e 100644 --- a/moses/ChartTranslationOptionList.h +++ b/moses/ChartTranslationOptionList.h @@ -60,6 +60,7 @@ public: void Clear(); void ApplyThreshold(); + void Evaluate(const InputPath &inputPath, const InputType &input); private: typedef std::vector<ChartTranslationOptions*> CollType; diff --git a/moses/ChartTranslationOptions.cpp b/moses/ChartTranslationOptions.cpp index 09fdaa1f1..c63741115 100644 --- a/moses/ChartTranslationOptions.cpp +++ b/moses/ChartTranslationOptions.cpp @@ -38,7 +38,7 @@ ChartTranslationOptions::ChartTranslationOptions(const TargetPhraseCollection &t const TargetPhrase *origTP = *iter; boost::shared_ptr<ChartTranslationOption> ptr(new ChartTranslationOption(*origTP)); - m_targetPhraseCollection.push_back(ptr); + m_collection.push_back(ptr); } } @@ -64,4 +64,14 @@ float ChartTranslationOptions::CalcEstimateOfBestScore( return estimateOfBestScore; } +void ChartTranslationOptions::Evaluate(const InputPath &inputPath, const InputType &input) +{ + CollType::iterator iter; + for (iter = m_collection.begin(); iter != m_collection.end(); ++iter) { + ChartTranslationOption &transOpt = **iter; + transOpt.Evaluate(inputPath, input); + } + +} + } diff --git a/moses/ChartTranslationOptions.h b/moses/ChartTranslationOptions.h index 6e0e4c070..b638d6cef 100644 --- a/moses/ChartTranslationOptions.h +++ b/moses/ChartTranslationOptions.h @@ -32,6 +32,8 @@ namespace Moses { class ChartTranslationOption; +class InputPath; +class InputType; /** Similar to a DottedRule, but contains a direct reference to a list * of translations and provdes an estimate of the best score. For a specific range in the input sentence @@ -63,7 +65,7 @@ public: //! @todo isn't the translation suppose to just contain 1 target phrase, not a whole collection of them? const CollType &GetTargetPhrases() const { - return m_targetPhraseCollection; + return m_collection; } //! the range in the source sentence this translation option covers @@ -79,10 +81,12 @@ public: return m_estimateOfBestScore; } + void Evaluate(const InputPath &inputPath, const InputType &input); + private: StackVec m_stackVec; //! vector of hypothesis list! - CollType m_targetPhraseCollection; + CollType m_collection; const WordsRange *m_wordsRange; float m_estimateOfBestScore; diff --git a/moses/Incremental.cpp b/moses/Incremental.cpp index dffcd3e3e..6a2e594eb 100644 --- a/moses/Incremental.cpp +++ b/moses/Incremental.cpp @@ -97,6 +97,10 @@ public: return vertex.BestChild(); } + void Evaluate(const InputPath &inputPath, const InputType &input) + { + // TODO for input lattice + } private: lm::WordIndex Convert(const Word &word) const; |