00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef moses_PhraseDictionary_h
00024 #define moses_PhraseDictionary_h
00025
00026 #include <iostream>
00027 #include <map>
00028 #include <memory>
00029 #include <list>
00030 #include <stdexcept>
00031 #include <vector>
00032 #include <string>
00033 #include <boost/unordered_map.hpp>
00034
00035 #ifdef WITH_THREADS
00036 #include <boost/thread/tss.hpp>
00037 #else
00038 #include <boost/scoped_ptr.hpp>
00039 #include <ctime>
00040 #endif
00041
00042 #include "moses/Phrase.h"
00043 #include "moses/TargetPhrase.h"
00044 #include "moses/TargetPhraseCollection.h"
00045 #include "moses/InputPath.h"
00046 #include "moses/FF/DecodeFeature.h"
00047 #include "moses/ContextScope.h"
00048
00049 namespace Moses
00050 {
00051
00052 class StaticData;
00053 class InputType;
00054 class Range;
00055 class ChartCellCollectionBase;
00056 class ChartRuleLookupManager;
00057 class ChartParser;
00058
00059
00060 typedef std::pair<TargetPhraseCollection::shared_ptr, clock_t> CacheCollEntry;
00061 typedef boost::unordered_map<size_t, CacheCollEntry> CacheColl;
00062
00066 class PhraseDictionary : public DecodeFeature
00067 {
00068 friend class PhraseDictionaryMultiModelCounts;
00069
00070
00071 public:
00072 virtual bool ProvidesPrefixCheck() const;
00073
00074 static const std::vector<PhraseDictionary*>& GetColl() {
00075 return s_staticColl;
00076 }
00077
00078 PhraseDictionary(const std::string &line, bool registerNow);
00079
00080 virtual ~PhraseDictionary() {
00081 }
00082
00084 size_t GetTableLimit() const {
00085 return m_tableLimit;
00086 }
00087
00089 size_t GetId() const {
00090 return m_id;
00091 }
00092
00093
00094
00095
00096
00098
00099 virtual
00100 bool
00101 PrefixExists(ttasksptr const& ttask, Phrase const& phrase) const;
00102
00103
00104
00105
00107
00108 public:
00109 virtual TargetPhraseCollection::shared_ptr
00110 GetTargetPhraseCollectionLEGACY(const Phrase& src) const;
00111
00112 virtual TargetPhraseCollection::shared_ptr
00113 GetTargetPhraseCollectionLEGACY(ttasksptr const& ttask,
00114 Phrase const& src) const {
00115 return GetTargetPhraseCollectionLEGACY(src);
00116 }
00117
00118 virtual void
00119 GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const;
00120
00121 virtual void
00122 GetTargetPhraseCollectionBatch
00123 (ttasksptr const& ttask, InputPathList const& inputPathQueue) const {
00124 GetTargetPhraseCollectionBatch(inputPathQueue);
00125 }
00126
00128 virtual void InitializeForInput(ttasksptr const& ttask) {
00129 }
00130
00131 virtual void CleanUpAfterSentenceProcessing(const InputType& source) {
00132 }
00133
00135 virtual ChartRuleLookupManager *CreateRuleLookupManager(
00136 const ChartParser &,
00137 const ChartCellCollectionBase &,
00138 std::size_t) = 0;
00139
00140 const std::string &GetFilePath() const {
00141 return m_filePath;
00142 }
00143
00144 const std::vector<FeatureFunction*> &GetFeaturesToApply() const {
00145 return m_featuresToApply;
00146 }
00147
00148 void SetParameter(const std::string& key, const std::string& value);
00149
00150
00152 virtual
00153 TargetPhraseCollectionWithSourcePhrase::shared_ptr
00154 GetTargetPhraseCollectionLEGACY(InputType const& src,Range const& range) const;
00155
00156 protected:
00157 static std::vector<PhraseDictionary*> s_staticColl;
00158
00159 size_t m_tableLimit;
00160 std::string m_filePath;
00161
00162
00163
00164 std::vector<FeatureFunction*> m_featuresToApply;
00165
00166
00167 void SetFeaturesToApply();
00168
00169 bool SatisfyBackoff(const InputPath &inputPath) const;
00170
00171
00172 size_t m_maxCacheSize;
00173
00174 #ifdef WITH_THREADS
00175
00176 mutable boost::thread_specific_ptr<CacheColl> m_cache;
00177 #else
00178 mutable boost::scoped_ptr<CacheColl> m_cache;
00179 #endif
00180
00181 virtual
00182 TargetPhraseCollection::shared_ptr
00183 GetTargetPhraseCollectionNonCacheLEGACY(const Phrase& src) const;
00184
00185 void ReduceCache() const;
00186
00187 protected:
00188 CacheColl &GetCache() const;
00189 size_t m_id;
00190
00191 };
00192
00193 }
00194 #endif