diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2013-06-20 15:50:41 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2013-06-20 15:50:41 +0400 |
commit | dc33fa3d3dc40eeb41acaec8046aba624894e5ae (patch) | |
tree | 756df6a507bb3b7488b4e17c36939906ec2c3ad5 | |
parent | e3f9a5be9bbadb46fc6658adfc38c8c8648070b3 (diff) |
redo parsing of feature function parameters
39 files changed, 220 insertions, 156 deletions
diff --git a/misc/queryPhraseTableMin.cpp b/misc/queryPhraseTableMin.cpp index 8b2b37ef3..57747d8f2 100644 --- a/misc/queryPhraseTableMin.cpp +++ b/misc/queryPhraseTableMin.cpp @@ -65,7 +65,7 @@ int main(int argc, char **argv) sourcePhrase.CreateFromString(Input, input, line, "||dummy_string||", NULL); TargetPhraseVectorPtr decodedPhraseColl - = pdc.GetTargetPhraseCollectionRaw(sourcePhrase); + = pdc.GetTargetPhraseCollectionRaw(sourcePhrase); if(decodedPhraseColl != NULL) { if(reportCounts) diff --git a/moses/DecodeFeature.cpp b/moses/DecodeFeature.cpp index 68bfbedac..2df753273 100644 --- a/moses/DecodeFeature.cpp +++ b/moses/DecodeFeature.cpp @@ -34,16 +34,6 @@ DecodeFeature::DecodeFeature( const std::string& description : StatelessFeatureFunction(description, line) { VERBOSE(2,"DecodeFeature:" << std::endl); - size_t ind = 0; - while (ind < m_args.size()) { - vector<string> &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } } DecodeFeature::DecodeFeature( const std::string& description diff --git a/moses/FF/DistortionScoreProducer.cpp b/moses/FF/DistortionScoreProducer.cpp index 328c833c8..c44d204bf 100644 --- a/moses/FF/DistortionScoreProducer.cpp +++ b/moses/FF/DistortionScoreProducer.cpp @@ -4,6 +4,8 @@ #include "moses/WordsRange.h" #include "moses/StaticData.h" +using namespace std; + namespace Moses { struct DistortionState_traditional : public FFState { @@ -19,6 +21,20 @@ struct DistortionState_traditional : public FFState { } }; +DistortionScoreProducer::DistortionScoreProducer(const std::string &line) + : StatefulFeatureFunction("Distortion", 1, line) { + size_t ind = 0; + while (ind < m_args.size()) { + vector<string> &args = m_args[ind]; + bool consumed = SetParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); + } else { + ++ind; + } + } +} + const FFState* DistortionScoreProducer::EmptyHypothesisState(const InputType &input) const { // fake previous translated phrase start and end diff --git a/moses/FF/DistortionScoreProducer.h b/moses/FF/DistortionScoreProducer.h index 4ac4b479a..aa194afe5 100644 --- a/moses/FF/DistortionScoreProducer.h +++ b/moses/FF/DistortionScoreProducer.h @@ -18,10 +18,7 @@ class WordsRange; class DistortionScoreProducer : public StatefulFeatureFunction { public: - DistortionScoreProducer(const std::string &line) - : StatefulFeatureFunction("Distortion", 1, line) { - CHECK(m_args.size() == 0); - } + DistortionScoreProducer(const std::string &line); bool IsUseable(const FactorMask &mask) const { return true; diff --git a/moses/FF/FeatureFunction.cpp b/moses/FF/FeatureFunction.cpp index 9b80899ab..f484fd1ed 100644 --- a/moses/FF/FeatureFunction.cpp +++ b/moses/FF/FeatureFunction.cpp @@ -49,17 +49,6 @@ void FeatureFunction::Initialize(const std::string& description, const std::stri { ParseLine(description, line); - size_t ind = 0; - while (ind < m_args.size()) { - vector<string> &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - if (m_description == "") { size_t index = description_counts.count(description); @@ -95,9 +84,8 @@ void FeatureFunction::ParseLine(const std::string& description, const std::strin m_numScoreComponents = Scan<size_t>(args[1]); } else if (args[0] == "name") { m_description = args[1]; - } - else { - m_args.push_back(args); + } else { + m_args.push_back(args); } } } @@ -107,7 +95,7 @@ bool FeatureFunction::SetParameter(const std::string& key, const std::string& va if (key == "tuneable") { m_tuneable = Scan<bool>(value); } else { - return false; + UTIL_THROW(util::Exception, "Unknown argument " << key << "=" << value); } return true; diff --git a/moses/FF/PhraseLengthFeature.cpp b/moses/FF/PhraseLengthFeature.cpp index 7d163b708..d419941e5 100644 --- a/moses/FF/PhraseLengthFeature.cpp +++ b/moses/FF/PhraseLengthFeature.cpp @@ -12,7 +12,16 @@ using namespace std; PhraseLengthFeature::PhraseLengthFeature(const std::string &line) :StatelessFeatureFunction("PhraseLengthFeature", 0, line) { - CHECK(m_args.size() == 0); + size_t ind = 0; + while (ind < m_args.size()) { + vector<string> &args = m_args[ind]; + bool consumed = SetParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); + } else { + ++ind; + } + } } void PhraseLengthFeature::Evaluate(const Phrase &source diff --git a/moses/FF/UnknownWordPenaltyProducer.cpp b/moses/FF/UnknownWordPenaltyProducer.cpp index c1a1b36af..86a561ebe 100644 --- a/moses/FF/UnknownWordPenaltyProducer.cpp +++ b/moses/FF/UnknownWordPenaltyProducer.cpp @@ -1,7 +1,26 @@ #include "UnknownWordPenaltyProducer.h" +#include <vector> +#include <string> + +using namespace std; namespace Moses { +UnknownWordPenaltyProducer::UnknownWordPenaltyProducer(const std::string &line) + : StatelessFeatureFunction("UnknownWordPenalty",1, line) { + m_tuneable = false; + + size_t ind = 0; + while (ind < m_args.size()) { + vector<string> &args = m_args[ind]; + bool consumed = SetParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); + } else { + ++ind; + } + } +} } diff --git a/moses/FF/UnknownWordPenaltyProducer.h b/moses/FF/UnknownWordPenaltyProducer.h index 1dc018386..3cfaefef4 100644 --- a/moses/FF/UnknownWordPenaltyProducer.h +++ b/moses/FF/UnknownWordPenaltyProducer.h @@ -15,11 +15,7 @@ class WordsRange; class UnknownWordPenaltyProducer : public StatelessFeatureFunction { public: - UnknownWordPenaltyProducer(const std::string &line) - : StatelessFeatureFunction("UnknownWordPenalty",1, line) { - m_tuneable = false; - CHECK(m_args.size() == 0); - } + UnknownWordPenaltyProducer(const std::string &line); bool IsUseable(const FactorMask &mask) const { return true; diff --git a/moses/FF/WordPenaltyProducer.cpp b/moses/FF/WordPenaltyProducer.cpp index 1dc425742..a93a62dde 100644 --- a/moses/FF/WordPenaltyProducer.cpp +++ b/moses/FF/WordPenaltyProducer.cpp @@ -2,8 +2,24 @@ #include "moses/TargetPhrase.h" #include "moses/ScoreComponentCollection.h" +using namespace std; + namespace Moses { +WordPenaltyProducer::WordPenaltyProducer(const std::string &line) + : StatelessFeatureFunction("WordPenalty",1, line) { + size_t ind = 0; + while (ind < m_args.size()) { + vector<string> &args = m_args[ind]; + bool consumed = SetParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); + } else { + ++ind; + } + } +} + void WordPenaltyProducer::Evaluate(const Phrase &source , const TargetPhrase &targetPhrase , ScoreComponentCollection &scoreBreakdown diff --git a/moses/FF/WordPenaltyProducer.h b/moses/FF/WordPenaltyProducer.h index 28a53c295..a59aa2a2d 100644 --- a/moses/FF/WordPenaltyProducer.h +++ b/moses/FF/WordPenaltyProducer.h @@ -12,10 +12,7 @@ class ScoreComponentCollection; class WordPenaltyProducer : public StatelessFeatureFunction { public: - WordPenaltyProducer(const std::string &line) - : StatelessFeatureFunction("WordPenalty",1, line) { - CHECK(m_args.size() == 0); - } + WordPenaltyProducer(const std::string &line); bool IsUseable(const FactorMask &mask) const { return true; diff --git a/moses/GenerationDictionary.cpp b/moses/GenerationDictionary.cpp index 26937f23f..c97ae9966 100644 --- a/moses/GenerationDictionary.cpp +++ b/moses/GenerationDictionary.cpp @@ -38,14 +38,16 @@ namespace Moses GenerationDictionary::GenerationDictionary(const std::string &line) : DecodeFeature("Generation", line) { - for (size_t i = 0; i < m_args.size(); ++i) { - const vector<string> &args = m_args[i]; - - if (args[0] == "path") { - m_filePath = args[1]; - } + size_t ind = 0; + while (ind < m_args.size()) { + vector<string> &args = m_args[ind]; + bool consumed = SetParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); + } else { + ++ind; + } } - } void GenerationDictionary::Load() @@ -133,5 +135,15 @@ const OutputWordCollection *GenerationDictionary::FindWord(const Word &word) con return ret; } +bool GenerationDictionary::SetParameter(const std::string& key, const std::string& value) +{ + if (key == "path") { + m_filePath = value; + } else { + return DecodeFeature::SetParameter(key, value); + } + return true; +} + } diff --git a/moses/GenerationDictionary.h b/moses/GenerationDictionary.h index d9023f7b7..192d10ea8 100644 --- a/moses/GenerationDictionary.h +++ b/moses/GenerationDictionary.h @@ -68,6 +68,7 @@ public: * Or NULL if the input word isn't found. The search function used is the WordComparer functor */ const OutputWordCollection *FindWord(const Word &word) const; + bool SetParameter(const std::string& key, const std::string& value); }; diff --git a/moses/LVoc.h b/moses/LVoc.h index 5f5423832..485e3f481 100644 --- a/moses/LVoc.h +++ b/moses/LVoc.h @@ -38,7 +38,7 @@ public: } LabelId add(const Key& k) { std::pair<typename M::iterator,bool> p - =m.insert(std::make_pair(k,data.size())); + =m.insert(std::make_pair(k,data.size())); if(p.second) data.push_back(k); CHECK(static_cast<size_t>(p.first->second)<data.size()); return p.first->second; diff --git a/moses/StaticData.cpp b/moses/StaticData.cpp index 6d8da54c2..864223394 100644 --- a/moses/StaticData.cpp +++ b/moses/StaticData.cpp @@ -938,7 +938,7 @@ const TranslationOptionList* StaticData::FindTransOptListInCache(const DecodeGra boost::mutex::scoped_lock lock(m_transOptCacheMutex); #endif std::map<std::pair<std::pair<size_t, std::string>, Phrase>, std::pair<TranslationOptionList*,clock_t> >::iterator iter - = m_transOptCache.find(key); + = m_transOptCache.find(key); if (iter == m_transOptCache.end()) return NULL; iter->second.second = clock(); // update last used time diff --git a/moses/StaticData.h b/moses/StaticData.h index 8eba8c774..c64b22940 100644 --- a/moses/StaticData.h +++ b/moses/StaticData.h @@ -673,7 +673,7 @@ public: return false; } std::map< std::string, std::set< std::string > >::const_iterator lookupIgnoreFF - = m_weightSettingIgnoreFF.find( m_currentWeightSetting ); + = m_weightSettingIgnoreFF.find( m_currentWeightSetting ); if (lookupIgnoreFF == m_weightSettingIgnoreFF.end()) { return false; } @@ -691,7 +691,7 @@ public: return false; } std::map< std::string, std::set< size_t > >::const_iterator lookupIgnoreDP - = m_weightSettingIgnoreDP.find( m_currentWeightSetting ); + = m_weightSettingIgnoreDP.find( m_currentWeightSetting ); if (lookupIgnoreDP == m_weightSettingIgnoreDP.end()) { return false; } diff --git a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp index 195f6708e..5dde99ade 100644 --- a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp +++ b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp @@ -234,12 +234,12 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection( std::vector<float> weightT = staticData.GetWeights(&m_dictionary); targetPhraseCollection - = tpcollBerkeleyDb->ConvertToMoses(m_inputFactorsVec - ,m_outputFactorsVec - ,m_dictionary - ,weightT - ,m_filePath - , m_dbWrapper.GetVocab()); + = tpcollBerkeleyDb->ConvertToMoses(m_inputFactorsVec + ,m_outputFactorsVec + ,m_dictionary + ,weightT + ,m_filePath + , m_dbWrapper.GetVocab()); delete tpcollBerkeleyDb; m_cache[tpCollFilePos] = targetPhraseCollection; diff --git a/moses/TranslationModel/CompactPT/LexicalReorderingTableCreator.cpp b/moses/TranslationModel/CompactPT/LexicalReorderingTableCreator.cpp index 7e60dec7d..655ed01ca 100644 --- a/moses/TranslationModel/CompactPT/LexicalReorderingTableCreator.cpp +++ b/moses/TranslationModel/CompactPT/LexicalReorderingTableCreator.cpp @@ -428,7 +428,7 @@ void CompressionTaskReordering::operator()() while(scoresNum < m_encodedScores.size()) { std::string scores = m_encodedScores[scoresNum]; std::string compressedScores - = m_creator.CompressEncodedScores(scores); + = m_creator.CompressEncodedScores(scores); std::string dummy; PackedItem packedItem(scoresNum, dummy, compressedScores, 0); diff --git a/moses/TranslationModel/CompactPT/PhraseDecoder.cpp b/moses/TranslationModel/CompactPT/PhraseDecoder.cpp index a15f301bb..085a7337c 100644 --- a/moses/TranslationModel/CompactPT/PhraseDecoder.cpp +++ b/moses/TranslationModel/CompactPT/PhraseDecoder.cpp @@ -61,7 +61,7 @@ PhraseDecoder::~PhraseDecoder() inline unsigned PhraseDecoder::GetSourceSymbolId(std::string& symbol) { boost::unordered_map<std::string, unsigned>::iterator it - = m_sourceSymbolsMap.find(symbol); + = m_sourceSymbolsMap.find(symbol); if(it != m_sourceSymbolsMap.end()) return it->second; @@ -200,7 +200,7 @@ TargetPhraseVectorPtr PhraseDecoder::CreateTargetPhraseCollection(const Phrase & if(m_coding == PREnc) { std::pair<TargetPhraseVectorPtr, size_t> cachedPhraseColl - = m_decodingCache.Retrieve(sourcePhrase); + = m_decodingCache.Retrieve(sourcePhrase); // Has been cached and is complete or does not need to be completed if(cachedPhraseColl.first != NULL && (!topLevel || cachedPhraseColl.second == 0)) @@ -255,7 +255,7 @@ TargetPhraseVectorPtr PhraseDecoder::DecodeCollection( if(m_coding == REnc) { for(size_t i = 0; i < sourcePhrase.GetSize(); i++) { std::string sourceWord - = sourcePhrase.GetWord(i).GetString(*m_input, false); + = sourcePhrase.GetWord(i).GetString(*m_input, false); unsigned idx = GetSourceSymbolId(sourceWord); sourceWords.push_back(idx); } diff --git a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp index 90125ffbf..c932ec3c8 100644 --- a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp +++ b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp @@ -41,6 +41,26 @@ using namespace std; namespace Moses { +PhraseDictionaryCompact::PhraseDictionaryCompact(const std::string &line) + :PhraseDictionary("PhraseDictionaryCompact", line) + ,m_inMemory(true) + ,m_useAlignmentInfo(true) + ,m_hash(10, 16) + ,m_phraseDecoder(0) + ,m_weight(0) +{ + size_t ind = 0; + while (ind < m_args.size()) { + vector<string> &args = m_args[ind]; + bool consumed = SetParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); + } else { + ++ind; + } + } +} + void PhraseDictionaryCompact::Load() { const StaticData &staticData = StaticData::Instance(); @@ -106,7 +126,7 @@ PhraseDictionaryCompact::GetTargetPhraseCollection(const Phrase &sourcePhrase) c // Retrieve target phrase collection from phrase table TargetPhraseVectorPtr decodedPhraseColl - = m_phraseDecoder->CreateTargetPhraseCollection(sourcePhrase, true); + = m_phraseDecoder->CreateTargetPhraseCollection(sourcePhrase, true); if(decodedPhraseColl != NULL && decodedPhraseColl->size()) { TargetPhraseVectorPtr tpv(new TargetPhraseVector(*decodedPhraseColl)); diff --git a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.h b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.h index 9aed22018..710f00f47 100644 --- a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.h +++ b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.h @@ -68,14 +68,7 @@ protected: std::vector<float> m_weight; public: - PhraseDictionaryCompact(const std::string &line) - :PhraseDictionary("PhraseDictionaryCompact", line) - ,m_inMemory(true) - ,m_useAlignmentInfo(true) - ,m_hash(10, 16) - ,m_phraseDecoder(0) - ,m_weight(0) { - } + PhraseDictionaryCompact(const std::string &line); ~PhraseDictionaryCompact(); diff --git a/moses/TranslationModel/CompactPT/PhraseTableCreator.cpp b/moses/TranslationModel/CompactPT/PhraseTableCreator.cpp index 33dcf3f8b..fc3b056c6 100644 --- a/moses/TranslationModel/CompactPT/PhraseTableCreator.cpp +++ b/moses/TranslationModel/CompactPT/PhraseTableCreator.cpp @@ -426,7 +426,7 @@ void PhraseTableCreator::AddTargetSymbolId(std::string& symbol) unsigned PhraseTableCreator::GetSourceSymbolId(std::string& symbol) { boost::unordered_map<std::string, unsigned>::iterator it - = m_sourceSymbolsMap.find(symbol); + = m_sourceSymbolsMap.find(symbol); if(it != m_sourceSymbolsMap.end()) return it->second; @@ -437,7 +437,7 @@ unsigned PhraseTableCreator::GetSourceSymbolId(std::string& symbol) unsigned PhraseTableCreator::GetTargetSymbolId(std::string& symbol) { boost::unordered_map<std::string, unsigned>::iterator it - = m_targetSymbolsMap.find(symbol); + = m_targetSymbolsMap.find(symbol); if(it != m_targetSymbolsMap.end()) return it->second; @@ -451,7 +451,7 @@ unsigned PhraseTableCreator::GetOrAddTargetSymbolId(std::string& symbol) boost::mutex::scoped_lock lock(m_mutex); #endif boost::unordered_map<std::string, unsigned>::iterator it - = m_targetSymbolsMap.find(symbol); + = m_targetSymbolsMap.find(symbol); if(it != m_targetSymbolsMap.end()) return it->second; @@ -1200,7 +1200,7 @@ void CompressionTask::operator()() while(collectionNum < m_encodedCollections.size()) { std::string collection = m_encodedCollections[collectionNum]; std::string compressedCollection - = m_creator.CompressEncodedCollection(collection); + = m_creator.CompressEncodedCollection(collection); std::string dummy; PackedItem packedItem(collectionNum, dummy, compressedCollection, 0); diff --git a/moses/TranslationModel/CompactPT/PhraseTableCreator.h b/moses/TranslationModel/CompactPT/PhraseTableCreator.h index b92df1697..fd5fc1581 100644 --- a/moses/TranslationModel/CompactPT/PhraseTableCreator.h +++ b/moses/TranslationModel/CompactPT/PhraseTableCreator.h @@ -143,7 +143,7 @@ public: return data; else { typename std::vector<DataType>::iterator it - = std::lower_bound(m_bestVec.begin(), m_bestVec.end(), data); + = std::lower_bound(m_bestVec.begin(), m_bestVec.end(), data); if(it != m_bestVec.end()) return *it; else diff --git a/moses/TranslationModel/PhraseDictionary.cpp b/moses/TranslationModel/PhraseDictionary.cpp index ec1caca6c..8d44f5b7c 100644 --- a/moses/TranslationModel/PhraseDictionary.cpp +++ b/moses/TranslationModel/PhraseDictionary.cpp @@ -34,16 +34,6 @@ PhraseDictionary::PhraseDictionary(const std::string &description, const std::st :DecodeFeature(description, line) ,m_tableLimit(20) // default { - size_t ind = 0; - while (ind < m_args.size()) { - vector<string> &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } } diff --git a/moses/TranslationModel/PhraseDictionaryMemory.cpp b/moses/TranslationModel/PhraseDictionaryMemory.cpp index b43828d82..f6b186de2 100644 --- a/moses/TranslationModel/PhraseDictionaryMemory.cpp +++ b/moses/TranslationModel/PhraseDictionaryMemory.cpp @@ -39,6 +39,20 @@ using namespace std; namespace Moses { +PhraseDictionaryMemory::PhraseDictionaryMemory(const std::string &line) + : RuleTableTrie("PhraseDictionaryMemory", line) +{ + size_t ind = 0; + while (ind < m_args.size()) { + vector<string> &args = m_args[ind]; + bool consumed = SetParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); + } else { + ++ind; + } + } +} TargetPhraseCollection &PhraseDictionaryMemory::GetOrCreateTargetPhraseCollection( const Phrase &source diff --git a/moses/TranslationModel/PhraseDictionaryMemory.h b/moses/TranslationModel/PhraseDictionaryMemory.h index 02022dce8..d1976a585 100644 --- a/moses/TranslationModel/PhraseDictionaryMemory.h +++ b/moses/TranslationModel/PhraseDictionaryMemory.h @@ -43,10 +43,7 @@ protected: } public: - PhraseDictionaryMemory(const std::string &line) - : RuleTableTrie("PhraseDictionaryMemory", line) { - CHECK(m_args.size() == 0); - } + PhraseDictionaryMemory(const std::string &line); const PhraseDictionaryNodeMemory &GetRootNode() const { return m_collection; diff --git a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp index 73fd87437..ebf703ad2 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp @@ -56,17 +56,6 @@ PhraseDictionaryMultiModel::PhraseDictionaryMultiModel(const std::string &line) PhraseDictionaryMultiModel::PhraseDictionaryMultiModel(const std::string &description, const std::string &line) :PhraseDictionary(description, line) { - size_t ind = 0; - while (ind < m_args.size()) { - vector<string> &args = m_args[ind]; - bool consumed = SetParameter(args[0], args[1]); - if (consumed) { - m_args.erase(m_args.begin() + ind); - } else { - ++ind; - } - } - if (description == "PhraseDictionaryMultiModelCounts") { CHECK(m_pdStr.size() == m_multimodelweights.size() || m_pdStr.size()*4 == m_multimodelweights.size()); } diff --git a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp index 19e0af1a0..3cc5c788a 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp @@ -107,7 +107,7 @@ bool PhraseDictionaryMultiModelCounts::SetParameter(const std::string& key, cons } else if (key == "target-table") { m_targetTable = Tokenize(value, ","); } else { - return PhraseDictionaryMultiModel::SetParameter(key, value); + return PhraseDictionaryMultiModel::SetParameter(key, value); } return true; diff --git a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp index c1940675e..dbe5b0ea1 100644 --- a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp +++ b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp @@ -29,7 +29,16 @@ PhraseDictionaryTreeAdaptor:: PhraseDictionaryTreeAdaptor(const std::string &line) : PhraseDictionary("PhraseDictionaryBinary", line) { - CHECK(m_args.size() == 0); + size_t ind = 0; + while (ind < m_args.size()) { + vector<string> &args = m_args[ind]; + bool consumed = SetParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); + } else { + ++ind; + } + } } PhraseDictionaryTreeAdaptor::~PhraseDictionaryTreeAdaptor() diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp index 64b8244e8..1d36ff675 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp @@ -30,6 +30,20 @@ using namespace std; namespace Moses { +PhraseDictionaryOnDisk::PhraseDictionaryOnDisk(const std::string &line) + : MyBase("PhraseDictionaryOnDisk", line) { + size_t ind = 0; + while (ind < m_args.size()) { + vector<string> &args = m_args[ind]; + bool consumed = SetParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); + } else { + ++ind; + } + } +} + PhraseDictionaryOnDisk::~PhraseDictionaryOnDisk() { } diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.h b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.h index 7837c977b..328b67736 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.h +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.h @@ -49,10 +49,7 @@ protected: const OnDiskPt::OnDiskWrapper &GetImplementation() const; public: - PhraseDictionaryOnDisk(const std::string &line) - : MyBase("PhraseDictionaryOnDisk", line) { - CHECK(m_args.size() == 0); - } + PhraseDictionaryOnDisk(const std::string &line); ~PhraseDictionaryOnDisk(); void Load(); diff --git a/moses/TranslationOptionCollection.cpp b/moses/TranslationOptionCollection.cpp index 462b59552..551be5d71 100644 --- a/moses/TranslationOptionCollection.cpp +++ b/moses/TranslationOptionCollection.cpp @@ -40,8 +40,8 @@ using namespace std; namespace Moses { InputLatticeNode::InputLatticeNode(const Phrase &phrase, const WordsRange &range) -:m_phrase(phrase) -,m_range(range) + :m_phrase(phrase) + ,m_range(range) { } diff --git a/moses/TranslationOptionCollectionConfusionNet.cpp b/moses/TranslationOptionCollectionConfusionNet.cpp index 26ec85b15..6984e4ec4 100644 --- a/moses/TranslationOptionCollectionConfusionNet.cpp +++ b/moses/TranslationOptionCollectionConfusionNet.cpp @@ -62,10 +62,10 @@ TranslationOptionCollectionConfusionNet::TranslationOptionCollectionConfusionNet // create subphrases by appending words to previous subphrases for (size_t startPos = 0; startPos < size; ++startPos) { - size_t maxSize = size - startPos; - size_t maxSizePhrase = StaticData::Instance().GetMaxPhraseLength(); - maxSize = std::min(maxSize, maxSizePhrase); - size_t end = startPos + maxSize - 1; + size_t maxSize = size - startPos; + size_t maxSizePhrase = StaticData::Instance().GetMaxPhraseLength(); + maxSize = std::min(maxSize, maxSizePhrase); + size_t end = startPos + maxSize - 1; for (size_t endPos = startPos + 1; endPos < end; ++endPos) { std::vector<SourcePath> &newSubphrases = GetPhrases(startPos, endPos); diff --git a/moses/TranslationOptionCollectionConfusionNet.h b/moses/TranslationOptionCollectionConfusionNet.h index 2b3ef67b8..4f24e3761 100644 --- a/moses/TranslationOptionCollectionConfusionNet.h +++ b/moses/TranslationOptionCollectionConfusionNet.h @@ -32,10 +32,10 @@ protected: , const InputFeature &inputFeature); void CreateTranslationOptionsForRange(const DecodeGraph &decodeStepList - , size_t startPosition - , size_t endPosition - , bool adhereTableLimit - , size_t graphInd); + , size_t startPosition + , size_t endPosition + , bool adhereTableLimit + , size_t graphInd); }; } diff --git a/moses/TranslationOptionCollectionText.cpp b/moses/TranslationOptionCollectionText.cpp index 00fc06b7b..20cb75711 100644 --- a/moses/TranslationOptionCollectionText.cpp +++ b/moses/TranslationOptionCollectionText.cpp @@ -47,8 +47,8 @@ TranslationOptionCollectionText::TranslationOptionCollectionText(Sentence const InputLatticeNode node(subphrase, range); if (range.GetNumWordsCovered() > 1) { - InputLatticeNode prevNode = GetPhrase(startPos, endPos - 1); - node.AddNext(prevNode); + InputLatticeNode prevNode = GetPhrase(startPos, endPos - 1); + node.AddNext(prevNode); } vec.push_back(node); diff --git a/moses/TranslationOptionCollectionText.h b/moses/TranslationOptionCollectionText.h index 4ce8fefe2..507853d3e 100644 --- a/moses/TranslationOptionCollectionText.h +++ b/moses/TranslationOptionCollectionText.h @@ -48,10 +48,10 @@ protected: std::vector<std::vector<InputLatticeNode> > m_collection; void CreateTranslationOptionsForRange(const DecodeGraph &decodeStepList - , size_t startPosition - , size_t endPosition - , bool adhereTableLimit - , size_t graphInd); + , size_t startPosition + , size_t endPosition + , bool adhereTableLimit + , size_t graphInd); }; } diff --git a/moses/TypeDef.h b/moses/TypeDef.h index 88011f60a..2b98b5bc3 100644 --- a/moses/TypeDef.h +++ b/moses/TypeDef.h @@ -108,27 +108,27 @@ enum DistortionOrientationOptions { enum PhraseTableImplementation { Memory = 0 - ,Binary = 1 - ,OnDisk = 2 - //,GlueRule = 3 - //,Joshua = 4 - //,MemorySourceLabel = 5 - ,SCFG = 6 - //,BerkeleyDb = 7 - ,SuffixArray = 8 - ,Hiero = 9 - ,ALSuffixArray = 10 - ,FuzzyMatch = 11 - ,Compact = 12 - ,Interpolated = 13 + ,Binary = 1 + ,OnDisk = 2 + //,GlueRule = 3 + //,Joshua = 4 + //,MemorySourceLabel = 5 + ,SCFG = 6 + //,BerkeleyDb = 7 + ,SuffixArray = 8 + ,Hiero = 9 + ,ALSuffixArray = 10 + ,FuzzyMatch = 11 + ,Compact = 12 + ,Interpolated = 13 }; enum InputTypeEnum { SentenceInput = 0 - ,ConfusionNetworkInput = 1 - ,WordLatticeInput = 2 - ,TreeInputType = 3 - ,WordLatticeInput2 = 4 + ,ConfusionNetworkInput = 1 + ,WordLatticeInput = 2 + ,TreeInputType = 3 + ,WordLatticeInput2 = 4 }; @@ -141,7 +141,7 @@ enum XmlInputType { enum DictionaryFind { Best = 0 - ,All = 1 + ,All = 1 }; enum ParsingAlgorithm { @@ -151,22 +151,22 @@ enum ParsingAlgorithm { enum SearchAlgorithm { Normal = 0 - ,CubePruning = 1 - ,CubeGrowing = 2 - ,ChartDecoding= 3 - ,NormalBatch = 4 - ,ChartIncremental = 5 + ,CubePruning = 1 + ,CubeGrowing = 2 + ,ChartDecoding= 3 + ,NormalBatch = 4 + ,ChartIncremental = 5 }; enum SourceLabelOverlap { SourceLabelOverlapAdd = 0 - ,SourceLabelOverlapReplace = 1 - ,SourceLabelOverlapDiscard = 2 + ,SourceLabelOverlapReplace = 1 + ,SourceLabelOverlapDiscard = 2 }; enum WordAlignmentSort { NoSort = 0 - ,TargetOrder = 1 + ,TargetOrder = 1 }; enum FormatType { diff --git a/phrase-extract/relax-parse-main.cpp b/phrase-extract/relax-parse-main.cpp index d3cb4c527..a58d4d97f 100644 --- a/phrase-extract/relax-parse-main.cpp +++ b/phrase-extract/relax-parse-main.cpp @@ -137,7 +137,7 @@ void LeftBinarize( SyntaxTree &tree, ParentNodes &parents ) const SplitPoints &point = *p; if (point.size() > 3) { const vector< SyntaxNode* >& topNodes - = tree.GetNodes( point[0], point[point.size()-1]-1); + = tree.GetNodes( point[0], point[point.size()-1]-1); string topLabel = topNodes[0]->GetLabel(); for(size_t i=2; i<point.size()-1; i++) { @@ -155,7 +155,7 @@ void RightBinarize( SyntaxTree &tree, ParentNodes &parents ) if (point.size() > 3) { int endPoint = point[point.size()-1]-1; const vector< SyntaxNode* >& topNodes - = tree.GetNodes( point[0], endPoint); + = tree.GetNodes( point[0], endPoint); string topLabel = topNodes[0]->GetLabel(); for(size_t i=1; i<point.size()-2; i++) { diff --git a/scripts/other/beautify.perl b/scripts/other/beautify.perl index 90f57575c..41c93850c 100755 --- a/scripts/other/beautify.perl +++ b/scripts/other/beautify.perl @@ -5,7 +5,7 @@ use File::Basename; sub Beautify($); -Beautify("/Users/hieuhoang/unison/workspace/github/mosesdecoder"); +Beautify("/home/hieu/workspace/github/mosesdecoder"); sub Beautify($) { diff --git a/symal/cmd.h b/symal/cmd.h index a728dda78..01a00abc0 100644 --- a/symal/cmd.h +++ b/symal/cmd.h @@ -33,14 +33,14 @@ extern "C" { #endif #if defined(__STDC__) -int DeclareParams(char *, ...); + int DeclareParams(char *, ...); #else -int DeclareParams(); + int DeclareParams(); #endif -int GetParams(int *n, char ***a,char *CmdFileName), - SPrintParams(), - PrintParams(); + int GetParams(int *n, char ***a,char *CmdFileName), + SPrintParams(), + PrintParams(); #ifdef __cplusplus } |