code cleanup and commenting brought about when documenting for jhu report

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@886 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
hieuhoang1972 2006-10-17 11:07:17 +00:00
parent 2c4971d5d5
commit d6f9458d59
61 changed files with 266 additions and 188 deletions

View File

@ -6,7 +6,7 @@
inline const char *index(const char *str, char search)
{
int i=0;
size_t i=0;
while (i< strlen(str) ){
if (str[i]==search) return &str[i];
}

View File

@ -247,8 +247,6 @@ void lmtable::loadtxt(istream& inp,const char* header){
//Checkbound with sorting of n-gram table on disk
#include "util.h"
void lmtable::checkbounds(int level){
char* tbl=table[level];

View File

@ -114,7 +114,7 @@ void OutputSurface(std::ostream &out, const Hypothesis *hypo, const std::vector<
void IOCommandLine::Backtrack(const Hypothesis *hypo){
if (hypo->GetPrevHypo() != NULL) {
VERBOSE(3,hypo->m_id << " <= ");
VERBOSE(3,hypo->GetId() << " <= ");
Backtrack(hypo->GetPrevHypo());
}
}
@ -193,11 +193,11 @@ void IOCommandLine::SetNBest(const LatticePathList &nBestList, long translationI
}
// translation components
vector<PhraseDictionaryBase*> pds = StaticData::Instance()->GetPhraseDictionaries();
vector<PhraseDictionary*> pds = StaticData::Instance()->GetPhraseDictionaries();
if (pds.size() > 0) {
if (labeledOutput)
m_nBestFile << "tm: ";
vector<PhraseDictionaryBase*>::iterator iter;
vector<PhraseDictionary*>::iterator iter;
for (iter = pds.begin(); iter != pds.end(); ++iter) {
vector<float> scores = path.GetScoreBreakdown().GetScoresForProducer(*iter);
for (size_t j = 0; j<scores.size(); ++j)

View File

@ -26,9 +26,9 @@ void PrintTranslationAnalysis(std::ostream &os, const Hypothesis* hypo)
std::vector<std::string> targetMap;
std::vector<unsigned int> lmAcc(0);
size_t lmCalls = 0;
bool doLMStats = ((*tpi)->_lmstats != 0);
bool doLMStats = ((*tpi)->GetLMStats() != 0);
if (doLMStats)
lmAcc.resize((*tpi)->_lmstats->size(), 0);
lmAcc.resize((*tpi)->GetLMStats()->size(), 0);
for (; tpi != translationPath.end(); ++tpi) {
std::ostringstream sms;
std::ostringstream tms;
@ -39,7 +39,7 @@ void PrintTranslationAnalysis(std::ostream &os, const Hypothesis* hypo)
// language model backoff stats,
if (doLMStats) {
std::vector<std::vector<unsigned int> >& lmstats = *(*tpi)->_lmstats;
std::vector<std::vector<unsigned int> >& lmstats = *(*tpi)->GetLMStats();
std::vector<std::vector<unsigned int> >::iterator i = lmstats.begin();
std::vector<unsigned int>::iterator acc = lmAcc.begin();
// std::cerr << "\n";

View File

@ -11,7 +11,7 @@
#include "Sentence.h"
struct CNStats {
unsigned created,destr,read,colls,words;
size_t created,destr,read,colls,words;
CNStats() : created(0),destr(0),read(0),colls(0),words(0) {}
~CNStats() {print(std::cerr);}
@ -152,7 +152,7 @@ bool ConfusionNet::ReadFormat1(std::istream& in,
data[i].resize(s);
for(size_t j=0;j<s;++j)
if(is>>word>>prob) {
data[i][j].second=log(prob);
data[i][j].second = (float) log(prob);
if(data[i][j].second<0) {
std::cerr<<"WARN: neg costs: "<<data[i][j].second<<" -> set to 0\n";
data[i][j].second=0.0;}
@ -197,7 +197,7 @@ std::ostream& operator<<(std::ostream& out,const ConfusionNet& cn)
}
TargetPhraseCollection const* ConfusionNet::
CreateTargetPhraseCollection(PhraseDictionaryBase const& d,
CreateTargetPhraseCollection(PhraseDictionary const& d,
const WordsRange& r) const
{
if(PhraseDictionaryTreeAdaptor const* pdict=
@ -206,7 +206,7 @@ CreateTargetPhraseCollection(PhraseDictionaryBase const& d,
std::cerr<<"ERROR: wrong phrase dictionary type for confusion net decoding!"
" Has to be PhraseDictionaryTreeAdaptor\n";
abort();
return NULL;
}
TranslationOptionCollection*

View File

@ -44,7 +44,7 @@ class ConfusionNet : public InputType {
const Word& GetWord(size_t pos) const;
TargetPhraseCollection const* CreateTargetPhraseCollection(PhraseDictionaryBase const& d,const WordsRange& r) const;
TargetPhraseCollection const* CreateTargetPhraseCollection(PhraseDictionary const& d,const WordsRange& r) const;
TranslationOptionCollection* CreateTranslationOptionCollection() const;

View File

@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include "DecodeStep.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "GenerationDictionary.h"
#include "StaticData.h"
@ -48,9 +48,9 @@ DecodeStep::DecodeStep(Dictionary *ptr, const DecodeStep* prev)
DecodeStep::~DecodeStep() {}
/** returns phrase table (dictionary) for translation step */
const PhraseDictionaryBase &DecodeStep::GetPhraseDictionary() const
const PhraseDictionary &DecodeStep::GetPhraseDictionary() const
{
return *static_cast<const PhraseDictionaryBase*>(m_ptr);
return *static_cast<const PhraseDictionary*>(m_ptr);
}
/** returns generation table (dictionary) for generation step */

View File

@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "TypeDef.h"
#include "Dictionary.h"
class PhraseDictionaryBase;
class PhraseDictionary;
class GenerationDictionary;
class TranslationOption;
class TranslationOptionCollection;
@ -88,7 +88,7 @@ public:
}
/** returns phrase table (dictionary) for translation step */
const PhraseDictionaryBase &GetPhraseDictionary() const;
const PhraseDictionary &GetPhraseDictionary() const;
/** returns generation table (dictionary) for generation step */
const GenerationDictionary &GetGenerationDictionary() const;

View File

@ -37,7 +37,7 @@ const GenerationDictionary &DecodeStepGeneration::GetGenerationDictionary() cons
}
TranslationOption *DecodeStepGeneration::MergeGeneration(const TranslationOption& oldTO, Phrase &mergePhrase
, const ScoreComponentCollection2& generationScore) const
, const ScoreComponentCollection& generationScore) const
{
if (IsFilteringStep()) {
if (!oldTO.IsCompatible(mergePhrase, m_conflictFactors)) return 0;
@ -49,7 +49,7 @@ TranslationOption *DecodeStepGeneration::MergeGeneration(const TranslationOption
}
// helpers
typedef pair<Word, ScoreComponentCollection2> WordPair;
typedef pair<Word, ScoreComponentCollection> WordPair;
typedef list< WordPair > WordList;
// 1st = word
// 2nd = score
@ -124,7 +124,7 @@ void DecodeStepGeneration::Process(const TranslationOption &inputPartialTranslOp
for (iterWordColl = wordColl->begin() ; iterWordColl != wordColl->end(); ++iterWordColl)
{
const Word &outputWord = (*iterWordColl).first;
const ScoreComponentCollection2& score = (*iterWordColl).second;
const ScoreComponentCollection& score = (*iterWordColl).second;
// enter into word list generated factor(s) and its(their) score(s)
wordList.push_back(WordPair(outputWord, score));
}
@ -147,7 +147,7 @@ void DecodeStepGeneration::Process(const TranslationOption &inputPartialTranslOp
// go thru each possible factor for each word & create hypothesis
for (size_t currIter = 0 ; currIter < numIteration ; currIter++)
{
ScoreComponentCollection2 generationScore; // total score for this string of words
ScoreComponentCollection generationScore; // total score for this string of words
// create vector of words with new factors for last phrase
for (size_t currPos = 0 ; currPos < targetLength ; currPos++)

View File

@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
class GenerationDictionary;
class Phrase;
class ScoreComponentCollection2;
class ScoreComponentCollection;
class DecodeStepGeneration : public DecodeStep
{
@ -44,7 +44,7 @@ public:
private:
TranslationOption *MergeGeneration(const TranslationOption& oldTO, Phrase &mergePhrase
, const ScoreComponentCollection2& generationScore) const;
, const ScoreComponentCollection& generationScore) const;
};

View File

@ -20,20 +20,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include "DecodeStepTranslation.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "TranslationOption.h"
#include "TranslationOptionCollection.h"
#include "PartialTranslOptColl.h"
#include "FactorCollection.h"
DecodeStepTranslation::DecodeStepTranslation(PhraseDictionaryBase* dict, const DecodeStep* prev)
DecodeStepTranslation::DecodeStepTranslation(PhraseDictionary* dict, const DecodeStep* prev)
: DecodeStep(dict, prev)
{
}
const PhraseDictionaryBase &DecodeStepTranslation::GetPhraseDictionary() const
const PhraseDictionary &DecodeStepTranslation::GetPhraseDictionary() const
{
return *static_cast<const PhraseDictionaryBase*>(m_ptr);
return *static_cast<const PhraseDictionary*>(m_ptr);
}
TranslationOption *DecodeStepTranslation::MergeTranslation(const TranslationOption& oldTO, const TargetPhrase &targetPhrase) const
@ -66,7 +66,7 @@ void DecodeStepTranslation::Process(const TranslationOption &inputPartialTranslO
// normal trans step
const WordsRange &sourceWordsRange = inputPartialTranslOpt.GetSourceWordsRange();
const PhraseDictionaryBase &phraseDictionary = decodeStep.GetPhraseDictionary();
const PhraseDictionary &phraseDictionary = decodeStep.GetPhraseDictionary();
const size_t currSize = inputPartialTranslOpt.GetTargetPhrase().GetSize();
const size_t tableLimit = phraseDictionary.GetTableLimit();

View File

@ -23,16 +23,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "DecodeStep.h"
class PhraseDictionaryBase;
class PhraseDictionary;
class TargetPhrase;
class DecodeStepTranslation : public DecodeStep
{
public:
DecodeStepTranslation(PhraseDictionaryBase* dict, const DecodeStep* prev);
DecodeStepTranslation(PhraseDictionary* dict, const DecodeStep* prev);
/** returns phrase table (dictionary) for translation step */
const PhraseDictionaryBase &GetPhraseDictionary() const;
const PhraseDictionary &GetPhraseDictionary() const;
virtual void Process(const TranslationOption &inputPartialTranslOpt
, const DecodeStep &decodeStep

View File

@ -120,7 +120,7 @@ GenerationDictionary::~GenerationDictionary()
}
}
unsigned int GenerationDictionary::GetNumScoreComponents() const
size_t GenerationDictionary::GetNumScoreComponents() const
{
return this->GetNoScoreComponents();
}

View File

@ -40,7 +40,7 @@ struct WordComparer
}
};
typedef std::map < Word , ScoreComponentCollection2 > OutputWordCollection;
typedef std::map < Word , ScoreComponentCollection > OutputWordCollection;
// 1st = output phrase
// 2nd = log probability (score)
@ -68,7 +68,7 @@ public:
, FactorDirection direction
, bool forceSingleFeatureValue);
unsigned int GetNumScoreComponents() const;
size_t GetNumScoreComponents() const;
const std::string GetScoreProducerDescription() const;
size_t GetSize() const

View File

@ -52,7 +52,7 @@ Hypothesis::Hypothesis(InputType const& source, const TargetPhrase &emptyTarget)
, m_languageModelStates(StaticData::Instance()->GetLMSize(), LanguageModelSingleFactor::UnknownState)
, m_arcList(NULL)
, m_id(0)
, _lmstats(0)
, m_lmstats(NULL)
{ // used for initial seeding of trans process
// initialize scores
//_hash_computed = false;
@ -79,7 +79,7 @@ Hypothesis::Hypothesis(const Hypothesis &prevHypo, const TranslationOption &tran
, m_languageModelStates(prevHypo.m_languageModelStates)
, m_arcList(NULL)
, m_id(s_HypothesesCreated++)
, _lmstats(0)
, m_lmstats(NULL)
{
// assert that we are not extending our hypothesis by retranslating something
// that this hypothesis has already translated!
@ -105,7 +105,7 @@ Hypothesis::~Hypothesis()
delete m_arcList;
m_arcList = NULL;
delete _lmstats; _lmstats = 0;
delete m_lmstats; m_lmstats = NULL;
}
}
@ -204,7 +204,7 @@ void Hypothesis::CalcLMScore(const LMList &languageModels)
// will be null if LM stats collection is disabled
if (StaticData::Instance()->IsComputeLMBackoffStats()) {
_lmstats = new vector<vector<unsigned int> >(languageModels.size(), vector<unsigned int>(0));
m_lmstats = new vector<vector<unsigned int> >(languageModels.size(), vector<unsigned int>(0));
}
size_t lmIdx = 0;
@ -222,8 +222,8 @@ void Hypothesis::CalcLMScore(const LMList &languageModels)
if(m_currTargetWordsRange.GetWordsCount() == 0) {
lmScore = 0; //the score associated with dropping source words is not part of the language model
} else { //non-empty target phrase
if (_lmstats)
(*_lmstats)[lmIdx].resize(m_currTargetWordsRange.GetWordsCount(), 0);
if (m_lmstats)
(*m_lmstats)[lmIdx].resize(m_currTargetWordsRange.GetWordsCount(), 0);
// 1st n-gram
vector<const Word*> contextFactor(nGramOrder);
@ -236,7 +236,7 @@ void Hypothesis::CalcLMScore(const LMList &languageModels)
contextFactor[index++] = &languageModel.GetSentenceStartArray();
}
lmScore = languageModel.GetValue(contextFactor);
if (_lmstats) { languageModel.GetState(contextFactor, &(*_lmstats)[lmIdx][nLmCallCount++]); }
if (m_lmstats) { languageModel.GetState(contextFactor, &(*m_lmstats)[lmIdx][nLmCallCount++]); }
//cout<<"context factor: "<<languageModel.GetValue(contextFactor)<<endl;
// main loop
@ -252,8 +252,8 @@ void Hypothesis::CalcLMScore(const LMList &languageModels)
contextFactor.back() = &GetWord(currPos);
lmScore += languageModel.GetValue(contextFactor);
if (_lmstats)
languageModel.GetState(contextFactor, &(*_lmstats)[lmIdx][nLmCallCount++]);
if (m_lmstats)
languageModel.GetState(contextFactor, &(*m_lmstats)[lmIdx][nLmCallCount++]);
//cout<<"context factor: "<<languageModel.GetValue(contextFactor)<<endl;
}
@ -265,15 +265,15 @@ void Hypothesis::CalcLMScore(const LMList &languageModels)
for (size_t i = 0 ; i < nGramOrder - 1 ; i ++)
{
int currPos = size - nGramOrder + i + 1;
int currPos = (int)(size - nGramOrder + i + 1);
if (currPos < 0)
contextFactor[i] = &languageModel.GetSentenceStartArray();
else
contextFactor[i] = &GetWord((size_t)currPos);
}
if (_lmstats) {
(*_lmstats)[lmIdx].resize((*_lmstats)[lmIdx].size() + 1); // extra space for the last call
lmScore += languageModel.GetValue(contextFactor, &m_languageModelStates[lmIdx], &(*_lmstats)[lmIdx][nLmCallCount++]);
if (m_lmstats) {
(*m_lmstats)[lmIdx].resize((*m_lmstats)[lmIdx].size() + 1); // extra space for the last call
lmScore += languageModel.GetValue(contextFactor, &m_languageModelStates[lmIdx], &(*m_lmstats)[lmIdx][nLmCallCount++]);
} else
lmScore += languageModel.GetValue(contextFactor, &m_languageModelStates[lmIdx]);
} else {
@ -281,8 +281,8 @@ void Hypothesis::CalcLMScore(const LMList &languageModels)
for (size_t i = 0 ; i < nGramOrder - 1 ; i++)
contextFactor[i] = contextFactor[i + 1];
contextFactor.back() = &GetWord(currPos);
if (_lmstats)
languageModel.GetState(contextFactor, &(*_lmstats)[lmIdx][nLmCallCount++]);
if (m_lmstats)
languageModel.GetState(contextFactor, &(*m_lmstats)[lmIdx][nLmCallCount++]);
}
m_languageModelStates[lmIdx]=languageModel.GetState(contextFactor);
}
@ -368,11 +368,6 @@ void Hypothesis::CalcFutureScore(const SquareMatrix &futureScore)
}
int Hypothesis::GetId()const{
return m_id;
}
const Hypothesis* Hypothesis::GetPrevHypo()const{
return m_prevHypo;
}
@ -384,7 +379,7 @@ void Hypothesis::PrintHypothesis(const InputType &source, float /*weightDistorti
{
// PLEASE DON'T WRITE TO COUT directly. use TRACE_ERR or cerr
TRACE_ERR("creating hypothesis "<< m_id <<" from "<< m_prevHypo->m_id<<" ( ");
int end = m_prevHypo->m_targetPhrase.GetSize()-1;
int end = (int)(m_prevHypo->m_targetPhrase.GetSize()-1);
int start = end-1;
if ( start < 0 ) start = 0;
if ( m_prevHypo->m_currTargetWordsRange.GetStartPos() == NOT_FOUND ) {

View File

@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "WordsBitmap.h"
#include "Sentence.h"
#include "Phrase.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "GenerationDictionary.h"
#include "LanguageModelSingleFactor.h"
#include "ScoreComponentCollection.h"
@ -72,27 +72,25 @@ protected:
bool m_wordDeleted;
float m_totalScore; /**< score so far */
float m_futureScore; /**< estimated future cost to translate rest of sentence */
ScoreComponentCollection2 m_scoreBreakdown; /**< detailed score break-down by components (for instance language model, word penalty, etc) */
ScoreComponentCollection m_scoreBreakdown; /**< detailed score break-down by components (for instance language model, word penalty, etc) */
std::vector<LanguageModelSingleFactor::State> m_languageModelStates; /**< relevant history for language model scoring -- used for recombination */
const Hypothesis *m_mainHypo;
ArcList *m_arcList; /**< all arcs that end at the same lattice point as this hypothesis */
int m_id; /**< numeric ID of this hypothesis, used for logging */
std::vector<std::vector<unsigned int> >* m_lmstats; /** Statistics: (see IsComputeLMBackoffStats() in StaticData.h */
static unsigned int s_HypothesesCreated; // Statistics: how many hypotheses were created in total
void CalcFutureScore(const SquareMatrix &futureScore);
//void CalcFutureScore(float futureScore[256][256]);
void CalcLMScore(const LMList &languageModels);
void CalcDistortionScore();
//TODO: add appropriate arguments to score calculator
// void GenerateNGramCompareHash() const;
// mutable size_t _hash;
// mutable bool _hash_computed;
public:
static unsigned int s_HypothesesCreated; // Statistics: how many hypotheses were created in total
int m_id; /**< numeric ID of this hypothesis, used for logging */
std::vector<std::vector<unsigned int> >* _lmstats; /** Statistics: (see IsComputeLMBackoffStats() in StaticData.h */
/** used by initial seeding of the translation process */
Hypothesis(InputType const& source, const TargetPhrase &emptyTarget);
/** used when creating a new hypothesis using a translation option (phrase translation) */
Hypothesis(const Hypothesis &prevHypo, const TranslationOption &transOpt);
public:
static ObjectPool<Hypothesis> &GetObjectPool()
@ -100,10 +98,6 @@ public:
return s_objectPool;
}
/** used by initial seeding of the translation process */
Hypothesis(InputType const& source, const TargetPhrase &emptyTarget);
/** used when creating a new hypothesis using a translation option (phrase translation) */
Hypothesis(const Hypothesis &prevHypo, const TranslationOption &transOpt);
~Hypothesis();
/** return the subclass of Hypothesis most appropriate to the given translation option */
@ -148,7 +142,10 @@ public:
void CalcScore(const StaticData& staticData, const SquareMatrix &futureScore);
int GetId() const;
int GetId()const
{
return m_id;
}
const Hypothesis* GetPrevHypo() const;
@ -245,12 +242,22 @@ public:
{
return m_arcList;
}
const ScoreComponentCollection2& GetScoreBreakdown() const
const ScoreComponentCollection& GetScoreBreakdown() const
{
return m_scoreBreakdown;
}
float GetTotalScore() const { return m_totalScore; }
float GetFutureScore() const { return m_futureScore; }
std::vector<std::vector<unsigned int> > *GetLMStats() const
{
return m_lmstats;
}
static unsigned int GetHypothesesCreated()
{
return s_HypothesesCreated;
}
};
std::ostream& operator<<(std::ostream& out, const Hypothesis& hypothesis);

View File

@ -1,3 +1,5 @@
// $Id: InputType.cpp 666 2006-08-11 21:04:38Z eherbst $
#include "InputType.h"
InputType::InputType(long translationId) : m_translationId(translationId) {}

View File

@ -9,7 +9,7 @@
class WordsRange;
class Factor;
class PhraseDictionaryBase;
class PhraseDictionary;
class TranslationOptionCollection;
// base class for sentences and confusion networks
@ -37,7 +37,7 @@ protected:
virtual void Print(std::ostream&) const=0;
//virtual TargetPhraseCollection const* CreateTargetPhraseCollection(PhraseDictionaryBase const& d,const WordsRange& r) const=0;
//virtual TargetPhraseCollection const* CreateTargetPhraseCollection(PhraseDictionary const& d,const WordsRange& r) const=0;
virtual TranslationOptionCollection* CreateTranslationOptionCollection() const=0;
virtual Phrase GetSubString(const WordsRange&) const =0;

View File

@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
using namespace std;
void LMList::CalcScore(const Phrase &phrase, float &retFullScore, float &retNGramScore, ScoreComponentCollection2* breakdown) const
void LMList::CalcScore(const Phrase &phrase, float &retFullScore, float &retNGramScore, ScoreComponentCollection* breakdown) const
{
const_iterator lmIter;
for (lmIter = begin(); lmIter != end(); ++lmIter)

View File

@ -6,11 +6,11 @@
class Phrase;
class ScoreColl;
class ScoreComponentCollection2;
class ScoreComponentCollection;
class LMList : public std::list < LanguageModel* >
{
public:
void CalcScore(const Phrase &phrase, float &retFullScore, float &retNGramScore, ScoreComponentCollection2* breakdown) const;
void CalcScore(const Phrase &phrase, float &retFullScore, float &retNGramScore, ScoreComponentCollection* breakdown) const;
};

View File

@ -41,7 +41,7 @@ LanguageModel::LanguageModel(bool registerScore)
LanguageModel::~LanguageModel() {}
// don't inline virtual funcs...
unsigned int LanguageModel::GetNumScoreComponents() const
size_t LanguageModel::GetNumScoreComponents() const
{
return 1;
}

View File

@ -41,7 +41,7 @@ protected:
std::string m_filename; //! for debugging purposes
size_t m_nGramOrder; //! max n-gram length contained in this LM
Word m_sentenceStartArray, m_sentenceEndArray; //! Contains factors which represents the beging and end words for this LM.
//! Usually word composed of <s> or </s>
//! Usually <s> and </s>
/** constructor to be called by inherited class
* \param registerScore whether this LM will be directly used to score sentence.
@ -59,7 +59,7 @@ public:
virtual ~LanguageModel();
//! see ScoreProducer.h
unsigned int GetNumScoreComponents() const;
size_t GetNumScoreComponents() const;
//! Single or multi-factor
virtual LMType GetLMType() const = 0;
@ -97,7 +97,7 @@ public:
return m_nGramOrder;
}
//! Contains factors which represents the beginning and end words for this LM. Usually word composed of <s> or </s>
//! Contains factors which represents the beging and end words for this LM. Usually <s> and </s>
const Word &GetSentenceStartArray() const
{
return m_sentenceStartArray;

View File

@ -1,4 +1,3 @@
// $Id$
/***********************************************************************

View File

@ -1,5 +1,25 @@
// $Id$
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2006 University of Edinburgh
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include "LanguageModelFactory.h"
#include "UserMessage.h"
#include "TypeDef.h"

View File

@ -153,7 +153,7 @@ float LanguageModelIRST::GetValue(const vector<const Word*> &contextFactor, Stat
*len = 0;
}
return TransformIRSTScore(m_lmtb->clprob(*m_lmtb_ng));
return TransformIRSTScore((float) m_lmtb->clprob(*m_lmtb_ng));
}

View File

@ -35,7 +35,6 @@ class Phrase;
class lmtable; // irst lm table
class ngram;
//! Wrapper around IRST LM implementation
class LanguageModelIRST : public LanguageModelSingleFactor
{
protected:

View File

@ -1,3 +1,22 @@
// $Id$
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2006 University of Edinburgh
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include "LanguageModelJoint.h"

View File

@ -27,24 +27,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
class FactorCollection;
class Factor;
/* Abstract class which represent an implement of single factor LM
* Currently inherited by SRI and IRST LM implmentations
*/
class LanguageModelSingleFactor : public LanguageModel
{
protected:
const Factor *m_sentenceStart, *m_sentenceEnd;
FactorType m_factorType;
//! constructor to be called by inherited class
LanguageModelSingleFactor(bool registerScore);
public:
//! ??? if LM return this state when calculating score, then agressive pruning cannot be done
static State UnknownState;
virtual ~LanguageModelSingleFactor();
//! load data from file
virtual void Load(const std::string &fileName
, FactorCollection &factorCollection
, FactorType factorType
@ -60,17 +54,15 @@ public:
{
return (phrase.GetSize()>0 && phrase.GetFactor(0, m_factorType) != NULL);
}
//! factor that represent sentence start. Usually <s>
const Factor *GetSentenceStart() const
{
return m_sentenceStart;
}
//! factor that represent sentence start. Usually </s>
const Factor *GetSentenceEnd() const
{
return m_sentenceEnd;
}
//! which factor type this LM uses
FactorType GetFactorType() const
{
return m_factorType;

View File

@ -72,7 +72,7 @@ LatticePath::LatticePath(const LatticePath &copy, size_t edgeIndex, const Hypoth
void LatticePath::CalcScore(const LatticePath &copy, size_t edgeIndex, const Hypothesis *arc)
{
ScoreComponentCollection2 adj = arc->GetScoreBreakdown();
ScoreComponentCollection adj = arc->GetScoreBreakdown();
adj.MinusEquals(copy.m_path[edgeIndex]->GetScoreBreakdown());
m_scoreBreakdown = copy.m_scoreBreakdown;
m_scoreBreakdown.PlusEquals(adj);

View File

@ -37,7 +37,7 @@ protected:
std::vector<const Hypothesis *> m_path;
size_t m_prevEdgeChanged;
ScoreComponentCollection2 m_scoreBreakdown;
ScoreComponentCollection m_scoreBreakdown;
float m_totalScore;
void CalcScore(const LatticePath &copy, size_t edgeIndex, const Hypothesis *arc);
@ -69,7 +69,7 @@ public:
void CreateDeviantPaths(LatticePathCollection &pathColl) const;
inline const ScoreComponentCollection2 &GetScoreBreakdown() const
inline const ScoreComponentCollection &GetScoreBreakdown() const
{
return m_scoreBreakdown;
}

View File

@ -43,7 +43,7 @@ Manager::Manager(InputType const& source, StaticData &staticData)
:m_source(source)
,m_hypoStack(source.GetSize() + 1)
,m_staticData(staticData)
,m_possibleTranslations(*source.CreateTranslationOptionCollection())
,m_possibleTranslations(source.CreateTranslationOptionCollection())
,m_initialTargetPhrase(Output)
{
std::vector < HypothesisCollection >::iterator iterStack;
@ -57,7 +57,7 @@ Manager::Manager(InputType const& source, StaticData &staticData)
Manager::~Manager()
{
delete &m_possibleTranslations;
delete m_possibleTranslations;
}
/**
@ -73,7 +73,7 @@ void Manager::ProcessSentence()
// 1. generation of source sentence is not done 1st
// 2. initial hypothesis factors are given in the sentence
//CreateTranslationOptions(m_source, phraseDictionary, lmListInitial);
m_possibleTranslations.CreateTranslationOptions(decodeStepList
m_possibleTranslations->CreateTranslationOptions(decodeStepList
, m_staticData.GetFactorCollection());
// initial seed hypothesis: nothing translated, no words produced
@ -102,9 +102,7 @@ void Manager::ProcessSentence()
ProcessOneHypothesis(hypothesis); // expand the hypothesis
}
// some logging
//OutputHypoStackSize();
//OutputHypoStack();
IFVERBOSE(2) { OutputHypoStackSize(); }
}
// some more logging
@ -135,7 +133,7 @@ void Manager::ProcessOneHypothesis(const Hypothesis &hypothesis)
if (!hypoBitmap.Overlap(WordsRange(startPos, endPos)))
{
ExpandAllHypotheses(hypothesis
, m_possibleTranslations.GetTranslationOptionList(WordsRange(startPos, endPos)));
, m_possibleTranslations->GetTranslationOptionList(WordsRange(startPos, endPos)));
}
}
}
@ -164,7 +162,7 @@ void Manager::ProcessOneHypothesis(const Hypothesis &hypothesis)
)
{
ExpandAllHypotheses(hypothesis
,m_possibleTranslations.GetTranslationOptionList(WordsRange(startPos, endPos)));
,m_possibleTranslations->GetTranslationOptionList(WordsRange(startPos, endPos)));
}
}
// filling in gap => just check for overlap
@ -174,7 +172,7 @@ void Manager::ProcessOneHypothesis(const Hypothesis &hypothesis)
&& !hypoBitmap.Overlap(WordsRange(startPos, endPos)))
{
ExpandAllHypotheses(hypothesis
,m_possibleTranslations.GetTranslationOptionList(WordsRange(startPos, endPos)));
,m_possibleTranslations->GetTranslationOptionList(WordsRange(startPos, endPos)));
}
}
// ignoring, continuing forward => be limited by start of gap
@ -184,7 +182,7 @@ void Manager::ProcessOneHypothesis(const Hypothesis &hypothesis)
&& !hypoBitmap.Overlap(WordsRange(startPos, endPos)))
{
ExpandAllHypotheses(hypothesis
,m_possibleTranslations.GetTranslationOptionList(WordsRange(startPos, endPos)));
,m_possibleTranslations->GetTranslationOptionList(WordsRange(startPos, endPos)));
}
}
}
@ -217,7 +215,7 @@ void Manager::ExpandHypothesis(const Hypothesis &hypothesis, const TranslationOp
{
// create hypothesis and calculate all its scores
Hypothesis *newHypo = hypothesis.CreateNext(transOpt);
newHypo->CalcScore(m_staticData, m_possibleTranslations.GetFutureScore());
newHypo->CalcScore(m_staticData, m_possibleTranslations->GetFutureScore());
// logging for the curious
IFVERBOSE(3) {

View File

@ -77,7 +77,7 @@ protected:
std::vector < HypothesisCollection > m_hypoStack; /**< stacks to store hypothesis (partial translations) */
// no of elements = no of words in source + 1
StaticData &m_staticData; /**< holds various kinds of constants, counters, and global data structures */
TranslationOptionCollection &m_possibleTranslations; /**< pre-computed list of translation options for the phrases in this sentence */
TranslationOptionCollection *m_possibleTranslations; /**< pre-computed list of translation options for the phrases in this sentence */
TargetPhrase m_initialTargetPhrase; /**< used to seed 1st hypo */
// functions for creating hypotheses

View File

@ -1,27 +1,49 @@
#include "PhraseDictionaryBase.h"
// $Id$
// vim:tabstop=2
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2006 University of Edinburgh
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include "PhraseDictionary.h"
#include "StaticData.h"
#include "InputType.h"
PhraseDictionaryBase::PhraseDictionaryBase(size_t noScoreComponent)
PhraseDictionary::PhraseDictionary(size_t noScoreComponent)
: Dictionary(noScoreComponent),m_tableLimit(0)
{
const_cast<ScoreIndexManager&>(StaticData::Instance()->GetScoreIndexManager()).AddScoreProducer(this);
}
PhraseDictionaryBase::~PhraseDictionaryBase() {}
PhraseDictionary::~PhraseDictionary() {}
const TargetPhraseCollection *PhraseDictionaryBase::
const TargetPhraseCollection *PhraseDictionary::
GetTargetPhraseCollection(InputType const& src,WordsRange const& range) const
{
return GetTargetPhraseCollection(src.GetSubString(range));
}
const std::string PhraseDictionaryBase::GetScoreProducerDescription() const
const std::string PhraseDictionary::GetScoreProducerDescription() const
{
return "Translation score, file=" + m_filename;
}
unsigned int PhraseDictionaryBase::GetNumScoreComponents() const
size_t PhraseDictionary::GetNumScoreComponents() const
{
return this->GetNoScoreComponents();
}

View File

@ -35,22 +35,22 @@ class StaticData;
class InputType;
class WordsRange;
class PhraseDictionaryBase : public Dictionary, public ScoreProducer
class PhraseDictionary : public Dictionary, public ScoreProducer
{
protected:
size_t m_tableLimit;
std::string m_filename; // just for debugging purposes
public:
PhraseDictionaryBase(size_t noScoreComponent);
virtual ~PhraseDictionaryBase();
PhraseDictionary(size_t noScoreComponent);
virtual ~PhraseDictionary();
DecodeType GetDecodeType() const { return Translate; }
size_t GetTableLimit() const { return m_tableLimit; }
virtual void InitializeForInput(InputType const&) {}
const std::string GetScoreProducerDescription() const;
unsigned int GetNumScoreComponents() const;
size_t GetNumScoreComponents() const;
virtual void SetWeightTransModel(const std::vector<float> &weightT)=0;

View File

@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <iterator>
#include <algorithm>
#include <sys/stat.h>
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "FactorCollection.h"
#include "Word.h"
#include "Util.h"
@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
using namespace std;
void PhraseDictionary::Load(const std::vector<FactorType> &input
void PhraseDictionaryMemory::Load(const std::vector<FactorType> &input
, const std::vector<FactorType> &output
, FactorCollection &factorCollection
, const string &filePath
@ -54,7 +54,7 @@ void PhraseDictionary::Load(const std::vector<FactorType> &input
//factors
m_inputFactors = FactorMask(input);
m_outputFactors = FactorMask(output);
VERBOSE(2,"PhraseDictionary: input=" << m_inputFactors << " output=" << m_outputFactors << std::endl);
VERBOSE(2,"PhraseDictionaryMemory: input=" << m_inputFactors << " output=" << m_outputFactors << std::endl);
// data from file
InputFileStream inFile(filePath);
@ -115,7 +115,7 @@ void PhraseDictionary::Load(const std::vector<FactorType> &input
m_collection.Sort(m_tableLimit);
}
TargetPhraseCollection *PhraseDictionary::CreateTargetPhraseCollection(const Phrase &source)
TargetPhraseCollection *PhraseDictionaryMemory::CreateTargetPhraseCollection(const Phrase &source)
{
const size_t size = source.GetSize();
@ -131,13 +131,13 @@ TargetPhraseCollection *PhraseDictionary::CreateTargetPhraseCollection(const Phr
return currNode->CreateTargetPhraseCollection();
}
void PhraseDictionary::AddEquivPhrase(const Phrase &source, const TargetPhrase &targetPhrase)
void PhraseDictionaryMemory::AddEquivPhrase(const Phrase &source, const TargetPhrase &targetPhrase)
{
TargetPhraseCollection &phraseColl = *CreateTargetPhraseCollection(source);
phraseColl.Add(new TargetPhrase(targetPhrase));
}
const TargetPhraseCollection *PhraseDictionary::GetTargetPhraseCollection(const Phrase &source) const
const TargetPhraseCollection *PhraseDictionaryMemory::GetTargetPhraseCollection(const Phrase &source) const
{ // exactly like CreateTargetPhraseCollection, but don't create
const size_t size = source.GetSize();
@ -153,11 +153,11 @@ const TargetPhraseCollection *PhraseDictionary::GetTargetPhraseCollection(const
return currNode->GetTargetPhraseCollection();
}
PhraseDictionary::~PhraseDictionary()
PhraseDictionaryMemory::~PhraseDictionaryMemory()
{
}
void PhraseDictionary::SetWeightTransModel(const vector<float> &weightT)
void PhraseDictionaryMemory::SetWeightTransModel(const vector<float> &weightT)
{
PhraseDictionaryNode::iterator iterDict;
for (iterDict = m_collection.begin() ; iterDict != m_collection.end() ; ++iterDict)
@ -168,7 +168,7 @@ void PhraseDictionary::SetWeightTransModel(const vector<float> &weightT)
}
}
bool PhraseDictionary::Contains(const vector< vector<string> > &phraseVector
bool PhraseDictionaryMemory::Contains(const vector< vector<string> > &phraseVector
, const list<Phrase> &inputPhraseList
, const vector<FactorType> &inputFactorType)
{
@ -182,10 +182,10 @@ bool PhraseDictionary::Contains(const vector< vector<string> > &phraseVector
return false;
}
TO_STRING_BODY(PhraseDictionary);
TO_STRING_BODY(PhraseDictionaryMemory);
// friend
ostream& operator<<(ostream& out, const PhraseDictionary& phraseDict)
ostream& operator<<(ostream& out, const PhraseDictionaryMemory& phraseDict)
{
const PhraseDictionaryNode &coll = phraseDict.m_collection;
PhraseDictionaryNode::const_iterator iter;

View File

@ -22,16 +22,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#pragma once
#include "PhraseDictionaryBase.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryNode.h"
/*** Implementation of a phrase table in a trie. Looking up a phrase of
* length n words requires n look-ups to find the TargetPhraseCollection.
*/
class PhraseDictionary : public PhraseDictionaryBase
class PhraseDictionaryMemory : public PhraseDictionary
{
typedef PhraseDictionaryBase MyBase;
friend std::ostream& operator<<(std::ostream&, const PhraseDictionary&);
typedef PhraseDictionary MyBase;
friend std::ostream& operator<<(std::ostream&, const PhraseDictionaryMemory&);
protected:
PhraseDictionaryNode m_collection;
@ -44,11 +44,11 @@ protected:
TargetPhraseCollection *CreateTargetPhraseCollection(const Phrase &source);
public:
PhraseDictionary(size_t noScoreComponent)
PhraseDictionaryMemory(size_t noScoreComponent)
: MyBase(noScoreComponent)
{
}
virtual ~PhraseDictionary();
virtual ~PhraseDictionaryMemory();
void Load(const std::vector<FactorType> &input
, const std::vector<FactorType> &output

View File

@ -21,7 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "PhraseDictionaryNode.h"
#include "TargetPhrase.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
PhraseDictionaryNode::~PhraseDictionaryNode()
{
@ -62,7 +62,7 @@ const PhraseDictionaryNode *PhraseDictionaryNode::GetChild(const Word &word) con
return NULL;
}
void PhraseDictionaryNode::SetWeightTransModel(const PhraseDictionary *phraseDictionary
void PhraseDictionaryNode::SetWeightTransModel(const PhraseDictionaryMemory *phraseDictionary
, const std::vector<float> &weightT)
{
// recursively set weights

View File

@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "Word.h"
#include "TargetPhraseCollection.h"
class PhraseDictionary;
class PhraseDictionaryMemory;
class PhraseDictionaryNode
{
@ -57,7 +57,7 @@ public:
return m_targetPhraseCollection;
}
// for mert
void SetWeightTransModel(const PhraseDictionary *phraseDictionary
void SetWeightTransModel(const PhraseDictionaryMemory *phraseDictionary
, const std::vector<float> &weightT);
// iterators

View File

@ -66,7 +66,7 @@ void PhraseDictionaryTreeAdaptor::Create(const std::vector<FactorType> &input
m_outputFactors = FactorMask(output);
VERBOSE(2,"PhraseDictionaryTreeAdaptor: input=" << m_inputFactors << " output=" << m_outputFactors << std::endl);
// set PhraseDictionaryBase members
// set PhraseDictionary members
m_tableLimit=tableLimit;
imp->Create(input,output,factorCollection,filePath,

View File

@ -4,7 +4,7 @@
#define PHRASEDICTIONARYTREEADAPTOR_H_
#include <vector>
#include "TypeDef.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "TargetPhraseCollection.h"
class Phrase;
@ -15,8 +15,8 @@ class InputType;
/*** Implementation of a phrase table in a trie that is binarized and
* stored on disk.
*/
class PhraseDictionaryTreeAdaptor : public PhraseDictionaryBase {
typedef PhraseDictionaryBase MyBase;
class PhraseDictionaryTreeAdaptor : public PhraseDictionary {
typedef PhraseDictionary MyBase;
PDTAimp *imp;
friend class PDTAimp;
PhraseDictionaryTreeAdaptor();

View File

@ -1,3 +1,5 @@
// $Id: LatticePath.cpp 560 2006-08-08 17:47:46Z redpony $
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2006 University of Edinburgh

View File

@ -3,7 +3,7 @@
#include "ScoreComponentCollection.h"
#include "StaticData.h"
ScoreComponentCollection2::ScoreComponentCollection2()
ScoreComponentCollection::ScoreComponentCollection()
: m_scores(StaticData::Instance()->GetTotalScoreComponents(), 0.0f)
, m_sim(&StaticData::Instance()->GetScoreIndexManager())
{}

View File

@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* some of these scores may be 0, this number is fixed (and generally quite small, ie, less
* than 15), for a given model.
*
* The values contained in ScoreComponentCollection2 objects are unweighted scores (log-probs).
* The values contained in ScoreComponentCollection objects are unweighted scores (log-probs).
*
* ScoreComponentCollection objects can be added and subtracted, which makes them appropriate
* to be the datatype used to return the result of a score computations (in this case they will
@ -44,8 +44,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* representing that score must extend the ScoreProducer abstract base class. For an example
* refer to the DistortionScoreProducer class.
*/
class ScoreComponentCollection2 {
friend std::ostream& operator<<(std::ostream& os, const ScoreComponentCollection2& rhs);
class ScoreComponentCollection {
friend std::ostream& operator<<(std::ostream& os, const ScoreComponentCollection& rhs);
friend class ScoreIndexManager;
private:
std::vector<float> m_scores;
@ -53,10 +53,10 @@ private:
public:
//! Create a new score collection with all values set to 0.0
ScoreComponentCollection2();
ScoreComponentCollection();
//! Clone a score collection
ScoreComponentCollection2(const ScoreComponentCollection2& rhs)
ScoreComponentCollection(const ScoreComponentCollection& rhs)
: m_scores(rhs.m_scores)
, m_sim(rhs.m_sim)
{}
@ -69,7 +69,7 @@ public:
}
//! add the score in rhs
void PlusEquals(const ScoreComponentCollection2& rhs)
void PlusEquals(const ScoreComponentCollection& rhs)
{
assert(m_scores.size() >= rhs.m_scores.size());
const size_t l = rhs.m_scores.size();
@ -77,7 +77,7 @@ public:
}
//! subtract the score in rhs
void MinusEquals(const ScoreComponentCollection2& rhs)
void MinusEquals(const ScoreComponentCollection& rhs)
{
assert(m_scores.size() >= rhs.m_scores.size());
const size_t l = rhs.m_scores.size();
@ -175,7 +175,7 @@ public:
};
inline std::ostream& operator<<(std::ostream& os, const ScoreComponentCollection2& rhs)
inline std::ostream& operator<<(std::ostream& os, const ScoreComponentCollection& rhs)
{
os << "<<" << rhs.m_scores[0];
for (size_t i=1; i<rhs.m_scores.size(); i++)

View File

@ -26,7 +26,7 @@ void ScoreIndexManager::AddScoreProducer(const ScoreProducer* sp)
VERBOSE(2,"Added ScoreProducer(" << sp << "): id=" << sp->GetScoreBookkeepingID() << std::endl);
}
void ScoreIndexManager::Debug_PrintLabeledScores(std::ostream& os, const ScoreComponentCollection2& scc) const
void ScoreIndexManager::Debug_PrintLabeledScores(std::ostream& os, const ScoreComponentCollection& scc) const
{
std::vector<float> weights(scc.m_scores.size(), 1.0f);
Debug_PrintLabeledWeightedScores(os, scc, weights);
@ -39,7 +39,7 @@ static std::string getFormat(float foo)
return buf;
}
void ScoreIndexManager::Debug_PrintLabeledWeightedScores(std::ostream& os, const ScoreComponentCollection2& scc, const std::vector<float>& weights) const
void ScoreIndexManager::Debug_PrintLabeledWeightedScores(std::ostream& os, const ScoreComponentCollection& scc, const std::vector<float>& weights) const
{
size_t cur_i = 0;
size_t cur_scoreType = 0;

View File

@ -7,7 +7,7 @@
#include <vector>
class ScoreProducer;
class ScoreComponentCollection2; // debugging only
class ScoreComponentCollection; // debugging only
class ScoreIndexManager
{
@ -19,8 +19,8 @@ public:
size_t GetEndIndex(size_t scoreBookkeepingID) const { return m_ends[scoreBookkeepingID]; }
size_t GetTotalNumberOfScores() const { return m_last; }
void Debug_PrintLabeledScores(std::ostream& os, const ScoreComponentCollection2& scc) const;
void Debug_PrintLabeledWeightedScores(std::ostream& os, const ScoreComponentCollection2& scc, const std::vector<float>& weights) const;
void Debug_PrintLabeledScores(std::ostream& os, const ScoreComponentCollection& scc) const;
void Debug_PrintLabeledWeightedScores(std::ostream& os, const ScoreComponentCollection& scc, const std::vector<float>& weights) const;
private:

View File

@ -36,7 +36,7 @@ public:
void CreateScoreBookkeepingID() { m_scoreBookkeepingId = s_globalScoreBookkeepingIdCounter++;}
//! returns the number of scores that a subclass produces.
//! For example, a language model conventionally produces 1, a translation table some arbitrary number, etc
virtual unsigned int GetNumScoreComponents() const = 0;
virtual size_t GetNumScoreComponents() const = 0;
//! returns a string description of this producer
virtual const std::string GetScoreProducerDescription() const = 0;

View File

@ -19,8 +19,9 @@ You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include "Sentence.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "TranslationOptionCollectionText.h"
#include "StaticData.h"
#include "Util.h"
@ -41,7 +42,7 @@ int Sentence::Read(std::istream& in,const std::vector<FactorType>& factorOrder,
}
TargetPhraseCollection const* Sentence::
CreateTargetPhraseCollection(PhraseDictionaryBase const& d,
CreateTargetPhraseCollection(PhraseDictionary const& d,
const WordsRange& r) const
{
Phrase src=GetSubString(r);

View File

@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "InputType.h"
class WordsRangs;
class PhraseDictionaryBase;
class PhraseDictionary;
class TranslationOptionCollection;
@ -62,7 +62,7 @@ class Sentence : public Phrase, public InputType
int Read(std::istream& in,const std::vector<FactorType>& factorOrder, FactorCollection &factorCollection);
void Print(std::ostream& out) const;
TargetPhraseCollection const* CreateTargetPhraseCollection(PhraseDictionaryBase const& d,const WordsRange& r) const;
TargetPhraseCollection const* CreateTargetPhraseCollection(PhraseDictionary const& d,const WordsRange& r) const;
TranslationOptionCollection* CreateTranslationOptionCollection() const;
};

View File

@ -1,3 +1,6 @@
// $Id: Sentence.cpp 822 2006-09-20 21:49:34Z redpony $
// vim:tabstop=2
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2006 University of Edinburgh

View File

@ -65,7 +65,7 @@ class SentenceStats
*/
void CalcFinalStats(const Hypothesis& bestHypo);
unsigned int GetTotalHypos() const {return Hypothesis::s_HypothesesCreated;}
unsigned int GetTotalHypos() const {return Hypothesis::GetHypothesesCreated();}
size_t GetNumHyposRecombined() const {return m_recombinationInfos.size();}
unsigned int GetNumHyposPruned() const {return m_numHyposPruned;}
unsigned int GetNumHyposDiscarded() const {return m_numHyposDiscarded;}

View File

@ -1,4 +1,24 @@
// $Id$
// vim:tabstop=2
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2006 University of Edinburgh
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include <string>
#include <iostream>

View File

@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <string>
#include <cassert>
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "DecodeStepTranslation.h"
#include "DecodeStepGeneration.h"
#include "GenerationDictionary.h"
@ -626,7 +626,7 @@ void StaticData::LoadPhraseTables(bool filter
filterPhrase = false;
VERBOSE(2,"using standard phrase tables");
PhraseDictionary *pd=new PhraseDictionary(noScoreComponent);
PhraseDictionaryMemory *pd=new PhraseDictionaryMemory(noScoreComponent);
pd->Load(input
, output
, m_factorCollection

View File

@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
class InputType;
class LexicalReordering;
class PhraseDictionaryBase;
class PhraseDictionary;
class GenerationDictionary;
class DistortionScoreProducer;
class WordPenaltyProducer;
@ -49,7 +49,7 @@ private:
static StaticData* s_instance;
protected:
FactorCollection m_factorCollection;
std::vector<PhraseDictionaryBase*> m_phraseDictionary;
std::vector<PhraseDictionary*> m_phraseDictionary;
std::vector<GenerationDictionary*> m_generationDictionary;
std::list < DecodeStep* > m_decodeStepList;
Parameter m_parameter;
@ -232,7 +232,7 @@ public:
{
return m_phraseDictionary.size();
}
std::vector<PhraseDictionaryBase*> GetPhraseDictionaries() const
std::vector<PhraseDictionary*> GetPhraseDictionaries() const
{
return m_phraseDictionary;
}

View File

@ -21,7 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <cassert>
#include "TargetPhrase.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "GenerationDictionary.h"
#include "LanguageModel.h"
#include "StaticData.h"

View File

@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ScoreComponentCollection.h"
class LMList;
class PhraseDictionaryBase;
class PhraseDictionary;
class GenerationDictionary;
class ScoreProducer;
@ -38,7 +38,7 @@ class TargetPhrase: public Phrase
friend std::ostream& operator<<(std::ostream&, const TargetPhrase&);
protected:
float m_transScore, m_ngramScore, m_fullScore;
ScoreComponentCollection2 m_scoreBreakdown;
ScoreComponentCollection m_scoreBreakdown;
// in case of confusion net, ptr to source phrase
Phrase const* m_sourcePhrase;
@ -51,7 +51,7 @@ public:
/*** Called immediately after creation to initialize scores.
*
* @param translationScoreProducer The PhraseDictionary that this TargetPhrase is contained by.
* @param translationScoreProducer The PhraseDictionaryMemory that this TargetPhrase is contained by.
* Used to identify where the scores for this phrase belong in the list of all scores.
* @param scoreVector the vector of scores (log probs) associated with this translation
* @param weighT the weights for the individual scores (t-weights in the .ini file)
@ -87,7 +87,7 @@ public:
{
return m_fullScore;
}
inline const ScoreComponentCollection2 &GetScoreBreakdown() const
inline const ScoreComponentCollection &GetScoreBreakdown() const
{
return m_scoreBreakdown;
}

View File

@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "TranslationOption.h"
#include "WordsBitmap.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "GenerationDictionary.h"
#include "LMList.h"
#include "StaticData.h"
@ -46,7 +46,7 @@ TranslationOption::TranslationOption(const WordsRange &wordsRange, const TargetP
{
}
void TranslationOption::MergeNewFeatures(const Phrase& phrase, const ScoreComponentCollection2& score, const std::vector<FactorType>& featuresToAdd)
void TranslationOption::MergeNewFeatures(const Phrase& phrase, const ScoreComponentCollection& score, const std::vector<FactorType>& featuresToAdd)
{
assert(phrase.GetSize() == m_targetPhrase.GetSize());
if (featuresToAdd.size() == 1) {

View File

@ -32,7 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "ScoreComponentCollection.h"
#include "StaticData.h"
class PhraseDictionaryBase;
class PhraseDictionary;
class GenerationDictionary;
/** Available phrase translation for a particular sentence pair.
@ -67,7 +67,7 @@ protected:
//! for example, know the full n-gram score since the length of the
//! TargetPhrase may be shorter than the n-gram order. But, if it is
//! possible to estimate, it is included here.
ScoreComponentCollection2 m_scoreBreakdown;
ScoreComponentCollection m_scoreBreakdown;
public:
/** constructor. Used by initial translation step */
@ -82,7 +82,7 @@ public:
bool IsCompatible(const Phrase& phrase, const std::vector<FactorType>& featuresToCheck) const;
/** used when precomputing (composing) translation options */
void MergeNewFeatures(const Phrase& phrase, const ScoreComponentCollection2& score, const std::vector<FactorType>& featuresToMerge);
void MergeNewFeatures(const Phrase& phrase, const ScoreComponentCollection& score, const std::vector<FactorType>& featuresToMerge);
/** returns target phrase */
inline const Phrase &GetTargetPhrase() const
@ -141,7 +141,7 @@ public:
}
/** returns detailed component scores */
inline const ScoreComponentCollection2 &GetScoreBreakdown() const
inline const ScoreComponentCollection &GetScoreBreakdown() const
{
return m_scoreBreakdown;
}

View File

@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "Sentence.h"
#include "DecodeStep.h"
#include "LanguageModel.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "FactorCollection.h"
#include "InputType.h"
#include "Util.h"
@ -119,7 +119,7 @@ void TranslationOptionCollection::Prune()
* This function calls for unknown words is complicated by the fact it must handle different input types.
* The call stack is
* Base::ProcessUnknownWord()
* Inherited::ProcessUnknownWord()
* Inherited::ProcessUnknownWord(position)
* Base::ProcessOneUnknownWord()
*
* \param decodeStepList list of decoding steps
@ -424,7 +424,7 @@ void TranslationOptionCollection::ProcessInitialTranslation(
, size_t endPos
, bool adhereTableLimit)
{
const PhraseDictionaryBase &phraseDictionary = decodeStep.GetPhraseDictionary();
const PhraseDictionary &phraseDictionary = decodeStep.GetPhraseDictionary();
const size_t tableLimit = phraseDictionary.GetTableLimit();
const WordsRange wordsRange(startPos, endPos);

View File

@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
class LanguageModel;
class FactorCollection;
class PhraseDictionary;
class PhraseDictionaryMemory;
class GenerationDictionary;
class InputType;
class LMList;

View File

@ -1,9 +1,10 @@
// $Id$
#include "TranslationOptionCollectionConfusionNet.h"
#include "ConfusionNet.h"
#include "DecodeStep.h"
#include "LanguageModel.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "FactorCollection.h"
#include "LMList.h"

View File

@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "Sentence.h"
#include "DecodeStep.h"
#include "LanguageModel.h"
#include "PhraseDictionary.h"
#include "PhraseDictionaryMemory.h"
#include "FactorCollection.h"
#include "WordsRange.h"
#include "LMList.h"