Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorales-t <ales-t@1f5c12ca-751b-0410-a591-d2e778427230>2011-02-08 20:15:50 +0300
committerales-t <ales-t@1f5c12ca-751b-0410-a591-d2e778427230>2011-02-08 20:15:50 +0300
commit83e2406f4250f255fe682bbe610abed6fe2f8584 (patch)
tree10fe4ed0a66461136bf1ecf58c847397ca22f22c /moses-cmd
parent47df5fd51c3370e34a78518ac74d66cfe2437ecf (diff)
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
Diffstat (limited to 'moses-cmd')
-rwxr-xr-xmoses-cmd/src/IOWrapper.cpp75
-rwxr-xr-xmoses-cmd/src/IOWrapper.h4
-rw-r--r--moses-cmd/src/Main.cpp6
3 files changed, 52 insertions, 33 deletions
diff --git a/moses-cmd/src/IOWrapper.cpp b/moses-cmd/src/IOWrapper.cpp
index 4d84a569f..e44ff8065 100755
--- a/moses-cmd/src/IOWrapper.cpp
+++ b/moses-cmd/src/IOWrapper.cpp
@@ -223,40 +223,55 @@ 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
- ,bool reportSegmentation, bool reportAllFactors, std::ofstream *alignmentStream)
+void OutputAlignment(std::ofstream *alignmentStream, const vector<const Hypothesis *> &edges)
{
- if ( hypo != NULL)
+ size_t targetOffset = 0;
+
+ for (int currEdge = (int)edges.size() - 1 ; currEdge >= 0 ; currEdge--)
{
- if (! StaticData::Instance().GetAlignmentOutputFile().empty() && alignmentStream)
+ const Hypothesis &edge = *edges[currEdge];
+ const TargetPhrase &tp = edge.GetCurrTargetPhrase();
+ size_t sourceOffset = edge.GetCurrSourceWordsRange().GetStartPos();
+ AlignmentInfo::const_iterator it;
+ for (it = tp.GetAlignmentInfo().begin(); it != tp.GetAlignmentInfo().end(); ++it)
{
- size_t targetOffset = 0;
-
- std::stack<const Hypothesis *> edges;
- const Hypothesis *currentHypo = hypo;
- while (currentHypo)
- {
- edges.push(currentHypo);
- currentHypo = currentHypo->GetPrevHypo();
- }
-
- while (!edges.empty())
- {
- const Hypothesis &edge = *edges.top();
- edges.pop();
- const TargetPhrase &tp = edge.GetCurrTargetPhrase();
- size_t sourceOffset = edge.GetCurrSourceWordsRange().GetStartPos();
- AlignmentInfo::const_iterator it;
- for (it = tp.GetAlignmentInfo().begin(); it != tp.GetAlignmentInfo().end(); ++it)
- {
- *alignmentStream << it->first + sourceOffset << "-" << it->second + targetOffset << " ";
- }
- targetOffset += tp.GetSize();
- }
- *alignmentStream << std::endl;
+ *alignmentStream << it->first + sourceOffset << "-" << it->second + targetOffset << " ";
+ }
+ targetOffset += tp.GetSize();
+ }
+ *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();
}
+
+ OutputAlignment(alignmentStream, edges);
+ }
+}
+
+void OutputAlignment(std::ofstream *alignmentStream, const TrellisPath &path)
+{
+ if (! StaticData::Instance().GetAlignmentOutputFile().empty() && alignmentStream)
+ {
+ OutputAlignment(alignmentStream, path.GetEdges());
+ }
+}
- OutputSurface(out, hypo->GetPrevHypo(), outputFactorOrder, reportSegmentation, reportAllFactors, NULL);
+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);
if (reportSegmentation == true
@@ -338,7 +353,7 @@ void IOWrapper::OutputBestHypo(const Hypothesis *hypo, long /*translationId*/, b
OutputInput(cout, hypo);
cout << "||| ";
}
- OutputSurface(cout, hypo, m_outputFactorOrder, reportSegmentation, reportAllFactors, NULL);
+ OutputSurface(cout, hypo, m_outputFactorOrder, reportSegmentation, reportAllFactors);
cout << endl;
}
}
diff --git a/moses-cmd/src/IOWrapper.h b/moses-cmd/src/IOWrapper.h
index 32ddf52f7..59d122b84 100755
--- a/moses-cmd/src/IOWrapper.h
+++ b/moses-cmd/src/IOWrapper.h
@@ -120,7 +120,7 @@ public:
IOWrapper *GetIODevice(const Moses::StaticData &staticData);
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>&,
const TranslationSystem* system, 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);
void OutputBestHypo(const Moses::TrellisPath &path, long /*translationId*/,bool reportSegmentation, bool reportAllFactors, std::ostream &out);
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
diff --git a/moses-cmd/src/Main.cpp b/moses-cmd/src/Main.cpp
index a360c9ff3..70b4c245c 100644
--- a/moses-cmd/src/Main.cpp
+++ b/moses-cmd/src/Main.cpp
@@ -139,8 +139,8 @@ class TranslationTask : public Task {
bestHypo,
staticData.GetOutputFactorOrder(),
staticData.GetReportSegmentation(),
- staticData.GetReportAllFactors(),
- m_alignmentStream);
+ staticData.GetReportAllFactors());
+ OutputAlignment(m_alignmentStream, bestHypo);
IFVERBOSE(1) {
debug << "BEST TRANSLATION: " << *bestHypo << endl;
}
@@ -186,6 +186,7 @@ class TranslationTask : public Task {
OutputBestHypo(conBestHypo, m_lineNumber,
staticData.GetReportSegmentation(),
staticData.GetReportAllFactors(),out);
+ OutputAlignment(m_alignmentStream, conBestHypo);
IFVERBOSE(2) { PrintUserTime("finished Consensus decoding"); }
}
else
@@ -195,6 +196,7 @@ class TranslationTask : public Task {
OutputBestHypo(mbrBestHypo, m_lineNumber,
staticData.GetReportSegmentation(),
staticData.GetReportAllFactors(),out);
+ OutputAlignment(m_alignmentStream, mbrBestHypo);
IFVERBOSE(2) { PrintUserTime("finished MBR decoding"); }
}