delete PhraseBasedFeatureContext

This commit is contained in:
Hieu Hoang 2013-08-23 14:25:25 +01:00
parent 4dfb625536
commit 1d653c87aa
14 changed files with 18 additions and 83 deletions

View File

@ -1171,16 +1171,6 @@
<type>2</type> <type>2</type>
<locationURI>virtual:/virtual</locationURI> <locationURI>virtual:/virtual</locationURI>
</link> </link>
<link>
<name>FF/PhraseBasedFeatureContext.cpp</name>
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/FF/PhraseBasedFeatureContext.cpp</locationURI>
</link>
<link>
<name>FF/PhraseBasedFeatureContext.h</name>
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/FF/PhraseBasedFeatureContext.h</locationURI>
</link>
<link> <link>
<name>FF/PhraseBoundaryFeature.cpp</name> <name>FF/PhraseBoundaryFeature.cpp</name>
<type>1</type> <type>1</type>

View File

@ -6,9 +6,6 @@ class ChartHypothesis;
class InputType; class InputType;
class TargetPhrase; class TargetPhrase;
/**
* Same as PhraseBasedFeatureContext, but for chart-based Moses.
**/
class ChartBasedFeatureContext class ChartBasedFeatureContext
{ {
//The context either has a hypothesis (during search) or a //The context either has a hypothesis (during search) or a

View File

@ -4,7 +4,6 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include <string> #include <string>
#include "PhraseBasedFeatureContext.h"
#include "ChartBasedFeatureContext.h" #include "ChartBasedFeatureContext.h"
#include "moses/TypeDef.h" #include "moses/TypeDef.h"

View File

@ -167,11 +167,11 @@ float GlobalLexicalModel::GetFromCacheOrScorePhrase( const TargetPhrase& targetP
} }
void GlobalLexicalModel::Evaluate void GlobalLexicalModel::Evaluate
(const PhraseBasedFeatureContext& context, (const Hypothesis& hypo,
ScoreComponentCollection* accumulator) const ScoreComponentCollection* accumulator) const
{ {
accumulator->PlusEquals( this, accumulator->PlusEquals( this,
GetFromCacheOrScorePhrase(context.GetHypothesis().GetCurrTargetPhrase()) ); GetFromCacheOrScorePhrase(hypo.GetCurrTargetPhrase()) );
} }
bool GlobalLexicalModel::IsUseable(const FactorMask &mask) const bool GlobalLexicalModel::IsUseable(const FactorMask &mask) const

View File

@ -68,7 +68,7 @@ public:
bool IsUseable(const FactorMask &mask) const; bool IsUseable(const FactorMask &mask) const;
void Evaluate(const PhraseBasedFeatureContext& context, void Evaluate(const Hypothesis& hypo,
ScoreComponentCollection* accumulator) const; ScoreComponentCollection* accumulator) const;

View File

@ -1,14 +0,0 @@
#include "PhraseBasedFeatureContext.h"
#include "moses/Hypothesis.h"
#include "moses/Manager.h"
#include "moses/TranslationOption.h"
namespace Moses
{
PhraseBasedFeatureContext::PhraseBasedFeatureContext(const Hypothesis* hypothesis) :
m_hypothesis(hypothesis),
m_translationOption(m_hypothesis->GetTranslationOption()),
m_source(m_hypothesis->GetManager().GetSource()) {}
}

View File

@ -1,37 +0,0 @@
#pragma once
namespace Moses
{
class Hypothesis;
class TranslationOption;
class InputType;
class TargetPhrase;
class WordsBitmap;
/**
* Contains all that a feature function can access without affecting recombination.
* For stateless features, this is all that it can access. Currently this is not
* used for stateful features, as it would need to be retro-fitted to the LM feature.
* TODO: Expose source segmentation,lattice path.
* XXX Don't add anything to the context that would break recombination XXX
**/
class PhraseBasedFeatureContext
{
// The context either has a hypothesis (during search), or a TranslationOption and
// source sentence (during pre-calculation).
const Hypothesis* m_hypothesis;
const TranslationOption& m_translationOption;
const InputType& m_source;
public:
PhraseBasedFeatureContext(const Hypothesis* hypothesis);
const Hypothesis& GetHypothesis() const {
return *m_hypothesis;
}
};
} // namespace

View File

@ -106,11 +106,11 @@ void PhrasePairFeature::Load()
} }
void PhrasePairFeature::Evaluate( void PhrasePairFeature::Evaluate(
const PhraseBasedFeatureContext& context, const Hypothesis& hypo,
ScoreComponentCollection* accumulator) const ScoreComponentCollection* accumulator) const
{ {
const TargetPhrase& target = context.GetHypothesis().GetCurrTargetPhrase(); const TargetPhrase& target = hypo.GetCurrTargetPhrase();
const Phrase& source = context.GetHypothesis().GetTranslationOption().GetInputPath().GetPhrase(); const Phrase& source = hypo.GetTranslationOption().GetInputPath().GetPhrase();
if (m_simple) { if (m_simple) {
ostringstream namestr; ostringstream namestr;
namestr << "pp_"; namestr << "pp_";
@ -131,7 +131,7 @@ void PhrasePairFeature::Evaluate(
accumulator->SparsePlusEquals(namestr.str(),1); accumulator->SparsePlusEquals(namestr.str(),1);
} }
if (m_domainTrigger) { if (m_domainTrigger) {
const Sentence& input = static_cast<const Sentence&>(context.GetHypothesis().GetInput()); const Sentence& input = static_cast<const Sentence&>(hypo.GetInput());
const bool use_topicid = input.GetUseTopicId(); const bool use_topicid = input.GetUseTopicId();
const bool use_topicid_prob = input.GetUseTopicIdAndProb(); const bool use_topicid_prob = input.GetUseTopicIdAndProb();
@ -199,7 +199,7 @@ void PhrasePairFeature::Evaluate(
} }
} }
if (m_sourceContext) { if (m_sourceContext) {
const Sentence& input = static_cast<const Sentence&>(context.GetHypothesis().GetInput()); const Sentence& input = static_cast<const Sentence&>(hypo.GetInput());
// range over source words to get context // range over source words to get context
for(size_t contextIndex = 0; contextIndex < input.GetSize(); contextIndex++ ) { for(size_t contextIndex = 0; contextIndex < input.GetSize(); contextIndex++ ) {

View File

@ -37,7 +37,7 @@ public:
bool IsUseable(const FactorMask &mask) const; bool IsUseable(const FactorMask &mask) const;
void Evaluate(const PhraseBasedFeatureContext& context, void Evaluate(const Hypothesis& hypo,
ScoreComponentCollection* accumulator) const; ScoreComponentCollection* accumulator) const;
void EvaluateChart(const ChartBasedFeatureContext& context, void EvaluateChart(const ChartBasedFeatureContext& context,

View File

@ -23,7 +23,7 @@ public:
/** /**
* This should be implemented for features that apply to phrase-based models. * This should be implemented for features that apply to phrase-based models.
**/ **/
virtual void Evaluate(const PhraseBasedFeatureContext& context, virtual void Evaluate(const Hypothesis& hypo,
ScoreComponentCollection* accumulator) const { ScoreComponentCollection* accumulator) const {
} }

View File

@ -137,12 +137,12 @@ void WordTranslationFeature::Load()
} }
void WordTranslationFeature::Evaluate void WordTranslationFeature::Evaluate
(const PhraseBasedFeatureContext& context, (const Hypothesis& hypo,
ScoreComponentCollection* accumulator) const ScoreComponentCollection* accumulator) const
{ {
const Sentence& input = static_cast<const Sentence&>(context.GetHypothesis().GetInput()); const Sentence& input = static_cast<const Sentence&>(hypo.GetInput());
const TranslationOption& transOpt = context.GetHypothesis().GetTranslationOption(); const TranslationOption& transOpt = hypo.GetTranslationOption();
const TargetPhrase& targetPhrase = context.GetHypothesis().GetCurrTargetPhrase(); const TargetPhrase& targetPhrase = hypo.GetCurrTargetPhrase();
const AlignmentInfo &alignment = targetPhrase.GetAlignTerm(); const AlignmentInfo &alignment = targetPhrase.GetAlignTerm();
// process aligned words // process aligned words
@ -243,7 +243,7 @@ void WordTranslationFeature::Evaluate
} }
} }
if (m_sourceContext) { if (m_sourceContext) {
size_t globalSourceIndex = context.GetHypothesis().GetTranslationOption().GetStartPos() + sourceIndex; size_t globalSourceIndex = hypo.GetTranslationOption().GetStartPos() + sourceIndex;
if (!m_domainTrigger && globalSourceIndex == 0) { if (!m_domainTrigger && globalSourceIndex == 0) {
// add <s> trigger feature for source // add <s> trigger feature for source
stringstream feature; stringstream feature;

View File

@ -47,7 +47,7 @@ public:
return new DummyState(); return new DummyState();
} }
void Evaluate(const PhraseBasedFeatureContext& context, void Evaluate(const Hypothesis& hypo,
ScoreComponentCollection* accumulator) const; ScoreComponentCollection* accumulator) const;
void EvaluateChart(const ChartBasedFeatureContext& context, void EvaluateChart(const ChartBasedFeatureContext& context,

View File

@ -263,7 +263,7 @@ void Hypothesis::EvaluateWith(const StatelessFeatureFunction& slff)
{ {
const StaticData &staticData = StaticData::Instance(); const StaticData &staticData = StaticData::Instance();
if (! staticData.IsFeatureFunctionIgnored( slff )) { if (! staticData.IsFeatureFunctionIgnored( slff )) {
slff.Evaluate(PhraseBasedFeatureContext(this), &m_scoreBreakdown); slff.Evaluate(*this, &m_scoreBreakdown);
} }
} }

View File

@ -34,7 +34,7 @@ class MockStatelessFeatureFunction : public StatelessFeatureFunction
public: public:
MockStatelessFeatureFunction(const string& desc, size_t n, const string &line) : MockStatelessFeatureFunction(const string& desc, size_t n, const string &line) :
StatelessFeatureFunction(desc,n, line) {} StatelessFeatureFunction(desc,n, line) {}
virtual void Evaluate(const PhraseBasedFeatureContext&, ScoreComponentCollection*) const {} virtual void Evaluate(const Hypothesis&, ScoreComponentCollection*) const {}
virtual void EvaluateChart(const ChartBasedFeatureContext&, ScoreComponentCollection*) const {} virtual void EvaluateChart(const ChartBasedFeatureContext&, ScoreComponentCollection*) const {}
virtual void Evaluate(const TargetPhrase &targetPhrase virtual void Evaluate(const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown , ScoreComponentCollection &scoreBreakdown