mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
replace CHECK with UTIL_THROW_IF in Moses
This commit is contained in:
parent
c2c86ce50d
commit
22864c2b4b
@ -107,7 +107,7 @@ void BleuScoreFeature::SetParameter(const std::string& key, const std::string& v
|
||||
{
|
||||
if (key == "references") {
|
||||
vector<string> referenceFiles = Tokenize(value, ",");
|
||||
CHECK(referenceFiles.size());
|
||||
UTIL_THROW_IF(referenceFiles.size() == 0, util::Exception, "No reference file");
|
||||
vector<vector<string> > references(referenceFiles.size());
|
||||
|
||||
for (size_t i =0; i < referenceFiles.size(); ++i) {
|
||||
|
@ -49,7 +49,8 @@ int ControlRecombinationState::Compare(const FFState& other) const
|
||||
|
||||
std::vector<float> ControlRecombination::DefaultWeights() const
|
||||
{
|
||||
CHECK(m_numScoreComponents == 0);
|
||||
UTIL_THROW_IF(m_numScoreComponents, util::Exception,
|
||||
"ControlRecombination should not have any scores");
|
||||
vector<float> ret(0);
|
||||
return ret;
|
||||
}
|
||||
|
@ -13,7 +13,8 @@ namespace Moses
|
||||
GlobalLexicalModelUnlimited::GlobalLexicalModelUnlimited(const std::string &line)
|
||||
:StatelessFeatureFunction(0, line)
|
||||
{
|
||||
CHECK(false); // TODO need to update arguments to key=value
|
||||
UTIL_THROW(util::Exception,
|
||||
"GlobalLexicalModelUnlimited hasn't been refactored for new feature function framework yet"); // TODO need to update arguments to key=value
|
||||
|
||||
const vector<string> modelSpec = Tokenize(line);
|
||||
|
||||
|
@ -32,9 +32,7 @@ void OpSequenceModel :: readLanguageModel(const char *lmFile)
|
||||
|
||||
void OpSequenceModel::Load()
|
||||
{
|
||||
|
||||
readLanguageModel(m_lmPath.c_str());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -84,7 +84,8 @@ void SourceWordDeletionFeature::ComputeFeatures(const Phrase &source,
|
||||
|
||||
// flag aligned words
|
||||
bool aligned[16];
|
||||
CHECK(sourceLength < 16);
|
||||
UTIL_THROW_IF(sourceLength >= 16, util::Exception,
|
||||
"Source length must be less than 16 words");
|
||||
for(size_t i=0; i<sourceLength; i++)
|
||||
aligned[i] = false;
|
||||
for (AlignmentInfo::const_iterator alignmentPoint = alignmentInfo.begin(); alignmentPoint != alignmentInfo.end(); alignmentPoint++)
|
||||
|
@ -69,7 +69,7 @@ FFState* TargetBigramFeature::Evaluate(const Hypothesis& cur_hypo,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{
|
||||
const TargetBigramState* tbState = dynamic_cast<const TargetBigramState*>(prev_state);
|
||||
CHECK(tbState);
|
||||
assert(tbState);
|
||||
|
||||
// current hypothesis target phrase
|
||||
const Phrase& targetPhrase = cur_hypo.GetCurrTargetPhrase();
|
||||
|
@ -74,7 +74,8 @@ void TargetWordInsertionFeature::ComputeFeatures(const Phrase &source,
|
||||
|
||||
// flag aligned words
|
||||
bool aligned[16];
|
||||
CHECK(targetLength < 16);
|
||||
UTIL_THROW_IF(targetLength >= 16, util::Exception,
|
||||
"Target length must be less than 16 words");
|
||||
for(size_t i=0; i<targetLength; i++) {
|
||||
aligned[i] = false;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "StaticData.h"
|
||||
#include "TypeDef.h"
|
||||
#include "AlignmentInfo.h"
|
||||
#include "util/check.hh"
|
||||
#include "util/exception.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -61,7 +61,7 @@ void InputPath::SetTargetPhrases(const PhraseDictionary &phraseDictionary
|
||||
const Word &InputPath::GetLastWord() const
|
||||
{
|
||||
size_t len = m_phrase.GetSize();
|
||||
CHECK(len);
|
||||
UTIL_THROW_IF(len == 0, util::Exception, "Input path phrase cannot be empty");
|
||||
const Word &ret = m_phrase.GetWord(len - 1);
|
||||
return ret;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ private:
|
||||
* \param size maximum size of suffix
|
||||
*/
|
||||
size_t CalcSuffix(const ChartHypothesis &hypo, int featureID, Phrase &ret, size_t size) const {
|
||||
CHECK(m_contextPrefix.GetSize() <= m_numTargetTerminals);
|
||||
UTIL_THROW_IF(m_contextPrefix.GetSize() > m_numTargetTerminals, util::Exception, "Error");
|
||||
|
||||
// special handling for small hypotheses
|
||||
// does the prefix match the entire hypothesis string? -> just copy prefix
|
||||
|
@ -394,7 +394,8 @@ LanguageModel *ConstructKenLM(const std::string &line)
|
||||
vector<string> toks = Tokenize(line);
|
||||
for (size_t i = 1; i < toks.size(); ++i) {
|
||||
vector<string> args = Tokenize(toks[i], "=");
|
||||
CHECK(args.size() == 2);
|
||||
UTIL_THROW_IF(args.size() != 2, util::Exception,
|
||||
"Incorrect format of KenLM property: " << toks[i]);
|
||||
|
||||
if (args[0] == "factor") {
|
||||
factorType = Scan<FactorType>(args[1]);
|
||||
|
@ -59,7 +59,7 @@ void LanguageModelRandLM::Load()
|
||||
FactorCollection &factorCollection = FactorCollection::Instance();
|
||||
int cache_MB = 50; // increase cache size
|
||||
m_lm = randlm::RandLM::initRandLM(m_filePath, m_nGramOrder, cache_MB);
|
||||
CHECK(m_lm != NULL);
|
||||
UTIL_THROW_IF(m_lm == NULL, util::Exception, "RandLM object not created");
|
||||
// get special word ids
|
||||
m_oov_id = m_lm->getWordID(m_lm->getOOV());
|
||||
CreateFactors(factorCollection);
|
||||
|
@ -162,7 +162,9 @@ LMResult LanguageModelSRI::GetValue(const vector<const Word*> &contextFactor, St
|
||||
}
|
||||
ngram[count] = Vocab_None;
|
||||
|
||||
CHECK((*contextFactor[count-1])[factorType] != NULL);
|
||||
UTIL_THROW_IF((*contextFactor[count-1])[factorType] == NULL,
|
||||
util::Exception,
|
||||
"No factor " << factorType << " at position " << (count-1));
|
||||
// call sri lm fn
|
||||
VocabIndex lmId = GetLmID((*contextFactor[count-1])[factorType]);
|
||||
ret = GetValue(lmId, ngram+1);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include "Util.h"
|
||||
#include "util/exception.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -127,7 +128,7 @@ CNAlt getCNAlt(const std::string& in, int &c)
|
||||
for (; ind < toks.size() - 1; ++ind) {
|
||||
const string &tok = toks[ind];
|
||||
vector<string> keyValue = Moses::Tokenize(tok, "=");
|
||||
CHECK(keyValue.size() == 2);
|
||||
UTIL_THROW_IF(keyValue.size() != 2, util::Exception, "Format error: " << tok);
|
||||
float prob = Moses::Scan<float>(keyValue[1]);
|
||||
sparseFeatures[ keyValue[0] ] = prob;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "moses/TranslationModel/PhraseDictionaryTreeAdaptor.h"
|
||||
#include "Util.h"
|
||||
#include "util/tokenize_piece.hh"
|
||||
#include "util/exception.hh"
|
||||
#include "moses/FF/InputFeature.h"
|
||||
|
||||
namespace Moses
|
||||
@ -117,7 +118,7 @@ public:
|
||||
}
|
||||
|
||||
void CleanUp() {
|
||||
CHECK(m_dict);
|
||||
assert(m_dict);
|
||||
m_dict->FreeMemory();
|
||||
for(size_t i=0; i<m_tgtColls.size(); ++i) delete m_tgtColls[i];
|
||||
m_tgtColls.clear();
|
||||
@ -129,7 +130,7 @@ public:
|
||||
TargetPhraseCollectionWithSourcePhrase const*
|
||||
GetTargetPhraseCollection(Phrase const &src) const {
|
||||
|
||||
CHECK(m_dict);
|
||||
assert(m_dict);
|
||||
if(src.GetSize()==0) return 0;
|
||||
|
||||
std::pair<MapSrc2Tgt::iterator,bool> piter;
|
||||
@ -312,7 +313,9 @@ public:
|
||||
std::vector<std::pair<float,size_t> >& costs,
|
||||
const std::vector<Phrase> &sourcePhrases) const {
|
||||
// convert into TargetPhraseCollection
|
||||
CHECK(tCands.size() == sourcePhrases.size());
|
||||
UTIL_THROW_IF(tCands.size() != sourcePhrases.size(),
|
||||
util::Exception,
|
||||
"Number of target phrases must equal number of source phrases");
|
||||
|
||||
TargetPhraseCollectionWithSourcePhrase *rv=new TargetPhraseCollectionWithSourcePhrase;
|
||||
|
||||
@ -349,7 +352,7 @@ public:
|
||||
};
|
||||
|
||||
void CacheSource(ConfusionNet const& src) {
|
||||
CHECK(m_dict);
|
||||
assert(m_dict);
|
||||
const size_t srcSize=src.GetSize();
|
||||
|
||||
std::vector<size_t> exploredPaths(srcSize+1,0);
|
||||
@ -400,7 +403,7 @@ public:
|
||||
State curr(stack.back());
|
||||
stack.pop_back();
|
||||
|
||||
CHECK(curr.end()<srcSize);
|
||||
UTIL_THROW_IF(curr.end() >= srcSize, util::Exception, "Error");
|
||||
const ConfusionNet::Column &currCol=src[curr.end()];
|
||||
// in a given column, loop over all possibilities
|
||||
for(size_t colidx=0; colidx<currCol.size(); ++colidx) {
|
||||
@ -410,7 +413,9 @@ public:
|
||||
bool isEpsilon=(s=="" || s==EPSILON);
|
||||
|
||||
//assert that we have the right number of link params in this CN option
|
||||
CHECK(currCol[colidx].second.denseScores.size() >= m_numInputScores);
|
||||
UTIL_THROW_IF(currCol[colidx].second.denseScores.size() < m_numInputScores,
|
||||
util::Exception,
|
||||
"Incorrect number of input scores");
|
||||
|
||||
// do not start with epsilon (except at first position)
|
||||
if(isEpsilon && curr.begin()==curr.end() && curr.begin()>0) continue;
|
||||
@ -468,7 +473,8 @@ public:
|
||||
for(size_t i=0; i<tcands.size(); ++i) {
|
||||
//put input scores in first - already logged, just drop in directly
|
||||
std::vector<float> transcores(m_obj->GetNumScoreComponents());
|
||||
CHECK(transcores.size()==weightTrans.size());
|
||||
UTIL_THROW_IF(transcores.size() != weightTrans.size(), util::Exception,
|
||||
"Incorrect number of translation scores");
|
||||
|
||||
//put in phrase table scores, logging as we insert
|
||||
std::transform(tcands[i].scores.begin()
|
||||
|
@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include "Util.h"
|
||||
|
||||
#include "util/string_piece.hh"
|
||||
#include "util/exception.hh"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -154,7 +155,8 @@ public:
|
||||
}
|
||||
|
||||
void RemoveWord(size_t pos) {
|
||||
CHECK(pos < m_words.size());
|
||||
UTIL_THROW_IF(pos >= m_words.size(), util::Exception,
|
||||
"Referencing position " << pos << " out of bound");
|
||||
m_words.erase(m_words.begin() + pos);
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ bool ReorderingConstraint::Check( const WordsBitmap &bitmap, size_t startPos, si
|
||||
// nothing to be checked, we are done
|
||||
if (! IsActive() ) return true;
|
||||
|
||||
VERBOSE(3,"CHECK " << bitmap << " " << startPos << "-" << endPos);
|
||||
VERBOSE(3,"Check " << bitmap << " " << startPos << "-" << endPos);
|
||||
|
||||
// check walls
|
||||
size_t firstGapPos = bitmap.GetFirstGapPos();
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#include "util/check.hh"
|
||||
#include "util/exception.hh"
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
@ -97,7 +97,7 @@ public:
|
||||
~RuleCube();
|
||||
|
||||
float GetTopScore() const {
|
||||
CHECK(!m_queue.empty());
|
||||
UTIL_THROW_IF(m_queue.empty(), util::Exception, "Empty queue, nothing to pop");
|
||||
RuleCubeItem *item = m_queue.top();
|
||||
return item->GetScore();
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "RuleCubeQueue.h"
|
||||
#include "WordsRange.h"
|
||||
#include "Util.h"
|
||||
#include "util/exception.hh"
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
@ -84,9 +85,9 @@ void RuleCubeItem::CreateHypothesis(const ChartTranslationOptions &transOpt,
|
||||
|
||||
ChartHypothesis *RuleCubeItem::ReleaseHypothesis()
|
||||
{
|
||||
CHECK(m_hypothesis);
|
||||
UTIL_THROW_IF(m_hypothesis == NULL, util::Exception, "Hypothesis is NULL");
|
||||
ChartHypothesis *hypo = m_hypothesis;
|
||||
m_hypothesis = 0;
|
||||
m_hypothesis = NULL;
|
||||
return hypo;
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ Sentence::CreateTranslationOptionCollection() const
|
||||
size_t maxNoTransOptPerCoverage = StaticData::Instance().GetMaxNoTransOptPerCoverage();
|
||||
float transOptThreshold = StaticData::Instance().GetTranslationOptionThreshold();
|
||||
TranslationOptionCollection *rv= new TranslationOptionCollectionText(*this, maxNoTransOptPerCoverage, transOptThreshold);
|
||||
CHECK(rv);
|
||||
assert(rv);
|
||||
return rv;
|
||||
}
|
||||
void Sentence::Print(std::ostream& out) const
|
||||
|
@ -21,7 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include "util/check.hh"
|
||||
#include "util/exception.hh"
|
||||
#include "util/tokenize_piece.hh"
|
||||
|
||||
@ -229,7 +228,8 @@ void TargetPhrase::SetProperties(const StringPiece &str)
|
||||
tok = tok.substr(0, endPos - 1);
|
||||
|
||||
vector<string> keyValue = TokenizeFirstOnly(tok, " ");
|
||||
CHECK(keyValue.size() == 2);
|
||||
UTIL_THROW_IF(keyValue.size() != 2, util::Exception,
|
||||
"Incorrect format of property: " << str);
|
||||
SetProperty(keyValue[0], keyValue[1]);
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,7 @@ public:
|
||||
}
|
||||
|
||||
void SetId(size_t pos, wordID_t id) {
|
||||
CHECK(pos < words.size());
|
||||
words[pos] = id;
|
||||
words.at(pos) = id;
|
||||
}
|
||||
bool operator<(const SAPhrase& phr2) const {
|
||||
return words < phr2.words;
|
||||
|
@ -153,7 +153,7 @@ void TranslationOptionCollectionText::CreateXmlOptionsForRange(size_t startPos,
|
||||
InputPath &TranslationOptionCollectionText::GetInputPath(size_t startPos, size_t endPos)
|
||||
{
|
||||
size_t offset = endPos - startPos;
|
||||
CHECK(offset < m_inputPathMatrix[startPos].size());
|
||||
assert(offset < m_inputPathMatrix[startPos].size());
|
||||
return *m_inputPathMatrix[startPos][offset];
|
||||
}
|
||||
|
||||
|
@ -71,10 +71,12 @@ void Word::Merge(const Word &sourceWord)
|
||||
std::string Word::GetString(const vector<FactorType> factorType,bool endWithBlank) const
|
||||
{
|
||||
stringstream strme;
|
||||
CHECK(factorType.size() <= MAX_NUM_FACTORS);
|
||||
const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter();
|
||||
bool firstPass = true;
|
||||
for (unsigned int i = 0 ; i < factorType.size() ; i++) {
|
||||
UTIL_THROW_IF(factorType[i] >= MAX_NUM_FACTORS, util::Exception,
|
||||
"Trying to reference factor " << factorType[i] << ". Max factor is " << MAX_NUM_FACTORS);
|
||||
|
||||
const Factor *factor = m_factorArray[factorType[i]];
|
||||
if (factor != NULL) {
|
||||
if (firstPass) {
|
||||
|
@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include <iostream>
|
||||
#include "TypeDef.h"
|
||||
#include "Util.h"
|
||||
#include "util/exception.hh"
|
||||
|
||||
#ifdef WIN32
|
||||
#undef max
|
||||
@ -79,7 +80,7 @@ public:
|
||||
}
|
||||
|
||||
inline size_t GetNumWordsBetween(const WordsRange& x) const {
|
||||
CHECK(!Overlap(x));
|
||||
UTIL_THROW_IF(Overlap(x), util::Exception, "Overlapping ranges");
|
||||
|
||||
if (x.m_endPos < m_startPos) {
|
||||
return m_startPos - x.m_endPos - 1;
|
||||
|
@ -373,8 +373,7 @@ bool ProcessAndStripXMLTags(string &line, vector<XmlOption*> &res, ReorderingCon
|
||||
targetPhrase.Evaluate(sourcePhrase);
|
||||
|
||||
XmlOption *option = new XmlOption(range,targetPhrase);
|
||||
|
||||
CHECK(option);
|
||||
assert(option);
|
||||
|
||||
res.push_back(option);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user