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_HypothesisStackCubePruning_h 00023 #define moses_HypothesisStackCubePruning_h 00024 00025 #include <limits> 00026 #include <map> 00027 #include <set> 00028 #include "Hypothesis.h" 00029 #include "BitmapContainer.h" 00030 #include "HypothesisStack.h" 00031 00032 namespace Moses 00033 { 00034 00035 class BitmapContainer; 00036 class TranslationOptionList; 00037 class Manager; 00038 00039 typedef std::map<WordsBitmap, BitmapContainer*> _BMType; 00040 00042 class HypothesisStackCubePruning : public HypothesisStack 00043 { 00044 public: 00045 friend std::ostream& operator<<(std::ostream&, const HypothesisStackCubePruning&); 00046 00047 protected: 00048 _BMType m_bitmapAccessor; 00049 00050 float m_bestScore; 00051 float m_worstScore; 00052 float m_beamWidth; 00053 size_t m_maxHypoStackSize; 00054 bool m_nBestIsEnabled; 00059 std::pair<HypothesisStackCubePruning::iterator, bool> Add(Hypothesis *hypothesis); 00060 00062 void RemoveAll(); 00063 00064 public: 00065 HypothesisStackCubePruning(Manager& manager); 00066 ~HypothesisStackCubePruning() { 00067 RemoveAll(); 00068 m_bitmapAccessor.clear(); 00069 } 00070 00079 bool AddPrune(Hypothesis *hypothesis); 00080 00081 void AddInitial(Hypothesis *hypo); 00082 00086 inline void SetMaxHypoStackSize(size_t maxHypoStackSize) { 00087 m_maxHypoStackSize = maxHypoStackSize; 00088 } 00089 00090 inline size_t GetMaxHypoStackSize() const { 00091 return m_maxHypoStackSize; 00092 } 00093 00098 inline void SetBeamWidth(float beamWidth) { 00099 m_beamWidth = beamWidth; 00100 } 00101 00103 inline float GetBestScore() const { 00104 return m_bestScore; 00105 } 00106 00108 inline float GetWorstScore() const { 00109 return m_worstScore; 00110 } 00111 00112 void AddHypothesesToBitmapContainers(); 00113 00114 const _BMType& GetBitmapAccessor() const { 00115 return m_bitmapAccessor; 00116 } 00117 00118 void SetBitmapAccessor(const WordsBitmap &newBitmap 00119 , HypothesisStackCubePruning &stack 00120 , const WordsRange &range 00121 , BitmapContainer &bitmapContainer 00122 , const SquareMatrix &futureScore 00123 , const TranslationOptionList &transOptList); 00124 00131 void PruneToSize(size_t newSize); 00132 00134 const Hypothesis *GetBestHypothesis() const; 00136 std::vector<const Hypothesis*> GetSortedList() const; 00137 00141 void CleanupArcList(); 00142 00143 TO_STRING(); 00144 }; 00145 00146 } 00147 #endif
1.5.9