mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
add OutputAlignment() to BaseManager.
This commit is contained in:
parent
fb25616bdd
commit
184e79f4d6
@ -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;
|
||||
|
||||
|
||||
};
|
||||
|
@ -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
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user