2006-08-05 20:00:56 +04:00
|
|
|
// $Id$
|
|
|
|
|
2006-08-04 22:29:47 +04:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <algorithm>
|
2006-08-08 03:44:32 +04:00
|
|
|
#include "StaticData.h"
|
2006-08-04 22:29:47 +04:00
|
|
|
#include "Hypothesis.h"
|
|
|
|
#include "TranslationAnalysis.h"
|
|
|
|
|
|
|
|
namespace TranslationAnalysis {
|
|
|
|
|
|
|
|
void PrintTranslationAnalysis(std::ostream &os, const Hypothesis* hypo)
|
|
|
|
{
|
2006-08-08 03:44:32 +04:00
|
|
|
os << std::endl << "TRANSLATION HYPOTHESIS DETAILS:" << std::endl;
|
2006-08-04 22:29:47 +04:00
|
|
|
std::vector<const Hypothesis*> translationPath;
|
|
|
|
while (hypo) {
|
|
|
|
translationPath.push_back(hypo);
|
|
|
|
hypo = hypo->GetPrevHypo();
|
|
|
|
}
|
|
|
|
std::reverse(translationPath.begin(), translationPath.end());
|
|
|
|
|
|
|
|
std::vector<std::string> droppedWords;
|
|
|
|
std::vector<const Hypothesis*>::iterator tpi = translationPath.begin();
|
|
|
|
++tpi; // skip initial translation state
|
|
|
|
std::vector<std::string> sourceMap;
|
|
|
|
std::vector<std::string> targetMap;
|
2006-08-15 02:44:01 +04:00
|
|
|
std::vector<unsigned int> lmAcc(0);
|
|
|
|
size_t lmCalls = 0;
|
2006-10-17 15:07:17 +04:00
|
|
|
bool doLMStats = ((*tpi)->GetLMStats() != 0);
|
2006-08-15 02:44:01 +04:00
|
|
|
if (doLMStats)
|
2006-10-17 15:07:17 +04:00
|
|
|
lmAcc.resize((*tpi)->GetLMStats()->size(), 0);
|
2006-08-04 22:29:47 +04:00
|
|
|
for (; tpi != translationPath.end(); ++tpi) {
|
|
|
|
std::ostringstream sms;
|
|
|
|
std::ostringstream tms;
|
|
|
|
std::string target = (*tpi)->GetTargetPhraseStringRep();
|
|
|
|
std::string source = (*tpi)->GetSourcePhraseStringRep();
|
|
|
|
WordsRange twr = (*tpi)->GetCurrTargetWordsRange();
|
|
|
|
WordsRange swr = (*tpi)->GetCurrSourceWordsRange();
|
2006-08-15 02:44:01 +04:00
|
|
|
|
|
|
|
// language model backoff stats,
|
|
|
|
if (doLMStats) {
|
2006-10-17 15:07:17 +04:00
|
|
|
std::vector<std::vector<unsigned int> >& lmstats = *(*tpi)->GetLMStats();
|
2006-08-15 02:44:01 +04:00
|
|
|
std::vector<std::vector<unsigned int> >::iterator i = lmstats.begin();
|
|
|
|
std::vector<unsigned int>::iterator acc = lmAcc.begin();
|
2007-02-23 02:44:38 +03:00
|
|
|
|
2006-08-15 02:44:01 +04:00
|
|
|
for (; i != lmstats.end(); ++i, ++acc) {
|
|
|
|
std::vector<unsigned int>::iterator j = i->begin();
|
|
|
|
lmCalls += i->size();
|
|
|
|
for (; j != i->end(); ++j) {
|
|
|
|
(*acc) += *j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-04 22:29:47 +04:00
|
|
|
bool epsilon = false;
|
|
|
|
if (target == "") {
|
|
|
|
target="<EPSILON>";
|
|
|
|
epsilon = true;
|
|
|
|
droppedWords.push_back(source);
|
|
|
|
}
|
2006-08-08 03:44:32 +04:00
|
|
|
os << " SOURCE: " << swr << " " << source << std::endl
|
|
|
|
<< " TRANSLATED AS: " << target << std::endl;
|
2006-08-04 22:29:47 +04:00
|
|
|
size_t twr_i = twr.GetStartPos();
|
|
|
|
size_t swr_i = swr.GetStartPos();
|
|
|
|
if (!epsilon) { sms << twr_i; }
|
|
|
|
if (epsilon) { tms << "del(" << swr_i << ")"; } else { tms << swr_i; }
|
|
|
|
swr_i++; twr_i++;
|
2006-08-11 20:48:03 +04:00
|
|
|
for (; twr_i <= twr.GetEndPos() && twr.GetEndPos() != NOT_FOUND; twr_i++) {
|
|
|
|
sms << '-' << twr_i;
|
|
|
|
}
|
|
|
|
for (; swr_i <= swr.GetEndPos() && swr.GetEndPos() != NOT_FOUND; swr_i++) {
|
2006-08-04 22:29:47 +04:00
|
|
|
tms << '-' << swr_i;
|
|
|
|
}
|
|
|
|
if (!epsilon) targetMap.push_back(sms.str());
|
|
|
|
sourceMap.push_back(tms.str());
|
|
|
|
}
|
|
|
|
std::vector<std::string>::iterator si = sourceMap.begin();
|
|
|
|
std::vector<std::string>::iterator ti = targetMap.begin();
|
2006-08-08 03:44:32 +04:00
|
|
|
os << std::endl << "SOURCE/TARGET SPANS:";
|
|
|
|
os << std::endl << " SOURCE:";
|
2006-08-04 22:29:47 +04:00
|
|
|
for (; si != sourceMap.end(); ++si) {
|
|
|
|
os << " " << *si;
|
|
|
|
}
|
2006-08-08 03:44:32 +04:00
|
|
|
os << std::endl << " TARGET:";
|
2006-08-04 22:29:47 +04:00
|
|
|
for (; ti != targetMap.end(); ++ti) {
|
|
|
|
os << " " << *ti;
|
|
|
|
}
|
2006-08-15 02:44:01 +04:00
|
|
|
os << std::endl << std::endl;
|
|
|
|
if (doLMStats && lmCalls > 0) {
|
|
|
|
std::vector<unsigned int>::iterator acc = lmAcc.begin();
|
2007-02-16 21:08:37 +03:00
|
|
|
const LMList& lmlist = StaticData::Instance().GetAllLM();
|
2006-08-15 02:44:01 +04:00
|
|
|
LMList::const_iterator i = lmlist.begin();
|
|
|
|
for (; acc != lmAcc.end(); ++acc, ++i) {
|
|
|
|
char buf[256];
|
2007-05-16 01:37:25 +04:00
|
|
|
sprintf(buf, "%.4f", (float)(*acc)/(float)lmCalls);
|
2006-08-15 02:44:01 +04:00
|
|
|
os << (*i)->GetScoreProducerDescription() <<", AVG N-GRAM LENGTH: " << buf << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2006-08-04 22:29:47 +04:00
|
|
|
|
|
|
|
if (droppedWords.size() > 0) {
|
|
|
|
std::vector<std::string>::iterator dwi = droppedWords.begin();
|
2006-08-08 03:44:32 +04:00
|
|
|
os << std::endl << "WORDS/PHRASES DROPPED:" << std::endl;
|
2006-08-04 22:29:47 +04:00
|
|
|
for (; dwi != droppedWords.end(); ++dwi) {
|
2006-08-11 20:48:03 +04:00
|
|
|
os << "\tdropped=" << *dwi << std::endl;
|
2006-08-04 22:29:47 +04:00
|
|
|
}
|
|
|
|
}
|
2006-08-08 03:44:32 +04:00
|
|
|
os << std::endl << "SCORES (UNWEIGHTED/WEIGHTED):" << std::endl;
|
2007-02-16 21:08:37 +03:00
|
|
|
StaticData::Instance().GetScoreIndexManager().Debug_PrintLabeledWeightedScores(os, translationPath.back()->GetScoreBreakdown(), StaticData::Instance().GetAllWeights());
|
2006-08-08 03:44:32 +04:00
|
|
|
os << std::endl;
|
2006-08-04 22:29:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|