00001 // $Id$ 00002 // vim:tabstop=2 00003 00004 /*********************************************************************** 00005 Moses - factored phrase-based language decoder 00006 Copyright (C) 2006 University of Edinburgh 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 ***********************************************************************/ 00022 00023 #ifndef moses_PhraseDictionaryNode_h 00024 #define moses_PhraseDictionaryNode_h 00025 00026 #include <map> 00027 #include <vector> 00028 #include <iterator> 00029 #include "Word.h" 00030 #include "TargetPhraseCollection.h" 00031 00032 namespace Moses 00033 { 00034 00035 class PhraseDictionaryMemory; 00036 class PhraseDictionaryFeature; 00037 00040 class PhraseDictionaryNode 00041 { 00042 typedef std::map<Word, PhraseDictionaryNode> NodeMap; 00043 00044 // only these classes are allowed to instantiate this class 00045 friend class PhraseDictionaryMemory; 00046 friend class std::map<Word, PhraseDictionaryNode>; 00047 00048 protected: 00049 NodeMap m_map; 00050 TargetPhraseCollection *m_targetPhraseCollection; 00051 00052 PhraseDictionaryNode() 00053 :m_targetPhraseCollection(NULL) 00054 {} 00055 public: 00056 ~PhraseDictionaryNode(); 00057 00058 void Sort(size_t tableLimit); 00059 PhraseDictionaryNode *GetOrCreateChild(const Word &word); 00060 const PhraseDictionaryNode *GetChild(const Word &word) const; 00061 const TargetPhraseCollection *GetTargetPhraseCollection() const { 00062 return m_targetPhraseCollection; 00063 } 00064 TargetPhraseCollection *CreateTargetPhraseCollection() { 00065 if (m_targetPhraseCollection == NULL) 00066 m_targetPhraseCollection = new TargetPhraseCollection(); 00067 return m_targetPhraseCollection; 00068 } 00069 00070 // iterators 00071 typedef NodeMap::iterator iterator; 00072 typedef NodeMap::const_iterator const_iterator; 00073 const_iterator begin() const { 00074 return m_map.begin(); 00075 } 00076 const_iterator end() const { 00077 return m_map.end(); 00078 } 00079 iterator begin() { 00080 return m_map.begin(); 00081 } 00082 iterator end() { 00083 return m_map.end(); 00084 } 00085 }; 00086 00087 } 00088 #endif
1.5.9