00001 // $Id$ 00002 /*********************************************************************** 00003 Moses - factored phrase-based language decoder 00004 Copyright (C) 2010 Hieu Hoang 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 ***********************************************************************/ 00020 #pragma once 00021 00022 #include <vector> 00023 #include "util/check.hh" 00024 00025 #include "DotChart.h" 00026 00027 namespace OnDiskPt 00028 { 00029 class PhraseNode; 00030 } 00031 00032 00033 namespace Moses 00034 { 00035 class DottedRuleOnDisk : public DottedRule 00036 { 00037 public: 00038 // used only to init dot stack. 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 { return m_lastNode; } 00052 00053 bool Done() const { return m_done; } 00054 void Done(bool value) const { m_done = value; } 00055 00056 private: 00057 const OnDiskPt::PhraseNode &m_lastNode; 00058 mutable bool m_done; 00059 }; 00060 00061 class DottedRuleCollOnDisk 00062 { 00063 protected: 00064 typedef std::vector<const DottedRuleOnDisk*> CollType; 00065 CollType m_coll; 00066 00067 public: 00068 typedef CollType::iterator iterator; 00069 typedef CollType::const_iterator const_iterator; 00070 00071 const_iterator begin() const { 00072 return m_coll.begin(); 00073 } 00074 const_iterator end() const { 00075 return m_coll.end(); 00076 } 00077 iterator begin() { 00078 return m_coll.begin(); 00079 } 00080 iterator end() { 00081 return m_coll.end(); 00082 } 00083 00084 const DottedRuleOnDisk &Get(size_t ind) const { 00085 return *m_coll[ind]; 00086 } 00087 00088 void Add(const DottedRuleOnDisk *dottedRule) { 00089 m_coll.push_back(dottedRule); 00090 } 00091 void Delete(size_t ind) { 00092 //delete m_coll[ind]; 00093 m_coll.erase(m_coll.begin() + ind); 00094 } 00095 00096 size_t GetSize() const { 00097 return m_coll.size(); 00098 } 00099 00100 }; 00101 00102 class SavedNodeOnDisk 00103 { 00104 const DottedRuleOnDisk *m_dottedRule; 00105 00106 public: 00107 SavedNodeOnDisk(const DottedRuleOnDisk *dottedRule) 00108 :m_dottedRule(dottedRule) { 00109 CHECK(m_dottedRule); 00110 } 00111 00112 ~SavedNodeOnDisk() { 00113 delete m_dottedRule; 00114 } 00115 00116 const DottedRuleOnDisk &GetDottedRule() const { 00117 return *m_dottedRule; 00118 } 00119 }; 00120 00121 class DottedRuleStackOnDisk 00122 { 00123 // coll of coll of processed rules 00124 public: 00125 typedef std::vector<SavedNodeOnDisk*> SavedNodeColl; 00126 00127 protected: 00128 typedef std::vector<DottedRuleCollOnDisk*> CollType; 00129 CollType m_coll; 00130 00131 SavedNodeColl m_savedNode; 00132 00133 public: 00134 typedef CollType::iterator iterator; 00135 typedef CollType::const_iterator const_iterator; 00136 00137 const_iterator begin() const { 00138 return m_coll.begin(); 00139 } 00140 const_iterator end() const { 00141 return m_coll.end(); 00142 } 00143 iterator begin() { 00144 return m_coll.begin(); 00145 } 00146 iterator end() { 00147 return m_coll.end(); 00148 } 00149 00150 DottedRuleStackOnDisk(size_t size); 00151 ~DottedRuleStackOnDisk(); 00152 00153 const DottedRuleCollOnDisk &Get(size_t pos) const { 00154 return *m_coll[pos]; 00155 } 00156 DottedRuleCollOnDisk &Get(size_t pos) { 00157 return *m_coll[pos]; 00158 } 00159 00160 const DottedRuleCollOnDisk &back() const { 00161 return *m_coll.back(); 00162 } 00163 00164 void Add(size_t pos, const DottedRuleOnDisk *dottedRule) { 00165 CHECK(dottedRule); 00166 00167 m_coll[pos]->Add(dottedRule); 00168 m_savedNode.push_back(new SavedNodeOnDisk(dottedRule)); 00169 } 00170 00171 const SavedNodeColl &GetSavedNodeColl() const { 00172 return m_savedNode; 00173 } 00174 00175 void SortSavedNodes(); 00176 00177 }; 00178 00179 } 00180
1.5.9