00001 // $Id$ 00002 // vim:tabstop=2 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_PhraseDictionaryCompact_h 00023 #define moses_PhraseDictionaryCompact_h 00024 00025 #include <boost/unordered_map.hpp> 00026 00027 #ifdef WITH_THREADS 00028 #ifdef BOOST_HAS_PTHREADS 00029 #include <boost/thread/mutex.hpp> 00030 #endif 00031 #endif 00032 00033 #include "moses/TranslationModel/PhraseDictionary.h" 00034 #include "moses/ThreadPool.h" 00035 00036 #include "BlockHashIndex.h" 00037 #include "StringVector.h" 00038 #include "PhraseDecoder.h" 00039 #include "TargetPhraseCollectionCache.h" 00040 00041 namespace Moses 00042 { 00043 00044 class PhraseDecoder; 00045 00046 class PhraseDictionaryCompact : public PhraseDictionary 00047 { 00048 protected: 00049 friend class PhraseDecoder; 00050 00051 static bool s_inMemoryByDefault; 00052 bool m_inMemory; 00053 bool m_useAlignmentInfo; 00054 00055 typedef std::vector<TargetPhraseCollection::shared_ptr > PhraseCache; 00056 typedef boost::thread_specific_ptr<PhraseCache> SentenceCache; 00057 static SentenceCache m_sentenceCache; 00058 00059 BlockHashIndex m_hash; 00060 PhraseDecoder* m_phraseDecoder; 00061 00062 StringVector<unsigned char, size_t, MmapAllocator> m_targetPhrasesMapped; 00063 StringVector<unsigned char, size_t, std::allocator> m_targetPhrasesMemory; 00064 00065 public: 00066 PhraseDictionaryCompact(const std::string &line); 00067 00068 ~PhraseDictionaryCompact(); 00069 00070 void Load(AllOptions::ptr const& opts); 00071 00072 TargetPhraseCollection::shared_ptr GetTargetPhraseCollectionNonCacheLEGACY(const Phrase &source) const; 00073 TargetPhraseVectorPtr GetTargetPhraseCollectionRaw(const Phrase &source) const; 00074 00075 void AddEquivPhrase(const Phrase &source, const TargetPhrase &targetPhrase); 00076 00077 void CacheForCleanup(TargetPhraseCollection::shared_ptr tpc); 00078 void CleanUpAfterSentenceProcessing(const InputType &source); 00079 static void SetStaticDefaultParameters(Parameter const& param); 00080 00081 virtual ChartRuleLookupManager *CreateRuleLookupManager( 00082 const ChartParser &, 00083 const ChartCellCollectionBase &, 00084 std::size_t) { 00085 assert(false); 00086 return 0; 00087 } 00088 00089 TO_STRING(); 00090 00091 }; 00092 00093 } 00094 #endif