diff --git a/OnDiskPt/OnDiskWrapper.cpp b/OnDiskPt/OnDiskWrapper.cpp index 88fb14201..57fae5162 100644 --- a/OnDiskPt/OnDiskWrapper.cpp +++ b/OnDiskPt/OnDiskWrapper.cpp @@ -225,8 +225,7 @@ Word *OnDiskWrapper::ConvertFromMoses(const std::vector &fact bool isNonTerminal = origWord.IsNonTerminal(); Word *newWord = new Word(isNonTerminal); - string str; - util::StringStream strme(str); + util::StringStream strme; size_t factorType = factorsVec[0]; const Moses::Factor *factor = origWord.GetFactor(factorType); @@ -246,7 +245,7 @@ Word *OnDiskWrapper::ConvertFromMoses(const std::vector &fact } // for (size_t factorType bool found; - uint64_t vocabId = m_vocab.GetVocabId(str, found); + uint64_t vocabId = m_vocab.GetVocabId(strme.str(), found); if (!found) { // factor not in phrase table -> phrse definately not in. exit delete newWord; diff --git a/lm/filter/arpa_io.cc b/lm/filter/arpa_io.cc index 2cae60f9a..cf2721ed5 100644 --- a/lm/filter/arpa_io.cc +++ b/lm/filter/arpa_io.cc @@ -33,10 +33,9 @@ template void WriteCounts(Stream &out, const std::vector &number) { - std::string buf; - util::StringStream stream(buf); + util::StringStream stream; WriteCounts(stream, number); - return buf.size(); + return stream.str().size(); } bool IsEntirelyWhiteSpace(const StringPiece &line) { diff --git a/moses/FF/GlobalLexicalModelUnlimited.cpp b/moses/FF/GlobalLexicalModelUnlimited.cpp index fbbeeda47..15eec019c 100644 --- a/moses/FF/GlobalLexicalModelUnlimited.cpp +++ b/moses/FF/GlobalLexicalModelUnlimited.cpp @@ -132,13 +132,12 @@ void GlobalLexicalModelUnlimited::EvaluateWhenApplied(const Hypothesis& cur_hypo } if (m_biasFeature) { - string str; - util::StringStream feature(str); + util::StringStream feature; feature << "glm_"; feature << targetString; feature << "~"; feature << "**BIAS**"; - accumulator->SparsePlusEquals(str, 1); + accumulator->SparsePlusEquals(feature.str(), 1); } boost::unordered_set alreadyScored; @@ -167,14 +166,13 @@ void GlobalLexicalModelUnlimited::EvaluateWhenApplied(const Hypothesis& cur_hypo if (m_sourceContext) { if (sourceIndex == 0) { // add trigger feature for source - string str; - util::StringStream feature(str); + util::StringStream feature; feature << "glm_"; feature << targetString; feature << "~"; feature << ","; feature << sourceString; - accumulator->SparsePlusEquals(str, 1); + accumulator->SparsePlusEquals(feature.str(), 1); alreadyScored.insert(sourceHash); } @@ -186,15 +184,14 @@ void GlobalLexicalModelUnlimited::EvaluateWhenApplied(const Hypothesis& cur_hypo contextExists = FindStringPiece(m_vocabSource, contextString ) != m_vocabSource.end(); if (m_unrestricted || contextExists) { - string str; - util::StringStream feature(str); + util::StringStream feature; feature << "glm_"; feature << targetString; feature << "~"; feature << sourceString; feature << ","; feature << contextString; - accumulator->SparsePlusEquals(str, 1); + accumulator->SparsePlusEquals(feature.str(), 1); alreadyScored.insert(sourceHash); } } @@ -308,13 +305,12 @@ void GlobalLexicalModelUnlimited::EvaluateWhenApplied(const Hypothesis& cur_hypo } } } else { - string str; - util::StringStream feature(str); + util::StringStream feature; feature << "glm_"; feature << targetString; feature << "~"; feature << sourceString; - accumulator->SparsePlusEquals(str, 1); + accumulator->SparsePlusEquals(feature.str(), 1); alreadyScored.insert(sourceHash); } @@ -328,8 +324,7 @@ void GlobalLexicalModelUnlimited::AddFeature(ScoreComponentCollection* accumulat StringPiece sourceTrigger, StringPiece sourceWord, StringPiece targetTrigger, StringPiece targetWord) const { - string str; - util::StringStream feature(str); + util::StringStream feature; feature << "glm_"; feature << targetTrigger; feature << ","; @@ -338,7 +333,7 @@ void GlobalLexicalModelUnlimited::AddFeature(ScoreComponentCollection* accumulat feature << sourceTrigger; feature << ","; feature << sourceWord; - accumulator->SparsePlusEquals(str, 1); + accumulator->SparsePlusEquals(feature.str(), 1); } diff --git a/moses/FF/LexicalReordering/SparseReordering.cpp b/moses/FF/LexicalReordering/SparseReordering.cpp index e027fc4fe..f8416a284 100644 --- a/moses/FF/LexicalReordering/SparseReordering.cpp +++ b/moses/FF/LexicalReordering/SparseReordering.cpp @@ -27,8 +27,7 @@ const std::string& SparseReorderingFeatureKey::Name (const string& wordListId) { static string kSep = "-"; static string name; - std::string str; - util::StringStream buf(str); + util::StringStream buf; // type side position id word reotype if (type == Phrase) { buf << "phr"; @@ -56,7 +55,7 @@ const std::string& SparseReorderingFeatureKey::Name (const string& wordListId) buf << word->GetString(); buf << kSep; buf << reoType; - name = str; + name = buf.str(); return name; } @@ -90,10 +89,9 @@ SparseReordering::SparseReordering(const map& config, const Lexic ReadWeightMap(i->second); m_useWeightMap = true; for (int reoType=0; reoType<=LRModel::MAX; ++reoType) { - std::string str; - util::StringStream buf(str); + util::StringStream buf; buf << reoType; - m_featureMap2.push_back(m_producer->GetFeatureName(str)); + m_featureMap2.push_back(m_producer->GetFeatureName(buf.str())); } } else if (fields[0] == "phrase") { diff --git a/moses/FF/PhraseBoundaryFeature.cpp b/moses/FF/PhraseBoundaryFeature.cpp index 1a127d9e4..b4a00b1ca 100644 --- a/moses/FF/PhraseBoundaryFeature.cpp +++ b/moses/FF/PhraseBoundaryFeature.cpp @@ -62,8 +62,7 @@ void PhraseBoundaryFeature::AddFeatures( ScoreComponentCollection* scores) const { for (size_t i = 0; i < factors.size(); ++i) { - std::string str; - util::StringStream name(str); + util::StringStream name; name << side << ":"; name << factors[i]; name << ":"; diff --git a/moses/FF/PhraseLengthFeature.cpp b/moses/FF/PhraseLengthFeature.cpp index 55cd2f847..9dbb0235e 100644 --- a/moses/FF/PhraseLengthFeature.cpp +++ b/moses/FF/PhraseLengthFeature.cpp @@ -26,16 +26,13 @@ void PhraseLengthFeature::EvaluateInIsolation(const Phrase &source size_t sourceLength = source.GetSize(); // create feature names - string nameSourceStr; - util::StringStream nameSource(nameSourceStr); + util::StringStream nameSource; nameSource << "s" << sourceLength; - string nameTargetStr; - util::StringStream nameTarget(nameTargetStr); + util::StringStream nameTarget; nameTarget << "t" << targetLength; - string nameBothStr; - util::StringStream nameBoth(nameBothStr); + util::StringStream nameBoth; nameBoth << sourceLength << "," << targetLength; // increase feature counts diff --git a/moses/FF/PhrasePairFeature.cpp b/moses/FF/PhrasePairFeature.cpp index 920317c00..d531d9a54 100644 --- a/moses/FF/PhrasePairFeature.cpp +++ b/moses/FF/PhrasePairFeature.cpp @@ -127,8 +127,7 @@ void PhrasePairFeature::EvaluateWithSourceContext(const InputType &input const bool use_topicid_prob = isnt.GetUseTopicIdAndProb(); // compute pair - string pairStr; - util::StringStream pair(pairStr); + util::StringStream pair; pair << ReplaceTilde( source.GetWord(0).GetFactor(m_sourceFactorId)->GetString() ); for (size_t i = 1; i < source.GetSize(); ++i) { @@ -148,8 +147,7 @@ void PhrasePairFeature::EvaluateWithSourceContext(const InputType &input if(use_topicid) { // use topicid as trigger const long topicid = isnt.GetTopicId(); - string featureStr; - util::StringStream feature(featureStr); + util::StringStream feature; feature << m_description << "_"; if (topicid == -1) @@ -164,15 +162,13 @@ void PhrasePairFeature::EvaluateWithSourceContext(const InputType &input // use topic probabilities const vector &topicid_prob = *(isnt.GetTopicIdAndProb()); if (atol(topicid_prob[0].c_str()) == -1) { - string featureStr; - util::StringStream feature(featureStr); + 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) { - string featureStr; - util::StringStream feature(featureStr); + util::StringStream feature; feature << m_description << "_"; feature << topicid_prob[i]; feature << "_"; @@ -186,8 +182,7 @@ void PhrasePairFeature::EvaluateWithSourceContext(const InputType &input const long docid = isnt.GetDocumentId(); for (set::const_iterator p = m_vocabDomain[docid].begin(); p != m_vocabDomain[docid].end(); ++p) { string sourceTrigger = *p; - string str; - util::StringStream namestr(str); + util::StringStream namestr; namestr << m_description << "_"; namestr << sourceTrigger; namestr << "_"; @@ -215,8 +210,7 @@ void PhrasePairFeature::EvaluateWithSourceContext(const InputType &input sourceTriggerExists = FindStringPiece(m_vocabSource, sourceTrigger ) != m_vocabSource.end(); if (m_unrestricted || sourceTriggerExists) { - string str; - util::StringStream namestr(str); + util::StringStream namestr; namestr << m_description << "_"; namestr << sourceTrigger; namestr << "~"; @@ -246,8 +240,7 @@ void PhrasePairFeature::EvaluateInIsolation(const Phrase &source , ScoreComponentCollection &estimatedFutureScore) const { if (m_simple) { - string str; - util::StringStream namestr(str); + 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 e82f1cd2a..fe1a4f648 100644 --- a/moses/FF/RulePairUnlexicalizedSource.cpp +++ b/moses/FF/RulePairUnlexicalizedSource.cpp @@ -58,8 +58,7 @@ void RulePairUnlexicalizedSource::EvaluateInIsolation(const Phrase &source } } - string str; - util::StringStream namestr(str); + util::StringStream namestr; for (size_t posT=0; posT scores(numFeatureValuesInConfig, 0.0f); for (size_t i = 0; i < numFeatureValuesInConfig; i++) diff --git a/moses/LM/Ken.cpp b/moses/LM/Ken.cpp index dba2df30a..f982ffcff 100644 --- a/moses/LM/Ken.cpp +++ b/moses/LM/Ken.cpp @@ -488,8 +488,7 @@ LanguageModel *ConstructKenLM(const std::string &lineOrig) util::TokenIter argument(lineOrig, ' '); ++argument; // KENLM - string str; - util::StringStream line(str); + util::StringStream line; line << "KENLM"; for (; argument; ++argument) { @@ -512,7 +511,7 @@ LanguageModel *ConstructKenLM(const std::string &lineOrig) } } - return ConstructKenLM(str, filePath, factorType, lazy); + return ConstructKenLM(line.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 93c719c91..4214c3d63 100644 --- a/moses/LM/Remote.cpp +++ b/moses/LM/Remote.cpp @@ -97,8 +97,7 @@ LMResult LanguageModelRemote::GetValue(const std::vector &contextFa cur->boState = *reinterpret_cast(&m_curId); ++m_curId; - std::string out; - util::StringStream os(out); + util::StringStream os; os << "prob "; if (event_word == NULL) { os << ""; @@ -114,7 +113,7 @@ LMResult LanguageModelRemote::GetValue(const std::vector &contextFa } } os << "\n"; - write(sock, out.c_str(), out.size()); + write(sock, os.str().c_str(), os.str().size()); char res[6]; int r = read(sock, res, 6); int errors = 0; diff --git a/moses/Parameter.cpp b/moses/Parameter.cpp index eb79f1452..f6058cbd8 100644 --- a/moses/Parameter.cpp +++ b/moses/Parameter.cpp @@ -702,8 +702,7 @@ ConvertWeightArgsPhraseModel(const string &oldWeightName) size_t currOldInd = 0; for(size_t currDict = 0 ; currDict < translationVector.size(); currDict++) { - string ptLineStr; - util::StringStream ptLine(ptLineStr); + util::StringStream ptLine; vector token = Tokenize(translationVector[currDict]); @@ -799,7 +798,7 @@ ConvertWeightArgsPhraseModel(const string &oldWeightName) ptLine << "alignment-path=" << token[6] << " "; } - AddFeature(ptLineStr); + AddFeature(ptLine.str()); } // for(size_t currDict = 0 ; currDict < translationVector.size(); currDict++) { } // if (GetParam("ttable-file").size() > 0) { @@ -862,8 +861,7 @@ ConvertWeightArgsDistortion() } SetWeight("LexicalReordering", indTable, weights); - string str; - util::StringStream strme(str); + util::StringStream strme; strme << "LexicalReordering " << "type=" << toks[1] << " "; @@ -877,7 +875,7 @@ ConvertWeightArgsDistortion() strme << "num-features=" << toks[2] << " "; strme << "path=" << toks[3]; - AddFeature(str); + AddFeature(strme.str()); } } @@ -1010,14 +1008,13 @@ ConvertWeightArgsGeneration(const std::string &oldWeightName, const std::string } SetWeight(newWeightName, indTable, weights); - string str; - util::StringStream strme(str); + util::StringStream strme; strme << "Generation " << "input-factor=" << modelToks[0] << " " << "output-factor=" << modelToks[1] << " " << "num-features=" << modelToks[2] << " " << "path=" << modelToks[3]; - AddFeature(str); + AddFeature(strme.str()); } } diff --git a/moses/Phrase.cpp b/moses/Phrase.cpp index f7400515a..e47e0b4b9 100644 --- a/moses/Phrase.cpp +++ b/moses/Phrase.cpp @@ -118,8 +118,7 @@ std::string Phrase::GetStringRep(const vector factorsToPrint) const { bool markUnknown = StaticData::Instance().GetMarkUnknown(); - string str; - util::StringStream strme(str); + util::StringStream strme; for (size_t pos = 0 ; pos < GetSize() ; pos++) { if (markUnknown && GetWord(pos).IsOOV()) { strme << StaticData::Instance().GetUnknownWordPrefix(); @@ -130,7 +129,7 @@ std::string Phrase::GetStringRep(const vector factorsToPrint) const } } - return str; + return strme.str(); } Word &Phrase::AddWord() diff --git a/moses/StaticData.cpp b/moses/StaticData.cpp index d05917740..341e4d0cc 100644 --- a/moses/StaticData.cpp +++ b/moses/StaticData.cpp @@ -640,21 +640,19 @@ void StaticData::LoadDecodeGraphsOld(const vector &mappingVector, const switch (decodeType) { case Translate: if(index>=pts.size()) { - string str; - util::StringStream strme(str); + util::StringStream strme; strme << "No phrase dictionary with index " << index << " available!"; - UTIL_THROW(util::Exception, str); + UTIL_THROW(util::Exception, strme.str()); } decodeStep = new DecodeStepTranslation(pts[index], prev, *featuresRemaining); break; case Generate: if(index>=gens.size()) { - string str; - util::StringStream strme(str); + util::StringStream strme; strme << "No generation dictionary with index " << index << " available!"; - UTIL_THROW(util::Exception, str); + UTIL_THROW(util::Exception, strme.str()); } decodeStep = new DecodeStepGeneration(gens[index], prev, *featuresRemaining); break; diff --git a/moses/Syntax/F2S/GlueRuleSynthesizer.cpp b/moses/Syntax/F2S/GlueRuleSynthesizer.cpp index a181d0b9e..1e00c594a 100644 --- a/moses/Syntax/F2S/GlueRuleSynthesizer.cpp +++ b/moses/Syntax/F2S/GlueRuleSynthesizer.cpp @@ -56,8 +56,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( TargetPhrase *targetPhrase = new TargetPhrase(); - std::string alignmentSSStr; - util::StringStream alignmentSS(alignmentSSStr); + util::StringStream alignmentSS; for (std::size_t i = 0; i < e.tail.size(); ++i) { const Word &symbol = e.tail[i]->pvertex.symbol; if (symbol.IsNonTerminal()) { @@ -77,7 +76,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( targetPhrase->EvaluateInIsolation(m_dummySourcePhrase); Word *targetLhs = new Word(staticData.GetOutputDefaultNonTerminal()); targetPhrase->SetTargetLHS(targetLhs); - targetPhrase->SetAlignmentInfo(alignmentSSStr); + targetPhrase->SetAlignmentInfo(alignmentSS.str()); return targetPhrase; } diff --git a/moses/Syntax/T2S/GlueRuleSynthesizer.cpp b/moses/Syntax/T2S/GlueRuleSynthesizer.cpp index 4fed9e9ab..0a0c07eea 100644 --- a/moses/Syntax/T2S/GlueRuleSynthesizer.cpp +++ b/moses/Syntax/T2S/GlueRuleSynthesizer.cpp @@ -47,8 +47,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( TargetPhrase *targetPhrase = new TargetPhrase(); - std::string alignmentSSStr; - util::StringStream alignmentSS(alignmentSSStr); + util::StringStream alignmentSS; for (std::size_t i = 0; i < node.children.size(); ++i) { const Word &symbol = node.children[i]->pvertex.symbol; if (symbol.IsNonTerminal()) { @@ -68,7 +67,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( targetPhrase->EvaluateInIsolation(sourceRhs); Word *targetLhs = new Word(staticData.GetOutputDefaultNonTerminal()); targetPhrase->SetTargetLHS(targetLhs); - targetPhrase->SetAlignmentInfo(alignmentSSStr); + targetPhrase->SetAlignmentInfo(alignmentSS.str()); return targetPhrase; } diff --git a/moses/TranslationAnalysis.cpp b/moses/TranslationAnalysis.cpp index e01bc71e5..ebca957ce 100644 --- a/moses/TranslationAnalysis.cpp +++ b/moses/TranslationAnalysis.cpp @@ -41,11 +41,9 @@ void PrintTranslationAnalysis(std::ostream &os, const Hypothesis* hypo) if (doLMStats) lmAcc.resize((*tpi)->GetLMStats()->size(), 0); for (; tpi != translationPath.end(); ++tpi) { - std::string smsStr; - util::StringStream sms(smsStr); + util::StringStream sms; - std::string tmsStr; - util::StringStream tms(tmsStr); + util::StringStream tms; std::string target = (*tpi)->GetTargetPhraseStringRep(); std::string source = (*tpi)->GetSourcePhraseStringRep(); WordsRange twr = (*tpi)->GetCurrTargetWordsRange(); @@ -93,8 +91,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(smsStr); - sourceMap.push_back(tmsStr); + if (!epsilon) targetMap.push_back(sms.str()); + sourceMap.push_back(tms.str()); } 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 bec411d5a..4130bd6a4 100644 --- a/moses/TranslationModel/CompactPT/BlockHashIndex.cpp +++ b/moses/TranslationModel/CompactPT/BlockHashIndex.cpp @@ -368,12 +368,11 @@ void BlockHashIndex::CalcHash(size_t current, void* source_void) if(lastKey > temp) { if(source->nkeys != 2 || temp != "###DUMMY_KEY###") { - std::string str; - util::StringStream strme(str); + util::StringStream strme; 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); + UTIL_THROW2(strme.str()); } } lastKey = temp; diff --git a/moses/TranslationModel/CompactPT/BlockHashIndex.h b/moses/TranslationModel/CompactPT/BlockHashIndex.h index 85cc4e550..3de46272a 100644 --- a/moses/TranslationModel/CompactPT/BlockHashIndex.h +++ b/moses/TranslationModel/CompactPT/BlockHashIndex.h @@ -146,12 +146,11 @@ public: size_t current = m_landmarks.size(); if(m_landmarks.size() && m_landmarks.back().str() >= keys[0]) { - std::string str; - util::StringStream strme(str); + util::StringStream strme; 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); + UTIL_THROW2(strme.str()); } m_landmarks.push_back(keys[0]); diff --git a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp index 209425f07..b877bb04d 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp @@ -39,10 +39,9 @@ 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 { - string str; - util::StringStream msg(str); + util::StringStream msg; msg << "combination mode unknown: " << m_mode; - throw runtime_error(str); + throw runtime_error(msg.str()); } } @@ -212,10 +211,9 @@ 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) { - string str; - util::StringStream strme(str); + util::StringStream strme; 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, str); + UTIL_THROW(util::Exception, strme.str()); } else { raw_weights = *weights_ptr; } diff --git a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp index 50edaf2c7..b4ed1bf73 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp @@ -57,10 +57,9 @@ void PhraseDictionaryMultiModelCounts::SetParameter(const std::string& key, cons else if (m_mode == "interpolate") m_combineFunction = LinearInterpolationFromCounts; else { - string str; - util::StringStream msg(str); + util::StringStream msg; msg << "combination mode unknown: " << m_mode; - throw runtime_error(str); + throw runtime_error(msg.str()); } } else if (key == "lex-e2f") { m_lexE2FStr = Tokenize(value, ","); diff --git a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp index e7e5ff377..f0c744155 100644 --- a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp +++ b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp @@ -53,8 +53,7 @@ void PhraseDictionaryTreeAdaptor::InitializeForInput(ttasksptr const& ttask) vector weight = staticData.GetWeights(this); if(m_numScoreComponents!=weight.size()) { - string str; - util::StringStream strme(str); + util::StringStream strme; 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 f2a60ea3d..9386f8d81 100644 --- a/moses/TranslationModel/RuleTable/LoaderStandard.cpp +++ b/moses/TranslationModel/RuleTable/LoaderStandard.cpp @@ -126,22 +126,20 @@ void ReformatHieroRule(const string &lineOrig, string &out) ReformatHieroRule(1, targetPhraseString, ntAlign); ReformateHieroScore(scoreString); - std::string alignStr; - util::StringStream align(alignStr); + util::StringStream align; map >::const_iterator iterAlign; for (iterAlign = ntAlign.begin(); iterAlign != ntAlign.end(); ++iterAlign) { const pair &alignPoint = iterAlign->second; align << alignPoint.first << "-" << alignPoint.second << " "; } - std::string str; - util::StringStream ret(str); + util::StringStream ret; ret << sourcePhraseString << " ||| " << targetPhraseString << " ||| " << scoreString << " ||| " - << alignStr; + << align.str(); - out = str; + out = ret.str(); } bool RuleTableLoaderStandard::Load(FormatType format diff --git a/moses/TranslationModel/fuzzy-match/SentenceAlignment.cpp b/moses/TranslationModel/fuzzy-match/SentenceAlignment.cpp index c07acc2b9..eabdd8753 100644 --- a/moses/TranslationModel/fuzzy-match/SentenceAlignment.cpp +++ b/moses/TranslationModel/fuzzy-match/SentenceAlignment.cpp @@ -14,13 +14,12 @@ namespace tmmt { std::string SentenceAlignment::getTargetString(const Vocabulary &vocab) const { - std::string str; - util::StringStream strme(str); + util::StringStream strme; for (size_t i = 0; i < target.size(); ++i) { const WORD &word = vocab.GetWord(target[i]); strme << word << " "; } - return str; + return strme.str(); } } diff --git a/moses/TranslationModel/fuzzy-match/SentenceAlignment.h b/moses/TranslationModel/fuzzy-match/SentenceAlignment.h index f0118436b..4d6dc430c 100644 --- a/moses/TranslationModel/fuzzy-match/SentenceAlignment.h +++ b/moses/TranslationModel/fuzzy-match/SentenceAlignment.h @@ -28,13 +28,12 @@ struct SentenceAlignment { std::string getTargetString(const Vocabulary &vocab) const; std::string getAlignmentString() const { - std::string str; - util::StringStream strme(str); + util::StringStream strme; for (size_t i = 0; i < alignment.size(); ++i) { const std::pair &alignPair = alignment[i]; strme << alignPair.first << "-" << alignPair.second << " "; } - return str; + return strme.str(); } }; diff --git a/moses/Word.cpp b/moses/Word.cpp index e4fb84935..c0041b173 100644 --- a/moses/Word.cpp +++ b/moses/Word.cpp @@ -80,8 +80,7 @@ void Word::Merge(const Word &sourceWord) std::string Word::GetString(const vector factorType,bool endWithBlank) const { - string str; - util::StringStream strme(str); + util::StringStream strme; const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter(); bool firstPass = true; unsigned int stop = min(max_fax(),factorType.size()); @@ -101,7 +100,7 @@ std::string Word::GetString(const vector factorType,bool endWithBlan } } if(endWithBlank) strme << " "; - return str; + return strme.str(); } StringPiece Word::GetString(FactorType factorType) const diff --git a/util/exception.cc b/util/exception.cc index e644d2cb7..5ba06f065 100644 --- a/util/exception.cc +++ b/util/exception.cc @@ -25,7 +25,8 @@ void Exception::SetLocation(const char *file, unsigned int line, const char *fun */ std::string old_text; std::swap(old_text, what_); - StringStream stream(what_); + StringStream stream; + stream << what_; stream << file << ':' << line; if (func) stream << " in " << func << " threw "; if (child_name) { diff --git a/util/string_stream.hh b/util/string_stream.hh index cab072292..6760b58ba 100644 --- a/util/string_stream.hh +++ b/util/string_stream.hh @@ -11,9 +11,13 @@ namespace util { class StringStream : public FakeOStream { public: // Semantics: appends to string. Remember to clear first! - explicit StringStream(std::string &out) - : out_(out) {} + explicit StringStream() + {} + /* + explicit StringStream(std::string &out) + : out_(out) {} + */ StringStream &flush() { return *this; } StringStream &write(const void *data, std::size_t length) { @@ -39,7 +43,7 @@ class StringStream : public FakeOStream { } private: - std::string &out_; + std::string out_; }; } // namespace diff --git a/util/string_stream_test.cc b/util/string_stream_test.cc index 3a7734feb..150c44baa 100644 --- a/util/string_stream_test.cc +++ b/util/string_stream_test.cc @@ -11,9 +11,9 @@ namespace util { namespace { template void TestEqual(const T value) { - std::string str; - StringStream(str) << value; - BOOST_CHECK_EQUAL(boost::lexical_cast(value), str); + StringStream strme; + strme << value; + BOOST_CHECK_EQUAL(boost::lexical_cast(value), strme.str()); } template void TestCorners() {