From 0859e9a844cc23ff04b09b4ac3d580da9197d1a1 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Wed, 13 May 2015 17:05:43 +0700 Subject: [PATCH 1/2] Remove trailing whitespace from C++ files. --- moses/BaseManager.cpp | 16 ++++++++-------- moses/ChartManager.cpp | 2 +- moses/ExportInterface.cpp | 2 +- moses/HypergraphOutput.cpp | 16 ++++++++-------- moses/IOWrapper.cpp | 22 +++++++++++----------- moses/Manager.cpp | 4 ++-- moses/Parameter.cpp | 4 ++-- moses/TranslationModel/UG/mmsapt.cpp | 2 +- moses/TranslationTask.cpp | 2 +- moses/parameters/ContextParameters.cpp | 14 +++++++------- 10 files changed, 42 insertions(+), 42 deletions(-) diff --git a/moses/BaseManager.cpp b/moses/BaseManager.cpp index 70bacdede..291b813f0 100644 --- a/moses/BaseManager.cpp +++ b/moses/BaseManager.cpp @@ -36,7 +36,7 @@ OutputSearchGraphAsHypergraph(std::ostream& out) const UTIL_THROW2("Not implemented."); } -void +void BaseManager:: OutputSearchGraphAsHypergraph(std::string const& fname, size_t const precision) const { @@ -44,12 +44,12 @@ OutputSearchGraphAsHypergraph(std::string const& fname, size_t const precision) if (! boost::filesystem::exists(odir)) boost::filesystem::create_directory(odir); UTIL_THROW_IF2(!boost::filesystem::is_directory(odir), - "Cannot output hypergraphs to " << odir + "Cannot output hypergraphs to " << odir << " because that path exists but is not a directory."); - // not clear why we need to output the weights every time we dump a search + // not clear why we need to output the weights every time we dump a search // graph into a file again, but that's what the old code did. - + string weightsFile = odir + "/weights"; TRACE_ERR("The weights file is " << weightsFile << "\n"); ofstream weightsOut; @@ -60,23 +60,23 @@ OutputSearchGraphAsHypergraph(std::string const& fname, size_t const precision) // (or the translation task) StaticData::Instance().GetAllWeights().Save(weightsOut); weightsOut.close(); - + boost::iostreams::filtering_ostream file; if (boost::ends_with(fname, ".gz")) file.push(boost::iostreams::gzip_compressor()); else if (boost::ends_with(fname, ".bz2")) file.push( boost::iostreams::bzip2_compressor() ); file.push( boost::iostreams::file_sink(fname, ios_base::out) ); - if (file.is_complete() && file.good()) + if (file.is_complete() && file.good()) { file.setf(std::ios::fixed); file.precision(precision); this->OutputSearchGraphAsHypergraph(file); file.flush(); } - else + else { - TRACE_ERR("Cannot output hypergraph for line " + TRACE_ERR("Cannot output hypergraph for line " << this->GetSource().GetTranslationId() << " because the output file " << fname << " is not open or not ready for writing" diff --git a/moses/ChartManager.cpp b/moses/ChartManager.cpp index 9170b2a7c..d59b68cc8 100644 --- a/moses/ChartManager.cpp +++ b/moses/ChartManager.cpp @@ -291,7 +291,7 @@ void ChartManager::FindReachableHypotheses( } } -void +void ChartManager:: OutputSearchGraphAsHypergraph(std::ostream& out) const { diff --git a/moses/ExportInterface.cpp b/moses/ExportInterface.cpp index 790196edd..0ceeceec1 100644 --- a/moses/ExportInterface.cpp +++ b/moses/ExportInterface.cpp @@ -228,7 +228,7 @@ batch_run() // set up task of translating one sentence boost::shared_ptr task = TranslationTask::create(source, ioWrapper); - if (source->GetContext()) + if (source->GetContext()) task->SetContextString(*source->GetContext()); else task->SetContextString(context_string); diff --git a/moses/HypergraphOutput.cpp b/moses/HypergraphOutput.cpp index 412f92578..470d35ba2 100644 --- a/moses/HypergraphOutput.cpp +++ b/moses/HypergraphOutput.cpp @@ -47,9 +47,9 @@ namespace Moses template class HypergraphOutput; template class HypergraphOutput; -void +void ChartSearchGraphWriterMoses:: -WriteHypos(const ChartHypothesisCollection& hypos, +WriteHypos(const ChartHypothesisCollection& hypos, const map &reachable) const { @@ -62,20 +62,20 @@ WriteHypos(const ChartHypothesisCollection& hypos, } const ChartArcList *arcList = mainHypo.GetArcList(); - if (arcList) + if (arcList) { ChartArcList::const_iterator iterArc; - for (iterArc = arcList->begin(); iterArc != arcList->end(); ++iterArc) + for (iterArc = arcList->begin(); iterArc != arcList->end(); ++iterArc) { const ChartHypothesis &arc = **iterArc; - if (reachable.find(arc.GetId()) != reachable.end()) + if (reachable.find(arc.GetId()) != reachable.end()) (*m_out) << m_lineNumber << " " << arc << endl; } } } } -void +void ChartSearchGraphWriterHypergraph:: WriteHeader(size_t winners, size_t losers) const { @@ -83,7 +83,7 @@ WriteHeader(size_t winners, size_t losers) const (*m_out) << winners << " " << (winners+losers) << endl; } -void +void ChartSearchGraphWriterHypergraph:: WriteHypos(const ChartHypothesisCollection& hypos, const map &reachable) const @@ -113,7 +113,7 @@ WriteHypos(const ChartHypothesisCollection& hypos, } } (*m_out) << edges.size() << endl; - for (vector::const_iterator ei = edges.begin(); + for (vector::const_iterator ei = edges.begin(); ei != edges.end(); ++ei) { const ChartHypothesis* hypo = *ei; const TargetPhrase& target = hypo->GetCurrTargetPhrase(); diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp index 3e7b916ca..1e93d868d 100644 --- a/moses/IOWrapper.cpp +++ b/moses/IOWrapper.cpp @@ -97,12 +97,12 @@ IOWrapper::IOWrapper() // context buffering for context-sensitive decoding m_look_ahead = staticData.GetContextParameters().look_ahead; m_look_back = staticData.GetContextParameters().look_back; - + m_inputType = staticData.GetInputType(); UTIL_THROW_IF2((m_look_ahead || m_look_back) && m_inputType != SentenceInput, "Context-sensitive decoding currently works only with sentence input."); - + m_currentLine = staticData.GetStartTranslationId(); m_inputFactorOrder = &staticData.GetInputFactorOrder(); @@ -223,7 +223,7 @@ IOWrapper::IOWrapper() std::string& fmt = m_hypergraph_output_filepattern; // first, determine the output directory if (p && p->size() > 2) fmt = p->at(2); - else if (nBestFilePath.size() && nBestFilePath != "-" && + else if (nBestFilePath.size() && nBestFilePath != "-" && ! boost::starts_with(nBestFilePath, "/dev/stdout")) { fmt = boost::filesystem::path(nBestFilePath).parent_path().string(); @@ -233,7 +233,7 @@ IOWrapper::IOWrapper() if (*fmt.rbegin() != '/') fmt += "/"; std::string extension = (p && p->size() > 1 ? p->at(1) : std::string("txt")); UTIL_THROW_IF2(extension != "txt" && extension != "gz" && extension != "bz2", - "Unknown compression type '" << extension + "Unknown compression type '" << extension << "' for hypergraph output!"); fmt += string("%d.") + extension; @@ -278,10 +278,10 @@ IOWrapper:: GetBufferedInput() { switch(m_inputType) { - case SentenceInput: - return BufferInput(); - case ConfusionNetworkInput: - return BufferInput(); + case SentenceInput: + return BufferInput(); + case ConfusionNetworkInput: + return BufferInput(); case WordLatticeInput: return BufferInput(); case TreeInputType: @@ -294,7 +294,7 @@ GetBufferedInput() TRACE_ERR("Unknown input type: " << m_inputType << "\n"); return boost::shared_ptr(); } - + } boost::shared_ptr @@ -304,7 +304,7 @@ IOWrapper::ReadInput() boost::lock_guard lock(m_lock); #endif boost::shared_ptr source = GetBufferedInput(); - if (source) + if (source) { source->SetTranslationId(m_currentLine++); this->set_context_for(*source); @@ -313,7 +313,7 @@ IOWrapper::ReadInput() return source; } -void +void IOWrapper:: set_context_for(InputType& source) { diff --git a/moses/Manager.cpp b/moses/Manager.cpp index 9d56d4cfa..7580b4e6e 100644 --- a/moses/Manager.cpp +++ b/moses/Manager.cpp @@ -1982,10 +1982,10 @@ void Manager::OutputSearchGraphSLF() const // static char const* key = "output-search-graph-hypergraph"; // PARAM_VEC const* p = staticData.GetParameter().GetParam(key); // ScoreComponentCollection const& weights = staticData.GetAllWeights(); -// string const& nBestFile = staticData.GetNBestFilePath(); +// string const& nBestFile = staticData.GetNBestFilePath(); // HypergraphOutput hypergraphOutput(PRECISION, p, nBestFile, weights); // hypergraphOutput.Write(*this); - + // } void Manager::OutputLatticeMBRNBest(std::ostream& out, const vector& solutions,long translationId) const diff --git a/moses/Parameter.cpp b/moses/Parameter.cpp index 2f04e90d3..599d70938 100644 --- a/moses/Parameter.cpp +++ b/moses/Parameter.cpp @@ -240,9 +240,9 @@ Parameter::Parameter() AddParam(misc_opts,"feature-name-overwrite", "Override feature name (NOT arguments). Eg. SRILM-->KENLM, PhraseDictionaryMemory-->PhraseDictionaryScope3"); AddParam(misc_opts,"feature", "All the feature functions should be here"); - AddParam(misc_opts,"context-string", + AddParam(misc_opts,"context-string", "A (tokenized) string containing context words for context-sensitive translation."); - AddParam(misc_opts,"context-window", + AddParam(misc_opts,"context-window", "Context window (in words) for context-sensitive translation: {+|-|+-}."); // Compact phrase table and reordering table. diff --git a/moses/TranslationModel/UG/mmsapt.cpp b/moses/TranslationModel/UG/mmsapt.cpp index 2b11da968..7eac93b38 100644 --- a/moses/TranslationModel/UG/mmsapt.cpp +++ b/moses/TranslationModel/UG/mmsapt.cpp @@ -217,7 +217,7 @@ namespace Moses m_bias_log = &std::cerr; else if (m_bias_logfile == "/dev/stdout") m_bias_log = &std::cout; - else + else { m_bias_logger.reset(new ofstream(m_bias_logfile.c_str())); m_bias_log = m_bias_logger.get(); diff --git a/moses/TranslationTask.cpp b/moses/TranslationTask.cpp index 0b425ef23..190bb0b7e 100644 --- a/moses/TranslationTask.cpp +++ b/moses/TranslationTask.cpp @@ -178,7 +178,7 @@ void TranslationTask::Run() // Output search graph in hypergraph format for Kenneth Heafield's // lazy hypergraph decoder; writes to stderr - if (StaticData::Instance().GetOutputSearchGraphHypergraph()) + if (StaticData::Instance().GetOutputSearchGraphHypergraph()) { size_t transId = manager->GetSource().GetTranslationId(); string fname = io->GetHypergraphOutputFileName(transId); diff --git a/moses/parameters/ContextParameters.cpp b/moses/parameters/ContextParameters.cpp index 541fd344e..b88945878 100644 --- a/moses/parameters/ContextParameters.cpp +++ b/moses/parameters/ContextParameters.cpp @@ -17,27 +17,27 @@ init(Parameter& params) std::string context_window; params.SetParameter(context_window, "context-window", std::string("")); - if (context_window == "") + if (context_window == "") return; size_t p = context_window.find_first_of("0123456789"); - if (p == 0) + if (p == 0) look_back = look_ahead = atoi(context_window.c_str()); - if (p == 1) + if (p == 1) { - if (context_window[0] == '-') + if (context_window[0] == '-') look_back = atoi(context_window.substr(1).c_str()); - else if (context_window[0] == '+') + else if (context_window[0] == '+') look_ahead = atoi(context_window.substr(1).c_str()); else UTIL_THROW2("Invalid specification of context window."); } - if (p == 2) + if (p == 2) { if (context_window.substr(0,2) == "+-" || context_window.substr(0,2) == "-+") look_back = look_ahead = atoi(context_window.substr(p).c_str()); - else + else UTIL_THROW2("Invalid specification of context window."); } } From 5173b9f6172cb695461b00826da935c2b2907c78 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Wed, 13 May 2015 11:29:16 +0100 Subject: [PATCH 2/2] beautify. Add sed for trailing spaces --- moses/BaseManager.cpp | 31 +++++------ moses/BaseManager.h | 6 +-- moses/HypergraphOutput.cpp | 22 ++++---- moses/Hypothesis.h | 2 +- moses/IOWrapper.cpp | 74 ++++++++++++-------------- moses/IOWrapper.h | 42 +++++++-------- moses/Incremental.h | 4 +- moses/InputType.h | 17 +++--- moses/Parameter.cpp | 4 +- moses/StaticData.h | 16 +++--- moses/Syntax/Manager.h | 4 +- moses/TranslationTask.cpp | 11 ++-- moses/Util.h | 2 +- moses/parameters/ContextParameters.cpp | 32 ++++++----- scripts/other/beautify.perl | 4 ++ 15 files changed, 130 insertions(+), 141 deletions(-) diff --git a/moses/BaseManager.cpp b/moses/BaseManager.cpp index 291b813f0..ce1a5c5d9 100644 --- a/moses/BaseManager.cpp +++ b/moses/BaseManager.cpp @@ -44,8 +44,8 @@ OutputSearchGraphAsHypergraph(std::string const& fname, size_t const precision) if (! boost::filesystem::exists(odir)) boost::filesystem::create_directory(odir); UTIL_THROW_IF2(!boost::filesystem::is_directory(odir), - "Cannot output hypergraphs to " << odir - << " because that path exists but is not a directory."); + "Cannot output hypergraphs to " << odir + << " because that path exists but is not a directory."); // not clear why we need to output the weights every time we dump a search // graph into a file again, but that's what the old code did. @@ -67,21 +67,18 @@ OutputSearchGraphAsHypergraph(std::string const& fname, size_t const precision) else if (boost::ends_with(fname, ".bz2")) file.push( boost::iostreams::bzip2_compressor() ); file.push( boost::iostreams::file_sink(fname, ios_base::out) ); - if (file.is_complete() && file.good()) - { - file.setf(std::ios::fixed); - file.precision(precision); - this->OutputSearchGraphAsHypergraph(file); - file.flush(); - } - else - { - TRACE_ERR("Cannot output hypergraph for line " - << this->GetSource().GetTranslationId() - << " because the output file " << fname - << " is not open or not ready for writing" - << std::endl); - } + if (file.is_complete() && file.good()) { + file.setf(std::ios::fixed); + file.precision(precision); + this->OutputSearchGraphAsHypergraph(file); + file.flush(); + } else { + TRACE_ERR("Cannot output hypergraph for line " + << this->GetSource().GetTranslationId() + << " because the output file " << fname + << " is not open or not ready for writing" + << std::endl); + } file.pop(); } diff --git a/moses/BaseManager.h b/moses/BaseManager.h index c24e41ad3..422b61c1f 100644 --- a/moses/BaseManager.h +++ b/moses/BaseManager.h @@ -66,13 +66,13 @@ public: // virtual void OutputSearchGraphHypergraph() const = 0; virtual void OutputSearchGraphAsHypergraph(std::ostream& out) const; - virtual void OutputSearchGraphAsHypergraph(std::string const& fname, - size_t const precision) const; + virtual void OutputSearchGraphAsHypergraph(std::string const& fname, + size_t const precision) const; /*** * to be called after processing a sentence */ virtual void CalcDecoderStatistics() const = 0; - + }; } diff --git a/moses/HypergraphOutput.cpp b/moses/HypergraphOutput.cpp index 470d35ba2..830f97ba8 100644 --- a/moses/HypergraphOutput.cpp +++ b/moses/HypergraphOutput.cpp @@ -50,7 +50,7 @@ template class HypergraphOutput; void ChartSearchGraphWriterMoses:: WriteHypos(const ChartHypothesisCollection& hypos, - const map &reachable) const + const map &reachable) const { ChartHypothesisCollection::const_iterator iter; @@ -62,16 +62,14 @@ WriteHypos(const ChartHypothesisCollection& hypos, } const ChartArcList *arcList = mainHypo.GetArcList(); - if (arcList) - { - ChartArcList::const_iterator iterArc; - for (iterArc = arcList->begin(); iterArc != arcList->end(); ++iterArc) - { - const ChartHypothesis &arc = **iterArc; - if (reachable.find(arc.GetId()) != reachable.end()) - (*m_out) << m_lineNumber << " " << arc << endl; - } + if (arcList) { + ChartArcList::const_iterator iterArc; + for (iterArc = arcList->begin(); iterArc != arcList->end(); ++iterArc) { + const ChartHypothesis &arc = **iterArc; + if (reachable.find(arc.GetId()) != reachable.end()) + (*m_out) << m_lineNumber << " " << arc << endl; } + } } } @@ -86,7 +84,7 @@ WriteHeader(size_t winners, size_t losers) const void ChartSearchGraphWriterHypergraph:: WriteHypos(const ChartHypothesisCollection& hypos, - const map &reachable) const + const map &reachable) const { ChartHypothesisCollection::const_iterator iter; @@ -114,7 +112,7 @@ WriteHypos(const ChartHypothesisCollection& hypos, } (*m_out) << edges.size() << endl; for (vector::const_iterator ei = edges.begin(); - ei != edges.end(); ++ei) { + ei != edges.end(); ++ei) { const ChartHypothesis* hypo = *ei; const TargetPhrase& target = hypo->GetCurrTargetPhrase(); size_t ntIndex = 0; diff --git a/moses/Hypothesis.h b/moses/Hypothesis.h index e1e95fbf3..0ce75b83c 100644 --- a/moses/Hypothesis.h +++ b/moses/Hypothesis.h @@ -313,7 +313,7 @@ struct CompareHypothesisTotalScore { ObjectPool &pool = Hypothesis::GetObjectPool(); \ pool.freeObject(hypo); \ } \ - + #else #define FREEHYPO(hypo) delete hypo #endif diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp index 1e93d868d..29769f180 100644 --- a/moses/IOWrapper.cpp +++ b/moses/IOWrapper.cpp @@ -101,7 +101,7 @@ IOWrapper::IOWrapper() m_inputType = staticData.GetInputType(); UTIL_THROW_IF2((m_look_ahead || m_look_back) && m_inputType != SentenceInput, - "Context-sensitive decoding currently works only with sentence input."); + "Context-sensitive decoding currently works only with sentence input."); m_currentLine = staticData.GetStartTranslationId(); @@ -224,17 +224,15 @@ IOWrapper::IOWrapper() // first, determine the output directory if (p && p->size() > 2) fmt = p->at(2); else if (nBestFilePath.size() && nBestFilePath != "-" && - ! boost::starts_with(nBestFilePath, "/dev/stdout")) - { - fmt = boost::filesystem::path(nBestFilePath).parent_path().string(); - if (fmt.empty()) fmt = "."; - } - else fmt = boost::filesystem::current_path().string() + "/hypergraph"; + ! boost::starts_with(nBestFilePath, "/dev/stdout")) { + fmt = boost::filesystem::path(nBestFilePath).parent_path().string(); + if (fmt.empty()) fmt = "."; + } else fmt = boost::filesystem::current_path().string() + "/hypergraph"; if (*fmt.rbegin() != '/') fmt += "/"; std::string extension = (p && p->size() > 1 ? p->at(1) : std::string("txt")); UTIL_THROW_IF2(extension != "txt" && extension != "gz" && extension != "bz2", - "Unknown compression type '" << extension - << "' for hypergraph output!"); + "Unknown compression type '" << extension + << "' for hypergraph output!"); fmt += string("%d.") + extension; if (staticData.GetParameter().GetParam("spe-src")) { @@ -304,11 +302,10 @@ IOWrapper::ReadInput() boost::lock_guard lock(m_lock); #endif boost::shared_ptr source = GetBufferedInput(); - if (source) - { - source->SetTranslationId(m_currentLine++); - this->set_context_for(*source); - } + if (source) { + source->SetTranslationId(m_currentLine++); + this->set_context_for(*source); + } m_past_input.push_back(source); return source; } @@ -320,37 +317,32 @@ set_context_for(InputType& source) boost::shared_ptr context(new string); list >::iterator m = m_past_input.end(); // remove obsolete past input from buffer: - if (m_past_input.end() != m_past_input.begin()) - { - for (size_t cnt = 0; cnt < m_look_back && --m != m_past_input.begin(); - cnt += (*m)->GetSize()); - while (m_past_input.begin() != m) m_past_input.pop_front(); - } + if (m_past_input.end() != m_past_input.begin()) { + for (size_t cnt = 0; cnt < m_look_back && --m != m_past_input.begin(); + cnt += (*m)->GetSize()); + while (m_past_input.begin() != m) m_past_input.pop_front(); + } // cerr << string(80,'=') << endl; - if (m_past_input.size()) - { - m = m_past_input.begin(); - *context += (*m)->ToString(); - // cerr << (*m)->ToString() << endl; - for (++m; m != m_past_input.end(); ++m) - { - // cerr << "\n" << (*m)->ToString() << endl; - *context += string(" ") + (*m)->ToString(); - } - // cerr << string(80,'-') << endl; + if (m_past_input.size()) { + m = m_past_input.begin(); + *context += (*m)->ToString(); + // cerr << (*m)->ToString() << endl; + for (++m; m != m_past_input.end(); ++m) { + // cerr << "\n" << (*m)->ToString() << endl; + *context += string(" ") + (*m)->ToString(); } + // cerr << string(80,'-') << endl; + } // cerr << source.ToString() << endl; - if (m_future_input.size()) - { - // cerr << string(80,'-') << endl; - for (m = m_future_input.begin(); m != m_future_input.end(); ++m) - { - // if (m != m_future_input.begin()) cerr << "\n"; - // cerr << (*m)->ToString() << endl; - if (context->size()) *context += " "; - *context += (*m)->ToString(); - } + if (m_future_input.size()) { + // cerr << string(80,'-') << endl; + for (m = m_future_input.begin(); m != m_future_input.end(); ++m) { + // if (m != m_future_input.begin()) cerr << "\n"; + // cerr << (*m)->ToString() << endl; + if (context->size()) *context += " "; + *context += (*m)->ToString(); } + } // cerr << string(80,'=') << endl; source.SetContext(context); } diff --git a/moses/IOWrapper.h b/moses/IOWrapper.h index 07acf6e77..f1bcefa92 100644 --- a/moses/IOWrapper.h +++ b/moses/IOWrapper.h @@ -119,7 +119,7 @@ protected: size_t m_look_ahead; /// for context-sensitive decoding: # of wrds to look ahead size_t m_look_back; /// for context-sensitive decoding: # of wrds to look back size_t m_buffered_ahead; /// number of words buffered ahead - // For context-sensitive decoding: + // For context-sensitive decoding: // Number of context words ahead and before the current sentence. std::string m_hypergraph_output_filepattern; @@ -184,14 +184,14 @@ public: std::ifstream *spe_src, *spe_trg, *spe_aln; private: - template + template boost::shared_ptr BufferInput(); boost::shared_ptr GetBufferedInput(); - void + void set_context_for(InputType& source); }; @@ -202,27 +202,23 @@ BufferInput() { boost::shared_ptr source; boost::shared_ptr ret; - if (m_future_input.size()) - { - ret = m_future_input.front(); - m_future_input.pop_front(); - m_buffered_ahead -= ret->GetSize(); - } - else - { - source.reset(new itype); - if (!source->Read(*m_inputStream, *m_inputFactorOrder)) - return ret; - ret = source; - } + if (m_future_input.size()) { + ret = m_future_input.front(); + m_future_input.pop_front(); + m_buffered_ahead -= ret->GetSize(); + } else { + source.reset(new itype); + if (!source->Read(*m_inputStream, *m_inputFactorOrder)) + return ret; + ret = source; + } - while (m_buffered_ahead < m_look_ahead) - { - source.reset(new itype); - if (!source->Read(*m_inputStream, *m_inputFactorOrder)) break; - m_future_input.push_back(source); - m_buffered_ahead += source->GetSize(); - } + while (m_buffered_ahead < m_look_ahead) { + source.reset(new itype); + if (!source->Read(*m_inputStream, *m_inputFactorOrder)) break; + m_future_input.push_back(source); + m_buffered_ahead += source->GetSize(); + } return ret; } diff --git a/moses/Incremental.h b/moses/Incremental.h index 3f679d57c..1ef78e8ac 100644 --- a/moses/Incremental.h +++ b/moses/Incremental.h @@ -57,9 +57,9 @@ public: void OutputSearchGraphSLF() const { } - void + void OutputSearchGraphAsHypergraph - ( std::string const& fname, size_t const precision ) const + ( std::string const& fname, size_t const precision ) const { } diff --git a/moses/InputType.h b/moses/InputType.h index 398af0cbf..655823a3f 100644 --- a/moses/InputType.h +++ b/moses/InputType.h @@ -173,13 +173,16 @@ public: //! number of words in this sentence/confusion network virtual size_t GetSize() const =0; - virtual boost::shared_ptr const& - GetContext() const { return m_context; } - - virtual void - SetContext(boost::shared_ptr const& ctx) - { m_context = ctx; } - + virtual boost::shared_ptr const& + GetContext() const { + return m_context; + } + + virtual void + SetContext(boost::shared_ptr const& ctx) { + m_context = ctx; + } + //! populate this InputType with data from in stream virtual int Read(std::istream& in,const std::vector& factorOrder) =0; diff --git a/moses/Parameter.cpp b/moses/Parameter.cpp index 599d70938..33441570f 100644 --- a/moses/Parameter.cpp +++ b/moses/Parameter.cpp @@ -241,9 +241,9 @@ Parameter::Parameter() AddParam(misc_opts,"feature", "All the feature functions should be here"); AddParam(misc_opts,"context-string", - "A (tokenized) string containing context words for context-sensitive translation."); + "A (tokenized) string containing context words for context-sensitive translation."); AddParam(misc_opts,"context-window", - "Context window (in words) for context-sensitive translation: {+|-|+-}."); + "Context window (in words) for context-sensitive translation: {+|-|+-}."); // Compact phrase table and reordering table. po::options_description cpt_opts("Options when using compact phrase and reordering tables."); diff --git a/moses/StaticData.h b/moses/StaticData.h index 20b8f1506..7e71f0881 100644 --- a/moses/StaticData.h +++ b/moses/StaticData.h @@ -301,7 +301,9 @@ public: } const ContextParameters& - GetContextParameters() const { return m_context_parameters; } + GetContextParameters() const { + return m_context_parameters; + } const std::vector &GetInputFactorOrder() const { return m_inputFactorOrder; @@ -449,15 +451,15 @@ public: } bool IsNBestEnabled() const { - return (!m_nBestFilePath.empty() || m_mbr || m_useLatticeMBR || m_mira || - m_outputSearchGraph || m_outputSearchGraphSLF || - m_outputSearchGraphHypergraph || m_useConsensusDecoding || + return (!m_nBestFilePath.empty() || m_mbr || m_useLatticeMBR || m_mira || + m_outputSearchGraph || m_outputSearchGraphSLF || + m_outputSearchGraphHypergraph || m_useConsensusDecoding || #ifdef HAVE_PROTOBUF - m_outputSearchGraphPB || + m_outputSearchGraphPB || #endif - !m_latticeSamplesFilePath.empty()); + !m_latticeSamplesFilePath.empty()); } - + size_t GetLatticeSamplesSize() const { return m_latticeSamplesSize; } diff --git a/moses/Syntax/Manager.h b/moses/Syntax/Manager.h index 8e26e0679..d62e2f72a 100644 --- a/moses/Syntax/Manager.h +++ b/moses/Syntax/Manager.h @@ -31,9 +31,9 @@ public: void OutputSearchGraph(OutputCollector *collector) const {} // void OutputSearchGraphHypergraph() const {} - void + void OutputSearchGraphAsHypergraph - ( std::string const& fname, size_t const precision ) const + ( std::string const& fname, size_t const precision ) const { } void OutputSearchGraphSLF() const {} diff --git a/moses/TranslationTask.cpp b/moses/TranslationTask.cpp index 190bb0b7e..61cdfc162 100644 --- a/moses/TranslationTask.cpp +++ b/moses/TranslationTask.cpp @@ -178,12 +178,11 @@ void TranslationTask::Run() // Output search graph in hypergraph format for Kenneth Heafield's // lazy hypergraph decoder; writes to stderr - if (StaticData::Instance().GetOutputSearchGraphHypergraph()) - { - size_t transId = manager->GetSource().GetTranslationId(); - string fname = io->GetHypergraphOutputFileName(transId); - manager->OutputSearchGraphAsHypergraph(fname, PRECISION); - } + if (StaticData::Instance().GetOutputSearchGraphHypergraph()) { + size_t transId = manager->GetSource().GetTranslationId(); + string fname = io->GetHypergraphOutputFileName(transId); + manager->OutputSearchGraphAsHypergraph(fname, PRECISION); + } additionalReportingTime.stop(); diff --git a/moses/Util.h b/moses/Util.h index 43443eb02..b6d4ef613 100644 --- a/moses/Util.h +++ b/moses/Util.h @@ -427,7 +427,7 @@ inline float CalcTranslationScore(const std::vector &probVector, out << *this; \ return out.str(); \ } \ - + //! delete and remove every element of a collection object such as set, list etc template void RemoveAllInColl(COLL &coll) diff --git a/moses/parameters/ContextParameters.cpp b/moses/parameters/ContextParameters.cpp index b88945878..76f529e67 100644 --- a/moses/parameters/ContextParameters.cpp +++ b/moses/parameters/ContextParameters.cpp @@ -23,22 +23,20 @@ init(Parameter& params) size_t p = context_window.find_first_of("0123456789"); if (p == 0) look_back = look_ahead = atoi(context_window.c_str()); - if (p == 1) - { - if (context_window[0] == '-') - look_back = atoi(context_window.substr(1).c_str()); - else if (context_window[0] == '+') - look_ahead = atoi(context_window.substr(1).c_str()); - else - UTIL_THROW2("Invalid specification of context window."); - } - if (p == 2) - { - if (context_window.substr(0,2) == "+-" || - context_window.substr(0,2) == "-+") - look_back = look_ahead = atoi(context_window.substr(p).c_str()); - else - UTIL_THROW2("Invalid specification of context window."); - } + if (p == 1) { + if (context_window[0] == '-') + look_back = atoi(context_window.substr(1).c_str()); + else if (context_window[0] == '+') + look_ahead = atoi(context_window.substr(1).c_str()); + else + UTIL_THROW2("Invalid specification of context window."); + } + if (p == 2) { + if (context_window.substr(0,2) == "+-" || + context_window.substr(0,2) == "-+") + look_back = look_ahead = atoi(context_window.substr(p).c_str()); + else + UTIL_THROW2("Invalid specification of context window."); + } } } diff --git a/scripts/other/beautify.perl b/scripts/other/beautify.perl index 130afd56b..c3438ace1 100755 --- a/scripts/other/beautify.perl +++ b/scripts/other/beautify.perl @@ -56,6 +56,10 @@ sub Beautify($) my $cmd = "astyle --style='k&r' -s2 -v $name"; #print STDERR "Executing: $cmd \n"; `$cmd`; + + $cmd = "sed -i 's\/[ \\t]*\$\/\/' \"$name\""; + #print STDERR "Executing: $cmd \n"; + `$cmd`; } } }