replace CHECK with UTIL_THROW_IF in Moses

This commit is contained in:
Hieu Hoang 2013-11-21 14:55:41 +00:00
parent 8381f0c95c
commit 3c0eaac9a3
3 changed files with 25 additions and 18 deletions

View File

@ -57,7 +57,7 @@ public:
const WordsRange* m_transOptRange;
bool operator()(const Hypothesis* hypoA, const Hypothesis* hypoB) const {
CHECK(m_transOptRange != NULL);
UTIL_THROW_IF2(m_transOptRange == NULL, "Words range not set");
const StaticData &staticData = StaticData::Instance();
@ -160,11 +160,13 @@ BackwardsEdge::BackwardsEdge(const BitmapContainer &prevBitmapContainer
}
if (m_translations.size() > 1) {
CHECK(m_translations.Get(0)->GetFutureScore() >= m_translations.Get(1)->GetFutureScore());
UTIL_THROW_IF2(m_translations.Get(0)->GetFutureScore() < m_translations.Get(1)->GetFutureScore(),
"Non-monotonic future score");
}
if (m_hypotheses.size() > 1) {
CHECK(m_hypotheses[0]->GetTotalScore() >= m_hypotheses[1]->GetTotalScore());
UTIL_THROW_IF2(m_hypotheses[0]->GetTotalScore() < m_hypotheses[1]->GetTotalScore(),
"Non-monotonic total score");
}
HypothesisScoreOrdererWithDistortion orderer (&transOptRange);
@ -213,8 +215,8 @@ BackwardsEdge::SeenPosition(const size_t x, const size_t y)
void
BackwardsEdge::SetSeenPosition(const size_t x, const size_t y)
{
CHECK(x < (1<<17));
CHECK(y < (1<<17));
UTIL_THROW_IF2(x >= (1<<17), "Error");
UTIL_THROW_IF2(y >= (1<<17), "Error");
m_seenPosition.insert((x<<16) + y);
}
@ -378,7 +380,7 @@ BitmapContainer::AddHypothesis(Hypothesis *hypothesis)
++iter;
}
CHECK(itemExists == false);
UTIL_THROW_IF2(itemExists, "Duplicate hypotheses");
m_hypotheses.push_back(hypothesis);
}
@ -421,12 +423,13 @@ BitmapContainer::ProcessBestHypothesis()
HypothesisQueueItem *item = Dequeue();
// If the priority queue is exhausted, we are done and should have exited
CHECK(item != NULL);
UTIL_THROW_IF2(item == NULL, "Null object");
// check we are pulling things off of priority queue in right order
if (!Empty()) {
HypothesisQueueItem *check = Dequeue(true);
CHECK(item->GetHypothesis()->GetTotalScore() >= check->GetHypothesis()->GetTotalScore());
UTIL_THROW_IF2(item->GetHypothesis()->GetTotalScore() < check->GetHypothesis()->GetTotalScore(),
"Non-monotonic total score");
}
// Logging for the criminally insane

View File

