From d6f9458d5927a000f0c4fdb3252861daa1210ac0 Mon Sep 17 00:00:00 2001 From: hieuhoang1972 Date: Tue, 17 Oct 2006 11:07:17 +0000 Subject: [PATCH] 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 --- irstlm/src/index.h | 2 +- irstlm/src/lmtable.cpp | 2 - moses-cmd/src/IOCommandLine.cpp | 6 +-- moses-cmd/src/TranslationAnalysis.cpp | 6 +-- moses/src/ConfusionNet.cpp | 8 ++-- moses/src/ConfusionNet.h | 2 +- moses/src/DecodeStep.cpp | 6 +-- moses/src/DecodeStep.h | 4 +- moses/src/DecodeStepGeneration.cpp | 8 ++-- moses/src/DecodeStepGeneration.h | 4 +- moses/src/DecodeStepTranslation.cpp | 10 ++--- moses/src/DecodeStepTranslation.h | 6 +-- moses/src/GenerationDictionary.cpp | 2 +- moses/src/GenerationDictionary.h | 4 +- moses/src/Hypothesis.cpp | 37 +++++++--------- moses/src/Hypothesis.h | 43 +++++++++++-------- moses/src/InputType.cpp | 2 + moses/src/InputType.h | 4 +- moses/src/LMList.cpp | 2 +- moses/src/LMList.h | 4 +- moses/src/LanguageModel.cpp | 2 +- moses/src/LanguageModel.h | 6 +-- moses/src/LanguageModelChunking.cpp | 1 - moses/src/LanguageModelFactory.cpp | 20 +++++++++ moses/src/LanguageModelIRST.cpp | 2 +- moses/src/LanguageModelIRST.h | 1 - moses/src/LanguageModelJoint.cpp | 19 ++++++++ moses/src/LanguageModelSingleFactor.h | 10 +---- moses/src/LatticePath.cpp | 2 +- moses/src/LatticePath.h | 4 +- moses/src/Manager.cpp | 20 ++++----- moses/src/Manager.h | 2 +- moses/src/PhraseDictionary.cpp | 34 ++++++++++++--- moses/src/PhraseDictionary.h | 8 ++-- moses/src/PhraseDictionaryMemory.cpp | 22 +++++----- moses/src/PhraseDictionaryMemory.h | 12 +++--- moses/src/PhraseDictionaryNode.cpp | 4 +- moses/src/PhraseDictionaryNode.h | 4 +- moses/src/PhraseDictionaryTreeAdaptor.cpp | 2 +- moses/src/PhraseDictionaryTreeAdaptor.h | 6 +-- moses/src/PhraseReference.cpp | 2 + moses/src/ScoreComponentCollection.cpp | 2 +- moses/src/ScoreComponentCollection.h | 16 +++---- moses/src/ScoreIndexManager.cpp | 4 +- moses/src/ScoreIndexManager.h | 6 +-- moses/src/ScoreProducer.h | 2 +- moses/src/Sentence.cpp | 5 ++- moses/src/Sentence.h | 4 +- moses/src/SentenceStats.cpp | 3 ++ moses/src/SentenceStats.h | 2 +- moses/src/SquareMatrix.cpp | 20 +++++++++ moses/src/StaticData.cpp | 4 +- moses/src/StaticData.h | 6 +-- moses/src/TargetPhrase.cpp | 2 +- moses/src/TargetPhrase.h | 8 ++-- moses/src/TranslationOption.cpp | 4 +- moses/src/TranslationOption.h | 8 ++-- moses/src/TranslationOptionCollection.cpp | 6 +-- moses/src/TranslationOptionCollection.h | 2 +- ...ranslationOptionCollectionConfusionNet.cpp | 3 +- moses/src/TranslationOptionCollectionText.cpp | 2 +- 61 files changed, 266 insertions(+), 188 deletions(-) diff --git a/irstlm/src/index.h b/irstlm/src/index.h index 500587989..e4e29d793 100644 --- a/irstlm/src/index.h +++ b/irstlm/src/index.h @@ -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]; } diff --git a/irstlm/src/lmtable.cpp b/irstlm/src/lmtable.cpp index 6ffa6afe6..5e153eaad 100644 --- a/irstlm/src/lmtable.cpp +++ b/irstlm/src/lmtable.cpp @@ -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]; diff --git a/moses-cmd/src/IOCommandLine.cpp b/moses-cmd/src/IOCommandLine.cpp index 79cbf9139..ea0a489ef 100755 --- a/moses-cmd/src/IOCommandLine.cpp +++ b/moses-cmd/src/IOCommandLine.cpp @@ -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 pds = StaticData::Instance()->GetPhraseDictionaries(); + vector pds = StaticData::Instance()->GetPhraseDictionaries(); if (pds.size() > 0) { if (labeledOutput) m_nBestFile << "tm: "; - vector::iterator iter; + vector::iterator iter; for (iter = pds.begin(); iter != pds.end(); ++iter) { vector scores = path.GetScoreBreakdown().GetScoresForProducer(*iter); for (size_t j = 0; j targetMap; std::vector 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 >& lmstats = *(*tpi)->_lmstats; + std::vector >& lmstats = *(*tpi)->GetLMStats(); std::vector >::iterator i = lmstats.begin(); std::vector::iterator acc = lmAcc.begin(); // std::cerr << "\n"; diff --git a/moses/src/ConfusionNet.cpp b/moses/src/ConfusionNet.cpp index aa5062a10..d257e6773 100644 --- a/moses/src/ConfusionNet.cpp +++ b/moses/src/ConfusionNet.cpp @@ -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>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: "< 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* diff --git a/moses/src/ConfusionNet.h b/moses/src/ConfusionNet.h index 03101e829..d041f42f0 100644 --- a/moses/src/ConfusionNet.h +++ b/moses/src/ConfusionNet.h @@ -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; diff --git a/moses/src/DecodeStep.cpp b/moses/src/DecodeStep.cpp index ab659537e..0d55cd889 100644 --- a/moses/src/DecodeStep.cpp +++ b/moses/src/DecodeStep.cpp @@ -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(m_ptr); + return *static_cast(m_ptr); } /** returns generation table (dictionary) for generation step */ diff --git a/moses/src/DecodeStep.h b/moses/src/DecodeStep.h index b6dae8c1b..107edbc1c 100644 --- a/moses/src/DecodeStep.h +++ b/moses/src/DecodeStep.h @@ -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; diff --git a/moses/src/DecodeStepGeneration.cpp b/moses/src/DecodeStepGeneration.cpp index 0677424a2..c9da96e6a 100644 --- a/moses/src/DecodeStepGeneration.cpp +++ b/moses/src/DecodeStepGeneration.cpp @@ -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 WordPair; +typedef pair 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++) diff --git a/moses/src/DecodeStepGeneration.h b/moses/src/DecodeStepGeneration.h index f4ab90761..1bdaa2652 100644 --- a/moses/src/DecodeStepGeneration.h +++ b/moses/src/DecodeStepGeneration.h @@ -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; }; diff --git a/moses/src/DecodeStepTranslation.cpp b/moses/src/DecodeStepTranslation.cpp index 1095f0024..a9964b8ed 100644 --- a/moses/src/DecodeStepTranslation.cpp +++ b/moses/src/DecodeStepTranslation.cpp @@ -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(m_ptr); + return *static_cast(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(); diff --git a/moses/src/DecodeStepTranslation.h b/moses/src/DecodeStepTranslation.h index 218892ddc..8bdd1b52d 100644 --- a/moses/src/DecodeStepTranslation.h +++ b/moses/src/DecodeStepTranslation.h @@ -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 diff --git a/moses/src/GenerationDictionary.cpp b/moses/src/GenerationDictionary.cpp index 4e91fdbfd..70057a490 100755 --- a/moses/src/GenerationDictionary.cpp +++ b/moses/src/GenerationDictionary.cpp @@ -120,7 +120,7 @@ GenerationDictionary::~GenerationDictionary() } } -unsigned int GenerationDictionary::GetNumScoreComponents() const +size_t GenerationDictionary::GetNumScoreComponents() const { return this->GetNoScoreComponents(); } diff --git a/moses/src/GenerationDictionary.h b/moses/src/GenerationDictionary.h index d97f5d679..b9e5e1e71 100755 --- a/moses/src/GenerationDictionary.h +++ b/moses/src/GenerationDictionary.h @@ -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 diff --git a/moses/src/Hypothesis.cpp b/moses/src/Hypothesis.cpp index 0e946aa5f..43924722b 100755 --- a/moses/src/Hypothesis.cpp +++ b/moses/src/Hypothesis.cpp @@ -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 >(languageModels.size(), vector(0)); + m_lmstats = new vector >(languageModels.size(), vector(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 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: "<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 ) { diff --git a/moses/src/Hypothesis.h b/moses/src/Hypothesis.h index df1a423e0..3addea260 100755 --- a/moses/src/Hypothesis.h +++ b/moses/src/Hypothesis.h @@ -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 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 >* 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 >* _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 &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 > *GetLMStats() const + { + return m_lmstats; + } + + static unsigned int GetHypothesesCreated() + { + return s_HypothesesCreated; + } }; std::ostream& operator<<(std::ostream& out, const Hypothesis& hypothesis); diff --git a/moses/src/InputType.cpp b/moses/src/InputType.cpp index a348a1a72..65a165263 100644 --- a/moses/src/InputType.cpp +++ b/moses/src/InputType.cpp @@ -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) {} diff --git a/moses/src/InputType.h b/moses/src/InputType.h index 0e3f4f8a5..ed0f8f3da 100644 --- a/moses/src/InputType.h +++ b/moses/src/InputType.h @@ -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; diff --git a/moses/src/LMList.cpp b/moses/src/LMList.cpp index d9565a96c..c15212df6 100644 --- a/moses/src/LMList.cpp +++ b/moses/src/LMList.cpp @@ -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) diff --git a/moses/src/LMList.h b/moses/src/LMList.h index f54121fad..b8ba15c0b 100644 --- a/moses/src/LMList.h +++ b/moses/src/LMList.h @@ -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; }; diff --git a/moses/src/LanguageModel.cpp b/moses/src/LanguageModel.cpp index b6efd431e..72eb495df 100755 --- a/moses/src/LanguageModel.cpp +++ b/moses/src/LanguageModel.cpp @@ -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; } diff --git a/moses/src/LanguageModel.h b/moses/src/LanguageModel.h index e4785ae2c..587992a6b 100755 --- a/moses/src/LanguageModel.h +++ b/moses/src/LanguageModel.h @@ -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 or + //! Usually and /** 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 or + //! Contains factors which represents the beging and end words for this LM. Usually and const Word &GetSentenceStartArray() const { return m_sentenceStartArray; diff --git a/moses/src/LanguageModelChunking.cpp b/moses/src/LanguageModelChunking.cpp index 622e0c177..0f3812d43 100644 --- a/moses/src/LanguageModelChunking.cpp +++ b/moses/src/LanguageModelChunking.cpp @@ -1,4 +1,3 @@ - // $Id$ /*********************************************************************** diff --git a/moses/src/LanguageModelFactory.cpp b/moses/src/LanguageModelFactory.cpp index ff6dca627..7ad9a02bb 100644 --- a/moses/src/LanguageModelFactory.cpp +++ b/moses/src/LanguageModelFactory.cpp @@ -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" diff --git a/moses/src/LanguageModelIRST.cpp b/moses/src/LanguageModelIRST.cpp index 48dac601c..43fbe6a06 100755 --- a/moses/src/LanguageModelIRST.cpp +++ b/moses/src/LanguageModelIRST.cpp @@ -153,7 +153,7 @@ float LanguageModelIRST::GetValue(const vector &contextFactor, Stat *len = 0; } - return TransformIRSTScore(m_lmtb->clprob(*m_lmtb_ng)); + return TransformIRSTScore((float) m_lmtb->clprob(*m_lmtb_ng)); } diff --git a/moses/src/LanguageModelIRST.h b/moses/src/LanguageModelIRST.h index c95c58c3d..d7c04092a 100755 --- a/moses/src/LanguageModelIRST.h +++ b/moses/src/LanguageModelIRST.h @@ -35,7 +35,6 @@ class Phrase; class lmtable; // irst lm table class ngram; -//! Wrapper around IRST LM implementation class LanguageModelIRST : public LanguageModelSingleFactor { protected: diff --git a/moses/src/LanguageModelJoint.cpp b/moses/src/LanguageModelJoint.cpp index 6cbaec845..3ad8dbbd9 100644 --- a/moses/src/LanguageModelJoint.cpp +++ b/moses/src/LanguageModelJoint.cpp @@ -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" diff --git a/moses/src/LanguageModelSingleFactor.h b/moses/src/LanguageModelSingleFactor.h index 2b13f92c6..d9d7b1a15 100644 --- a/moses/src/LanguageModelSingleFactor.h +++ b/moses/src/LanguageModelSingleFactor.h @@ -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 + const Factor *GetSentenceStart() const { return m_sentenceStart; } - //! factor that represent sentence start. Usually const Factor *GetSentenceEnd() const { return m_sentenceEnd; } - //! which factor type this LM uses FactorType GetFactorType() const { return m_factorType; diff --git a/moses/src/LatticePath.cpp b/moses/src/LatticePath.cpp index f47ca9141..d6721304f 100755 --- a/moses/src/LatticePath.cpp +++ b/moses/src/LatticePath.cpp @@ -72,7 +72,7 @@ LatticePath::LatticePath(const LatticePath ©, size_t edgeIndex, const Hypoth void LatticePath::CalcScore(const LatticePath ©, 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); diff --git a/moses/src/LatticePath.h b/moses/src/LatticePath.h index efb57179d..993fb8d82 100755 --- a/moses/src/LatticePath.h +++ b/moses/src/LatticePath.h @@ -37,7 +37,7 @@ protected: std::vector m_path; size_t m_prevEdgeChanged; - ScoreComponentCollection2 m_scoreBreakdown; + ScoreComponentCollection m_scoreBreakdown; float m_totalScore; void CalcScore(const LatticePath ©, 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; } diff --git a/moses/src/Manager.cpp b/moses/src/Manager.cpp index 7e2f7ee4a..366e2a880 100755 --- a/moses/src/Manager.cpp +++ b/moses/src/Manager.cpp @@ -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) { diff --git a/moses/src/Manager.h b/moses/src/Manager.h index fa30de99c..c5f577b6c 100755 --- a/moses/src/Manager.h +++ b/moses/src/Manager.h @@ -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 diff --git a/moses/src/PhraseDictionary.cpp b/moses/src/PhraseDictionary.cpp index 22cced60d..bb498994b 100644 --- a/moses/src/PhraseDictionary.cpp +++ b/moses/src/PhraseDictionary.cpp @@ -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(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(); } diff --git a/moses/src/PhraseDictionary.h b/moses/src/PhraseDictionary.h index 519526256..21658f3d3 100644 --- a/moses/src/PhraseDictionary.h +++ b/moses/src/PhraseDictionary.h @@ -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 &weightT)=0; diff --git a/moses/src/PhraseDictionaryMemory.cpp b/moses/src/PhraseDictionaryMemory.cpp index 3f4cfbf28..8e2489f75 100755 --- a/moses/src/PhraseDictionaryMemory.cpp +++ b/moses/src/PhraseDictionaryMemory.cpp @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include -#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 &input +void PhraseDictionaryMemory::Load(const std::vector &input , const std::vector &output , FactorCollection &factorCollection , const string &filePath @@ -54,7 +54,7 @@ void PhraseDictionary::Load(const std::vector &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 &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 &weightT) +void PhraseDictionaryMemory::SetWeightTransModel(const vector &weightT) { PhraseDictionaryNode::iterator iterDict; for (iterDict = m_collection.begin() ; iterDict != m_collection.end() ; ++iterDict) @@ -168,7 +168,7 @@ void PhraseDictionary::SetWeightTransModel(const vector &weightT) } } -bool PhraseDictionary::Contains(const vector< vector > &phraseVector +bool PhraseDictionaryMemory::Contains(const vector< vector > &phraseVector , const list &inputPhraseList , const vector &inputFactorType) { @@ -182,10 +182,10 @@ bool PhraseDictionary::Contains(const vector< vector > &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; diff --git a/moses/src/PhraseDictionaryMemory.h b/moses/src/PhraseDictionaryMemory.h index a6abc0d1c..a43da42f3 100755 --- a/moses/src/PhraseDictionaryMemory.h +++ b/moses/src/PhraseDictionaryMemory.h @@ -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 &input , const std::vector &output diff --git a/moses/src/PhraseDictionaryNode.cpp b/moses/src/PhraseDictionaryNode.cpp index 227b58ef2..2188b5d35 100644 --- a/moses/src/PhraseDictionaryNode.cpp +++ b/moses/src/PhraseDictionaryNode.cpp @@ -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 &weightT) { // recursively set weights diff --git a/moses/src/PhraseDictionaryNode.h b/moses/src/PhraseDictionaryNode.h index 7b9b52411..a2746fda6 100644 --- a/moses/src/PhraseDictionaryNode.h +++ b/moses/src/PhraseDictionaryNode.h @@ -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 &weightT); // iterators diff --git a/moses/src/PhraseDictionaryTreeAdaptor.cpp b/moses/src/PhraseDictionaryTreeAdaptor.cpp index fc9374d5e..a33c3c63b 100644 --- a/moses/src/PhraseDictionaryTreeAdaptor.cpp +++ b/moses/src/PhraseDictionaryTreeAdaptor.cpp @@ -66,7 +66,7 @@ void PhraseDictionaryTreeAdaptor::Create(const std::vector &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, diff --git a/moses/src/PhraseDictionaryTreeAdaptor.h b/moses/src/PhraseDictionaryTreeAdaptor.h index ffbb475a0..cbd98a38d 100644 --- a/moses/src/PhraseDictionaryTreeAdaptor.h +++ b/moses/src/PhraseDictionaryTreeAdaptor.h @@ -4,7 +4,7 @@ #define PHRASEDICTIONARYTREEADAPTOR_H_ #include #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(); diff --git a/moses/src/PhraseReference.cpp b/moses/src/PhraseReference.cpp index 7c51a1efc..57411dfe1 100644 --- a/moses/src/PhraseReference.cpp +++ b/moses/src/PhraseReference.cpp @@ -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 diff --git a/moses/src/ScoreComponentCollection.cpp b/moses/src/ScoreComponentCollection.cpp index bbf8d5920..fe653a049 100644 --- a/moses/src/ScoreComponentCollection.cpp +++ b/moses/src/ScoreComponentCollection.cpp @@ -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()) {} diff --git a/moses/src/ScoreComponentCollection.h b/moses/src/ScoreComponentCollection.h index 10d0a9464..f057b25f7 100644 --- a/moses/src/ScoreComponentCollection.h +++ b/moses/src/ScoreComponentCollection.h @@ -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 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& factorOrder, } TargetPhraseCollection const* Sentence:: -CreateTargetPhraseCollection(PhraseDictionaryBase const& d, +CreateTargetPhraseCollection(PhraseDictionary const& d, const WordsRange& r) const { Phrase src=GetSubString(r); diff --git a/moses/src/Sentence.h b/moses/src/Sentence.h index b33d700cb..88036c92d 100755 --- a/moses/src/Sentence.h +++ b/moses/src/Sentence.h @@ -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& 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; }; diff --git a/moses/src/SentenceStats.cpp b/moses/src/SentenceStats.cpp index 70ce1022e..bcd39f95d 100644 --- a/moses/src/SentenceStats.cpp +++ b/moses/src/SentenceStats.cpp @@ -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 diff --git a/moses/src/SentenceStats.h b/moses/src/SentenceStats.h index 8c4dc92a5..4c4b44de3 100644 --- a/moses/src/SentenceStats.h +++ b/moses/src/SentenceStats.h @@ -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;} diff --git a/moses/src/SquareMatrix.cpp b/moses/src/SquareMatrix.cpp index 347837f9b..2eff4f91e 100644 --- a/moses/src/SquareMatrix.cpp +++ b/moses/src/SquareMatrix.cpp @@ -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 #include diff --git a/moses/src/StaticData.cpp b/moses/src/StaticData.cpp index 083e6edf4..35ac2ebc9 100755 --- a/moses/src/StaticData.cpp +++ b/moses/src/StaticData.cpp @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#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 diff --git a/moses/src/StaticData.h b/moses/src/StaticData.h index 1e49b2e7d..b8d5e26d7 100755 --- a/moses/src/StaticData.h +++ b/moses/src/StaticData.h @@ -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 m_phraseDictionary; + std::vector m_phraseDictionary; std::vector m_generationDictionary; std::list < DecodeStep* > m_decodeStepList; Parameter m_parameter; @@ -232,7 +232,7 @@ public: { return m_phraseDictionary.size(); } - std::vector GetPhraseDictionaries() const + std::vector GetPhraseDictionaries() const { return m_phraseDictionary; } diff --git a/moses/src/TargetPhrase.cpp b/moses/src/TargetPhrase.cpp index 412b5888c..6a0bc06ee 100644 --- a/moses/src/TargetPhrase.cpp +++ b/moses/src/TargetPhrase.cpp @@ -21,7 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include "TargetPhrase.h" -#include "PhraseDictionary.h" +#include "PhraseDictionaryMemory.h" #include "GenerationDictionary.h" #include "LanguageModel.h" #include "StaticData.h" diff --git a/moses/src/TargetPhrase.h b/moses/src/TargetPhrase.h index b69b5e82f..2cd305145 100644 --- a/moses/src/TargetPhrase.h +++ b/moses/src/TargetPhrase.h @@ -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; } diff --git a/moses/src/TranslationOption.cpp b/moses/src/TranslationOption.cpp index 7fbb73849..cb2e80570 100755 --- a/moses/src/TranslationOption.cpp +++ b/moses/src/TranslationOption.cpp @@ -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& featuresToAdd) +void TranslationOption::MergeNewFeatures(const Phrase& phrase, const ScoreComponentCollection& score, const std::vector& featuresToAdd) { assert(phrase.GetSize() == m_targetPhrase.GetSize()); if (featuresToAdd.size() == 1) { diff --git a/moses/src/TranslationOption.h b/moses/src/TranslationOption.h index 7a1971d4d..2f89668c4 100755 --- a/moses/src/TranslationOption.h +++ b/moses/src/TranslationOption.h @@ -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& featuresToCheck) const; /** used when precomputing (composing) translation options */ - void MergeNewFeatures(const Phrase& phrase, const ScoreComponentCollection2& score, const std::vector& featuresToMerge); + void MergeNewFeatures(const Phrase& phrase, const ScoreComponentCollection& score, const std::vector& 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; } diff --git a/moses/src/TranslationOptionCollection.cpp b/moses/src/TranslationOptionCollection.cpp index 80edc0afd..2ee822398 100644 --- a/moses/src/TranslationOptionCollection.cpp +++ b/moses/src/TranslationOptionCollection.cpp @@ -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); diff --git a/moses/src/TranslationOptionCollection.h b/moses/src/TranslationOptionCollection.h index b71e7094e..f62e0f133 100755 --- a/moses/src/TranslationOptionCollection.h +++ b/moses/src/TranslationOptionCollection.h @@ -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; diff --git a/moses/src/TranslationOptionCollectionConfusionNet.cpp b/moses/src/TranslationOptionCollectionConfusionNet.cpp index 945a2ee07..4f548d6ca 100644 --- a/moses/src/TranslationOptionCollectionConfusionNet.cpp +++ b/moses/src/TranslationOptionCollectionConfusionNet.cpp @@ -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" diff --git a/moses/src/TranslationOptionCollectionText.cpp b/moses/src/TranslationOptionCollectionText.cpp index 0e12ee0c3..a594ded06 100644 --- a/moses/src/TranslationOptionCollectionText.cpp +++ b/moses/src/TranslationOptionCollectionText.cpp @@ -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"