From cfb1ab34c7d3178e4264d5bba876ddef6125e18f Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Fri, 2 Oct 2015 20:12:39 +0100 Subject: [PATCH] use util::StringStream --- OnDiskPt/OnDiskWrapper.cpp | 7 +++++-- moses-cmd/Main.cpp | 8 ++++++++ moses/FF/LexicalReordering/SparseReordering.cpp | 11 +++++++---- moses/FF/OSM-Feature/osmHyp.cpp | 6 +----- moses/FeatureVector.cpp | 6 ++++-- moses/GenerationDictionary.cpp | 8 +++++--- moses/Hypothesis.h | 2 +- moses/LM/Ken.cpp | 6 ++++-- moses/LM/Remote.cpp | 7 ++++--- moses/Parameter.cpp | 16 ++++++++++------ moses/Phrase.cpp | 6 ++++-- moses/ScoreComponentCollection.cpp | 10 ++++------ moses/StaticData.cpp | 10 ++++++---- moses/Syntax/F2S/GlueRuleSynthesizer.cpp | 6 ++++-- moses/Syntax/T2S/GlueRuleSynthesizer.cpp | 5 +++-- moses/TranslationAnalysis.cpp | 12 ++++++++---- .../CompactPT/BlockHashIndex.cpp | 12 +++++++----- .../TranslationModel/CompactPT/BlockHashIndex.h | 12 +++++++----- .../PhraseDictionaryMultiModel.cpp | 11 +++++++---- .../PhraseDictionaryMultiModelCounts.cpp | 6 ++++-- .../PhraseDictionaryTreeAdaptor.cpp | 4 +++- .../RuleTable/LoaderStandard.cpp | 10 ++++++---- .../fuzzy-match/SentenceAlignment.cpp | 6 ++++-- .../fuzzy-match/SentenceAlignment.h | 6 ++++-- moses/Word.cpp | 6 ++++-- 25 files changed, 124 insertions(+), 75 deletions(-) diff --git a/OnDiskPt/OnDiskWrapper.cpp b/OnDiskPt/OnDiskWrapper.cpp index 3bfb7d2b1..88fb14201 100644 --- a/OnDiskPt/OnDiskWrapper.cpp +++ b/OnDiskPt/OnDiskWrapper.cpp @@ -25,6 +25,7 @@ #include "OnDiskWrapper.h" #include "moses/Factor.h" #include "util/exception.hh" +#include "util/string_stream.hh" using namespace std; @@ -223,7 +224,9 @@ Word *OnDiskWrapper::ConvertFromMoses(const std::vector &fact { bool isNonTerminal = origWord.IsNonTerminal(); Word *newWord = new Word(isNonTerminal); - stringstream strme; + + string str; + util::StringStream strme(str); size_t factorType = factorsVec[0]; const Moses::Factor *factor = origWord.GetFactor(factorType); @@ -243,7 +246,7 @@ Word *OnDiskWrapper::ConvertFromMoses(const std::vector &fact } // for (size_t factorType bool found; - uint64_t vocabId = m_vocab.GetVocabId(strme.str(), found); + uint64_t vocabId = m_vocab.GetVocabId(str, found); if (!found) { // factor not in phrase table -> phrse definately not in. exit delete newWord; diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index 7de3206fd..07e833f73 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -23,10 +23,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Moses main wrapper for executable for single-threaded and multi-threaded, simply calling decoder_main. **/ #include "moses/ExportInterface.h" +#include "util/string_stream.hh" /** main function of the command line version of the decoder **/ int main(int argc, char** argv) { + std::string output; + util::StringStream strme2(output); + strme2 << StringPiece("JJJJ"); + strme2 << std::string("kkkk"); + + std::cout << output; + return decoder_main(argc, argv); } diff --git a/moses/FF/LexicalReordering/SparseReordering.cpp b/moses/FF/LexicalReordering/SparseReordering.cpp index 6c81ca414..e027fc4fe 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,8 @@ const std::string& SparseReorderingFeatureKey::Name (const string& wordListId) { static string kSep = "-"; static string name; - ostringstream buf; + std::string str; + util::StringStream buf(str); // type side position id word reotype if (type == Phrase) { buf << "phr"; @@ -54,7 +56,7 @@ const std::string& SparseReorderingFeatureKey::Name (const string& wordListId) buf << word->GetString(); buf << kSep; buf << reoType; - name = buf.str(); + name = str; return name; } @@ -88,9 +90,10 @@ SparseReordering::SparseReordering(const map& config, const Lexic ReadWeightMap(i->second); m_useWeightMap = true; for (int reoType=0; reoType<=LRModel::MAX; ++reoType) { - ostringstream buf; + std::string str; + util::StringStream buf(str); buf << reoType; - m_featureMap2.push_back(m_producer->GetFeatureName(buf.str())); + m_featureMap2.push_back(m_producer->GetFeatureName(str)); } } else if (fields[0] == "phrase") { diff --git a/moses/FF/OSM-Feature/osmHyp.cpp b/moses/FF/OSM-Feature/osmHyp.cpp index c012fdf4c..f7afbc782 100644 --- a/moses/FF/OSM-Feature/osmHyp.cpp +++ b/moses/FF/OSM-Feature/osmHyp.cpp @@ -182,11 +182,7 @@ int osmHypothesis :: firstOpenGap(vector & coverageVector) string osmHypothesis :: intToString(int num) { - - std::ostringstream stm; - stm< scores(numFeatureValuesInConfig, 0.0f); for (size_t i = 0; i < numFeatureValuesInConfig; i++) diff --git a/moses/Hypothesis.h b/moses/Hypothesis.h index cd0974554..79787e287 100644 --- a/moses/Hypothesis.h +++ b/moses/Hypothesis.h @@ -209,7 +209,7 @@ public: if (m_prevHypo != NULL) { m_prevHypo->ToStream(out); } - out << (Phrase) GetCurrTargetPhrase(); + out << (const Phrase&) GetCurrTargetPhrase(); } std::string GetOutputString() const { diff --git a/moses/LM/Ken.cpp b/moses/LM/Ken.cpp index 3a93190f7..dba2df30a 100644 --- a/moses/LM/Ken.cpp +++ b/moses/LM/Ken.cpp @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "lm/model.hh" #include "util/exception.hh" #include "util/tokenize_piece.hh" +#include "util/string_stream.hh" #include "Ken.h" #include "Base.h" @@ -487,7 +488,8 @@ LanguageModel *ConstructKenLM(const std::string &lineOrig) util::TokenIter argument(lineOrig, ' '); ++argument; // KENLM - stringstream line; + string str; + util::StringStream line(str); line << "KENLM"; for (; argument; ++argument) { @@ -510,7 +512,7 @@ LanguageModel *ConstructKenLM(const std::string &lineOrig) } } - return ConstructKenLM(line.str(), filePath, factorType, lazy); + return ConstructKenLM(str, filePath, factorType, lazy); } LanguageModel *ConstructKenLM(const std::string &line, const std::string &file, FactorType factorType, bool lazy) diff --git a/moses/LM/Remote.cpp b/moses/LM/Remote.cpp index 33946442a..93c719c91 100644 --- a/moses/LM/Remote.cpp +++ b/moses/LM/Remote.cpp @@ -5,6 +5,7 @@ #include #include "Remote.h" #include "moses/Factor.h" +#include "util/string_stream.hh" #if !defined(_WIN32) && !defined(_WIN64) #include @@ -96,7 +97,8 @@ LMResult LanguageModelRemote::GetValue(const std::vector &contextFa cur->boState = *reinterpret_cast(&m_curId); ++m_curId; - std::ostringstream os; + std::string out; + util::StringStream os(out); os << "prob "; if (event_word == NULL) { os << ""; @@ -111,8 +113,7 @@ LMResult LanguageModelRemote::GetValue(const std::vector &contextFa os << ' ' << f->GetString(); } } - os << std::endl; - std::string out = os.str(); + os << "\n"; write(sock, out.c_str(), out.size()); char res[6]; int r = read(sock, res, 6); diff --git a/moses/Parameter.cpp b/moses/Parameter.cpp index 564b2e506..eb79f1452 100644 --- a/moses/Parameter.cpp +++ b/moses/Parameter.cpp @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "Util.h" #include "InputFileStream.h" #include "StaticData.h" +#include "util/string_stream.hh" #include "util/exception.hh" #include "util/random.hh" #include @@ -701,7 +702,8 @@ ConvertWeightArgsPhraseModel(const string &oldWeightName) size_t currOldInd = 0; for(size_t currDict = 0 ; currDict < translationVector.size(); currDict++) { - stringstream ptLine; + string ptLineStr; + util::StringStream ptLine(ptLineStr); vector token = Tokenize(translationVector[currDict]); @@ -797,7 +799,7 @@ ConvertWeightArgsPhraseModel(const string &oldWeightName) ptLine << "alignment-path=" << token[6] << " "; } - AddFeature(ptLine.str()); + AddFeature(ptLineStr); } // for(size_t currDict = 0 ; currDict < translationVector.size(); currDict++) { } // if (GetParam("ttable-file").size() > 0) { @@ -860,7 +862,8 @@ ConvertWeightArgsDistortion() } SetWeight("LexicalReordering", indTable, weights); - stringstream strme; + string str; + util::StringStream strme(str); strme << "LexicalReordering " << "type=" << toks[1] << " "; @@ -874,7 +877,7 @@ ConvertWeightArgsDistortion() strme << "num-features=" << toks[2] << " "; strme << "path=" << toks[3]; - AddFeature(strme.str()); + AddFeature(str); } } @@ -1007,13 +1010,14 @@ ConvertWeightArgsGeneration(const std::string &oldWeightName, const std::string } SetWeight(newWeightName, indTable, weights); - stringstream strme; + string str; + util::StringStream strme(str); strme << "Generation " << "input-factor=" << modelToks[0] << " " << "output-factor=" << modelToks[1] << " " << "num-features=" << modelToks[2] << " " << "path=" << modelToks[3]; - AddFeature(strme.str()); + AddFeature(str); } } diff --git a/moses/Phrase.cpp b/moses/Phrase.cpp index 7a9e847ba..f7400515a 100644 --- a/moses/Phrase.cpp +++ b/moses/Phrase.cpp @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "StaticData.h" // GetMaxNumFactors #include "util/string_piece.hh" +#include "util/string_stream.hh" #include "util/tokenize_piece.hh" using namespace std; @@ -117,7 +118,8 @@ std::string Phrase::GetStringRep(const vector factorsToPrint) const { bool markUnknown = StaticData::Instance().GetMarkUnknown(); - stringstream strme; + string str; + util::StringStream strme(str); for (size_t pos = 0 ; pos < GetSize() ; pos++) { if (markUnknown && GetWord(pos).IsOOV()) { strme << StaticData::Instance().GetUnknownWordPrefix(); @@ -128,7 +130,7 @@ std::string Phrase::GetStringRep(const vector factorsToPrint) const } } - return strme.str(); + return str; } Word &Phrase::AddWord() diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp index 4d79d5565..c3e55b5c7 100644 --- a/moses/ScoreComponentCollection.cpp +++ b/moses/ScoreComponentCollection.cpp @@ -88,9 +88,8 @@ void ScoreComponentCollection::MultiplyEquals(const FeatureFunction* sp, float s { std::string prefix = sp->GetScoreProducerDescription() + FName::SEP; for(FVector::FNVmap::const_iterator i = m_scores.cbegin(); i != m_scores.cend(); i++) { - std::stringstream name; - name << i->first; - if (starts_with(name.str(), prefix)) + const std::string &name = i->first.name(); + if (starts_with(name, prefix)) m_scores[i->first] = i->second * scalar; } } @@ -101,9 +100,8 @@ size_t ScoreComponentCollection::GetNumberWeights(const FeatureFunction* sp) std::string prefix = sp->GetScoreProducerDescription() + FName::SEP; size_t weights = 0; for(FVector::FNVmap::const_iterator i = m_scores.cbegin(); i != m_scores.cend(); i++) { - std::stringstream name; - name << i->first; - if (starts_with(name.str(), prefix)) + const std::string &name = i->first.name(); + if (starts_with(name, prefix)) weights++; } return weights; diff --git a/moses/StaticData.cpp b/moses/StaticData.cpp index 53b60e850..d05917740 100644 --- a/moses/StaticData.cpp +++ b/moses/StaticData.cpp @@ -640,19 +640,21 @@ void StaticData::LoadDecodeGraphsOld(const vector &mappingVector, const switch (decodeType) { case Translate: if(index>=pts.size()) { - stringstream strme; + string str; + util::StringStream strme(str); strme << "No phrase dictionary with index " << index << " available!"; - UTIL_THROW(util::Exception, strme.str()); + UTIL_THROW(util::Exception, str); } decodeStep = new DecodeStepTranslation(pts[index], prev, *featuresRemaining); break; case Generate: if(index>=gens.size()) { - stringstream strme; + string str; + util::StringStream strme(str); strme << "No generation dictionary with index " << index << " available!"; - UTIL_THROW(util::Exception, strme.str()); + UTIL_THROW(util::Exception, str); } decodeStep = new DecodeStepGeneration(gens[index], prev, *featuresRemaining); break; diff --git a/moses/Syntax/F2S/GlueRuleSynthesizer.cpp b/moses/Syntax/F2S/GlueRuleSynthesizer.cpp index 09423f5d3..a181d0b9e 100644 --- a/moses/Syntax/F2S/GlueRuleSynthesizer.cpp +++ b/moses/Syntax/F2S/GlueRuleSynthesizer.cpp @@ -4,6 +4,7 @@ #include "moses/FF/UnknownWordPenaltyProducer.h" #include "moses/StaticData.h" +#include "util/string_stream.hh" namespace Moses { @@ -55,7 +56,8 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( TargetPhrase *targetPhrase = new TargetPhrase(); - std::ostringstream alignmentSS; + std::string alignmentSSStr; + util::StringStream alignmentSS(alignmentSSStr); for (std::size_t i = 0; i < e.tail.size(); ++i) { const Word &symbol = e.tail[i]->pvertex.symbol; if (symbol.IsNonTerminal()) { @@ -75,7 +77,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( targetPhrase->EvaluateInIsolation(m_dummySourcePhrase); Word *targetLhs = new Word(staticData.GetOutputDefaultNonTerminal()); targetPhrase->SetTargetLHS(targetLhs); - targetPhrase->SetAlignmentInfo(alignmentSS.str()); + targetPhrase->SetAlignmentInfo(alignmentSSStr); return targetPhrase; } diff --git a/moses/Syntax/T2S/GlueRuleSynthesizer.cpp b/moses/Syntax/T2S/GlueRuleSynthesizer.cpp index 9c6dd91ab..4fed9e9ab 100644 --- a/moses/Syntax/T2S/GlueRuleSynthesizer.cpp +++ b/moses/Syntax/T2S/GlueRuleSynthesizer.cpp @@ -47,7 +47,8 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( TargetPhrase *targetPhrase = new TargetPhrase(); - std::ostringstream alignmentSS; + std::string alignmentSSStr; + util::StringStream alignmentSS(alignmentSSStr); for (std::size_t i = 0; i < node.children.size(); ++i) { const Word &symbol = node.children[i]->pvertex.symbol; if (symbol.IsNonTerminal()) { @@ -67,7 +68,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( targetPhrase->EvaluateInIsolation(sourceRhs); Word *targetLhs = new Word(staticData.GetOutputDefaultNonTerminal()); targetPhrase->SetTargetLHS(targetLhs); - targetPhrase->SetAlignmentInfo(alignmentSS.str()); + targetPhrase->SetAlignmentInfo(alignmentSSStr); return targetPhrase; } diff --git a/moses/TranslationAnalysis.cpp b/moses/TranslationAnalysis.cpp index ed948f6b6..e01bc71e5 100644 --- a/moses/TranslationAnalysis.cpp +++ b/moses/TranslationAnalysis.cpp @@ -10,6 +10,7 @@ #include "moses/FF/StatefulFeatureFunction.h" #include "moses/FF/StatelessFeatureFunction.h" #include "moses/LM/Base.h" +#include "util/string_stream.hh" using namespace Moses; @@ -40,8 +41,11 @@ void PrintTranslationAnalysis(std::ostream &os, const Hypothesis* hypo) if (doLMStats) lmAcc.resize((*tpi)->GetLMStats()->size(), 0); for (; tpi != translationPath.end(); ++tpi) { - std::ostringstream sms; - std::ostringstream tms; + std::string smsStr; + util::StringStream sms(smsStr); + + std::string tmsStr; + util::StringStream tms(tmsStr); std::string target = (*tpi)->GetTargetPhraseStringRep(); std::string source = (*tpi)->GetSourcePhraseStringRep(); WordsRange twr = (*tpi)->GetCurrTargetWordsRange(); @@ -89,8 +93,8 @@ void PrintTranslationAnalysis(std::ostream &os, const Hypothesis* hypo) for (; swr_i <= swr.GetEndPos() && swr.GetEndPos() != NOT_FOUND; swr_i++) { tms << '-' << swr_i; } - if (!epsilon) targetMap.push_back(sms.str()); - sourceMap.push_back(tms.str()); + if (!epsilon) targetMap.push_back(smsStr); + sourceMap.push_back(tmsStr); } std::vector::iterator si = sourceMap.begin(); std::vector::iterator ti = targetMap.begin(); diff --git a/moses/TranslationModel/CompactPT/BlockHashIndex.cpp b/moses/TranslationModel/CompactPT/BlockHashIndex.cpp index 70184eaa0..bec411d5a 100644 --- a/moses/TranslationModel/CompactPT/BlockHashIndex.cpp +++ b/moses/TranslationModel/CompactPT/BlockHashIndex.cpp @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "BlockHashIndex.h" #include "CmphStringVectorAdapter.h" #include "util/exception.hh" +#include "util/string_stream.hh" #ifdef HAVE_CMPH #include "cmph.h" @@ -367,11 +368,12 @@ void BlockHashIndex::CalcHash(size_t current, void* source_void) if(lastKey > temp) { if(source->nkeys != 2 || temp != "###DUMMY_KEY###") { - std::stringstream strme; - strme << "ERROR: Input file does not appear to be sorted with LC_ALL=C sort" << std::endl; - strme << "1: " << lastKey << std::endl; - strme << "2: " << temp << std::endl; - UTIL_THROW2(strme.str()); + std::string str; + util::StringStream strme(str); + strme << "ERROR: Input file does not appear to be sorted with LC_ALL=C sort\n"; + strme << "1: " << lastKey << "\n"; + strme << "2: " << temp << "\n"; + UTIL_THROW2(str); } } lastKey = temp; diff --git a/moses/TranslationModel/CompactPT/BlockHashIndex.h b/moses/TranslationModel/CompactPT/BlockHashIndex.h index 0f20fa1b2..85cc4e550 100644 --- a/moses/TranslationModel/CompactPT/BlockHashIndex.h +++ b/moses/TranslationModel/CompactPT/BlockHashIndex.h @@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "StringVector.h" #include "PackedArray.h" #include "util/exception.hh" +#include "util/string_stream.hh" #ifdef WITH_THREADS #include "moses/ThreadPool.h" @@ -145,11 +146,12 @@ public: size_t current = m_landmarks.size(); if(m_landmarks.size() && m_landmarks.back().str() >= keys[0]) { - std::stringstream strme; - strme << "ERROR: Input file does not appear to be sorted with LC_ALL=C sort" << std::endl; - strme << "1: " << m_landmarks.back().str() << std::endl; - strme << "2: " << keys[0] << std::endl; - UTIL_THROW2(strme.str()); + std::string str; + util::StringStream strme(str); + strme << "ERROR: Input file does not appear to be sorted with LC_ALL=C sort\n"; + strme << "1: " << m_landmarks.back().str() << "\n"; + strme << "2: " << keys[0] << "\n"; + UTIL_THROW2(str); } m_landmarks.push_back(keys[0]); diff --git a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp index 8fc891979..209425f07 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp @@ -17,6 +17,7 @@ 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 "util/exception.hh" +#include "util/string_stream.hh" #include "moses/TranslationModel/PhraseDictionaryMultiModel.h" @@ -38,9 +39,10 @@ PhraseDictionaryMultiModel::PhraseDictionaryMultiModel(const std::string &line) } else if (m_mode == "all" || m_mode == "all-restrict") { UTIL_THROW2("Implementation has moved: use PhraseDictionaryGroup with restrict=true/false"); } else { - ostringstream msg; + string str; + util::StringStream msg(str); msg << "combination mode unknown: " << m_mode; - throw runtime_error(msg.str()); + throw runtime_error(str); } } @@ -210,9 +212,10 @@ std::vector > PhraseDictionaryMultiModel::getWeights(size_t n raw_weights.push_back(1.0/m_numModels); //uniform weights created online } } else if(weights_ptr->size() != m_numModels && weights_ptr->size() != m_numModels * numWeights) { - std::stringstream strme; + string str; + util::StringStream strme(str); strme << "Must have either one multimodel weight per model (" << m_numModels << "), or one per weighted feature and model (" << numWeights << "*" << m_numModels << "). You have " << weights_ptr->size() << "."; - UTIL_THROW(util::Exception, strme.str()); + UTIL_THROW(util::Exception, str); } else { raw_weights = *weights_ptr; } diff --git a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp index 773e027cc..50edaf2c7 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ***********************************************************************/ #include "util/exception.hh" #include "util/tokenize.hh" +#include "util/string_stream.hh" #include "moses/TranslationModel/PhraseDictionaryMultiModelCounts.h" using namespace std; @@ -56,9 +57,10 @@ void PhraseDictionaryMultiModelCounts::SetParameter(const std::string& key, cons else if (m_mode == "interpolate") m_combineFunction = LinearInterpolationFromCounts; else { - ostringstream msg; + string str; + util::StringStream msg(str); msg << "combination mode unknown: " << m_mode; - throw runtime_error(msg.str()); + throw runtime_error(str); } } else if (key == "lex-e2f") { m_lexE2FStr = Tokenize(value, ","); diff --git a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp index ca1638708..e7e5ff377 100644 --- a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp +++ b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp @@ -15,6 +15,7 @@ #include "moses/PDTAimp.h" #include "moses/TranslationTask.h" #include "util/exception.hh" +#include "util/string_stream.hh" using namespace std; @@ -52,7 +53,8 @@ void PhraseDictionaryTreeAdaptor::InitializeForInput(ttasksptr const& ttask) vector weight = staticData.GetWeights(this); if(m_numScoreComponents!=weight.size()) { - std::stringstream strme; + string str; + util::StringStream strme(str); UTIL_THROW2("ERROR: mismatch of number of scaling factors: " << weight.size() << " " << m_numScoreComponents); } diff --git a/moses/TranslationModel/RuleTable/LoaderStandard.cpp b/moses/TranslationModel/RuleTable/LoaderStandard.cpp index f9e6ac6fd..f2a60ea3d 100644 --- a/moses/TranslationModel/RuleTable/LoaderStandard.cpp +++ b/moses/TranslationModel/RuleTable/LoaderStandard.cpp @@ -126,20 +126,22 @@ void ReformatHieroRule(const string &lineOrig, string &out) ReformatHieroRule(1, targetPhraseString, ntAlign); ReformateHieroScore(scoreString); - stringstream align; + std::string alignStr; + util::StringStream align(alignStr); map >::const_iterator iterAlign; for (iterAlign = ntAlign.begin(); iterAlign != ntAlign.end(); ++iterAlign) { const pair &alignPoint = iterAlign->second; align << alignPoint.first << "-" << alignPoint.second << " "; } - stringstream ret; + std::string str; + util::StringStream ret(str); ret << sourcePhraseString << " ||| " << targetPhraseString << " ||| " << scoreString << " ||| " - << align.str(); + << alignStr; - out = ret.str(); + out = str; } bool RuleTableLoaderStandard::Load(FormatType format diff --git a/moses/TranslationModel/fuzzy-match/SentenceAlignment.cpp b/moses/TranslationModel/fuzzy-match/SentenceAlignment.cpp index 9003817d8..c07acc2b9 100644 --- a/moses/TranslationModel/fuzzy-match/SentenceAlignment.cpp +++ b/moses/TranslationModel/fuzzy-match/SentenceAlignment.cpp @@ -7,18 +7,20 @@ // #include +#include "util/string_stream.hh" #include "SentenceAlignment.h" namespace tmmt { std::string SentenceAlignment::getTargetString(const Vocabulary &vocab) const { - std::stringstream strme; + std::string str; + util::StringStream strme(str); for (size_t i = 0; i < target.size(); ++i) { const WORD &word = vocab.GetWord(target[i]); strme << word << " "; } - return strme.str(); + return str; } } diff --git a/moses/TranslationModel/fuzzy-match/SentenceAlignment.h b/moses/TranslationModel/fuzzy-match/SentenceAlignment.h index a777c1eb0..f0118436b 100644 --- a/moses/TranslationModel/fuzzy-match/SentenceAlignment.h +++ b/moses/TranslationModel/fuzzy-match/SentenceAlignment.h @@ -12,6 +12,7 @@ #include #include #include "Vocabulary.h" +#include "util/string_stream.hh" namespace tmmt { @@ -27,12 +28,13 @@ struct SentenceAlignment { std::string getTargetString(const Vocabulary &vocab) const; std::string getAlignmentString() const { - std::stringstream strme; + std::string str; + util::StringStream strme(str); for (size_t i = 0; i < alignment.size(); ++i) { const std::pair &alignPair = alignment[i]; strme << alignPair.first << "-" << alignPair.second << " "; } - return strme.str(); + return str; } }; diff --git a/moses/Word.cpp b/moses/Word.cpp index f55be5ee8..e4fb84935 100644 --- a/moses/Word.cpp +++ b/moses/Word.cpp @@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "FactorCollection.h" #include "StaticData.h" // needed to determine the FactorDelimiter #include "util/exception.hh" +#include "util/string_stream.hh" #include "util/tokenize_piece.hh" using namespace std; @@ -79,7 +80,8 @@ void Word::Merge(const Word &sourceWord) std::string Word::GetString(const vector factorType,bool endWithBlank) const { - stringstream strme; + string str; + util::StringStream strme(str); const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter(); bool firstPass = true; unsigned int stop = min(max_fax(),factorType.size()); @@ -99,7 +101,7 @@ std::string Word::GetString(const vector factorType,bool endWithBlan } } if(endWithBlank) strme << " "; - return strme.str(); + return str; } StringPiece Word::GetString(FactorType factorType) const