From f2d218f8ee5a5273451337c921046fc5e4c1a658 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Wed, 2 Oct 2013 20:02:05 +0100 Subject: [PATCH] move checking of legacy phrase-table to StaticData --- moses/ConfusionNet.cpp | 1 - moses/ConfusionNet.h | 1 + moses/InputType.cpp | 1 + moses/StaticData.cpp | 19 ++++++++++++++- moses/StaticData.h | 7 ++++++ ...ranslationOptionCollectionConfusionNet.cpp | 21 ++--------------- .../TranslationOptionCollectionConfusionNet.h | 3 --- moses/TranslationOptionCollectionLattice.cpp | 23 +++---------------- moses/TranslationOptionCollectionLattice.h | 2 -- moses/WordLattice.cpp | 2 ++ moses/WordLattice.h | 1 - 11 files changed, 34 insertions(+), 47 deletions(-) diff --git a/moses/ConfusionNet.cpp b/moses/ConfusionNet.cpp index fdfde0a86..91bc1959f 100644 --- a/moses/ConfusionNet.cpp +++ b/moses/ConfusionNet.cpp @@ -5,7 +5,6 @@ #include "FactorCollection.h" #include "Util.h" -#include "moses/TranslationModel/PhraseDictionaryTreeAdaptor.h" #include "TranslationOptionCollectionConfusionNet.h" #include "StaticData.h" #include "Sentence.h" diff --git a/moses/ConfusionNet.h b/moses/ConfusionNet.h index f6bac4aa8..42f6b260b 100644 --- a/moses/ConfusionNet.h +++ b/moses/ConfusionNet.h @@ -76,6 +76,7 @@ public: return m_defaultLabelSet; } + }; std::ostream& operator<<(std::ostream& out,const ConfusionNet& cn); diff --git a/moses/InputType.cpp b/moses/InputType.cpp index 1ca3da63b..8e58d6692 100644 --- a/moses/InputType.cpp +++ b/moses/InputType.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "InputType.h" #include "ChartTranslationOptions.h" +#include "StaticData.h" namespace Moses { diff --git a/moses/StaticData.cpp b/moses/StaticData.cpp index cb52ed042..ab1102846 100644 --- a/moses/StaticData.cpp +++ b/moses/StaticData.cpp @@ -41,7 +41,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "InputFileStream.h" #include "ScoreComponentCollection.h" #include "DecodeGraph.h" -#include "moses/TranslationModel/PhraseDictionary.h" +#include "TranslationModel/PhraseDictionary.h" +#include "TranslationModel/PhraseDictionaryTreeAdaptor.h" #ifdef WITH_THREADS #include @@ -915,6 +916,7 @@ void StaticData::LoadFeatureFunctions() pt->Load(); } + CheckLEGACYPT(); } bool StaticData::CheckWeights() const @@ -1065,5 +1067,20 @@ void StaticData::OverrideFeatures() } +// check whether we should be using the old code to support binary phrase-table. +// eventually, we'll stop support the binary phrase-table and delete this legacy code +void StaticData::CheckLEGACYPT() +{ + for (size_t i = 0; i < m_phraseDictionary.size(); ++i) { + const PhraseDictionary *phraseDictionary = m_phraseDictionary[i]; + if (dynamic_cast(phraseDictionary) != NULL) { + m_useLegacyPT = true; + return; + } + } + + m_useLegacyPT = false; +} + } // namespace diff --git a/moses/StaticData.h b/moses/StaticData.h index d18c9ad98..62c6f64f7 100644 --- a/moses/StaticData.h +++ b/moses/StaticData.h @@ -208,6 +208,7 @@ protected: std::map< std::string, std::set< size_t > > m_weightSettingIgnoreDP; // decoding path FactorType m_placeHolderFactor; + bool m_useLegacyPT; StaticData(); @@ -223,6 +224,7 @@ protected: bool m_continuePartialTranslation; std::string m_binPath; + public: bool IsAlwaysCreateDirectTranslationOption() const { @@ -751,6 +753,11 @@ public: FactorType GetPlaceholderFactor() const { return m_placeHolderFactor; } + + void CheckLEGACYPT(); + bool GetUseLegacyPT() const + { return m_useLegacyPT; } + }; } diff --git a/moses/TranslationOptionCollectionConfusionNet.cpp b/moses/TranslationOptionCollectionConfusionNet.cpp index 41c5d6fda..b548ecce9 100644 --- a/moses/TranslationOptionCollectionConfusionNet.cpp +++ b/moses/TranslationOptionCollectionConfusionNet.cpp @@ -126,10 +126,6 @@ TranslationOptionCollectionConfusionNet::TranslationOptionCollectionConfusionNet } // for (iterPath = prevPaths.begin(); iterPath != prevPaths.end(); ++iterPath) { } } - - // check whether we should be using the old code to supportbinary phrase-table. - // eventually, we'll stop support the binary phrase-table and delete this legacy code - CheckLEGACY(); } InputPathList &TranslationOptionCollectionConfusionNet::GetInputPathList(size_t startPos, size_t endPos) @@ -166,7 +162,7 @@ void TranslationOptionCollectionConfusionNet::ProcessUnknownWord(size_t sourcePo void TranslationOptionCollectionConfusionNet::CreateTranslationOptions() { - if (!m_useLegacy) { + if (!StaticData::Instance().GetUseLegacyPT()) { GetTargetPhraseCollectionBatch(); } TranslationOptionCollection::CreateTranslationOptions(); @@ -188,7 +184,7 @@ void TranslationOptionCollectionConfusionNet::CreateTranslationOptionsForRange( , bool adhereTableLimit , size_t graphInd) { - if (m_useLegacy) { + if (StaticData::Instance().GetUseLegacyPT()) { CreateTranslationOptionsForRangeLEGACY(decodeGraph, startPos, endPos, adhereTableLimit, graphInd); } else { CreateTranslationOptionsForRangeNew(decodeGraph, startPos, endPos, adhereTableLimit, graphInd); @@ -300,19 +296,6 @@ void TranslationOptionCollectionConfusionNet::CreateTranslationOptionsForRangeLE } } -void TranslationOptionCollectionConfusionNet::CheckLEGACY() -{ - const std::vector &pts = StaticData::Instance().GetPhraseDictionaries(); - for (size_t i = 0; i < pts.size(); ++i) { - const PhraseDictionary *phraseDictionary = pts[i]; - if (dynamic_cast(phraseDictionary) != NULL) { - m_useLegacy = true; - return; - } - } - - m_useLegacy = false; -} } diff --git a/moses/TranslationOptionCollectionConfusionNet.h b/moses/TranslationOptionCollectionConfusionNet.h index 9cb7323f9..ee53f35eb 100644 --- a/moses/TranslationOptionCollectionConfusionNet.h +++ b/moses/TranslationOptionCollectionConfusionNet.h @@ -19,8 +19,6 @@ public: typedef std::vector< std::vector > InputPathMatrix; protected: - bool m_useLegacy; - InputPathMatrix m_inputPathMatrix; /*< contains translation options */ InputPathList &GetInputPathList(size_t startPos, size_t endPos); @@ -30,7 +28,6 @@ protected: , bool adhereTableLimit , size_t graphInd); - void CheckLEGACY(); void CreateTranslationOptionsForRangeLEGACY(const DecodeGraph &decodeStepList , size_t startPosition , size_t endPosition diff --git a/moses/TranslationOptionCollectionLattice.cpp b/moses/TranslationOptionCollectionLattice.cpp index 0eeb5c58f..9585872f6 100644 --- a/moses/TranslationOptionCollectionLattice.cpp +++ b/moses/TranslationOptionCollectionLattice.cpp @@ -126,10 +126,6 @@ TranslationOptionCollectionLattice::TranslationOptionCollectionLattice( } // for (iterPath = prevPaths.begin(); iterPath != prevPaths.end(); ++iterPath) { } } - - // check whether we should be using the old code to supportbinary phrase-table. - // eventually, we'll stop support the binary phrase-table and delete this legacy code - CheckLEGACY(); } InputPathList &TranslationOptionCollectionLattice::GetInputPathList(size_t startPos, size_t endPos) @@ -166,7 +162,7 @@ void TranslationOptionCollectionLattice::ProcessUnknownWord(size_t sourcePos) void TranslationOptionCollectionLattice::CreateTranslationOptions() { - if (!m_useLegacy) { + if (!StaticData::Instance().GetUseLegacyPT()) { GetTargetPhraseCollectionBatch(); } TranslationOptionCollection::CreateTranslationOptions(); @@ -188,7 +184,7 @@ void TranslationOptionCollectionLattice::CreateTranslationOptionsForRange( , bool adhereTableLimit , size_t graphInd) { - if (m_useLegacy) { + if (StaticData::Instance().GetUseLegacyPT()) { CreateTranslationOptionsForRangeLEGACY(decodeGraph, startPos, endPos, adhereTableLimit, graphInd); } else { CreateTranslationOptionsForRangeNew(decodeGraph, startPos, endPos, adhereTableLimit, graphInd); @@ -300,20 +296,7 @@ void TranslationOptionCollectionLattice::CreateTranslationOptionsForRangeLEGACY( } } -void TranslationOptionCollectionLattice::CheckLEGACY() -{ - const std::vector &pts = StaticData::Instance().GetPhraseDictionaries(); - for (size_t i = 0; i < pts.size(); ++i) { - const PhraseDictionary *phraseDictionary = pts[i]; - if (dynamic_cast(phraseDictionary) != NULL) { - m_useLegacy = true; - return; - } - } - m_useLegacy = false; -} - -} +} // namespace diff --git a/moses/TranslationOptionCollectionLattice.h b/moses/TranslationOptionCollectionLattice.h index d54cf9aa9..9644f743e 100644 --- a/moses/TranslationOptionCollectionLattice.h +++ b/moses/TranslationOptionCollectionLattice.h @@ -18,7 +18,6 @@ public: typedef std::vector< std::vector > InputPathMatrix; protected: - bool m_useLegacy; InputPathMatrix m_inputPathMatrix; /*< contains translation options */ @@ -29,7 +28,6 @@ protected: , bool adhereTableLimit , size_t graphInd); - void CheckLEGACY(); void CreateTranslationOptionsForRangeLEGACY(const DecodeGraph &decodeStepList , size_t startPosition , size_t endPosition diff --git a/moses/WordLattice.cpp b/moses/WordLattice.cpp index 4e81b13e3..90f16b3d0 100644 --- a/moses/WordLattice.cpp +++ b/moses/WordLattice.cpp @@ -5,6 +5,7 @@ #include "Util.h" #include "FloydWarshall.h" #include "TranslationOptionCollectionLattice.h" +#include "TranslationOptionCollectionConfusionNet.h" #include "moses/FF/InputFeature.h" #include "util/check.hh" @@ -214,6 +215,7 @@ WordLattice::CreateTranslationOptionCollection() const return rv; } + std::ostream& operator<<(std::ostream &out, const WordLattice &obj) { out << "next_nodes="; diff --git a/moses/WordLattice.h b/moses/WordLattice.h index 816720667..4b20b725a 100644 --- a/moses/WordLattice.h +++ b/moses/WordLattice.h @@ -46,7 +46,6 @@ public: { return next_nodes[pos]; } TranslationOptionCollection *CreateTranslationOptionCollection() const; - }; }