Word alignment output also works with MBR decoding.

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@3875 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
ales-t 2011-02-08 17:15:50 +00:00
parent 47df5fd51c
commit 83e2406f42
3 changed files with 53 additions and 34 deletions

View File

@ -223,27 +223,13 @@ void OutputSurface(std::ostream &out, const Phrase &phrase, const std::vector<Fa
} }
} }
void OutputSurface(std::ostream &out, const Hypothesis *hypo, const std::vector<FactorType> &outputFactorOrder void OutputAlignment(std::ofstream *alignmentStream, const vector<const Hypothesis *> &edges)
,bool reportSegmentation, bool reportAllFactors, std::ofstream *alignmentStream)
{ {
if ( hypo != NULL)
{
if (! StaticData::Instance().GetAlignmentOutputFile().empty() && alignmentStream)
{
size_t targetOffset = 0; size_t targetOffset = 0;
std::stack<const Hypothesis *> edges; for (int currEdge = (int)edges.size() - 1 ; currEdge >= 0 ; currEdge--)
const Hypothesis *currentHypo = hypo;
while (currentHypo)
{ {
edges.push(currentHypo); const Hypothesis &edge = *edges[currEdge];
currentHypo = currentHypo->GetPrevHypo();
}
while (!edges.empty())
{
const Hypothesis &edge = *edges.top();
edges.pop();
const TargetPhrase &tp = edge.GetCurrTargetPhrase(); const TargetPhrase &tp = edge.GetCurrTargetPhrase();
size_t sourceOffset = edge.GetCurrSourceWordsRange().GetStartPos(); size_t sourceOffset = edge.GetCurrSourceWordsRange().GetStartPos();
AlignmentInfo::const_iterator it; AlignmentInfo::const_iterator it;
@ -254,9 +240,38 @@ void OutputSurface(std::ostream &out, const Hypothesis *hypo, const std::vector<
targetOffset += tp.GetSize(); targetOffset += tp.GetSize();
} }
*alignmentStream << std::endl; *alignmentStream << std::endl;
}
void OutputAlignment(std::ofstream *alignmentStream, const Hypothesis *hypo)
{
if (hypo && ! StaticData::Instance().GetAlignmentOutputFile().empty() && alignmentStream)
{
std::vector<const Hypothesis *> edges;
const Hypothesis *currentHypo = hypo;
while (currentHypo)
{
edges.push_back(currentHypo);
currentHypo = currentHypo->GetPrevHypo();
} }
OutputSurface(out, hypo->GetPrevHypo(), outputFactorOrder, reportSegmentation, reportAllFactors, NULL); OutputAlignment(alignmentStream, edges);
}
}
void OutputAlignment(std::ofstream *alignmentStream, const TrellisPath &path)
{
if (! StaticData::Instance().GetAlignmentOutputFile().empty() && alignmentStream)
{
OutputAlignment(alignmentStream, path.GetEdges());
}
}
void OutputSurface(std::ostream &out, const Hypothesis *hypo, const std::vector<FactorType> &outputFactorOrder
,bool reportSegmentation, bool reportAllFactors)
{
if ( hypo != NULL)
{
OutputSurface(out, hypo->GetPrevHypo(), outputFactorOrder, reportSegmentation, reportAllFactors);
OutputSurface(out, hypo->GetCurrTargetPhrase(), outputFactorOrder, reportAllFactors); OutputSurface(out, hypo->GetCurrTargetPhrase(), outputFactorOrder, reportAllFactors);
if (reportSegmentation == true if (reportSegmentation == true
@ -338,7 +353,7 @@ void IOWrapper::OutputBestHypo(const Hypothesis *hypo, long /*translationId*/, b
OutputInput(cout, hypo); OutputInput(cout, hypo);
cout << "||| "; cout << "||| ";
} }
OutputSurface(cout, hypo, m_outputFactorOrder, reportSegmentation, reportAllFactors, NULL); OutputSurface(cout, hypo, m_outputFactorOrder, reportSegmentation, reportAllFactors);
cout << endl; cout << endl;
} }
} }

View File

@ -120,7 +120,7 @@ public:
IOWrapper *GetIODevice(const Moses::StaticData &staticData); IOWrapper *GetIODevice(const Moses::StaticData &staticData);
bool ReadInput(IOWrapper &ioWrapper, Moses::InputTypeEnum inputType, Moses::InputType*& source); bool ReadInput(IOWrapper &ioWrapper, Moses::InputTypeEnum inputType, Moses::InputType*& source);
void OutputSurface(std::ostream &out, const Moses::Hypothesis *hypo, const std::vector<Moses::FactorType> &outputFactorOrder ,bool reportSegmentation, bool reportAllFactors, std::ofstream *alignmentStream); void OutputSurface(std::ostream &out, const Moses::Hypothesis *hypo, const std::vector<Moses::FactorType> &outputFactorOrder ,bool reportSegmentation, bool reportAllFactors);
void OutputNBest(std::ostream& out, const Moses::TrellisPathList &nBestList, const std::vector<Moses::FactorType>&, void OutputNBest(std::ostream& out, const Moses::TrellisPathList &nBestList, const std::vector<Moses::FactorType>&,
const TranslationSystem* system, long translationId); const TranslationSystem* system, long translationId);
void OutputLatticeMBRNBest(std::ostream& out, const std::vector<LatticeMBRSolution>& solutions,long translationId); void OutputLatticeMBRNBest(std::ostream& out, const std::vector<LatticeMBRSolution>& solutions,long translationId);
@ -128,5 +128,7 @@ void OutputBestHypo(const std::vector<Moses::Word>& mbrBestHypo, long /*transla
bool reportSegmentation, bool reportAllFactors, std::ostream& out); bool reportSegmentation, bool reportAllFactors, std::ostream& out);
void OutputBestHypo(const Moses::TrellisPath &path, long /*translationId*/,bool reportSegmentation, bool reportAllFactors, std::ostream &out); void OutputBestHypo(const Moses::TrellisPath &path, long /*translationId*/,bool reportSegmentation, bool reportAllFactors, std::ostream &out);
void OutputInput(std::ostream& os, const Hypothesis* hypo); void OutputInput(std::ostream& os, const Hypothesis* hypo);
void OutputAlignment(std::ofstream *alignmentStream, const Hypothesis *hypo);
void OutputAlignment(std::ofstream *alignmentStream, const TrellisPath &path);
#endif #endif

View File

@ -139,8 +139,8 @@ class TranslationTask : public Task {
bestHypo, bestHypo,
staticData.GetOutputFactorOrder(), staticData.GetOutputFactorOrder(),
staticData.GetReportSegmentation(), staticData.GetReportSegmentation(),
staticData.GetReportAllFactors(), staticData.GetReportAllFactors());
m_alignmentStream); OutputAlignment(m_alignmentStream, bestHypo);
IFVERBOSE(1) { IFVERBOSE(1) {
debug << "BEST TRANSLATION: " << *bestHypo << endl; debug << "BEST TRANSLATION: " << *bestHypo << endl;
} }
@ -186,6 +186,7 @@ class TranslationTask : public Task {
OutputBestHypo(conBestHypo, m_lineNumber, OutputBestHypo(conBestHypo, m_lineNumber,
staticData.GetReportSegmentation(), staticData.GetReportSegmentation(),
staticData.GetReportAllFactors(),out); staticData.GetReportAllFactors(),out);
OutputAlignment(m_alignmentStream, conBestHypo);
IFVERBOSE(2) { PrintUserTime("finished Consensus decoding"); } IFVERBOSE(2) { PrintUserTime("finished Consensus decoding"); }
} }
else else
@ -195,6 +196,7 @@ class TranslationTask : public Task {
OutputBestHypo(mbrBestHypo, m_lineNumber, OutputBestHypo(mbrBestHypo, m_lineNumber,
staticData.GetReportSegmentation(), staticData.GetReportSegmentation(),
staticData.GetReportAllFactors(),out); staticData.GetReportAllFactors(),out);
OutputAlignment(m_alignmentStream, mbrBestHypo);
IFVERBOSE(2) { PrintUserTime("finished MBR decoding"); } IFVERBOSE(2) { PrintUserTime("finished MBR decoding"); }
} }