00001 #pragma once 00002 00003 #include <map> 00004 #include <vector> 00005 00006 #include <boost/functional/hash.hpp> 00007 #include <boost/unordered_map.hpp> 00008 #include <boost/version.hpp> 00009 00010 #include "moses/Syntax/RuleTable.h" 00011 #include "moses/Syntax/SymbolEqualityPred.h" 00012 #include "moses/Syntax/SymbolHasher.h" 00013 #include "moses/TargetPhrase.h" 00014 #include "moses/TargetPhraseCollection.h" 00015 #include "moses/Terminal.h" 00016 #include "moses/Util.h" 00017 #include "moses/Word.h" 00018 00019 #include "RuleTrie.h" 00020 00021 namespace Moses 00022 { 00023 namespace Syntax 00024 { 00025 namespace T2S 00026 { 00027 00028 class HyperTree: public RuleTable 00029 { 00030 public: 00031 class Node 00032 { 00033 public: 00034 typedef boost::unordered_map<std::vector<Factor*>, Node> Map; 00035 00036 bool IsLeaf() const { 00037 return m_map.empty(); 00038 } 00039 00040 bool HasRules() const { 00041 return !m_targetPhraseCollection.IsEmpty(); 00042 } 00043 00044 void Prune(std::size_t tableLimit); 00045 void Sort(std::size_t tableLimit); 00046 00047 Node *GetOrCreateChild(const HyperPath::NodeSeq &); 00048 00049 const Node *GetChild(const HyperPath::NodeSeq &) const; 00050 00051 const TargetPhraseCollection::shared_ptr GetTargetPhraseCollection() const 00052 return m_targetPhraseCollection; 00053 } 00054 00055 TargetPhraseCollection::shared_ptr GetTargetPhraseCollection() 00056 return m_targetPhraseCollection; 00057 } 00058 00059 const Map &GetMap() const 00060 { 00061 return m_map; 00062 } 00063 00064 private: 00065 Map m_map; 00066 TargetPhraseCollection m_targetPhraseCollection; 00067 }; 00068 00069 HyperTree(const RuleTableFF *ff) : RuleTable(ff) {} 00070 00071 const Node &GetRootNode() const 00072 { 00073 return m_root; 00074 } 00075 00076 private: 00077 friend class RuleTrieCreator; 00078 00079 TargetPhraseCollection::shared_ptr GetOrCreateTargetPhraseCollection( 00080 const Word &sourceLHS, const Phrase &sourceRHS); 00081 00082 Node &GetOrCreateNode(const Phrase &sourceRHS); 00083 00084 void SortAndPrune(std::size_t); 00085 00086 Node m_root; 00087 }; 00088 00089 } // namespace T2S 00090 } // namespace Syntax 00091 } // namespace Moses