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 #ifndef moses_cmd_IOWrapper_h
00036 #define moses_cmd_IOWrapper_h
00037
00038 #include <cassert>
00039 #include <fstream>
00040 #include <ostream>
00041 #include <vector>
00042 #include "util/check.hh"
00043
00044 #include "moses/TypeDef.h"
00045 #include "moses/Sentence.h"
00046 #include "moses/FactorTypeSet.h"
00047 #include "moses/FactorCollection.h"
00048 #include "moses/Hypothesis.h"
00049 #include "moses/OutputCollector.h"
00050 #include "moses/TrellisPathList.h"
00051 #include "moses/InputFileStream.h"
00052 #include "moses/InputType.h"
00053 #include "moses/WordLattice.h"
00054 #include "LatticeMBR.h"
00055
00056 namespace Moses
00057 {
00058 class ScoreComponentCollection;
00059 }
00060
00061 namespace MosesCmd
00062 {
00063
00066 class IOWrapper
00067 {
00068 protected:
00069 long m_translationId;
00070
00071 const std::vector<Moses::FactorType> &m_inputFactorOrder;
00072 const std::vector<Moses::FactorType> &m_outputFactorOrder;
00073 const Moses::FactorMask &m_inputFactorUsed;
00074 std::string m_inputFilePath;
00075 Moses::InputFileStream *m_inputFile;
00076 std::istream *m_inputStream;
00077 std::ostream *m_nBestStream
00078 ,*m_outputWordGraphStream,*m_outputSearchGraphStream;
00079 std::ostream *m_detailedTranslationReportingStream;
00080 std::ofstream *m_alignmentOutputStream;
00081 bool m_surpressSingleBestOutput;
00082
00083 void Initialization(const std::vector<Moses::FactorType> &inputFactorOrder
00084 , const std::vector<Moses::FactorType> &outputFactorOrder
00085 , const Moses::FactorMask &inputFactorUsed
00086 , size_t nBestSize
00087 , const std::string &nBestFilePath);
00088
00089
00090 public:
00091 IOWrapper(const std::vector<Moses::FactorType> &inputFactorOrder
00092 , const std::vector<Moses::FactorType> &outputFactorOrder
00093 , const Moses::FactorMask &inputFactorUsed
00094 , size_t nBestSize
00095 , const std::string &nBestFilePath);
00096
00097 IOWrapper(const std::vector<Moses::FactorType> &inputFactorOrder
00098 , const std::vector<Moses::FactorType> &outputFactorOrder
00099 , const Moses::FactorMask &inputFactorUsed
00100 , size_t nBestSize
00101 , const std::string &nBestFilePath
00102 , const std::string &infilePath);
00103 ~IOWrapper();
00104
00105 Moses::InputType* GetInput(Moses::InputType *inputType);
00106
00107 void OutputBestHypo(const Moses::Hypothesis *hypo, long translationId, bool reportSegmentation, bool reportAllFactors);
00108 void OutputLatticeMBRNBestList(const std::vector<LatticeMBRSolution>& solutions,long translationId);
00109 void Backtrack(const Moses::Hypothesis *hypo);
00110
00111 void ResetTranslationId() {
00112 m_translationId = 0;
00113 }
00114
00115 std::ofstream *GetAlignmentOutputStream() {
00116 return m_alignmentOutputStream;
00117 }
00118
00119 std::ostream &GetOutputWordGraphStream() {
00120 return *m_outputWordGraphStream;
00121 }
00122 std::ostream &GetOutputSearchGraphStream() {
00123 return *m_outputSearchGraphStream;
00124 }
00125
00126 std::ostream &GetDetailedTranslationReportingStream() {
00127 assert (m_detailedTranslationReportingStream);
00128 return *m_detailedTranslationReportingStream;
00129 }
00130 };
00131
00132 IOWrapper *GetIOWrapper(const Moses::StaticData &staticData);
00133 bool ReadInput(IOWrapper &ioWrapper, Moses::InputTypeEnum inputType, Moses::InputType*& source);
00134 void OutputBestSurface(std::ostream &out, const Moses::Hypothesis *hypo, const std::vector<Moses::FactorType> &outputFactorOrder, bool reportSegmentation, bool reportAllFactors);
00135 void OutputLatticeMBRNBest(std::ostream& out, const std::vector<LatticeMBRSolution>& solutions,long translationId);
00136 void OutputBestHypo(const std::vector<Moses::Word>& mbrBestHypo, long ,
00137 bool reportSegmentation, bool reportAllFactors, std::ostream& out);
00138 void OutputBestHypo(const Moses::TrellisPath &path, long ,bool reportSegmentation, bool reportAllFactors, std::ostream &out);
00139 void OutputInput(std::ostream& os, const Moses::Hypothesis* hypo);
00140 void OutputAlignment(Moses::OutputCollector* collector, size_t lineNo, const Moses::Hypothesis *hypo);
00141 void OutputAlignment(Moses::OutputCollector* collector, size_t lineNo, const Moses::TrellisPath &path);
00142 void OutputAlignment(std::ostream &out, const Moses::Hypothesis *hypo);
00143
00144 void OutputNBest(std::ostream& out
00145 , const Moses::TrellisPathList &nBestList
00146 , const std::vector<Moses::FactorType>& outputFactorOrder
00147 , long translationId
00148 , bool reportSegmentation);
00149 void OutputAllFeatureScores(const Moses::ScoreComponentCollection &features
00150 , std::ostream &out);
00151 void OutputFeatureScores( std::ostream& out
00152 , const Moses::ScoreComponentCollection &features
00153 , const Moses::FeatureFunction *ff
00154 , std::string &lastName );
00155
00156 }
00157
00158 #endif