implement Evaluate(inputpath, input) for chart translation options. Plumbing for lattice input

This commit is contained in:
Hieu Hoang 2013-08-13 12:12:58 +01:00
parent af74ee1968
commit f676100328
8 changed files with 49 additions and 3 deletions

View File

@ -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

View File

@ -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);
}
}
}

View File

@ -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);
};
}

View File

@ -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);
}
}
}

View File

@ -60,6 +60,7 @@ public:
void Clear();
void ApplyThreshold();
void Evaluate(const InputPath &inputPath, const InputType &input);
private:
typedef std::vector<ChartTranslationOptions*> CollType;

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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;