mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-10-27 03:49:57 +03:00
replace CHECK with UTIL_THROW_IF in moses-cmd
This commit is contained in:
parent
d9be81596e
commit
3ffc5e7a8f
@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "moses/InputFileStream.h"
|
||||
#include "moses/FF/StatefulFeatureFunction.h"
|
||||
#include "moses/FF/StatelessFeatureFunction.h"
|
||||
#include "util/exception.hh"
|
||||
|
||||
#include "IOWrapper.h"
|
||||
|
||||
@ -166,13 +167,17 @@ void IOWrapper::Initialization(const std::vector<FactorType> &/*inputFactorOrder
|
||||
if (staticData.IsDetailedTranslationReportingEnabled()) {
|
||||
const std::string &path = staticData.GetDetailedTranslationReportingFilePath();
|
||||
m_detailedTranslationReportingStream = new std::ofstream(path.c_str());
|
||||
CHECK(m_detailedTranslationReportingStream->good());
|
||||
UTIL_THROW_IF(!m_detailedTranslationReportingStream->good(),
|
||||
util::FileOpenException,
|
||||
"File for output of detailed translation report could not be open");
|
||||
}
|
||||
|
||||
// sentence alignment output
|
||||
if (! staticData.GetAlignmentOutputFile().empty()) {
|
||||
m_alignmentOutputStream = new ofstream(staticData.GetAlignmentOutputFile().c_str());
|
||||
CHECK(m_alignmentOutputStream->good());
|
||||
UTIL_THROW_IF(!m_alignmentOutputStream->good(),
|
||||
util::FileOpenException,
|
||||
"File for output of word alignment could not be open");
|
||||
}
|
||||
|
||||
}
|
||||
@ -202,7 +207,9 @@ std::map<size_t, const Factor*> GetPlaceholders(const Hypothesis &hypo, FactorTy
|
||||
const Factor *factor = inputPhrase.GetFactor(sourcePos, placeholderFactor);
|
||||
if (factor) {
|
||||
std::set<size_t> targetPos = hypo.GetTranslationOption().GetTargetPhrase().GetAlignTerm().GetAlignmentsForSource(sourcePos);
|
||||
CHECK(targetPos.size() == 1);
|
||||
UTIL_THROW_IF(targetPos.size() != 1,
|
||||
util::Exception,
|
||||
"Placeholder should be aligned to 1, and only 1, word");
|
||||
ret[*targetPos.begin()] = factor;
|
||||
}
|
||||
}
|
||||
@ -216,7 +223,9 @@ std::map<size_t, const Factor*> GetPlaceholders(const Hypothesis &hypo, FactorTy
|
||||
void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector<FactorType> &outputFactorOrder,
|
||||
char reportSegmentation, bool reportAllFactors)
|
||||
{
|
||||
CHECK(outputFactorOrder.size() > 0);
|
||||
UTIL_THROW_IF(outputFactorOrder.size() == 0,
|
||||
util::Exception,
|
||||
"Must specific at least 1 output factor");
|
||||
const TargetPhrase& phrase = edge.GetCurrTargetPhrase();
|
||||
bool markUnknown = StaticData::Instance().GetMarkUnknown();
|
||||
if (reportAllFactors == true) {
|
||||
@ -242,7 +251,9 @@ void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector<
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(factor);
|
||||
UTIL_THROW_IF(factor == NULL,
|
||||
util::Exception,
|
||||
"No factor 0 at position " << pos);
|
||||
|
||||
//preface surface form with UNK if marking unknowns
|
||||
const Word &word = phrase.GetWord(pos);
|
||||
@ -254,7 +265,9 @@ void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector<
|
||||
|
||||
for (size_t i = 1 ; i < outputFactorOrder.size() ; i++) {
|
||||
const Factor *factor = phrase.GetFactor(pos, outputFactorOrder[i]);
|
||||
CHECK(factor);
|
||||
UTIL_THROW_IF(factor == NULL,
|
||||
util::Exception,
|
||||
"No factor " << i << " at position " << pos);
|
||||
|
||||
out << "|" << *factor;
|
||||
}
|
||||
@ -389,7 +402,9 @@ void OutputBestHypo(const std::vector<Word>& mbrBestHypo, long /*translationId*
|
||||
|
||||
for (size_t i = 0 ; i < mbrBestHypo.size() ; i++) {
|
||||
const Factor *factor = mbrBestHypo[i].GetFactor(StaticData::Instance().GetOutputFactorOrder()[0]);
|
||||
CHECK(factor);
|
||||
UTIL_THROW_IF(factor == NULL,
|
||||
util::Exception,
|
||||
"No factor 0 at position " << i);
|
||||
if (i>0) out << " " << *factor;
|
||||
else out << *factor;
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "LatticeMBR.h"
|
||||
#include "moses/Manager.h"
|
||||
#include "moses/StaticData.h"
|
||||
#include "util/exception.hh"
|
||||
|
||||
|
||||
using namespace std;
|
||||
@ -68,7 +69,9 @@ public:
|
||||
/** Add a parameter with key, command line argument, and default value */
|
||||
void addParam(gridkey key, const string& arg, float defaultValue) {
|
||||
m_args[arg] = key;
|
||||
CHECK(m_grid.find(key) == m_grid.end());
|
||||
UTIL_THROW_IF(m_grid.find(key) != m_grid.end(),
|
||||
util::Exception,
|
||||
"Couldn't find value for key " << (int) key);
|
||||
m_grid[key].push_back(defaultValue);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user