From 08d6f77cea935179c5d7d8361efa54cf8a6c07bd Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Mon, 29 Sep 2014 17:16:11 +0100 Subject: move TranslationAnalysis for both moses-cmd and moses-char-cmd into moses/ --- moses-cmd/Jamfile | 2 +- moses-cmd/Main.cpp | 2 +- moses-cmd/TranslationAnalysis.cpp | 137 -------------------------------------- moses-cmd/TranslationAnalysis.h | 24 ------- 4 files changed, 2 insertions(+), 163 deletions(-) delete mode 100644 moses-cmd/TranslationAnalysis.cpp delete mode 100644 moses-cmd/TranslationAnalysis.h (limited to 'moses-cmd') diff --git a/moses-cmd/Jamfile b/moses-cmd/Jamfile index 79af196e9..4f7e0e773 100644 --- a/moses-cmd/Jamfile +++ b/moses-cmd/Jamfile @@ -1,4 +1,4 @@ -alias deps : IOWrapper.cpp mbr.cpp LatticeMBR.cpp TranslationAnalysis.cpp ..//z ..//boost_iostreams ..//boost_filesystem ../moses//moses ; +alias deps : IOWrapper.cpp mbr.cpp LatticeMBR.cpp ..//z ..//boost_iostreams ..//boost_filesystem ../moses//moses ; exe moses : Main.cpp deps ; exe lmbrgrid : LatticeMBRGrid.cpp deps ; diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index a8b50db17..713ded2e3 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //#include #endif -#include "TranslationAnalysis.h" +#include "moses/TranslationAnalysis.h" #include "IOWrapper.h" #include "mbr.h" diff --git a/moses-cmd/TranslationAnalysis.cpp b/moses-cmd/TranslationAnalysis.cpp deleted file mode 100644 index e77486162..000000000 --- a/moses-cmd/TranslationAnalysis.cpp +++ /dev/null @@ -1,137 +0,0 @@ -// $Id$ - -#include -#include -#include -#include "moses/StaticData.h" -#include "moses/Hypothesis.h" -#include "TranslationAnalysis.h" -#include "moses/FF/StatefulFeatureFunction.h" -#include "moses/FF/StatelessFeatureFunction.h" -#include "moses/LM/Base.h" - -using namespace Moses; - -namespace TranslationAnalysis -{ - -void PrintTranslationAnalysis(std::ostream &os, const Hypothesis* hypo) -{ - os << std::endl << "TRANSLATION HYPOTHESIS DETAILS:" << std::endl; - std::vector translationPath; - - while (hypo) { - translationPath.push_back(hypo); - hypo = hypo->GetPrevHypo(); - } - - std::reverse(translationPath.begin(), translationPath.end()); - std::vector droppedWords; - std::vector::iterator tpi = translationPath.begin(); - if(tpi == translationPath.end()) - return; - ++tpi; // skip initial translation state - std::vector sourceMap; - std::vector targetMap; - std::vector lmAcc(0); - size_t lmCalls = 0; - bool doLMStats = ((*tpi)->GetLMStats() != 0); - if (doLMStats) - lmAcc.resize((*tpi)->GetLMStats()->size(), 0); - 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(); - const AlignmentInfo &alignmentInfo = (*tpi)->GetCurrTargetPhrase().GetAlignTerm(); - // language model backoff stats, - if (doLMStats) { - std::vector >& lmstats = *(*tpi)->GetLMStats(); - std::vector >::iterator i = lmstats.begin(); - std::vector::iterator acc = lmAcc.begin(); - - for (; i != lmstats.end(); ++i, ++acc) { - std::vector::iterator j = i->begin(); - lmCalls += i->size(); - for (; j != i->end(); ++j) { - (*acc) += *j; - } - } - } - - bool epsilon = false; - if (target == "") { - target=""; - epsilon = true; - droppedWords.push_back(source); - } - os << " SOURCE: " << swr << " " << source << std::endl - << " TRANSLATED AS: " << target << std::endl - << " WORD ALIGNED: " << alignmentInfo << std::endl; - 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++; - 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++) { - tms << '-' << swr_i; - } - if (!epsilon) targetMap.push_back(sms.str()); - sourceMap.push_back(tms.str()); - } - std::vector::iterator si = sourceMap.begin(); - std::vector::iterator ti = targetMap.begin(); - os << std::endl << "SOURCE/TARGET SPANS:"; - os << std::endl << " SOURCE:"; - for (; si != sourceMap.end(); ++si) { - os << " " << *si; - } - os << std::endl << " TARGET:"; - for (; ti != targetMap.end(); ++ti) { - os << " " << *ti; - } - os << std::endl << std::endl; - if (doLMStats && lmCalls > 0) { - std::vector::iterator acc = lmAcc.begin(); - - const std::vector &statefulFFs = StatefulFeatureFunction::GetStatefulFeatureFunctions(); - for (size_t i = 0; i < statefulFFs.size(); ++i) { - const StatefulFeatureFunction *ff = statefulFFs[i]; - const LanguageModel *lm = dynamic_cast(ff); - - if (lm) { - char buf[256]; - sprintf(buf, "%.4f", (float)(*acc)/(float)lmCalls); - os << lm->GetScoreProducerDescription() <<", AVG N-GRAM LENGTH: " << buf << std::endl; - - ++acc; - } - } - } - - if (droppedWords.size() > 0) { - std::vector::iterator dwi = droppedWords.begin(); - os << std::endl << "WORDS/PHRASES DROPPED:" << std::endl; - for (; dwi != droppedWords.end(); ++dwi) { - os << "\tdropped=" << *dwi << std::endl; - } - } - os << std::endl << "SCORES (UNWEIGHTED/WEIGHTED): "; - os << translationPath.back()->GetScoreBreakdown(); - os << " weighted(TODO)"; - os << std::endl; -} - -} diff --git a/moses-cmd/TranslationAnalysis.h b/moses-cmd/TranslationAnalysis.h deleted file mode 100644 index 348cfe512..000000000 --- a/moses-cmd/TranslationAnalysis.h +++ /dev/null @@ -1,24 +0,0 @@ -// $Id$ - -/* - * also see moses/SentenceStats - */ - -#ifndef moses_cmd_TranslationAnalysis_h -#define moses_cmd_TranslationAnalysis_h - -#include -#include "moses/Hypothesis.h" - -namespace TranslationAnalysis -{ - -/*** - * print details about the translation represented in hypothesis to - * os. Included information: phrase alignment, words dropped, scores - */ -void PrintTranslationAnalysis(std::ostream &os, const Moses::Hypothesis* hypo); - -} - -#endif -- cgit v1.2.3