00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #pragma once
00036
00037 #include <fstream>
00038 #include <vector>
00039 #include <set>
00040 #include "moses/TypeDef.h"
00041 #include "moses/Sentence.h"
00042 #include "moses/FactorTypeSet.h"
00043 #include "moses/ChartTrellisPathList.h"
00044 #include "moses/OutputCollector.h"
00045 #include "moses/ChartHypothesis.h"
00046 #include "moses/ChartTrellisPath.h"
00047 #include "search/applied.hh"
00048
00049 namespace Moses
00050 {
00051 class FactorCollection;
00052 class ChartTrellisPathList;
00053 class ScoreComponentCollection;
00054 }
00055
00056 namespace MosesChartCmd
00057 {
00058
00061 class IOWrapper
00062 {
00063 protected:
00064 typedef std::vector<std::pair<Moses::Word, Moses::WordsRange> > ApplicationContext;
00065
00066 long m_translationId;
00067
00068 const std::vector<Moses::FactorType> &m_inputFactorOrder;
00069 const std::vector<Moses::FactorType> &m_outputFactorOrder;
00070 const Moses::FactorMask &m_inputFactorUsed;
00071 std::ostream *m_outputSearchGraphStream;
00072 std::ostream *m_detailedTranslationReportingStream;
00073 std::ostream *m_alignmentInfoStream;
00074 std::string m_inputFilePath;
00075 std::istream *m_inputStream;
00076 Moses::OutputCollector *m_detailOutputCollector;
00077 Moses::OutputCollector *m_nBestOutputCollector;
00078 Moses::OutputCollector *m_searchGraphOutputCollector;
00079 Moses::OutputCollector *m_singleBestOutputCollector;
00080 Moses::OutputCollector *m_alignmentInfoCollector;
00081
00082 typedef std::set< std::pair<size_t, size_t> > Alignments;
00083 size_t OutputAlignmentNBest(Alignments &retAlign, const Moses::ChartTrellisNode &node, size_t startTarget);
00084 size_t OutputAlignment(Alignments &retAlign, const Moses::ChartHypothesis *hypo, size_t startTarget);
00085 void OutputAlignment(std::vector< std::set<size_t> > &retAlignmentsS2T, const Moses::AlignmentInfo &ai);
00086 void OutputTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId);
00087 void ReconstructApplicationContext(const Moses::ChartHypothesis &hypo,
00088 const Moses::Sentence &sentence,
00089 ApplicationContext &context);
00090 void WriteApplicationContext(std::ostream &out,
00091 const ApplicationContext &context);
00092
00093 void OutputAllFeatureScores(const Moses::ScoreComponentCollection &features
00094 , std::ostream &out);
00095 void OutputFeatureScores( std::ostream& out
00096 , const Moses::ScoreComponentCollection &features
00097 , const Moses::FeatureFunction *ff
00098 , std::string &lastName );
00099
00100 public:
00101 IOWrapper(const std::vector<Moses::FactorType> &inputFactorOrder
00102 , const std::vector<Moses::FactorType> &outputFactorOrder
00103 , const Moses::FactorMask &inputFactorUsed
00104 , size_t nBestSize
00105 , const std::string &nBestFilePath
00106 , const std::string &inputFilePath="");
00107 ~IOWrapper();
00108
00109 Moses::InputType* GetInput(Moses::InputType *inputType);
00110 void OutputBestHypo(const Moses::ChartHypothesis *hypo, long translationId);
00111 void OutputBestHypo(search::Applied applied, long translationId);
00112 void OutputBestHypo(const std::vector<const Moses::Factor*>& mbrBestHypo, long translationId);
00113 void OutputBestNone(long translationId);
00114 void OutputNBestList(const Moses::ChartTrellisPathList &nBestList, long translationId);
00115 void OutputNBestList(const std::vector<search::Applied> &nbest, long translationId);
00116 void OutputDetailedTranslationReport(const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId);
00117 void Backtrack(const Moses::ChartHypothesis *hypo);
00118
00119 void ResetTranslationId();
00120
00121 Moses::OutputCollector *GetSearchGraphOutputCollector() {
00122 return m_searchGraphOutputCollector;
00123 }
00124
00125 void OutputAlignment(size_t translationId , const Moses::ChartHypothesis *hypo);
00126
00127 static void FixPrecision(std::ostream &, size_t size=3);
00128 };
00129
00130 }