00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef moses_Hypergraph_Output_h
00024 #define moses_Hypergraph_Output_h
00025
00026 #include <ostream>
00027 #include "moses/parameters/AllOptions.h"
00028
00033 namespace Moses
00034 {
00035
00036 class ChartHypothesisCollection;
00037
00038 template<class M>
00039 class HypergraphOutput
00040 {
00041
00042 public:
00044 HypergraphOutput(size_t precision);
00045
00047 void Write(const M& manager) const;
00048
00049 private:
00050 size_t m_precision;
00051 std::string m_hypergraphDir;
00052 std::string m_compression;
00053 bool m_appendSuffix;
00054 };
00055
00056
00060 class ChartSearchGraphWriter
00061 {
00062 protected:
00063 AllOptions::ptr m_options;
00064 ChartSearchGraphWriter(AllOptions::ptr const& opts) : m_options(opts) { }
00065 public:
00066 virtual void WriteHeader(size_t winners, size_t losers) const = 0;
00067 virtual void WriteHypos(const ChartHypothesisCollection& hypos,
00068 const std::map<unsigned, bool> &reachable) const = 0;
00069
00070 };
00071
00073 class ChartSearchGraphWriterMoses : public virtual ChartSearchGraphWriter
00074 {
00075 public:
00076 ChartSearchGraphWriterMoses(AllOptions::ptr const& opts,
00077 std::ostream* out, size_t lineNumber)
00078 : ChartSearchGraphWriter(opts), m_out(out), m_lineNumber(lineNumber) {}
00079 virtual void WriteHeader(size_t, size_t) const {
00080
00081 }
00082 virtual void WriteHypos(const ChartHypothesisCollection& hypos,
00083 const std::map<unsigned, bool> &reachable) const;
00084
00085 private:
00086 std::ostream* m_out;
00087 size_t m_lineNumber;
00088 };
00089
00091 class ChartSearchGraphWriterHypergraph : public virtual ChartSearchGraphWriter
00092 {
00093 public:
00094 ChartSearchGraphWriterHypergraph(AllOptions::ptr const& opts, std::ostream* out)
00095 : ChartSearchGraphWriter(opts), m_out(out), m_nodeId(0) { }
00096 virtual void WriteHeader(size_t winners, size_t losers) const;
00097 virtual void WriteHypos(const ChartHypothesisCollection& hypos,
00098 const std::map<unsigned, bool> &reachable) const;
00099
00100 private:
00101 std::ostream* m_out;
00102 mutable size_t m_nodeId;
00103 mutable std::map<size_t,size_t> m_hypoIdToNodeId;
00104 };
00105
00106 }
00107 #endif