Write translation details to a named file instead of cerr.

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@3243 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
pjwilliams 2010-05-08 15:51:59 +00:00
parent dcb8aafca7
commit 2a5b262503
8 changed files with 53 additions and 12 deletions

View File

@ -59,6 +59,7 @@ IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder
,m_inputFactorUsed(inputFactorUsed)
,m_nBestStream(NULL)
,m_outputSearchGraphStream(NULL)
,m_detailedTranslationReportingStream(0)
,m_inputFilePath(inputFilePath)
{
const StaticData &staticData = StaticData::Instance();
@ -97,7 +98,13 @@ IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder
m_outputSearchGraphStream = file;
file->open(fileName.c_str());
}
// detailed translation reporting
if (staticData.IsDetailedTranslationReportingEnabled())
{
const std::string &path = staticData.GetDetailedTranslationReportingFilePath();
m_detailedTranslationReportingStream = new std::ofstream(path.c_str());
}
}
IOWrapper::~IOWrapper()
@ -115,6 +122,8 @@ IOWrapper::~IOWrapper()
{
delete m_outputSearchGraphStream;
}
delete m_detailedTranslationReportingStream;
}
InputType*IOWrapper::GetInput(InputType* inputType)
@ -222,11 +231,11 @@ void OutputInput(std::ostream& os, const MosesChart::Hypothesis* hypo)
}
*/
void OutputTranslationOptions(const MosesChart::Hypothesis *hypo, long translationId)
void OutputTranslationOptions(std::ostream &out, const MosesChart::Hypothesis *hypo, long translationId)
{ // recursive
if (hypo != NULL)
{
cerr << "Trans Opt " << translationId << " " << hypo->GetCurrSourceRange() << ": " << hypo->GetCurrChartRule()
out << "Trans Opt " << translationId << " " << hypo->GetCurrSourceRange() << ": " << hypo->GetCurrChartRule()
<< " " << hypo->GetTotalScore() << hypo->GetScoreBreakdown()
<< endl;
}
@ -236,7 +245,7 @@ void OutputTranslationOptions(const MosesChart::Hypothesis *hypo, long translati
for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter)
{
const MosesChart::Hypothesis *prevHypo = *iter;
OutputTranslationOptions(prevHypo, translationId);
OutputTranslationOptions(out, prevHypo, translationId);
}
}
@ -257,7 +266,7 @@ void IOWrapper::OutputBestHypo(const MosesChart::Hypothesis *hypo, long translat
if (StaticData::Instance().IsDetailedTranslationReportingEnabled())
{
OutputTranslationOptions(hypo, translationId);
OutputTranslationOptions(*m_detailedTranslationReportingStream, hypo, translationId);
}
if (!m_surpressSingleBestOutput)

View File

@ -61,6 +61,7 @@ protected:
const std::vector<Moses::FactorType> &m_outputFactorOrder;
const Moses::FactorMask &m_inputFactorUsed;
std::ostream *m_nBestStream, *m_outputSearchGraphStream;
std::ostream *m_detailedTranslationReportingStream;
std::string m_inputFilePath;
std::istream *m_inputStream;
bool m_surpressSingleBestOutput;

View File

@ -60,6 +60,7 @@ IOWrapper::IOWrapper(
,m_nBestStream(NULL)
,m_outputWordGraphStream(NULL)
,m_outputSearchGraphStream(NULL)
,m_detailedTranslationReportingStream(0)
{
Initialization(inputFactorOrder, outputFactorOrder
, inputFactorUsed
@ -104,6 +105,7 @@ IOWrapper::~IOWrapper()
{
delete m_outputSearchGraphStream;
}
delete m_detailedTranslationReportingStream;
}
void IOWrapper::Initialization(const std::vector<FactorType> &inputFactorOrder
@ -153,6 +155,13 @@ void IOWrapper::Initialization(const std::vector<FactorType> &inputFactorOrder
m_outputSearchGraphStream = file;
file->open(fileName.c_str());
}
// detailed translation reporting
if (staticData.IsDetailedTranslationReportingEnabled())
{
const std::string &path = staticData.GetDetailedTranslationReportingFilePath();
m_detailedTranslationReportingStream = new std::ofstream(path.c_str());
}
}
InputType*IOWrapper::GetInput(InputType* inputType)

View File

@ -60,6 +60,7 @@ protected:
const Moses::FactorMask &m_inputFactorUsed;
std::ostream *m_nBestStream
,*m_outputWordGraphStream,*m_outputSearchGraphStream;
std::ostream *m_detailedTranslationReportingStream;
std::string m_inputFilePath;
std::istream *m_inputStream;
Moses::InputFileStream *m_inputFile;
@ -103,6 +104,11 @@ public:
{
return *m_outputSearchGraphStream;
}
std::ostream &GetDetailedTranslationReportingStream()
{
return *m_detailedTranslationReportingStream;
}
};
IOWrapper *GetIODevice(const Moses::StaticData &staticData);

View File

@ -223,7 +223,8 @@ int main(int argc, char* argv[])
if (staticData.IsDetailedTranslationReportingEnabled()) {
TranslationAnalysis::PrintTranslationAnalysis(std::cerr, manager.GetBestHypothesis());
std::ostream &out = ioWrapper->GetDetailedTranslationReportingStream();
TranslationAnalysis::PrintTranslationAnalysis(out, manager.GetBestHypothesis());
}
IFVERBOSE(2) { PrintUserTime("Sentence Decoding Time:"); }

View File

@ -68,7 +68,7 @@ Parameter::Parameter()
AddParam("report-segmentation", "t", "report phrase segmentation in the output");
AddParam("stack", "s", "maximum stack size for histogram pruning");
AddParam("stack-diversity", "sd", "minimum number of hypothesis of each coverage in stack (default 0)");
AddParam("translation-details", "T", "for each best translation hypothesis, print out details about what sourcce spans were used, dropped");
AddParam("translation-details", "T", "for each best hypothesis, report translation details to the given file");
AddParam("ttable-file", "location and properties of the translation tables");
AddParam("ttable-limit", "ttl", "maximum number of translation table entries per input phrase");
AddParam("translation-option-threshold", "tot", "threshold for translation options relative to best for input phrase");

View File

@ -71,7 +71,7 @@ StaticData::StaticData()
,m_numInputScores(0)
,m_distortionScoreProducer(0)
,m_wpProducer(0)
,m_isDetailedTranslationReportingEnabled(false)
,m_detailedTranslationReportingFilePath()
,m_onlyDistinctNBest(false)
,m_factorDelimiter("|") // default delimiter between factors
,m_isAlwaysCreateDirectTranslationOption(false)
@ -270,8 +270,19 @@ bool StaticData::LoadData(Parameter *parameter)
SetBooleanParameter( &m_printAllDerivations , "print-all-derivations", false );
// additional output
SetBooleanParameter( &m_isDetailedTranslationReportingEnabled,
"translation-details", false );
if (m_parameter->isParamSpecified("translation-details"))
{
const vector<string> &args = m_parameter->GetParam("translation-details");
if (args.size() == 1)
{
m_detailedTranslationReportingFilePath = args[0];
}
else
{
UserMessage::Add(string("the translation-details option requires exactly one filename argument"));
return false;
}
}
// score weights
m_weightWordPenalty = Scan<float>( m_parameter->GetParam("weight-w")[0] );

View File

@ -138,7 +138,7 @@ protected:
bool m_reportSegmentation;
bool m_reportAllFactors;
bool m_reportAllFactorsNBest;
bool m_isDetailedTranslationReportingEnabled;
std::string m_detailedTranslationReportingFilePath;
bool m_onlyDistinctNBest;
bool m_UseAlignmentInfo;
bool m_PrintAlignmentInfo;
@ -423,7 +423,11 @@ public:
}
bool IsDetailedTranslationReportingEnabled() const
{
return m_isDetailedTranslationReportingEnabled;
return !m_detailedTranslationReportingFilePath.empty();
}
const std::string &GetDetailedTranslationReportingFilePath() const
{
return m_detailedTranslationReportingFilePath;
}
bool IsLabeledNBestList() const