00001 // $Id$ 00002 // vim:tabstop=2 00003 /*********************************************************************** 00004 Moses - factored phrase-based language decoder 00005 Copyright (C) 2010 Hieu Hoang 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 ***********************************************************************/ 00021 #pragma once 00022 00023 #include <set> 00024 #include "ChartHypothesis.h" 00025 #include "RuleCube.h" 00026 00027 00028 namespace Moses 00029 { 00030 00031 class ChartSearchGraphWriter; 00032 struct AllOptions; 00033 00035 class ChartHypothesisScoreOrderer 00036 { 00037 public: 00038 bool operator()(const ChartHypothesis* hypoA, const ChartHypothesis* hypoB) const { 00039 return hypoA->GetFutureScore() > hypoB->GetFutureScore(); 00040 } 00041 }; 00042 00046 class ChartHypothesisCollection 00047 { 00048 friend std::ostream& operator<<(std::ostream&, const ChartHypothesisCollection&); 00049 00050 protected: 00051 //typedef std::set<ChartHypothesis*, ChartHypothesisRecombinationOrderer> HCType; 00052 typedef boost::unordered_set< ChartHypothesis*, UnorderedComparer<ChartHypothesis>, UnorderedComparer<ChartHypothesis> > HCType; 00053 HCType m_hypos; 00054 HypoList m_hyposOrdered; 00055 00056 float m_bestScore; 00057 float m_beamWidth; 00058 size_t m_maxHypoStackSize; 00059 bool m_nBestIsEnabled; 00061 std::pair<HCType::iterator, bool> Add(ChartHypothesis *hypo, ChartManager &manager); 00062 00063 public: 00064 typedef HCType::iterator iterator; 00065 typedef HCType::const_iterator const_iterator; 00067 const_iterator begin() const { 00068 return m_hypos.begin(); 00069 } 00070 const_iterator end() const { 00071 return m_hypos.end(); 00072 } 00073 00074 ChartHypothesisCollection(AllOptions const& opts); 00075 ~ChartHypothesisCollection(); 00076 bool AddHypothesis(ChartHypothesis *hypo, ChartManager &manager); 00077 00078 void Detach(const HCType::iterator &iter); 00079 void Remove(const HCType::iterator &iter); 00080 00081 void PruneToSize(ChartManager &manager); 00082 00083 size_t GetSize() const { 00084 return m_hypos.size(); 00085 } 00086 size_t GetHypo() const { 00087 return m_hypos.size(); 00088 } 00089 00090 void SortHypotheses(); 00091 void CleanupArcList(); 00092 00094 const HypoList &GetSortedHypotheses() const { 00095 return m_hyposOrdered; 00096 } 00097 00099 float GetBestScore() const { 00100 return m_bestScore; 00101 } 00102 00103 void WriteSearchGraph(const ChartSearchGraphWriter& writer, const std::map<unsigned,bool> &reachable) const; 00104 00105 }; 00106 00107 } // namespace 00108