@ -83,7 +83,7 @@ void ChartParserUnknown::Process(const Word &sourceWord, const WordsRange &range
Word *targetLHS = new Word(true);
targetLHS->CreateFromString(Output, staticData.GetOutputFactorOrder(), targetLHSStr, true);
CHECK(targetLHS->GetFactor(0) != NULL);
UTIL_THROW_IF2(targetLHS->GetFactor(0) == NULL, "Null factor for target LHS");
// add to dictionary
TargetPhrase *targetPhrase = new TargetPhrase();
@ -119,7 +119,7 @@ void ChartParserUnknown::Process(const Word &sourceWord, const WordsRange &range
Word *targetLHS = new Word(true);
targetLHS->CreateFromString(Output, staticData.GetOutputFactorOrder(), targetLHSStr, true);
CHECK(targetLHS->GetFactor(0) != NULL);
UTIL_THROW_IF2(targetLHS->GetFactor(0) == NULL, "Null factor for target LHS");
targetPhrase->GetScoreBreakdown().Assign(unknownWordPenaltyProducer, unknownScore);
targetPhrase->Evaluate(*unksrc);
@ -204,7 +204,8 @@ void ChartParser::CreateInputPaths(const InputType &input)
size_t size = input.GetSize();
m_inputPathMatrix.resize(size);
CHECK(input.GetType() == SentenceInput || input.GetType() == TreeInputType);
UTIL_THROW_IF2(input.GetType() != SentenceInput && input.GetType() != TreeInputType,
"Input must be a sentence or a tree, not lattice or confusion networks");
for (size_t phaseSize = 1; phaseSize <= size; ++phaseSize) {
for (size_t startPos = 0; startPos < size - phaseSize + 1; ++startPos) {
size_t endPos = startPos + phaseSize -1;
@ -237,14 +238,16 @@ const InputPath &ChartParser::GetInputPath(WordsRange &range) const
const InputPath &ChartParser::GetInputPath(size_t startPos, size_t endPos) const
{
size_t offset = endPos - startPos;
CHECK(offset < m_inputPathMatrix[startPos].size());
UTIL_THROW_IF2(offset >= m_inputPathMatrix[startPos].size(),
"Out of bound: " << offset);
return *m_inputPathMatrix[startPos][offset];
}
InputPath &ChartParser::GetInputPath(size_t startPos, size_t endPos)
{
size_t offset = endPos - startPos;
CHECK(offset < m_inputPathMatrix[startPos].size());
UTIL_THROW_IF2(offset >= m_inputPathMatrix[startPos].size(),
"Out of bound: " << offset);
return *m_inputPathMatrix[startPos][offset];
}
/*

View File

@ -58,7 +58,7 @@ Phrase::~Phrase()
void Phrase::MergeFactors(const Phrase &copy)
{
CHECK(GetSize() == copy.GetSize());
UTIL_THROW_IF2(GetSize() != copy.GetSize(), "Both phrases need to be the same size to merge");
size_t size = GetSize();
const size_t maxNumFactors = MAX_NUM_FACTORS;
for (size_t currPos = 0 ; currPos < size ; currPos++) {
@ -73,14 +73,14 @@ void Phrase::MergeFactors(const Phrase &copy)
void Phrase::MergeFactors(const Phrase &copy, FactorType factorType)
{
CHECK(GetSize() == copy.GetSize());
UTIL_THROW_IF2(GetSize() != copy.GetSize(), "Both phrases need to be the same size to merge");
for (size_t currPos = 0 ; currPos < GetSize() ; currPos++)
SetFactor(currPos, factorType, copy.GetFactor(currPos, factorType));
}
void Phrase::MergeFactors(const Phrase &copy, const std::vector<FactorType>& factorVec)
{
CHECK(GetSize() == copy.GetSize());
UTIL_THROW_IF2(GetSize() != copy.GetSize(), "Both phrases need to be the same size to merge");
for (size_t currPos = 0 ; currPos < GetSize() ; currPos++)
for (std::vector<FactorType>::const_iterator i = factorVec.begin();
i != factorVec.end(); ++i) {
@ -194,7 +194,6 @@ void Phrase::CreateFromString(FactorDirection direction
assert((*lhs)->IsNonTerminal());
} else {
numWords = annotatedWordVector.size();
//CHECK(lhs == NULL);
if (lhs) {
(*lhs) = NULL;
}
@ -211,7 +210,9 @@ void Phrase::CreateFromString(FactorDirection direction
isNonTerminal = true;
size_t nextPos = annotatedWord.find('[', 1);
CHECK(nextPos != string::npos);
UTIL_THROW_IF2(nextPos == string::npos,
"Incorrect formatting of non-terminal. Should have 2 non-terms, eg. [X][X]. "
<< "Current string: " << annotatedWord);
if (direction == Input)
annotatedWord = annotatedWord.substr(1, nextPos - 2);