00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #pragma once
00023
00024 #include <vector>
00025 #include <boost/unordered_map.hpp>
00026 #include "ChartCell.h"
00027 #include "ChartCellCollection.h"
00028 #include "Range.h"
00029 #include "SentenceStats.h"
00030 #include "ChartTranslationOptionList.h"
00031 #include "ChartParser.h"
00032 #include "ChartKBestExtractor.h"
00033 #include "BaseManager.h"
00034 #include "moses/Syntax/KBestExtractor.h"
00035
00036 namespace Moses
00037 {
00038
00039 class ChartHypothesis;
00040 class ChartSearchGraphWriter;
00041
00044 class ChartManager : public BaseManager
00045 {
00046 private:
00047 ChartCellCollection m_hypoStackColl;
00048 std::auto_ptr<SentenceStats> m_sentenceStats;
00049 clock_t m_start;
00050 unsigned m_hypothesisId;
00051
00052 ChartParser m_parser;
00053
00054 ChartTranslationOptionList m_translationOptionList;
00056
00057 void FindReachableHypotheses(
00058 const ChartHypothesis *hypo, std::map<unsigned,bool> &reachable , size_t* winners, size_t* losers) const;
00059 void WriteSearchGraph(const ChartSearchGraphWriter& writer) const;
00060
00061
00062 void OutputNBestList(OutputCollector *collector,
00063 const ChartKBestExtractor::KBestVec &nBestList,
00064 long translationId) const;
00065 size_t CalcSourceSize(const Moses::ChartHypothesis *hypo) const;
00066 size_t OutputAlignmentNBest(Alignments &retAlign,
00067 const Moses::ChartKBestExtractor::Derivation &derivation,
00068 size_t startTarget) const;
00069 size_t OutputAlignment(Alignments &retAlign,
00070 const Moses::ChartHypothesis *hypo,
00071 size_t startTarget) const;
00072 void OutputDetailedTranslationReport(
00073 OutputCollector *collector,
00074 const ChartHypothesis *hypo,
00075 const Sentence &sentence,
00076 long translationId) const;
00077 void OutputTranslationOptions(std::ostream &out,
00078 ApplicationContext &applicationContext,
00079 const ChartHypothesis *hypo,
00080 const Sentence &sentence,
00081 long translationId) const;
00082 void OutputTranslationOption(std::ostream &out,
00083 ApplicationContext &applicationContext,
00084 const ChartHypothesis *hypo,
00085 const Sentence &sentence,
00086 long translationId) const;
00087 void ReconstructApplicationContext(const ChartHypothesis &hypo,
00088 const Sentence &sentence,
00089 ApplicationContext &context) const;
00090 void OutputTreeFragmentsTranslationOptions(std::ostream &out,
00091 ApplicationContext &applicationContext,
00092 const ChartHypothesis *hypo,
00093 const Sentence &sentence,
00094 long translationId) const;
00095 void OutputDetailedAllTranslationReport(
00096 OutputCollector *collector,
00097 const std::vector<boost::shared_ptr<Moses::ChartKBestExtractor::Derivation> > &nBestList,
00098 const Sentence &sentence,
00099 long translationId) const;
00100 void OutputBestHypo(OutputCollector *collector, const ChartHypothesis *hypo, long translationId) const;
00101 void Backtrack(const ChartHypothesis *hypo) const;
00102
00103 public:
00104 ChartManager(ttasksptr const& ttask);
00105 ~ChartManager();
00106 void Decode();
00107 void AddXmlChartOptions();
00108 const ChartHypothesis *GetBestHypothesis() const;
00109 void CalcNBest(size_t n, std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > &nBestList, bool onlyDistinct=false) const;
00110
00112 void OutputSearchGraphMoses(std::ostream &outputSearchGraphStream) const;
00113
00115 void OutputSearchGraphAsHypergraph(std::ostream &outputSearchGraphStream) const;
00116
00118 SentenceStats& GetSentenceStats() const {
00119 return *m_sentenceStats;
00120 }
00121
00122
00123 const ChartCellCollection& GetChartCellCollection() const {
00124 return m_hypoStackColl;
00125 }
00126
00127 void CalcDecoderStatistics() const {
00128 }
00129
00130 void ResetSentenceStats(const InputType& source) {
00131 m_sentenceStats = std::auto_ptr<SentenceStats>(new SentenceStats(source));
00132 }
00133
00135 unsigned GetNextHypoId() {
00136 return m_hypothesisId++;
00137 }
00138
00139 const ChartParser &GetParser() const {
00140 return m_parser;
00141 }
00142
00143
00144 void OutputBest(OutputCollector *collector) const;
00145 void OutputNBest(OutputCollector *collector) const;
00146 void OutputLatticeSamples(OutputCollector *collector) const {
00147 }
00148 void OutputAlignment(OutputCollector *collector) const;
00149 void OutputDetailedTranslationReport(OutputCollector *collector) const;
00150 void OutputUnknowns(OutputCollector *collector) const;
00151 void OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const;
00152 void OutputWordGraph(OutputCollector *collector) const {
00153 }
00154 void OutputSearchGraph(OutputCollector *collector) const;
00155 void OutputSearchGraphSLF() const {
00156 }
00157
00158
00159 };
00160
00161 }
00162