|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef moses_PhraseDictionary_h |
|
#define moses_PhraseDictionary_h |
|
|
|
#include <iostream> |
|
#include <map> |
|
#include <memory> |
|
#include <list> |
|
#include <stdexcept> |
|
#include <vector> |
|
#include <string> |
|
#include <boost/unordered_map.hpp> |
|
|
|
#ifdef WITH_THREADS |
|
#include <boost/thread/tss.hpp> |
|
#else |
|
#include <boost/scoped_ptr.hpp> |
|
#include <ctime> |
|
#endif |
|
|
|
#include "moses/Phrase.h" |
|
#include "moses/TargetPhrase.h" |
|
#include "moses/TargetPhraseCollection.h" |
|
#include "moses/InputPath.h" |
|
#include "moses/FF/DecodeFeature.h" |
|
#include "moses/ContextScope.h" |
|
|
|
namespace Moses |
|
{ |
|
|
|
class StaticData; |
|
class InputType; |
|
class Range; |
|
class ChartCellCollectionBase; |
|
class ChartRuleLookupManager; |
|
class ChartParser; |
|
|
|
|
|
typedef std::pair<TargetPhraseCollection::shared_ptr, clock_t> CacheCollEntry; |
|
typedef boost::unordered_map<size_t, CacheCollEntry> CacheColl; |
|
|
|
|
|
|
|
|
|
class PhraseDictionary : public DecodeFeature |
|
{ |
|
friend class PhraseDictionaryMultiModelCounts; |
|
|
|
|
|
public: |
|
virtual bool ProvidesPrefixCheck() const; |
|
|
|
static const std::vector<PhraseDictionary*>& GetColl() { |
|
return s_staticColl; |
|
} |
|
|
|
PhraseDictionary(const std::string &line, bool registerNow); |
|
|
|
virtual ~PhraseDictionary() { |
|
} |
|
|
|
|
|
size_t GetTableLimit() const { |
|
return m_tableLimit; |
|
} |
|
|
|
|
|
size_t GetId() const { |
|
return m_id; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual |
|
bool |
|
PrefixExists(ttasksptr const& ttask, Phrase const& phrase) const; |
|
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
virtual TargetPhraseCollection::shared_ptr |
|
GetTargetPhraseCollectionLEGACY(const Phrase& src) const; |
|
|
|
virtual TargetPhraseCollection::shared_ptr |
|
GetTargetPhraseCollectionLEGACY(ttasksptr const& ttask, |
|
Phrase const& src) const { |
|
return GetTargetPhraseCollectionLEGACY(src); |
|
} |
|
|
|
virtual void |
|
GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const; |
|
|
|
virtual void |
|
GetTargetPhraseCollectionBatch |
|
(ttasksptr const& ttask, InputPathList const& inputPathQueue) const { |
|
GetTargetPhraseCollectionBatch(inputPathQueue); |
|
} |
|
|
|
|
|
virtual void InitializeForInput(ttasksptr const& ttask) { |
|
} |
|
|
|
virtual void CleanUpAfterSentenceProcessing(const InputType& source) { |
|
} |
|
|
|
|
|
virtual ChartRuleLookupManager *CreateRuleLookupManager( |
|
const ChartParser &, |
|
const ChartCellCollectionBase &, |
|
std::size_t) = 0; |
|
|
|
const std::string &GetFilePath() const { |
|
return m_filePath; |
|
} |
|
|
|
const std::vector<FeatureFunction*> &GetFeaturesToApply() const { |
|
return m_featuresToApply; |
|
} |
|
|
|
void SetParameter(const std::string& key, const std::string& value); |
|
|
|
|
|
|
|
virtual |
|
TargetPhraseCollectionWithSourcePhrase::shared_ptr |
|
GetTargetPhraseCollectionLEGACY(InputType const& src,Range const& range) const; |
|
|
|
protected: |
|
static std::vector<PhraseDictionary*> s_staticColl; |
|
|
|
size_t m_tableLimit; |
|
std::string m_filePath; |
|
|
|
|
|
|
|
std::vector<FeatureFunction*> m_featuresToApply; |
|
|
|
|
|
void SetFeaturesToApply(); |
|
|
|
bool SatisfyBackoff(const InputPath &inputPath) const; |
|
|
|
|
|
size_t m_maxCacheSize; |
|
|
|
#ifdef WITH_THREADS |
|
|
|
mutable boost::thread_specific_ptr<CacheColl> m_cache; |
|
#else |
|
mutable boost::scoped_ptr<CacheColl> m_cache; |
|
#endif |
|
|
|
virtual |
|
TargetPhraseCollection::shared_ptr |
|
GetTargetPhraseCollectionNonCacheLEGACY(const Phrase& src) const; |
|
|
|
void ReduceCache() const; |
|
|
|
protected: |
|
CacheColl &GetCache() const; |
|
size_t m_id; |
|
|
|
}; |
|
|
|
} |
|
#endif |
|
|