mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 21:03:22 +03:00
Make sure all stateless features implement new interface.
And disable a couple that are not really stateless.
This commit is contained in:
parent
bc340ab7a2
commit
475e7501e1
@ -70,6 +70,23 @@ public:
|
||||
std::string GetScoreProducerWeightShortName(unsigned) const;
|
||||
|
||||
virtual bool ComputeValueInTranslationOption() const;
|
||||
void Evaluate( const TranslationOption& translationOption,
|
||||
const InputType& inputType,
|
||||
const WordsBitmap& coverageVector,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{
|
||||
//don't expect this to be called
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
void EvaluateChart(
|
||||
const ChartHypothesis& cur_hypo,
|
||||
int featureID,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{
|
||||
//Nor this.
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -49,13 +49,11 @@ public:
|
||||
virtual void Evaluate(const TranslationOption& translationOption,
|
||||
const InputType& inputType,
|
||||
const WordsBitmap& coverageVector,
|
||||
ScoreComponentCollection* accumulator) const {}
|
||||
//TODO: Warn if unimplemented
|
||||
ScoreComponentCollection* accumulator) const = 0;
|
||||
|
||||
virtual void EvaluateChart(const ChartHypothesis& cur_hypo,
|
||||
int featureID,
|
||||
ScoreComponentCollection* accumulator) const {}
|
||||
//TODO: Warn if unimplemented
|
||||
ScoreComponentCollection* accumulator) const = 0;
|
||||
|
||||
//If true, then the feature is evaluated before search begins, and stored in
|
||||
//the TranslationOptionCollection. Note that for PhraseDictionary and
|
||||
|
@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include "ScoreComponentCollection.h"
|
||||
#include "Phrase.h"
|
||||
@ -87,6 +88,24 @@ public:
|
||||
*/
|
||||
const OutputWordCollection *FindWord(const Word &word) const;
|
||||
virtual bool ComputeValueInTranslationOption() const;
|
||||
|
||||
//Usual feature function methods are not implemented
|
||||
virtual void Evaluate(const TranslationOption& translationOption,
|
||||
const InputType& inputType,
|
||||
const WordsBitmap& coverageVector,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
virtual void EvaluateChart(const ChartHypothesis& cur_hypo,
|
||||
int featureID,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@ -134,6 +135,23 @@ public:
|
||||
PhraseDictionary* GetDictionary();
|
||||
size_t GetDictIndex() const;
|
||||
|
||||
//Usual feature function methods are not implemented
|
||||
virtual void Evaluate(const TranslationOption& translationOption,
|
||||
const InputType& inputType,
|
||||
const WordsBitmap& coverageVector,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
virtual void EvaluateChart(const ChartHypothesis& cur_hypo,
|
||||
int featureID,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
size_t m_dictIndex;
|
||||
|
||||
|
@ -1108,7 +1108,8 @@ bool StaticData::LoadGlobalLexicalModelUnlimited()
|
||||
|
||||
const vector<FactorType> inputFactors = Tokenize<FactorType>(factors[0],",");
|
||||
const vector<FactorType> outputFactors = Tokenize<FactorType>(factors[1],",");
|
||||
GlobalLexicalModelUnlimited* glmu = new GlobalLexicalModelUnlimited(inputFactors, outputFactors, biasFeature, ignorePunctuation, context);
|
||||
throw runtime_error("GlobalLexicalModelUnlimited should be reimplemented as a stateful feature");
|
||||
GlobalLexicalModelUnlimited* glmu = NULL; // new GlobalLexicalModelUnlimited(inputFactors, outputFactors, biasFeature, ignorePunctuation, context);
|
||||
m_globalLexicalModelsUnlimited.push_back(glmu);
|
||||
if (restricted) {
|
||||
cerr << "loading word translation word lists from " << filenameSource << " and " << filenameTarget << endl;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "Hypothesis.h"
|
||||
#include "ChartHypothesis.h"
|
||||
#include "ScoreComponentCollection.h"
|
||||
#include "TranslationOption.h"
|
||||
|
||||
namespace Moses {
|
||||
|
||||
@ -30,10 +31,13 @@ bool TargetWordInsertionFeature::Load(const std::string &filePath)
|
||||
return true;
|
||||
}
|
||||
|
||||
void TargetWordInsertionFeature::Evaluate(const Hypothesis& cur_hypo,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
void TargetWordInsertionFeature::Evaluate(
|
||||
const TranslationOption& translationOption,
|
||||
const InputType& inputType,
|
||||
const WordsBitmap& coverageVector,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{
|
||||
const TargetPhrase& targetPhrase = cur_hypo.GetCurrTargetPhrase();
|
||||
const TargetPhrase& targetPhrase = translationOption.GetTargetPhrase();
|
||||
const AlignmentInfo &alignmentInfo = targetPhrase.GetAlignmentInfo();
|
||||
const AlignmentInfo::CollType &alignment = alignmentInfo.GetAlignments();
|
||||
ComputeFeatures(targetPhrase, accumulator, alignment);
|
||||
|
@ -29,8 +29,10 @@ public:
|
||||
}
|
||||
|
||||
bool Load(const std::string &filePath);
|
||||
void Evaluate(const Hypothesis& cur_hypo,
|
||||
ScoreComponentCollection* accumulator) const;
|
||||
void Evaluate( const TranslationOption& translationOption,
|
||||
const InputType& inputType,
|
||||
const WordsBitmap& coverageVector,
|
||||
ScoreComponentCollection* accumulator) const;
|
||||
|
||||
void EvaluateChart(
|
||||
const ChartHypothesis& cur_hypo,
|
||||
|
@ -1,11 +1,12 @@
|
||||
#include <sstream>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "WordTranslationFeature.h"
|
||||
#include "Phrase.h"
|
||||
#include "TargetPhrase.h"
|
||||
#include "Hypothesis.h"
|
||||
#include "ChartHypothesis.h"
|
||||
#include "ScoreComponentCollection.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "TranslationOption.h"
|
||||
|
||||
namespace Moses {
|
||||
|
||||
@ -52,10 +53,14 @@ bool WordTranslationFeature::Load(const std::string &filePathSource, const std::
|
||||
m_local->input = ∈
|
||||
}
|
||||
|
||||
void WordTranslationFeature::Evaluate(const Hypothesis& cur_hypo, ScoreComponentCollection* accumulator) const
|
||||
void WordTranslationFeature::Evaluate
|
||||
(const TranslationOption& translationOption,
|
||||
const InputType& inputType,
|
||||
const WordsBitmap& coverageVector,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{
|
||||
const Sentence& input = *(m_local->input);
|
||||
const TargetPhrase& targetPhrase = cur_hypo.GetCurrTargetPhrase();
|
||||
const TargetPhrase& targetPhrase = translationOption.GetTargetPhrase();
|
||||
const AlignmentInfo &alignment = targetPhrase.GetAlignmentInfo();
|
||||
|
||||
// process aligned words
|
||||
@ -100,7 +105,7 @@ void WordTranslationFeature::Evaluate(const Hypothesis& cur_hypo, ScoreComponent
|
||||
accumulator->SparsePlusEquals(featureName.str(), 1);
|
||||
}
|
||||
if (m_sourceContext) {
|
||||
size_t globalSourceIndex = cur_hypo.GetCurrSourceWordsRange().GetStartPos() + sourceIndex;
|
||||
size_t globalSourceIndex = translationOption.GetStartPos() + sourceIndex;
|
||||
if (globalSourceIndex == 0) {
|
||||
// add <s> trigger feature for source
|
||||
stringstream feature;
|
||||
@ -148,6 +153,8 @@ void WordTranslationFeature::Evaluate(const Hypothesis& cur_hypo, ScoreComponent
|
||||
}
|
||||
}
|
||||
if (m_targetContext) {
|
||||
throw runtime_error("Can't use target words outside current translation option in a stateless feature");
|
||||
/*
|
||||
size_t globalTargetIndex = cur_hypo.GetCurrTargetWordsRange().GetStartPos() + targetIndex;
|
||||
if (globalTargetIndex == 0) {
|
||||
// add <s> trigger feature for source
|
||||
@ -185,7 +192,7 @@ void WordTranslationFeature::Evaluate(const Hypothesis& cur_hypo, ScoreComponent
|
||||
feature << targetWord;
|
||||
accumulator->SparsePlusEquals(feature.str(), 1);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,8 +88,10 @@ public:
|
||||
return new DummyState();
|
||||
}
|
||||
|
||||
void Evaluate(const Hypothesis& cur_hypo,
|
||||
ScoreComponentCollection* accumulator) const;
|
||||
void Evaluate(const TranslationOption& translationOption,
|
||||
const InputType& inputType,
|
||||
const WordsBitmap& coverageVector,
|
||||
ScoreComponentCollection* accumulator) const;
|
||||
|
||||
void EvaluateChart(const ChartHypothesis& cur_hypo,
|
||||
int featureID,
|
||||
|
Loading…
Reference in New Issue
Block a user