00001 // $Id$ 00002 00003 /*********************************************************************** 00004 Moses - factored phrase-based language decoder 00005 Copyright (C) 2006 University of Edinburgh 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 00022 #ifndef moses_HypothesisStackNormal_h 00023 #define moses_HypothesisStackNormal_h 00024 00025 #include <limits> 00026 #include <set> 00027 #include "Hypothesis.h" 00028 #include "HypothesisStack.h" 00029 #include "Bitmap.h" 00030 00031 namespace Moses 00032 { 00033 // class Bitmap; 00034 // typedef size_t WordsBitmapID; 00035 00037 class HypothesisStackNormal: public HypothesisStack 00038 { 00039 public: 00040 friend std::ostream& operator<<(std::ostream&, const HypothesisStackNormal&); 00041 00042 protected: 00043 float m_bestScore; 00044 float m_worstScore; 00045 std::map< WordsBitmapID, float > m_diversityWorstScore; 00046 float m_beamWidth; 00047 size_t m_maxHypoStackSize; 00048 size_t m_minHypoStackDiversity; 00049 bool m_nBestIsEnabled; 00054 std::pair<HypothesisStackNormal::iterator, bool> Add(Hypothesis *hypothesis); 00055 00057 void RemoveAll(); 00058 00059 void SetWorstScoreForBitmap( WordsBitmapID id, float worstScore ) { 00060 m_diversityWorstScore[ id ] = worstScore; 00061 } 00062 00063 public: 00064 float GetWorstScoreForBitmap( WordsBitmapID id ) { 00065 if (m_diversityWorstScore.find( id ) == m_diversityWorstScore.end()) 00066 return -std::numeric_limits<float>::infinity(); 00067 return m_diversityWorstScore[ id ]; 00068 } 00069 virtual float GetWorstScoreForBitmap( const Bitmap &coverage ) { 00070 return GetWorstScoreForBitmap( coverage.GetID() ); 00071 } 00072 00073 HypothesisStackNormal(Manager& manager); 00074 00083 bool AddPrune(Hypothesis *hypothesis); 00084 00089 inline void SetMaxHypoStackSize(size_t maxHypoStackSize, size_t minHypoStackDiversity) { 00090 m_maxHypoStackSize = maxHypoStackSize; 00091 m_minHypoStackDiversity = minHypoStackDiversity; 00092 } 00093 00098 inline void SetBeamWidth(float beamWidth) { 00099 m_beamWidth = beamWidth; 00100 } 00102 inline float GetBestScore() const { 00103 return m_bestScore; 00104 } 00106 inline float GetWorstScore() const { 00107 return m_worstScore; 00108 } 00109 00116 void PruneToSize(size_t newSize); 00117 00119 const Hypothesis *GetBestHypothesis() const; 00121 std::vector<const Hypothesis*> GetSortedList() const; 00122 std::vector<Hypothesis*> GetSortedListNOTCONST(); 00123 00127 void CleanupArcList(); 00128 00129 TO_STRING(); 00130 }; 00131 00132 } 00133 #endif