00001 // $Id$ 00002 00003 #ifndef moses_PhraseDictionaryTreeAdaptor_h 00004 #define moses_PhraseDictionaryTreeAdaptor_h 00005 00006 #include "moses/TypeDef.h" 00007 #include "moses/TargetPhraseCollection.h" 00008 #include "moses/TranslationModel/PhraseDictionary.h" 00009 #include <vector> 00010 00011 #ifdef WITH_THREADS 00012 #include <boost/thread/tss.hpp> 00013 #else 00014 #include <boost/scoped_ptr.hpp> 00015 #endif 00016 00017 namespace Moses 00018 { 00019 00020 class Phrase; 00021 class PDTAimp; 00022 class Range; 00023 class InputType; 00024 00025 /*** Implementation of a phrase table in a trie that is binarized and 00026 * stored on disk. Wrapper around PDTAimp class 00027 */ 00028 class PhraseDictionaryTreeAdaptor : public PhraseDictionary 00029 { 00030 typedef PhraseDictionary MyBase; 00031 00032 #ifdef WITH_THREADS 00033 boost::thread_specific_ptr<PDTAimp> m_implementation; 00034 #else 00035 boost::scoped_ptr<PDTAimp> m_implementation; 00036 #endif 00037 00038 friend class PDTAimp; 00039 PhraseDictionaryTreeAdaptor(); 00040 PhraseDictionaryTreeAdaptor(const PhraseDictionaryTreeAdaptor&); 00041 void operator=(const PhraseDictionaryTreeAdaptor&); 00042 00043 PDTAimp& GetImplementation(); 00044 const PDTAimp& GetImplementation() const; 00045 00046 public: 00047 PhraseDictionaryTreeAdaptor(const std::string &line); 00048 virtual ~PhraseDictionaryTreeAdaptor(); 00049 void Load(AllOptions::ptr const& opts); 00050 00051 // enable/disable caching 00052 // you enable caching if you request the target candidates for a source phrase multiple times 00053 // if you do caching somewhere else, disable it 00054 // good settings for current Moses: disable for first factor, enable for other factors 00055 // default: enable 00056 00057 void EnableCache(); 00058 void DisableCache(); 00059 00060 // get translation candidates for a given source phrase 00061 // returns null pointer if nothing found 00062 TargetPhraseCollection::shared_ptr 00063 GetTargetPhraseCollectionNonCacheLEGACY(Phrase const &src) const; 00064 00065 void InitializeForInput(ttasksptr const& ttask); 00066 void CleanUpAfterSentenceProcessing(InputType const& source); 00067 00068 virtual ChartRuleLookupManager *CreateRuleLookupManager( 00069 const ChartParser &, 00070 const ChartCellCollectionBase &, 00071 std::size_t) { 00072 UTIL_THROW(util::Exception, "SCFG decoding not supported with binary phrase table"); 00073 return 0; 00074 } 00075 00076 // legacy 00077 TargetPhraseCollectionWithSourcePhrase::shared_ptr 00078 GetTargetPhraseCollectionLEGACY(InputType const& src, 00079 Range const & srcRange) const; 00080 00081 }; 00082 00083 } 00084 #endif