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 <iostream>
00025 #include <queue>
00026 #include <map>
00027 #include <vector>
00028 #include "Word.h"
00029 #include "Range.h"
00030 #include "NonTerminal.h"
00031 #include "ChartHypothesis.h"
00032 #include "ChartHypothesisCollection.h"
00033 #include "RuleCube.h"
00034 #include "ChartCellLabelSet.h"
00035
00036 #include <boost/scoped_ptr.hpp>
00037 #include <boost/functional/hash.hpp>
00038 #include <boost/unordered_map.hpp>
00039 #include <boost/version.hpp>
00040
00041 namespace Moses
00042 {
00043 class ChartSearchGraphWriter;
00044 class ChartTranslationOptionList;
00045 class ChartCellCollection;
00046 class ChartManager;
00047
00048 class ChartCellBase
00049 {
00050 public:
00051 ChartCellBase(size_t startPos, size_t endPos);
00052
00053 virtual ~ChartCellBase();
00054
00055 const ChartCellLabelSet &GetTargetLabelSet() const {
00056 return m_targetLabelSet;
00057 }
00058
00059 ChartCellLabelSet &MutableTargetLabelSet() {
00060 return m_targetLabelSet;
00061 }
00062
00063 const Range &GetCoverage() const {
00064 return m_coverage;
00065 }
00066
00067 protected:
00068 const Range m_coverage;
00069 ChartCellLabelSet m_targetLabelSet;
00070 };
00071
00075 class ChartCell : public ChartCellBase
00076 {
00077 friend std::ostream& operator<<(std::ostream&, const ChartCell&);
00078 public:
00079 #if defined(BOOST_VERSION) && (BOOST_VERSION >= 104200)
00080 typedef boost::unordered_map<Word,
00081 ChartHypothesisCollection,
00082 NonTerminalHasher,
00083 NonTerminalEqualityPred
00084 > MapType;
00085 #else
00086 typedef std::map<Word, ChartHypothesisCollection> MapType;
00087 #endif
00088
00089 protected:
00090 MapType m_hypoColl;
00091
00092 bool m_nBestIsEnabled;
00093 ChartManager &m_manager;
00094
00095 public:
00096 ChartCell(size_t startPos, size_t endPos, ChartManager &manager);
00097 ~ChartCell();
00098
00099 void Decode(const ChartTranslationOptionList &transOptList
00100 ,const ChartCellCollection &allChartCells);
00101
00103 const HypoList *GetSortedHypotheses(const Word &constituentLabel) const {
00104 MapType::const_iterator p = m_hypoColl.find(constituentLabel);
00105 return (p == m_hypoColl.end()) ? NULL : &(p->second.GetSortedHypotheses());
00106 }
00107
00109 const HypoList *GetAllSortedHypotheses() const;
00110
00111 bool AddHypothesis(ChartHypothesis *hypo);
00112
00113 void SortHypotheses();
00114 void PruneToSize();
00115
00116 const ChartHypothesis *GetBestHypothesis() const;
00117
00118 void CleanupArcList();
00119
00120 void OutputSizes(std::ostream &out) const;
00121 size_t GetSize() const;
00122
00123 void WriteSearchGraph(const ChartSearchGraphWriter& writer, const std::map<unsigned,bool> &reachable) const;
00124
00125 };
00126
00127 }
00128