delete LM:Useable(). Superseded by IsUseable() for all feature functions

This commit is contained in:
Hieu Hoang 2013-05-31 00:11:38 +01:00
parent 65d2d68bc5
commit bc0fdfbd79
7 changed files with 16 additions and 54 deletions

View File

@ -69,28 +69,25 @@ void LanguageModel::Evaluate(const Phrase &source
, ScoreComponentCollection &scoreBreakdown
, ScoreComponentCollection &estimatedFutureScore) const
{
if (Useable(targetPhrase)) {
// contains factors used by this LM
float fullScore, nGramScore;
size_t oovCount;
// contains factors used by this LM
float fullScore, nGramScore;
size_t oovCount;
CalcScore(targetPhrase, fullScore, nGramScore, oovCount);
float estimateScore = fullScore - nGramScore;
CalcScore(targetPhrase, fullScore, nGramScore, oovCount);
float estimateScore = fullScore - nGramScore;
if (StaticData::Instance().GetLMEnableOOVFeature()) {
vector<float> scores(2), estimateScores(2);
scores[0] = nGramScore;
scores[1] = oovCount;
scoreBreakdown.Assign(this, scores);
estimateScores[0] = estimateScore;
estimateScores[1] = 0;
estimatedFutureScore.Assign(this, estimateScores);
} else {
scoreBreakdown.Assign(this, nGramScore);
estimatedFutureScore.Assign(this, estimateScore);
}
if (StaticData::Instance().GetLMEnableOOVFeature()) {
vector<float> scores(2), estimateScores(2);
scores[0] = nGramScore;
scores[1] = oovCount;
scoreBreakdown.Assign(this, scores);
estimateScores[0] = estimateScore;
estimateScores[1] = 0;
estimatedFutureScore.Assign(this, estimateScores);
} else {
scoreBreakdown.Assign(this, nGramScore);
estimatedFutureScore.Assign(this, estimateScore);
}
}

View File

@ -64,15 +64,9 @@ public:
virtual const FFState* EmptyHypothesisState(const InputType &input) const = 0;
/* whether this LM can be used on a particular phrase.
* Should return false if phrase size = 0 or factor types required don't exists
*/
virtual bool Useable(const Phrase &phrase) const = 0;
/* calc total unweighted LM score of this phrase and return score via arguments.
* Return scores should always be in natural log, regardless of representation with LM implementation.
* Uses GetValue() of inherited class.
* Useable() should be called beforehand on the phrase
* \param fullScore scores of all unigram, bigram... of contiguous n-gram of the phrase
* \param ngramScore score of only n-gram of order m_nGramOrder
* \param oovCount number of LM OOVs

View File

@ -68,10 +68,6 @@ template <class Model> class LanguageModelKen : public LanguageModel
public:
LanguageModelKen(const std::string &description, const std::string &line, const std::string &file, FactorType factorType, bool lazy);
bool Useable(const Phrase &phrase) const {
return (phrase.GetSize()>0 && phrase.GetFactor(0, m_factorType) != NULL);
}
const FFState *EmptyHypothesisState(const InputType &/*input*/) const {
KenLMState *ret = new KenLMState();
ret->state = m_ngram->BeginSentenceState();

View File

@ -78,7 +78,6 @@ public:
virtual void InitializeForInput(InputType const& source);
virtual void CleanUpAfterSentenceProcessing(const InputType &source);
virtual const FFState* EmptyHypothesisState(const InputType& input) const;
virtual bool Useable(const Phrase& phrase) const;
virtual void CalcScore(const Phrase& phrase,
float& fullScore,
float& ngramScore,
@ -214,11 +213,6 @@ const FFState* LanguageModelLDHT::EmptyHypothesisState(
return NULL;
}
bool LanguageModelLDHT::Useable(const Phrase& phrase) const
{
return (phrase.GetSize() > 0 && phrase.GetFactor(0, m_factorType) != NULL);
}
void LanguageModelLDHT::CalcScore(const Phrase& phrase,
float& fullScore,
float& ngramScore,

View File

@ -24,20 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
namespace Moses
{
bool LanguageModelMultiFactor::Useable(const Phrase &phrase) const
{
if (phrase.GetSize()==0)
return false;
// whether phrase contains all factors in this LM
const Word &word = phrase.GetWord(0);
for (size_t currFactor = 0 ; currFactor < MAX_NUM_FACTORS ; ++currFactor) {
if (m_factorTypes[currFactor] && word[currFactor] == NULL)
return false;
}
return true;
}
}

View File

@ -50,7 +50,6 @@ public:
, const std::vector<FactorType> &factorTypes
, size_t nGramOrder) = 0;
bool Useable(const Phrase &phrase) const;
};
}

View File

@ -53,10 +53,6 @@ public:
bool IsUseable(const FactorMask &mask) const;
bool Useable(const Phrase &phrase) const {
return (phrase.GetSize()>0 && phrase.GetFactor(0, m_factorType) != NULL);
}
const Factor *GetSentenceStart() const {
return m_sentenceStart;
}