diff options
author | siddharth jain <sija@microsoft.com> | 2020-11-23 14:50:33 +0300 |
---|---|---|
committer | siddharth jain <sija@microsoft.com> | 2020-11-23 14:50:33 +0300 |
commit | b46da0dc507fd8bb34357647f7eae9a9cd7f49ad (patch) | |
tree | 10f703d664a97efc6384b95223bd2098b34587e5 | |
parent | bfc0bc57a34f64ae9a83a2ba181def04deb56ff4 (diff) |
appending relative path to lm at runtime
-rw-r--r-- | moses2/Moses2Wrapper.cpp | 29 | ||||
-rw-r--r-- | moses2/Moses2Wrapper.h | 2 |
2 files changed, 30 insertions, 1 deletions
diff --git a/moses2/Moses2Wrapper.cpp b/moses2/Moses2Wrapper.cpp index 343ddfa3b..c699bfd5e 100644 --- a/moses2/Moses2Wrapper.cpp +++ b/moses2/Moses2Wrapper.cpp @@ -4,9 +4,38 @@ #include "TranslationTask.h" using namespace std; namespace Moses2 { + //summary :: need to update the LM path at runtime with complete artifact path. + void Moses2Wrapper::UpdateLMPath(const std::string& filePath) { + auto file = filePath.substr(filePath.find_last_of("\\") + 1); + auto path = filePath.substr(0, filePath.find_last_of("\\")); + auto a = m_param->GetParam("feature"); + std::vector<std::string> feature; + for (int i = 0; i < a->size(); i++) { + auto abc = Tokenize(a->at(i)); + if (*abc.begin() == "KENLM") { + string s = ""; + for (int k = 0; k < abc.size(); k++) { + if (abc.at(k).find("path=") != string::npos) { + auto lm = abc.at(k).substr(abc.at(k).find_last_of("=") + 1); + s = s + "path=" + path + "\\" + lm + " "; + } + else { + s = s + abc.at(k) + " "; + } + } + feature.push_back(s.erase(s.find_last_not_of(" \n\r\t") + 1)); + } + else { + feature.push_back(a->at(i)); + } + } + m_param->OverwriteParam("feature", feature); + } + Moses2Wrapper::Moses2Wrapper(const std::string &filePath) { m_param = new Parameter(); m_param->LoadParam(filePath); + UpdateLMPath(filePath); m_system = new System(*m_param); } std::string Moses2Wrapper::Translate(const std::string &input , long id) { diff --git a/moses2/Moses2Wrapper.h b/moses2/Moses2Wrapper.h index 21aa19388..1a815e38f 100644 --- a/moses2/Moses2Wrapper.h +++ b/moses2/Moses2Wrapper.h @@ -12,7 +12,7 @@ namespace Moses2 { Moses2Wrapper(const std::string &filePath); ~Moses2Wrapper(); std::string Translate(const std::string &input, long id); - Moses2Wrapper* getInstance(const std::string& filePath); + void UpdateLMPath(const std::string &filePath); int getEngineVersion(); }; |