diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-02-06 18:52:25 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-02-06 18:52:25 +0300 |
commit | 755bd609f506fa6ce68a935f72499e055a6a4b6c (patch) | |
tree | 188ac45b2f1089c3df7ac5434fa87eeaeb925df0 /moses | |
parent | 4145999e3335592576bf2d4154834dcfe16e0a56 (diff) |
Using boost for prefix/suffix checks /Jeroen Vermeulen
Diffstat (limited to 'moses')
-rw-r--r-- | moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp index 90d5575a1..9c3f6b513 100644 --- a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp +++ b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include <queue> #include <algorithm> #include <sys/stat.h> +#include <boost/algorithm/string/predicate.hpp> #include "PhraseDictionaryCompact.h" #include "moses/FactorCollection.h" @@ -37,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "util/exception.hh" using namespace std; +using namespace boost::algorithm; namespace Moses { @@ -63,18 +65,9 @@ void PhraseDictionaryCompact::Load() std::string tFilePath = m_filePath; std::string suffix = ".minphr"; - if(tFilePath.substr(tFilePath.length() - suffix.length(), suffix.length()) == suffix) { - if(!FileExists(tFilePath)) { - throw runtime_error("Error: File " + tFilePath + " does not exit."); - exit(1); - } - } else { - if(FileExists(tFilePath + suffix)) { - tFilePath += suffix; - } else { - throw runtime_error("Error: File " + tFilePath + ".minphr does not exit."); - } - } + if (!ends_with(tFilePath, suffix)) tFilePath += suffix; + if (!FileExists(tFilePath)) + throw runtime_error("Error: File " + tFilePath + " does not exist."); m_phraseDecoder = new PhraseDecoder(*this, &m_input, &m_output, m_numScoreComponents, &m_weight); |