Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2013-04-23 11:36:24 +0400
committerKenneth Heafield <github@kheafield.com>2013-04-23 11:36:24 +0400
commit8a1e944bb428a0af9f6c82c26e5633361ce4052c (patch)
tree085bead007e147a22c6c602ae246bf95e4d29a5c /moses/Phrase.cpp
parent908c006e320bafa030896428ae3648d32b2094cb (diff)
Error messages
Diffstat (limited to 'moses/Phrase.cpp')
-rw-r--r--moses/Phrase.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/moses/Phrase.cpp b/moses/Phrase.cpp
index d5696b763..2e020ef69 100644
--- a/moses/Phrase.cpp
+++ b/moses/Phrase.cpp
@@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "Phrase.h"
#include "StaticData.h" // GetMaxNumFactors
+#include "util/exception.hh"
#include "util/string_piece.hh"
#include "util/tokenize_piece.hh"
@@ -174,6 +175,8 @@ void Phrase::CreateFromString(const std::vector<FactorType> &factorOrder, const
}
}
+class NonTerminalParseException : public util::Exception {};
+
void Phrase::CreateFromStringNewFormat(FactorDirection direction
, const std::vector<FactorType> &factorOrder
, const StringPiece &phraseString
@@ -199,6 +202,7 @@ void Phrase::CreateFromStringNewFormat(FactorDirection direction
isNonTerminal = true;
size_t nextPos = annotatedWord.find('[', 1);
+ UTIL_THROW_IF(nextPos == string::npos, NonTerminalParseException, "The string " << annotatedWord << " was parsed as a non-terminal but does not take the form [source][target].");
CHECK(nextPos != string::npos);
if (direction == Input)
@@ -216,8 +220,7 @@ void Phrase::CreateFromStringNewFormat(FactorDirection direction
// lhs
const StringPiece &annotatedWord = annotatedWordVector.back();
- CHECK(annotatedWord.size() >= 2 && *annotatedWord.data() == '[' && annotatedWord.data()[annotatedWord.size() - 1] == ']');
-
+ UTIL_THROW_IF(annotatedWord.size() < 2 || *annotatedWord.data() != '[' || annotatedWord.data()[annotatedWord.size() - 1] != ']', NonTerminalParseException, "The last entry should be a single non-terminal but was given as " << annotatedWord);
lhs.CreateFromString(direction, factorOrder, annotatedWord.substr(1, annotatedWord.size() - 2), true);
assert(lhs.IsNonTerminal());
}