diff options
author | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-12-07 19:07:11 +0300 |
---|---|---|
committer | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-12-07 19:07:11 +0300 |
commit | c4e45fb128e096f255a624b57b7826febdf06f2e (patch) | |
tree | 74455d64b0e45877c91dc2488838cfe01732b224 /moses/FF | |
parent | 2be2481feb2d68d6e4ba366d06fcfa51f7ff664e (diff) |
Code cleanup.
Diffstat (limited to 'moses/FF')
-rw-r--r-- | moses/FF/ConstrainedDecoding.cpp | 13 | ||||
-rw-r--r-- | moses/FF/ConstrainedDecoding.h | 2 | ||||
-rw-r--r-- | moses/FF/InternalTree.cpp | 21 | ||||
-rw-r--r-- | moses/FF/InternalTree.h | 1 | ||||
-rw-r--r-- | moses/FF/SoftMatchingFeature.cpp | 15 |
5 files changed, 30 insertions, 22 deletions
diff --git a/moses/FF/ConstrainedDecoding.cpp b/moses/FF/ConstrainedDecoding.cpp index 2ae2bffcc..eaf85b382 100644 --- a/moses/FF/ConstrainedDecoding.cpp +++ b/moses/FF/ConstrainedDecoding.cpp @@ -46,13 +46,12 @@ ConstrainedDecoding::ConstrainedDecoding(const std::string &line) ReadParameters(); } -void ConstrainedDecoding::Load() +void ConstrainedDecoding::Load(AllOptions const& opts) { const StaticData &staticData = StaticData::Instance(); bool addBeginEndWord - = ((staticData.options().search.algo == CYKPlus) - || (staticData.options().search.algo == ChartIncremental)); - + = ((opts.search.algo == CYKPlus) || (opts.search.algo == ChartIncremental)); + for(size_t i = 0; i < m_paths.size(); ++i) { InputFileStream constraintFile(m_paths[i]); std::string line; @@ -63,12 +62,10 @@ void ConstrainedDecoding::Load() Phrase phrase(0); if (vecStr.size() == 1) { sentenceID++; - // phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[0], staticData.GetFactorDelimiter(), NULL); - phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[0], NULL); + phrase.CreateFromString(Output, opts.output.factor_order, vecStr[0], NULL); } else if (vecStr.size() == 2) { sentenceID = Scan<long>(vecStr[0]); - // phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[1], staticData.GetFactorDelimiter(), NULL); - phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[1], NULL); + phrase.CreateFromString(Output, opts.output.factor_order, vecStr[1], NULL); } else { UTIL_THROW(util::Exception, "Reference file not loaded"); } diff --git a/moses/FF/ConstrainedDecoding.h b/moses/FF/ConstrainedDecoding.h index 769edd80f..955bc06df 100644 --- a/moses/FF/ConstrainedDecoding.h +++ b/moses/FF/ConstrainedDecoding.h @@ -36,7 +36,7 @@ class ConstrainedDecoding : public StatefulFeatureFunction public: ConstrainedDecoding(const std::string &line); - void Load(); + void Load(AllOptions const& opts); bool IsUseable(const FactorMask &mask) const { return true; diff --git a/moses/FF/InternalTree.cpp b/moses/FF/InternalTree.cpp index c38fc5747..6e6d878cd 100644 --- a/moses/FF/InternalTree.cpp +++ b/moses/FF/InternalTree.cpp @@ -7,8 +7,11 @@ namespace Moses InternalTree::InternalTree(const std::string & line, size_t start, size_t len, const bool nonterminal) { + std::vector<FactorType> const& oFactors + = StaticData::Instance().options().output.factor_order; if (len > 0) { - m_value.CreateFromString(Output, StaticData::Instance().GetOutputFactorOrder(), StringPiece(line).substr(start, len), nonterminal); + m_value.CreateFromString(Output, oFactors, StringPiece(line).substr(start, len), + nonterminal); } } @@ -18,7 +21,9 @@ InternalTree::InternalTree(const std::string & line, const bool nonterminal) size_t found = line.find_first_of("[] "); if (found == line.npos) { - m_value.CreateFromString(Output, StaticData::Instance().GetOutputFactorOrder(), line, nonterminal); + m_value.CreateFromString(Output, + StaticData::Instance().options().output.factor_order, + line, nonterminal); } else { AddSubTree(line, 0); } @@ -44,14 +49,18 @@ size_t InternalTree::AddSubTree(const std::string & line, size_t pos) pos = m_children.back()->AddSubTree(line, pos+1); } else { if (len > 0) { - m_value.CreateFromString(Output, StaticData::Instance().GetOutputFactorOrder(), StringPiece(line).substr(oldpos, len), false); + m_value.CreateFromString(Output, + StaticData::Instance().options().output.factor_order, + StringPiece(line).substr(oldpos, len), false); has_value = true; } pos = AddSubTree(line, pos+1); } } else if (token == ' ' || token == ']') { if (len > 0 && !has_value) { - m_value.CreateFromString(Output, StaticData::Instance().GetOutputFactorOrder(), StringPiece(line).substr(oldpos, len), true); + m_value.CreateFromString(Output, + StaticData::Instance().options().output.factor_order, + StringPiece(line).substr(oldpos, len), true); has_value = true; } else if (len > 0) { m_children.push_back(boost::make_shared<InternalTree>(line, oldpos, len, false)); @@ -81,7 +90,7 @@ std::string InternalTree::GetString(bool start) const ret += "["; } - ret += m_value.GetString(StaticData::Instance().GetOutputFactorOrder(), false); + ret += m_value.GetString(StaticData::Instance().options().output.factor_order, false); for (std::vector<TreePointer>::const_iterator it = m_children.begin(); it != m_children.end(); ++it) { ret += (*it)->GetString(false); } @@ -189,4 +198,4 @@ bool InternalTree::RecursiveSearch(const Word & label, std::vector<TreePointer>: return false; } -}
\ No newline at end of file +} diff --git a/moses/FF/InternalTree.h b/moses/FF/InternalTree.h index 29db0241e..165355d06 100644 --- a/moses/FF/InternalTree.h +++ b/moses/FF/InternalTree.h @@ -6,6 +6,7 @@ #include <vector> #include "FFState.h" #include "moses/Word.h" +#include "moses/StaticData.h" #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> #include "util/generator.hh" diff --git a/moses/FF/SoftMatchingFeature.cpp b/moses/FF/SoftMatchingFeature.cpp index 1bdfe70c2..830b82829 100644 --- a/moses/FF/SoftMatchingFeature.cpp +++ b/moses/FF/SoftMatchingFeature.cpp @@ -38,7 +38,7 @@ void SoftMatchingFeature::SetParameter(const std::string& key, const std::string bool SoftMatchingFeature::Load(const std::string& filePath) { - StaticData &staticData = StaticData::InstanceNonConst(); + StaticData &SD = StaticData::InstanceNonConst(); InputFileStream inStream(filePath); std::string line; @@ -52,14 +52,14 @@ bool SoftMatchingFeature::Load(const std::string& filePath) } Word LHS, RHS; - LHS.CreateFromString(Output, staticData.GetOutputFactorOrder(), tokens[0], true); - RHS.CreateFromString(Output, staticData.GetOutputFactorOrder(), tokens[1], true); + LHS.CreateFromString(Output, SD.options().output.factor_order, tokens[0], true); + RHS.CreateFromString(Output, SD.options().output.factor_order, tokens[1], true); m_softMatches[RHS[0]->GetId()].push_back(LHS); GetOrSetFeatureName(RHS, LHS); } - staticData.SetSoftMatches(m_softMatches); + SD.SetSoftMatches(m_softMatches); return true; } @@ -124,9 +124,10 @@ const std::string& SoftMatchingFeature::GetOrSetFeatureName(const Word& RHS, con boost::unique_lock<boost::shared_mutex> lock(m_accessLock); #endif std::string &name = m_nameCache[RHS[0]->GetId()][LHS[0]->GetId()]; - const std::vector<FactorType> &outputFactorOrder = StaticData::Instance().GetOutputFactorOrder(); - std::string LHS_string = LHS.GetString(outputFactorOrder, false); - std::string RHS_string = RHS.GetString(outputFactorOrder, false); + const std::vector<FactorType> & oFactors + = StaticData::Instance().options().output.factor_order; + std::string LHS_string = LHS.GetString(oFactors, false); + std::string RHS_string = RHS.GetString(oFactors, false); name = LHS_string + "->" + RHS_string; return name; } |