diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-10-18 01:00:34 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-10-18 01:00:34 +0300 |
commit | 173d958f4de905572307131a2e10c67612a9b4da (patch) | |
tree | 0d8ee3926dd138ed3ae3b8b19e10b1ab44fd19e0 /moses/FF | |
parent | 2683b58b537e12b23993c99f3a4e38b4106b2b34 (diff) | |
parent | ecbe68e6f87814134859d64e826bac9c56a4a15e (diff) |
Merge branch 'master' of github.com:moses-smt/mosesdecoder
Diffstat (limited to 'moses/FF')
-rw-r--r-- | moses/FF/FeatureFunction.cpp | 6 | ||||
-rw-r--r-- | moses/FF/GlobalLexicalModelUnlimited.cpp | 11 | ||||
-rw-r--r-- | moses/FF/LexicalReordering/SparseReordering.cpp | 5 | ||||
-rw-r--r-- | moses/FF/OSM-Feature/osmHyp.cpp | 6 | ||||
-rw-r--r-- | moses/FF/PhraseBoundaryFeature.cpp | 3 | ||||
-rw-r--r-- | moses/FF/PhraseLengthFeature.cpp | 7 | ||||
-rw-r--r-- | moses/FF/PhrasePairFeature.cpp | 17 | ||||
-rw-r--r-- | moses/FF/RulePairUnlexicalizedSource.cpp | 4 | ||||
-rw-r--r-- | moses/FF/SparseHieroReorderingFeature.cpp | 3 | ||||
-rw-r--r-- | moses/FF/TargetNgramFeature.cpp | 16 | ||||
-rw-r--r-- | moses/FF/TargetNgramFeature.h | 3 | ||||
-rw-r--r-- | moses/FF/WordTranslationFeature.cpp | 16 |
12 files changed, 50 insertions, 47 deletions
diff --git a/moses/FF/FeatureFunction.cpp b/moses/FF/FeatureFunction.cpp index 08ad26db8..9b1ea473b 100644 --- a/moses/FF/FeatureFunction.cpp +++ b/moses/FF/FeatureFunction.cpp @@ -112,12 +112,10 @@ void FeatureFunction::ParseLine(const std::string &line) if (m_description == "") { size_t index = description_counts.count(nameStub); - ostringstream dstream; - dstream << nameStub; - dstream << index; + string descr = SPrint(nameStub) + SPrint(index); description_counts.insert(nameStub); - m_description = dstream.str(); + m_description = descr; } } diff --git a/moses/FF/GlobalLexicalModelUnlimited.cpp b/moses/FF/GlobalLexicalModelUnlimited.cpp index 675af2b6b..15eec019c 100644 --- a/moses/FF/GlobalLexicalModelUnlimited.cpp +++ b/moses/FF/GlobalLexicalModelUnlimited.cpp @@ -5,6 +5,7 @@ #include "moses/Hypothesis.h" #include "moses/TranslationTask.h" #include "util/string_piece_hash.hh" +#include "util/string_stream.hh" using namespace std; @@ -131,7 +132,7 @@ void GlobalLexicalModelUnlimited::EvaluateWhenApplied(const Hypothesis& cur_hypo } if (m_biasFeature) { - stringstream feature; + util::StringStream feature; feature << "glm_"; feature << targetString; feature << "~"; @@ -165,7 +166,7 @@ void GlobalLexicalModelUnlimited::EvaluateWhenApplied(const Hypothesis& cur_hypo if (m_sourceContext) { if (sourceIndex == 0) { // add <s> trigger feature for source - stringstream feature; + util::StringStream feature; feature << "glm_"; feature << targetString; feature << "~"; @@ -183,7 +184,7 @@ void GlobalLexicalModelUnlimited::EvaluateWhenApplied(const Hypothesis& cur_hypo contextExists = FindStringPiece(m_vocabSource, contextString ) != m_vocabSource.end(); if (m_unrestricted || contextExists) { - stringstream feature; + util::StringStream feature; feature << "glm_"; feature << targetString; feature << "~"; @@ -304,7 +305,7 @@ void GlobalLexicalModelUnlimited::EvaluateWhenApplied(const Hypothesis& cur_hypo } } } else { - stringstream feature; + util::StringStream feature; feature << "glm_"; feature << targetString; feature << "~"; @@ -323,7 +324,7 @@ void GlobalLexicalModelUnlimited::AddFeature(ScoreComponentCollection* accumulat StringPiece sourceTrigger, StringPiece sourceWord, StringPiece targetTrigger, StringPiece targetWord) const { - stringstream feature; + util::StringStream feature; feature << "glm_"; feature << targetTrigger; feature << ","; diff --git a/moses/FF/LexicalReordering/SparseReordering.cpp b/moses/FF/LexicalReordering/SparseReordering.cpp index 6c81ca414..f8416a284 100644 --- a/moses/FF/LexicalReordering/SparseReordering.cpp +++ b/moses/FF/LexicalReordering/SparseReordering.cpp @@ -8,6 +8,7 @@ #include "util/file_piece.hh" #include "util/string_piece.hh" +#include "util/string_stream.hh" #include "util/tokenize_piece.hh" #include "LexicalReordering.h" @@ -26,7 +27,7 @@ const std::string& SparseReorderingFeatureKey::Name (const string& wordListId) { static string kSep = "-"; static string name; - ostringstream buf; + util::StringStream buf; // type side position id word reotype if (type == Phrase) { buf << "phr"; @@ -88,7 +89,7 @@ SparseReordering::SparseReordering(const map<string,string>& config, const Lexic ReadWeightMap(i->second); m_useWeightMap = true; for (int reoType=0; reoType<=LRModel::MAX; ++reoType) { - ostringstream buf; + util::StringStream buf; buf << reoType; m_featureMap2.push_back(m_producer->GetFeatureName(buf.str())); } diff --git a/moses/FF/OSM-Feature/osmHyp.cpp b/moses/FF/OSM-Feature/osmHyp.cpp index 5ca64ab75..246d75e55 100644 --- a/moses/FF/OSM-Feature/osmHyp.cpp +++ b/moses/FF/OSM-Feature/osmHyp.cpp @@ -165,11 +165,7 @@ int osmHypothesis :: firstOpenGap(vector <int> & coverageVector) string osmHypothesis :: intToString(int num) { - - std::ostringstream stm; - stm<<num; - - return stm.str(); + return SPrint(num); } diff --git a/moses/FF/PhraseBoundaryFeature.cpp b/moses/FF/PhraseBoundaryFeature.cpp index dc5f00ac0..75e4bf158 100644 --- a/moses/FF/PhraseBoundaryFeature.cpp +++ b/moses/FF/PhraseBoundaryFeature.cpp @@ -3,6 +3,7 @@ #include "moses/Hypothesis.h" #include "moses/TranslationOption.h" #include "moses/InputPath.h" +#include "util/string_stream.hh" using namespace std; @@ -53,7 +54,7 @@ void PhraseBoundaryFeature::AddFeatures( ScoreComponentCollection* scores) const { for (size_t i = 0; i < factors.size(); ++i) { - ostringstream name; + util::StringStream name; name << side << ":"; name << factors[i]; name << ":"; diff --git a/moses/FF/PhraseLengthFeature.cpp b/moses/FF/PhraseLengthFeature.cpp index 0eb0740b8..9dbb0235e 100644 --- a/moses/FF/PhraseLengthFeature.cpp +++ b/moses/FF/PhraseLengthFeature.cpp @@ -3,6 +3,7 @@ #include "moses/Hypothesis.h" #include "moses/ScoreComponentCollection.h" #include "moses/TranslationOption.h" +#include "util/string_stream.hh" namespace Moses { @@ -25,13 +26,13 @@ void PhraseLengthFeature::EvaluateInIsolation(const Phrase &source size_t sourceLength = source.GetSize(); // create feature names - stringstream nameSource; + util::StringStream nameSource; nameSource << "s" << sourceLength; - stringstream nameTarget; + util::StringStream nameTarget; nameTarget << "t" << targetLength; - stringstream nameBoth; + util::StringStream nameBoth; nameBoth << sourceLength << "," << targetLength; // increase feature counts diff --git a/moses/FF/PhrasePairFeature.cpp b/moses/FF/PhrasePairFeature.cpp index 1e343877c..d531d9a54 100644 --- a/moses/FF/PhrasePairFeature.cpp +++ b/moses/FF/PhrasePairFeature.cpp @@ -7,6 +7,7 @@ #include "moses/TranslationOption.h" #include "moses/InputPath.h" #include "util/string_piece_hash.hh" +#include "util/string_stream.hh" #include "util/exception.hh" using namespace std; @@ -126,7 +127,8 @@ void PhrasePairFeature::EvaluateWithSourceContext(const InputType &input const bool use_topicid_prob = isnt.GetUseTopicIdAndProb(); // compute pair - ostringstream pair; + util::StringStream pair; + pair << ReplaceTilde( source.GetWord(0).GetFactor(m_sourceFactorId)->GetString() ); for (size_t i = 1; i < source.GetSize(); ++i) { const Factor* sourceFactor = source.GetWord(i).GetFactor(m_sourceFactorId); @@ -145,7 +147,8 @@ void PhrasePairFeature::EvaluateWithSourceContext(const InputType &input if(use_topicid) { // use topicid as trigger const long topicid = isnt.GetTopicId(); - stringstream feature; + util::StringStream feature; + feature << m_description << "_"; if (topicid == -1) feature << "unk"; @@ -159,13 +162,13 @@ void PhrasePairFeature::EvaluateWithSourceContext(const InputType &input // use topic probabilities const vector<string> &topicid_prob = *(isnt.GetTopicIdAndProb()); if (atol(topicid_prob[0].c_str()) == -1) { - stringstream feature; + util::StringStream feature; feature << m_description << "_unk_"; feature << pair.str(); scoreBreakdown.SparsePlusEquals(feature.str(), 1); } else { for (size_t i=0; i+1 < topicid_prob.size(); i+=2) { - stringstream feature; + util::StringStream feature; feature << m_description << "_"; feature << topicid_prob[i]; feature << "_"; @@ -179,7 +182,7 @@ void PhrasePairFeature::EvaluateWithSourceContext(const InputType &input const long docid = isnt.GetDocumentId(); for (set<string>::const_iterator p = m_vocabDomain[docid].begin(); p != m_vocabDomain[docid].end(); ++p) { string sourceTrigger = *p; - ostringstream namestr; + util::StringStream namestr; namestr << m_description << "_"; namestr << sourceTrigger; namestr << "_"; @@ -207,7 +210,7 @@ void PhrasePairFeature::EvaluateWithSourceContext(const InputType &input sourceTriggerExists = FindStringPiece(m_vocabSource, sourceTrigger ) != m_vocabSource.end(); if (m_unrestricted || sourceTriggerExists) { - ostringstream namestr; + util::StringStream namestr; namestr << m_description << "_"; namestr << sourceTrigger; namestr << "~"; @@ -237,7 +240,7 @@ void PhrasePairFeature::EvaluateInIsolation(const Phrase &source , ScoreComponentCollection &estimatedFutureScore) const { if (m_simple) { - ostringstream namestr; + util::StringStream namestr; namestr << m_description << "_"; namestr << ReplaceTilde( source.GetWord(0).GetFactor(m_sourceFactorId)->GetString() ); for (size_t i = 1; i < source.GetSize(); ++i) { diff --git a/moses/FF/RulePairUnlexicalizedSource.cpp b/moses/FF/RulePairUnlexicalizedSource.cpp index d65810af8..fe1a4f648 100644 --- a/moses/FF/RulePairUnlexicalizedSource.cpp +++ b/moses/FF/RulePairUnlexicalizedSource.cpp @@ -4,7 +4,7 @@ #include "moses/ScoreComponentCollection.h" #include "moses/FactorCollection.h" #include <sstream> - +#include "util/string_stream.hh" using namespace std; @@ -58,7 +58,7 @@ void RulePairUnlexicalizedSource::EvaluateInIsolation(const Phrase &source } } - ostringstream namestr; + util::StringStream namestr; for (size_t posT=0; posT<targetPhrase.GetSize(); ++posT) { const Word &wordT = targetPhrase.GetWord(posT); diff --git a/moses/FF/SparseHieroReorderingFeature.cpp b/moses/FF/SparseHieroReorderingFeature.cpp index ee9d4b719..a6d3cea8e 100644 --- a/moses/FF/SparseHieroReorderingFeature.cpp +++ b/moses/FF/SparseHieroReorderingFeature.cpp @@ -6,6 +6,7 @@ #include "moses/Sentence.h" #include "util/exception.hh" +#include "util/string_stream.hh" #include "SparseHieroReorderingFeature.h" @@ -202,7 +203,7 @@ void SparseHieroReorderingFeature::EvaluateWhenApplied( targetLeftRulePos < targetRightRulePos))) { isMonotone = false; } - stringstream buf; + util::StringStream buf; buf << "h_"; //sparse reordering, Huck if (m_type == SourceLeft || m_type == SourceCombined) { buf << GetFactor(sourceLeftBoundaryWord,m_sourceVocab,m_sourceFactor)->GetString(); diff --git a/moses/FF/TargetNgramFeature.cpp b/moses/FF/TargetNgramFeature.cpp index ee2b46554..d75cec0bb 100644 --- a/moses/FF/TargetNgramFeature.cpp +++ b/moses/FF/TargetNgramFeature.cpp @@ -115,7 +115,7 @@ FFState* TargetNgramFeature::EvaluateWhenApplied(const Hypothesis& cur_hypo, // extract all ngrams from current hypothesis vector<Word> prev_words(tnState->GetWords()); - stringstream curr_ngram; + util::StringStream curr_ngram; bool skip = false; // include lower order ngrams? @@ -173,7 +173,7 @@ FFState* TargetNgramFeature::EvaluateWhenApplied(const Hypothesis& cur_hypo, if (cur_hypo.GetWordsBitmap().IsComplete()) { for (size_t n = m_n; n >= smallest_n; --n) { - stringstream last_ngram; + util::StringStream last_ngram; skip = false; for (size_t i = cur_hypo.GetSize() - n + 1; i < cur_hypo.GetSize() && !skip; ++i) appendNgram(cur_hypo.GetWord(i), skip, last_ngram); @@ -203,7 +203,7 @@ FFState* TargetNgramFeature::EvaluateWhenApplied(const Hypothesis& cur_hypo, return new TargetNgramState(new_prev_words); } -void TargetNgramFeature::appendNgram(const Word& word, bool& skip, stringstream &ngram) const +void TargetNgramFeature::appendNgram(const Word& word, bool& skip, util::StringStream &ngram) const { // const string& w = word.GetFactor(m_factorType)->GetString(); const StringPiece w = word.GetString(m_factorType); @@ -256,7 +256,7 @@ FFState* TargetNgramFeature::EvaluateWhenApplied(const ChartHypothesis& cur_hypo suffixTerminals++; // everything else else { - stringstream ngram; + util::StringStream ngram; ngram << m_baseName; if (m_factorType == 0) ngram << factorZero; @@ -367,7 +367,7 @@ FFState* TargetNgramFeature::EvaluateWhenApplied(const ChartHypothesis& cur_hypo suffixTerminals = 0; // remove duplicates - stringstream curr_ngram; + util::StringStream curr_ngram; curr_ngram << m_baseName; curr_ngram << (*contextFactor[m_n-2]).GetString(m_factorType); curr_ngram << ":"; @@ -393,7 +393,7 @@ FFState* TargetNgramFeature::EvaluateWhenApplied(const ChartHypothesis& cur_hypo // remove duplicates size_t size = contextFactor.size(); if (makePrefix && makeSuffix && (size <= m_n)) { - stringstream curr_ngram; + util::StringStream curr_ngram; curr_ngram << m_baseName; for (size_t i = 0; i < size; ++i) { curr_ngram << (*contextFactor[i]).GetString(m_factorType); @@ -411,7 +411,7 @@ FFState* TargetNgramFeature::EvaluateWhenApplied(const ChartHypothesis& cur_hypo void TargetNgramFeature::MakePrefixNgrams(std::vector<const Word*> &contextFactor, ScoreComponentCollection* accumulator, size_t numberOfStartPos, size_t offset) const { - stringstream ngram; + util::StringStream ngram; size_t size = contextFactor.size(); for (size_t k = 0; k < numberOfStartPos; ++k) { size_t max_end = (size < m_n+k+offset)? size: m_n+k+offset; @@ -436,7 +436,7 @@ void TargetNgramFeature::MakePrefixNgrams(std::vector<const Word*> &contextFacto void TargetNgramFeature::MakeSuffixNgrams(std::vector<const Word*> &contextFactor, ScoreComponentCollection* accumulator, size_t numberOfEndPos, size_t offset) const { - stringstream ngram; + util::StringStream ngram; for (size_t k = 0; k < numberOfEndPos; ++k) { size_t end_pos = contextFactor.size()-1-k-offset; for (int start_pos=end_pos-1; (start_pos >= 0) && (end_pos-start_pos < m_n); --start_pos) { diff --git a/moses/FF/TargetNgramFeature.h b/moses/FF/TargetNgramFeature.h index 7c694a65e..571f6d921 100644 --- a/moses/FF/TargetNgramFeature.h +++ b/moses/FF/TargetNgramFeature.h @@ -12,6 +12,7 @@ #include "moses/LM/SingleFactor.h" #include "moses/ChartHypothesis.h" #include "moses/ChartManager.h" +#include "util/string_stream.hh" namespace Moses { @@ -244,7 +245,7 @@ private: std::string m_baseName; - void appendNgram(const Word& word, bool& skip, std::stringstream& ngram) const; + void appendNgram(const Word& word, bool& skip, util::StringStream& ngram) const; void MakePrefixNgrams(std::vector<const Word*> &contextFactor, ScoreComponentCollection* accumulator, size_t numberOfStartPos = 1, size_t offset = 0) const; void MakeSuffixNgrams(std::vector<const Word*> &contextFactor, ScoreComponentCollection* accumulator, diff --git a/moses/FF/WordTranslationFeature.cpp b/moses/FF/WordTranslationFeature.cpp index 1059e34de..88d0ef3a4 100644 --- a/moses/FF/WordTranslationFeature.cpp +++ b/moses/FF/WordTranslationFeature.cpp @@ -179,7 +179,7 @@ void WordTranslationFeature::EvaluateWithSourceContext(const InputType &input if (m_simple) { // construct feature name - stringstream featureName; + util::StringStream featureName; featureName << m_description << "_"; featureName << sourceWord; featureName << "~"; @@ -193,7 +193,7 @@ void WordTranslationFeature::EvaluateWithSourceContext(const InputType &input if(use_topicid) { // use topicid as trigger const long topicid = sentence.GetTopicId(); - stringstream feature; + util::StringStream feature; feature << m_description << "_"; if (topicid == -1) feature << "unk"; @@ -209,7 +209,7 @@ void WordTranslationFeature::EvaluateWithSourceContext(const InputType &input // use topic probabilities const vector<string> &topicid_prob = *(input.GetTopicIdAndProb()); if (atol(topicid_prob[0].c_str()) == -1) { - stringstream feature; + util::StringStream feature; feature << m_description << "_unk_"; feature << sourceWord; feature << "~"; @@ -217,7 +217,7 @@ void WordTranslationFeature::EvaluateWithSourceContext(const InputType &input scoreBreakdown.SparsePlusEquals(feature.str(), 1); } else { for (size_t i=0; i+1 < topicid_prob.size(); i+=2) { - stringstream feature; + util::StringStream feature; feature << m_description << "_"; feature << topicid_prob[i]; feature << "_"; @@ -233,7 +233,7 @@ void WordTranslationFeature::EvaluateWithSourceContext(const InputType &input const long docid = input.GetDocumentId(); for (boost::unordered_set<std::string>::const_iterator p = m_vocabDomain[docid].begin(); p != m_vocabDomain[docid].end(); ++p) { string sourceTrigger = *p; - stringstream feature; + util::StringStream feature; feature << m_description << "_"; feature << sourceTrigger; feature << "_"; @@ -248,7 +248,7 @@ void WordTranslationFeature::EvaluateWithSourceContext(const InputType &input size_t globalSourceIndex = inputPath.GetWordsRange().GetStartPos() + sourceIndex; if (!m_domainTrigger && globalSourceIndex == 0) { // add <s> trigger feature for source - stringstream feature; + util::StringStream feature; feature << m_description << "_"; feature << "<s>,"; feature << sourceWord; @@ -278,7 +278,7 @@ void WordTranslationFeature::EvaluateWithSourceContext(const InputType &input if (m_domainTrigger) { if (sourceTriggerExists) { - stringstream feature; + util::StringStream feature; feature << m_description << "_"; feature << sourceTrigger; feature << "_"; @@ -288,7 +288,7 @@ void WordTranslationFeature::EvaluateWithSourceContext(const InputType &input scoreBreakdown.SparsePlusEquals(feature.str(), 1); } } else if (m_unrestricted || sourceTriggerExists) { - stringstream feature; + util::StringStream feature; feature << m_description << "_"; if (contextIndex < globalSourceIndex) { feature << sourceTrigger; |