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