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 00022 #pragma once 00023 00024 #include <vector> 00025 #include <boost/unordered_map.hpp> 00026 #include "ChartCell.h" 00027 #include "ChartCellCollection.h" 00028 #include "InputType.h" 00029 #include "WordsRange.h" 00030 #include "SentenceStats.h" 00031 #include "ChartTranslationOptionList.h" 00032 #include "ChartParser.h" 00033 00034 #include <boost/shared_ptr.hpp> 00035 00036 namespace Moses 00037 { 00038 00039 class ChartHypothesis; 00040 class ChartTrellisDetourQueue; 00041 class ChartTrellisNode; 00042 class ChartTrellisPath; 00043 class ChartTrellisPathList; 00044 00047 class ChartManager 00048 { 00049 private: 00050 static void CreateDeviantPaths(boost::shared_ptr<const ChartTrellisPath>, 00051 ChartTrellisDetourQueue &); 00052 00053 static void CreateDeviantPaths(boost::shared_ptr<const ChartTrellisPath>, 00054 const ChartTrellisNode &, 00055 ChartTrellisDetourQueue &); 00056 00057 InputType const& m_source; 00058 ChartCellCollection m_hypoStackColl; 00059 std::auto_ptr<SentenceStats> m_sentenceStats; 00060 clock_t m_start; 00061 unsigned m_hypothesisId; /* For handing out hypothesis ids to ChartHypothesis */ 00062 00063 ChartParser m_parser; 00064 00065 ChartTranslationOptionList m_translationOptionList; 00067 public: 00068 ChartManager(InputType const& source); 00069 ~ChartManager(); 00070 void ProcessSentence(); 00071 void AddXmlChartOptions(); 00072 const ChartHypothesis *GetBestHypothesis() const; 00073 void CalcNBest(size_t count, ChartTrellisPathList &ret, bool onlyDistinct=0) const; 00074 00075 void GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream) const; 00076 void FindReachableHypotheses( const ChartHypothesis *hypo, std::map<unsigned,bool> &reachable ) const; /* auxilliary function for GetSearchGraph */ 00077 00079 const InputType& GetSource() const { 00080 return m_source; 00081 } 00082 00084 SentenceStats& GetSentenceStats() const { 00085 return *m_sentenceStats; 00086 } 00087 00088 /*** 00089 * to be called after processing a sentence (which may consist of more than just calling ProcessSentence() ) 00090 * currently an empty function 00091 */ 00092 void CalcDecoderStatistics() const { 00093 } 00094 00095 void ResetSentenceStats(const InputType& source) { 00096 m_sentenceStats = std::auto_ptr<SentenceStats>(new SentenceStats(source)); 00097 } 00098 00100 unsigned GetNextHypoId() { 00101 return m_hypothesisId++; 00102 } 00103 00104 }; 00105 00106 } 00107
1.5.9