mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 12:52:29 +03:00
make binary pt threadable
This commit is contained in:
parent
991ea4f9c1
commit
cc2ec9bc3e
@ -28,65 +28,89 @@ PhraseDictionaryTreeAdaptor::
|
||||
PhraseDictionaryTreeAdaptor(const std::string &line)
|
||||
: PhraseDictionary("PhraseDictionaryTreeAdaptor", line)
|
||||
{
|
||||
imp = new PDTAimp(this,m_numInputScores);
|
||||
}
|
||||
|
||||
PhraseDictionaryTreeAdaptor::~PhraseDictionaryTreeAdaptor()
|
||||
{
|
||||
imp->CleanUp();
|
||||
delete imp;
|
||||
}
|
||||
|
||||
bool PhraseDictionaryTreeAdaptor::InitDictionary()
|
||||
{
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
|
||||
vector<float> weight = staticData.GetWeights(this);
|
||||
const LMList &languageModels = staticData.GetLMList();
|
||||
|
||||
if(m_numScoreComponents!=weight.size()) {
|
||||
std::stringstream strme;
|
||||
strme << "ERROR: mismatch of number of scaling factors: "<<weight.size()
|
||||
<<" "<<m_numScoreComponents<<"\n";
|
||||
UserMessage::Add(strme.str());
|
||||
return false;
|
||||
}
|
||||
|
||||
imp->Create(m_input, m_output, m_filePath, weight, languageModels);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PhraseDictionaryTreeAdaptor::InitializeForInput(InputType const& source)
|
||||
{
|
||||
imp->CleanUp();
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
|
||||
PDTAimp *obj = new PDTAimp(this,m_numInputScores);
|
||||
|
||||
const LMList &languageModels = staticData.GetLMList();
|
||||
|
||||
vector<float> weight = staticData.GetWeights(this);
|
||||
if(m_numScoreComponents!=weight.size()) {
|
||||
std::stringstream strme;
|
||||
strme << "ERROR: mismatch of number of scaling factors: "<<weight.size()
|
||||
<<" "<<m_numScoreComponents<<"\n";
|
||||
UserMessage::Add(strme.str());
|
||||
abort();
|
||||
}
|
||||
|
||||
obj->Create(m_input, m_output, m_filePath, weight, languageModels);
|
||||
|
||||
obj->CleanUp();
|
||||
// caching only required for confusion net
|
||||
if(ConfusionNet const* cn=dynamic_cast<ConfusionNet const*>(&source))
|
||||
imp->CacheSource(*cn);
|
||||
obj->CacheSource(*cn);
|
||||
|
||||
m_implementation.reset(obj);
|
||||
}
|
||||
|
||||
void PhraseDictionaryTreeAdaptor::CleanUpAfterSentenceProcessing(InputType const& source)
|
||||
{
|
||||
PDTAimp *obj = GetImplementation();
|
||||
obj->CleanUp();
|
||||
}
|
||||
|
||||
TargetPhraseCollection const*
|
||||
PhraseDictionaryTreeAdaptor::GetTargetPhraseCollection(Phrase const &src) const
|
||||
{
|
||||
return imp->GetTargetPhraseCollection(src);
|
||||
return GetImplementation()->GetTargetPhraseCollection(src);
|
||||
}
|
||||
|
||||
TargetPhraseCollection const*
|
||||
PhraseDictionaryTreeAdaptor::GetTargetPhraseCollection(InputType const& src,WordsRange const &range) const
|
||||
{
|
||||
if(imp->m_rangeCache.empty()) {
|
||||
return imp->GetTargetPhraseCollection(src.GetSubString(range));
|
||||
if(GetImplementation()->m_rangeCache.empty()) {
|
||||
return GetImplementation()->GetTargetPhraseCollection(src.GetSubString(range));
|
||||
} else {
|
||||
return imp->m_rangeCache[range.GetStartPos()][range.GetEndPos()];
|
||||
return GetImplementation()->m_rangeCache[range.GetStartPos()][range.GetEndPos()];
|
||||
}
|
||||
}
|
||||
|
||||
void PhraseDictionaryTreeAdaptor::EnableCache()
|
||||
{
|
||||
imp->useCache=1;
|
||||
GetImplementation()->useCache=1;
|
||||
}
|
||||
void PhraseDictionaryTreeAdaptor::DisableCache()
|
||||
{
|
||||
imp->useCache=0;
|
||||
GetImplementation()->useCache=0;
|
||||
}
|
||||
|
||||
PDTAimp* PhraseDictionaryTreeAdaptor::GetImplementation()
|
||||
{
|
||||
PDTAimp* dict;
|
||||
dict = m_implementation.get();
|
||||
CHECK(dict);
|
||||
return dict;
|
||||
}
|
||||
|
||||
const PDTAimp* PhraseDictionaryTreeAdaptor::GetImplementation() const
|
||||
{
|
||||
PDTAimp* dict;
|
||||
dict = m_implementation.get();
|
||||
CHECK(dict);
|
||||
return dict;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,12 +23,17 @@ class InputType;
|
||||
class PhraseDictionaryTreeAdaptor : public PhraseDictionary
|
||||
{
|
||||
typedef PhraseDictionary MyBase;
|
||||
PDTAimp *imp;
|
||||
|
||||
boost::thread_specific_ptr<PDTAimp> m_implementation;
|
||||
|
||||
friend class PDTAimp;
|
||||
PhraseDictionaryTreeAdaptor();
|
||||
PhraseDictionaryTreeAdaptor(const PhraseDictionaryTreeAdaptor&);
|
||||
void operator=(const PhraseDictionaryTreeAdaptor&);
|
||||
|
||||
PDTAimp* GetImplementation();
|
||||
const PDTAimp* GetImplementation() const;
|
||||
|
||||
public:
|
||||
PhraseDictionaryTreeAdaptor(const std::string &line);
|
||||
virtual ~PhraseDictionaryTreeAdaptor();
|
||||
@ -51,6 +56,7 @@ public:
|
||||
TargetPhraseCollection const* GetTargetPhraseCollection(InputType const& src,WordsRange const & srcRange) const;
|
||||
|
||||
virtual void InitializeForInput(InputType const& source);
|
||||
void CleanUpAfterSentenceProcessing(InputType const& source);
|
||||
|
||||
virtual ChartRuleLookupManager *CreateRuleLookupManager(
|
||||
const InputType &,
|
||||
|
Loading…
Reference in New Issue
Block a user