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:
authorPhil Williams <philip.williams@mac.com>2012-01-25 16:26:28 +0400
committerPhil Williams <philip.williams@mac.com>2012-01-25 16:26:28 +0400
commit72baeab59e19532a56b76ec154222bcda92b39dd (patch)
tree55d8cfb99aaa839ce379ef875dc92cb28c56bd67 /moses-chart-cmd
parent5254e7917b1e2e4d86fab27100f3cb6bc9c35c06 (diff)
moses_chart: rule lookup now produces a vector of stack pointers (and a
TargetPhraseCollection pointer) instead of a CYK+ dotted rule.
Diffstat (limited to 'moses-chart-cmd')
-rw-r--r--moses-chart-cmd/src/IOWrapper.cpp68
-rw-r--r--moses-chart-cmd/src/IOWrapper.h2
-rw-r--r--moses-chart-cmd/src/Main.cpp3
3 files changed, 66 insertions, 7 deletions
diff --git a/moses-chart-cmd/src/IOWrapper.cpp b/moses-chart-cmd/src/IOWrapper.cpp
index 2d9ee1dcb..3baaef38f 100644
--- a/moses-chart-cmd/src/IOWrapper.cpp
+++ b/moses-chart-cmd/src/IOWrapper.cpp
@@ -227,14 +227,71 @@ void OutputInput(std::ostream& os, const ChartHypothesis* hypo)
}
*/
-void OutputTranslationOptions(std::ostream &out, const ChartHypothesis *hypo, long translationId)
+namespace {
+
+typedef std::vector<std::pair<Word, WordsRange> > ApplicationContext;
+
+// Given a hypothesis and sentence, reconstructs the 'application context' --
+// the source RHS symbols of the SCFG rule that was applied, plus their spans.
+void ReconstructApplicationContext(const ChartHypothesis &hypo,
+ const Sentence &sentence,
+ ApplicationContext &context)
+{
+ context.clear();
+ const std::vector<const ChartHypothesis*> &prevHypos = hypo.GetPrevHypos();
+ std::vector<const ChartHypothesis*>::const_iterator p = prevHypos.begin();
+ std::vector<const ChartHypothesis*>::const_iterator end = prevHypos.end();
+ const WordsRange &span = hypo.GetCurrSourceRange();
+ size_t i = span.GetStartPos();
+ while (i <= span.GetEndPos()) {
+ if (p == end || i < (*p)->GetCurrSourceRange().GetStartPos()) {
+ // Symbol is a terminal.
+ const Word &symbol = sentence.GetWord(i);
+ context.push_back(std::make_pair(symbol, WordsRange(i, i)));
+ ++i;
+ } else {
+ // Symbol is a non-terminal.
+ const Word &symbol = (*p)->GetTargetLHS();
+ const WordsRange &range = (*p)->GetCurrSourceRange();
+ context.push_back(std::make_pair(symbol, range));
+ i = range.GetEndPos()+1;
+ ++p;
+ }
+ }
+}
+
+// Emulates the old operator<<(ostream &, const DottedRule &) function. The
+// output format is a bit odd (reverse order and double spacing between symbols)
+// but there are scripts and tools that expect the output of -T to look like
+// that.
+void WriteApplicationContext(std::ostream &out,
+ const ApplicationContext &context)
{
+ assert(!context.empty());
+ ApplicationContext::const_reverse_iterator p = context.rbegin();
+ while (true) {
+ out << p->second << "=" << p->first << " ";
+ if (++p == context.rend()) {
+ break;
+ }
+ out << " ";
+ }
+}
+
+} // anonymous namespace
+
+void OutputTranslationOptions(std::ostream &out, const ChartHypothesis *hypo, const Sentence &sentence, long translationId)
+{
+ static ApplicationContext applicationContext;
+
// recursive
if (hypo != NULL) {
+ ReconstructApplicationContext(*hypo, sentence, applicationContext);
out << "Trans Opt " << translationId
<< " " << hypo->GetCurrSourceRange()
- << ": " << hypo->GetTranslationOption().GetDottedRule()
- << ": " << hypo->GetCurrTargetPhrase().GetTargetLHS()
+ << ": ";
+ WriteApplicationContext(out, applicationContext);
+ out << ": " << hypo->GetCurrTargetPhrase().GetTargetLHS()
<< "->" << hypo->GetCurrTargetPhrase()
<< " " << hypo->GetTotalScore() << hypo->GetScoreBreakdown()
<< endl;
@@ -244,19 +301,20 @@ void OutputTranslationOptions(std::ostream &out, const ChartHypothesis *hypo, lo
std::vector<const ChartHypothesis*>::const_iterator iter;
for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) {
const ChartHypothesis *prevHypo = *iter;
- OutputTranslationOptions(out, prevHypo, translationId);
+ OutputTranslationOptions(out, prevHypo, sentence, translationId);
}
}
void IOWrapper::OutputDetailedTranslationReport(
const ChartHypothesis *hypo,
+ const Sentence &sentence,
long translationId)
{
if (hypo == NULL) {
return;
}
std::ostringstream out;
- OutputTranslationOptions(out, hypo, translationId);
+ OutputTranslationOptions(out, hypo, sentence, translationId);
CHECK(m_detailOutputCollector);
m_detailOutputCollector->Write(translationId, out.str());
}
diff --git a/moses-chart-cmd/src/IOWrapper.h b/moses-chart-cmd/src/IOWrapper.h
index 5936e7405..2dff534f8 100644
--- a/moses-chart-cmd/src/IOWrapper.h
+++ b/moses-chart-cmd/src/IOWrapper.h
@@ -82,7 +82,7 @@ public:
void OutputBestHypo(const Moses::ChartHypothesis *hypo, long translationId, bool reportSegmentation, bool reportAllFactors);
void OutputBestHypo(const std::vector<const Moses::Factor*>& mbrBestHypo, long translationId, bool reportSegmentation, bool reportAllFactors);
void OutputNBestList(const Moses::ChartTrellisPathList &nBestList, const Moses::ChartHypothesis *bestHypo, const Moses::TranslationSystem* system, long translationId);
- void OutputDetailedTranslationReport(const Moses::ChartHypothesis *hypo, long translationId);
+ void OutputDetailedTranslationReport(const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId);
void Backtrack(const Moses::ChartHypothesis *hypo);
void ResetTranslationId();
diff --git a/moses-chart-cmd/src/Main.cpp b/moses-chart-cmd/src/Main.cpp
index 868ce0732..b75d38aba 100644
--- a/moses-chart-cmd/src/Main.cpp
+++ b/moses-chart-cmd/src/Main.cpp
@@ -98,7 +98,8 @@ public:
}
if (staticData.IsDetailedTranslationReportingEnabled()) {
- m_ioWrapper.OutputDetailedTranslationReport(bestHypo, lineNumber);
+ const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
+ m_ioWrapper.OutputDetailedTranslationReport(bestHypo, sentence, lineNumber);
}
// n-best