00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <vector>
00023 #include "DotChart.h"
00024
00025 namespace OnDiskPt
00026 {
00027 class PhraseNode;
00028 }
00029
00030 namespace Moses
00031 {
00032
00035 class DottedRuleOnDisk : public DottedRule
00036 {
00037 public:
00038
00039 explicit DottedRuleOnDisk(const OnDiskPt::PhraseNode &lastNode)
00040 : DottedRule()
00041 , m_lastNode(lastNode)
00042 , m_done(false) {}
00043
00044 DottedRuleOnDisk(const OnDiskPt::PhraseNode &lastNode,
00045 const ChartCellLabel &cellLabel,
00046 const DottedRuleOnDisk &prev)
00047 : DottedRule(cellLabel, prev)
00048 , m_lastNode(lastNode)
00049 , m_done(false) {}
00050
00051 const OnDiskPt::PhraseNode &GetLastNode() const {
00052 return m_lastNode;
00053 }
00054
00055 bool Done() const {
00056 return m_done;
00057 }
00058 void Done(bool value) const {
00059 m_done = value;
00060 }
00061
00062 private:
00063 const OnDiskPt::PhraseNode &m_lastNode;
00064 mutable bool m_done;
00065 };
00066
00067 class DottedRuleCollOnDisk
00068 {
00069 protected:
00070 typedef std::vector<const DottedRuleOnDisk*> CollType;
00071 CollType m_coll;
00072
00073 public:
00074 typedef CollType::iterator iterator;
00075 typedef CollType::const_iterator const_iterator;
00076
00077 const_iterator begin() const {
00078 return m_coll.begin();
00079 }
00080 const_iterator end() const {
00081 return m_coll.end();
00082 }
00083 iterator begin() {
00084 return m_coll.begin();
00085 }
00086 iterator end() {
00087 return m_coll.end();
00088 }
00089
00090 const DottedRuleOnDisk &Get(size_t ind) const {
00091 return *m_coll[ind];
00092 }
00093
00094 void Add(const DottedRuleOnDisk *dottedRule) {
00095 m_coll.push_back(dottedRule);
00096 }
00097 void Delete(size_t ind) {
00098
00099 m_coll.erase(m_coll.begin() + ind);
00100 }
00101
00102 size_t GetSize() const {
00103 return m_coll.size();
00104 }
00105
00106 };
00107
00108 class SavedNodeOnDisk
00109 {
00110 const DottedRuleOnDisk *m_dottedRule;
00111
00112 public:
00113 SavedNodeOnDisk(const DottedRuleOnDisk *dottedRule)
00114 :m_dottedRule(dottedRule) {
00115 UTIL_THROW_IF2(m_dottedRule == NULL, "Dotted rule is null");
00116 }
00117
00118 ~SavedNodeOnDisk() {
00119 delete m_dottedRule;
00120 }
00121
00122 const DottedRuleOnDisk &GetDottedRule() const {
00123 return *m_dottedRule;
00124 }
00125 };
00126
00127 class DottedRuleStackOnDisk
00128 {
00129
00130 public:
00131 typedef std::vector<SavedNodeOnDisk*> SavedNodeColl;
00132
00133 protected:
00134 typedef std::vector<DottedRuleCollOnDisk*> CollType;
00135 CollType m_coll;
00136
00137 SavedNodeColl m_savedNode;
00138
00139 public:
00140 typedef CollType::iterator iterator;
00141 typedef CollType::const_iterator const_iterator;
00142
00143 const_iterator begin() const {
00144 return m_coll.begin();
00145 }
00146 const_iterator end() const {
00147 return m_coll.end();
00148 }
00149 iterator begin() {
00150 return m_coll.begin();
00151 }
00152 iterator end() {
00153 return m_coll.end();
00154 }
00155
00156 DottedRuleStackOnDisk(size_t size);
00157 ~DottedRuleStackOnDisk();
00158
00159 const DottedRuleCollOnDisk &Get(size_t pos) const {
00160 return *m_coll[pos];
00161 }
00162 DottedRuleCollOnDisk &Get(size_t pos) {
00163 return *m_coll[pos];
00164 }
00165
00166 const DottedRuleCollOnDisk &back() const {
00167 return *m_coll.back();
00168 }
00169
00170 void Add(size_t pos, const DottedRuleOnDisk *dottedRule) {
00171 UTIL_THROW_IF2(dottedRule == NULL, "Dotted rule is null");
00172
00173 m_coll[pos]->Add(dottedRule);
00174 m_savedNode.push_back(new SavedNodeOnDisk(dottedRule));
00175 }
00176
00177 const SavedNodeColl &GetSavedNodeColl() const {
00178 return m_savedNode;
00179 }
00180
00181 void SortSavedNodes();
00182
00183 };
00184
00185 }
00186