00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef moses_PhraseDictionaryGroup_h
00021 #define moses_PhraseDictionaryGroup_h
00022
00023 #include <boost/dynamic_bitset.hpp>
00024 #include <boost/unordered_map.hpp>
00025 #include <boost/thread/shared_mutex.hpp>
00026
00027 #include "moses/StaticData.h"
00028 #include "moses/TargetPhrase.h"
00029 #include "moses/Util.h"
00030
00031 #include "moses/FF/LexicalReordering/LexicalReordering.h"
00032
00033 #include "moses/TranslationModel/PhraseDictionary.h"
00034
00035 #ifdef PT_UG
00036 #include "moses/TranslationModel/UG/mmsapt.h"
00037 #endif
00038
00039 namespace Moses
00040 {
00041
00042 struct PDGroupPhrase {
00043 TargetPhrase* m_targetPhrase;
00044 std::vector<float> m_scores;
00045 boost::dynamic_bitset<> m_seenBy;
00046
00047 PDGroupPhrase() : m_targetPhrase(NULL) { }
00048
00049 PDGroupPhrase(TargetPhrase* targetPhrase, const std::vector<float>& scores, const size_t nModels)
00050 : m_targetPhrase(targetPhrase),
00051 m_scores(scores),
00052 m_seenBy(nModels) { }
00053 };
00054
00061 class PhraseDictionaryGroup: public PhraseDictionary
00062 {
00063
00064 public:
00065 PhraseDictionaryGroup(const std::string& line);
00066 void Load(AllOptions::ptr const& opts);
00067 TargetPhraseCollection::shared_ptr
00068 CreateTargetPhraseCollection(const ttasksptr& ttask,
00069 const Phrase& src) const;
00070 std::vector<std::vector<float> > getWeights(size_t numWeights,
00071 bool normalize) const;
00072 void CacheForCleanup(TargetPhraseCollection::shared_ptr tpc);
00073 void CleanUpAfterSentenceProcessing(const InputType& source);
00074 void CleanUpComponentModels(const InputType& source);
00075
00076 void GetTargetPhraseCollectionBatch(const ttasksptr& ttask,
00077 const InputPathList &inputPathQueue) const;
00078 TargetPhraseCollection::shared_ptr GetTargetPhraseCollectionLEGACY(
00079 const Phrase& src) const;
00080 TargetPhraseCollection::shared_ptr GetTargetPhraseCollectionLEGACY(
00081 const ttasksptr& ttask, const Phrase& src) const;
00082 void InitializeForInput(ttasksptr const& ttask);
00083 ChartRuleLookupManager* CreateRuleLookupManager(const ChartParser&,
00084 const ChartCellCollectionBase&, std::size_t);
00085 void SetParameter(const std::string& key, const std::string& value);
00086
00087 protected:
00088 std::vector<std::string> m_memberPDStrs;
00089 std::vector<PhraseDictionary*> m_memberPDs;
00090 std::vector<FeatureFunction*> m_pdFeature;
00091 size_t m_numModels;
00092 size_t m_totalModelScores;
00093 boost::dynamic_bitset<> m_seenByAll;
00094
00095 bool m_phraseCounts;
00096
00097 bool m_wordCounts;
00098
00099 bool m_modelBitmapCounts;
00100
00101 bool m_restrict;
00102
00103 bool m_haveDefaultScores;
00104 std::vector<float> m_defaultScores;
00105
00106 bool m_defaultAverageOthers;
00107 size_t m_scoresPerModel;
00108
00109 bool m_haveMmsaptLrFunc;
00110
00111 std::vector<LexicalReordering**> m_mmsaptLrFuncs;
00112
00113 typedef std::vector<TargetPhraseCollection::shared_ptr > PhraseCache;
00114 #ifdef WITH_THREADS
00115 boost::shared_mutex m_lock_cache;
00116 typedef std::map<boost::thread::id, PhraseCache> SentenceCache;
00117 #else
00118 typedef PhraseCache SentenceCache;
00119 #endif
00120 SentenceCache m_sentenceCache;
00121
00122 PhraseCache& GetPhraseCache() {
00123 #ifdef WITH_THREADS
00124 {
00125
00126 boost::shared_lock<boost::shared_mutex> read_lock(m_lock_cache);
00127 SentenceCache::iterator i = m_sentenceCache.find(
00128 boost::this_thread::get_id());
00129 if (i != m_sentenceCache.end())
00130 return i->second;
00131 }
00132 boost::unique_lock<boost::shared_mutex> lock(m_lock_cache);
00133 return m_sentenceCache[boost::this_thread::get_id()];
00134 #else
00135 return m_sentenceCache;
00136 #endif
00137 }
00138 };
00139
00140 }
00141
00142 #endif