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:
authorHieu Hoang <hieuhoang@gmail.com>2014-12-03 20:04:10 +0300
committerHieu Hoang <hieuhoang@gmail.com>2014-12-03 20:04:10 +0300
commitccbcc14ed863dc903bb8b2d84f5989ef806a0e75 (patch)
tree54af4d7b63bb27e48d6868a5413fbb83379afd06 /moses/Incremental.cpp
parent184e79f4d6943f1ada23ab1f8780cb1097e08121 (diff)
move OutputDetailedTranslationReport() to Managers
Diffstat (limited to 'moses/Incremental.cpp')
-rw-r--r--moses/Incremental.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/moses/Incremental.cpp b/moses/Incremental.cpp
index d366065a5..e05697cc8 100644
--- a/moses/Incremental.cpp
+++ b/moses/Incremental.cpp
@@ -319,6 +319,97 @@ void Manager::OutputNBestList(OutputCollector *collector, const std::vector<sear
collector->Write(translationId, out.str());
}
+void Manager::OutputDetailedTranslationReport(OutputCollector *collector) const
+{
+ if (collector && !completed_nbest_->empty()) {
+ const search::Applied &applied = completed_nbest_->at(0);
+ OutputDetailedTranslationReport(collector,
+ &applied,
+ static_cast<const Sentence&>(source_),
+ source_.GetTranslationId());
+ }
+
+}
+
+void Manager::OutputDetailedTranslationReport(
+ OutputCollector *collector,
+ const search::Applied *applied,
+ const Sentence &sentence,
+ long translationId) const
+{
+ if (applied == NULL) {
+ return;
+ }
+ std::ostringstream out;
+ ApplicationContext applicationContext;
+
+ OutputTranslationOptions(out, applicationContext, applied, sentence, translationId);
+ collector->Write(translationId, out.str());
+}
+
+void Manager::OutputTranslationOptions(std::ostream &out,
+ ApplicationContext &applicationContext,
+ const search::Applied *applied,
+ const Sentence &sentence, long translationId) const
+{
+ if (applied != NULL) {
+ OutputTranslationOption(out, applicationContext, applied, sentence, translationId);
+ out << std::endl;
+ }
+
+ // recursive
+ const search::Applied *child = applied->Children();
+ for (size_t i = 0; i < applied->GetArity(); i++) {
+ OutputTranslationOptions(out, applicationContext, child++, sentence, translationId);
+ }
+}
+
+void Manager::OutputTranslationOption(std::ostream &out,
+ ApplicationContext &applicationContext,
+ const search::Applied *applied,
+ const Sentence &sentence,
+ long translationId) const
+{
+ ReconstructApplicationContext(applied, sentence, applicationContext);
+ const TargetPhrase &phrase = *static_cast<const TargetPhrase*>(applied->GetNote().vp);
+ out << "Trans Opt " << translationId
+ << " " << applied->GetRange()
+ << ": ";
+ WriteApplicationContext(out, applicationContext);
+ out << ": " << phrase.GetTargetLHS()
+ << "->" << phrase
+ << " " << applied->GetScore(); // << hypo->GetScoreBreakdown() TODO: missing in incremental search hypothesis
+}
+
+// Given a hypothesis and sentence, reconstructs the 'application context' --
+// the source RHS symbols of the SCFG rule that was applied, plus their spans.
+void Manager::ReconstructApplicationContext(const search::Applied *applied,
+ const Sentence &sentence,
+ ApplicationContext &context) const
+{
+ context.clear();
+ const WordsRange &span = applied->GetRange();
+ const search::Applied *child = applied->Children();
+ size_t i = span.GetStartPos();
+ size_t j = 0;
+
+ while (i <= span.GetEndPos()) {
+ if (j == applied->GetArity() || i < child->GetRange().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 = static_cast<const TargetPhrase*>(child->GetNote().vp)->GetTargetLHS();
+ const WordsRange &range = child->GetRange();
+ context.push_back(std::make_pair(symbol, range));
+ i = range.GetEndPos()+1;
+ ++child;
+ ++j;
+ }
+ }
+}
namespace
{