add OutputAlignment() to BaseManager.

This commit is contained in:
Hieu Hoang 2014-12-03 15:00:36 +00:00
parent fb25616bdd
commit 184e79f4d6
5 changed files with 38 additions and 3 deletions

View File

@ -28,6 +28,7 @@ public:
// outputs
virtual void OutputNBest(OutputCollector *collector) const = 0;
virtual void OutputLatticeSamples(OutputCollector *collector) const = 0;
virtual void OutputAlignment(OutputCollector *collector) const = 0;
};

View File

@ -62,6 +62,8 @@ private:
void OutputNBestList(OutputCollector *collector, const std::vector<search::Applied> &nbest, long translationId) const;
void OutputLatticeSamples(OutputCollector *collector) const
{}
void OutputAlignment(OutputCollector *collector) const
{}
};

View File

@ -1680,10 +1680,42 @@ void Manager::OutputLatticeSamples(OutputCollector *collector) const
void Manager::OutputAlignment(OutputCollector *collector) const
{
if (collector) {
std::vector<const Hypothesis *> edges;
const Hypothesis *currentHypo = GetBestHypothesis();
while (currentHypo) {
edges.push_back(currentHypo);
currentHypo = currentHypo->GetPrevHypo();
}
OutputAlignment(collector,m_source.GetTranslationId(), edges);
}
}
void Manager::OutputAlignment(OutputCollector* collector, size_t lineNo , const Hypothesis *hypo) const
void Manager::OutputAlignment(OutputCollector* collector, size_t lineNo , const vector<const Hypothesis *> &edges) const
{
ostringstream out;
OutputAlignment(out, edges);
collector->Write(lineNo,out.str());
}
void Manager::OutputAlignment(ostream &out, const vector<const Hypothesis *> &edges) const
{
size_t targetOffset = 0;
for (int currEdge = (int)edges.size() - 1 ; currEdge >= 0 ; currEdge--) {
const Hypothesis &edge = *edges[currEdge];
const TargetPhrase &tp = edge.GetCurrTargetPhrase();
size_t sourceOffset = edge.GetCurrSourceWordsRange().GetStartPos();
OutputAlignment(out, tp.GetAlignTerm(), sourceOffset, targetOffset);
targetOffset += tp.GetSize();
}
// Removing std::endl here breaks -alignment-output-file, so stop doing that, please :)
// Or fix it somewhere else.
out << std::endl;
}
}

View File

@ -140,7 +140,8 @@ protected:
void OutputInput(std::ostream& os, const Hypothesis* hypo) const;
void OutputInput(std::vector<const Phrase*>& map, const Hypothesis* hypo) const;
std::map<size_t, const Factor*> GetPlaceholders(const Hypothesis &hypo, FactorType placeholderFactor) const;
void OutputAlignment(OutputCollector* collector, size_t lineNo , const Hypothesis *hypo) const;
void OutputAlignment(OutputCollector* collector, size_t lineNo , const std::vector<const Hypothesis *> &edges) const;
void OutputAlignment(std::ostream &out, const std::vector<const Hypothesis *> &edges) const;
public:
InputType const& m_source; /**< source sentence to be translated */

View File

@ -193,7 +193,6 @@ void TranslationTask::RunPb()
m_ioWrapper.OutputAlignment(out, bestHypo);
}
m_ioWrapper.OutputAlignment(m_ioWrapper.GetAlignmentInfoCollector(), m_source->GetTranslationId(), bestHypo);
manager.OutputAlignment(m_ioWrapper.GetAlignmentInfoCollector());
IFVERBOSE(1) {