mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
move initialization and cleanup functions to staticData
This commit is contained in:
parent
ea647fc658
commit
17898a9df3
@ -57,7 +57,7 @@ ChartManager::ChartManager(InputType const& source, const TranslationSystem* sys
|
||||
|
||||
ChartManager::~ChartManager()
|
||||
{
|
||||
m_system->CleanUpAfterSentenceProcessing(m_source);
|
||||
StaticData::Instance().CleanUpAfterSentenceProcessing(m_source);
|
||||
|
||||
clock_t end = clock();
|
||||
float et = (end - m_start);
|
||||
|
@ -127,7 +127,7 @@ ChartParser::ChartParser(InputType const &source, const TranslationSystem &syste
|
||||
m_source(source) {
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
|
||||
system.InitializeBeforeSentenceProcessing(source);
|
||||
staticData.InitializeBeforeSentenceProcessing(source);
|
||||
const std::vector<PhraseDictionaryFeature*> &dictionaries = staticData.GetPhraseDictionaries();
|
||||
m_ruleLookupManagers.reserve(dictionaries.size());
|
||||
for (std::vector<PhraseDictionaryFeature*>::const_iterator p = dictionaries.begin();
|
||||
|
@ -180,7 +180,7 @@ Manager::Manager(const InputType &source, const TranslationSystem &system) :
|
||||
n_best_(search::NBestConfig(StaticData::Instance().GetNBestSize())) {}
|
||||
|
||||
Manager::~Manager() {
|
||||
system_.CleanUpAfterSentenceProcessing(source_);
|
||||
StaticData::Instance().CleanUpAfterSentenceProcessing(source_);
|
||||
}
|
||||
|
||||
template <class Model, class Best> search::History Manager::PopulateBest(const Model &model, const std::vector<lm::WordIndex> &words, Best &out) {
|
||||
|
@ -59,7 +59,7 @@ Manager::Manager(size_t lineNumber, InputType const& source, SearchAlgorithm sea
|
||||
,m_hypoId(0)
|
||||
,m_source(source)
|
||||
{
|
||||
m_system->InitializeBeforeSentenceProcessing(source);
|
||||
StaticData::Instance().InitializeBeforeSentenceProcessing(source);
|
||||
}
|
||||
|
||||
Manager::~Manager()
|
||||
@ -67,7 +67,7 @@ Manager::~Manager()
|
||||
delete m_transOptColl;
|
||||
delete m_search;
|
||||
|
||||
m_system->CleanUpAfterSentenceProcessing(m_source);
|
||||
StaticData::Instance().CleanUpAfterSentenceProcessing(m_source);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +80,7 @@ void Manager::ProcessSentence()
|
||||
ResetSentenceStats(m_source);
|
||||
|
||||
// collect translation options for this sentence
|
||||
m_system->InitializeBeforeSentenceProcessing(m_source);
|
||||
StaticData::Instance().InitializeBeforeSentenceProcessing(m_source);
|
||||
|
||||
Timer getOptionsTime;
|
||||
getOptionsTime.start();
|
||||
|
@ -2028,6 +2028,49 @@ void StaticData::ConfigDictionaries() {
|
||||
|
||||
}
|
||||
|
||||
void StaticData::InitializeBeforeSentenceProcessing(const InputType& source) const {
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const std::vector<PhraseDictionaryFeature*> &phraseDictionaries = staticData.GetPhraseDictionaries();
|
||||
|
||||
for (vector<PhraseDictionaryFeature*>::const_iterator i = phraseDictionaries.begin();
|
||||
i != phraseDictionaries.end(); ++i) {
|
||||
(*i)->InitDictionary(NULL,source);
|
||||
}
|
||||
|
||||
const std::vector<LexicalReordering*> &reorderingTables = StaticData::Instance().GetReorderModels();
|
||||
for(size_t i=0;i<reorderingTables.size();++i) {
|
||||
reorderingTables[i]->InitializeForInput(source);
|
||||
}
|
||||
|
||||
/*
|
||||
for(size_t i=0;i<m_globalLexicalModels.size();++i) {
|
||||
m_globalLexicalModels[i]->InitializeForInput((Sentence const&)source);
|
||||
}
|
||||
*/
|
||||
|
||||
LMList lmList = StaticData::Instance().GetLMList();
|
||||
lmList.InitializeBeforeSentenceProcessing();
|
||||
}
|
||||
|
||||
void StaticData::CleanUpAfterSentenceProcessing(const InputType& source) const {
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const std::vector<PhraseDictionaryFeature*> &phraseDictionaries = staticData.GetPhraseDictionaries();
|
||||
const std::vector<GenerationDictionary*> &generationDictionaries = staticData.GetGenerationDictionaries();
|
||||
|
||||
for(size_t i=0;i<phraseDictionaries.size();++i)
|
||||
{
|
||||
PhraseDictionaryFeature &phraseDictionaryFeature = *phraseDictionaries[i];
|
||||
PhraseDictionary* phraseDictionary = const_cast<PhraseDictionary*>(phraseDictionaryFeature.GetDictionary());
|
||||
phraseDictionary->CleanUp(source);
|
||||
|
||||
}
|
||||
|
||||
for(size_t i=0;i<generationDictionaries.size();++i)
|
||||
generationDictionaries[i]->CleanUp(source);
|
||||
|
||||
LMList lmList = StaticData::Instance().GetLMList();
|
||||
lmList.CleanUpAfterSentenceProcessing(source);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
|
@ -789,6 +789,9 @@ public:
|
||||
//Called after adding the tables in order to set up the dictionaries
|
||||
void ConfigDictionaries();
|
||||
|
||||
//sentence (and thread) specific initialisationn and cleanup
|
||||
void InitializeBeforeSentenceProcessing(const InputType& source) const;
|
||||
void CleanUpAfterSentenceProcessing(const InputType& source) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -53,47 +53,5 @@ namespace Moses {
|
||||
}
|
||||
}
|
||||
|
||||
void TranslationSystem::InitializeBeforeSentenceProcessing(const InputType& source) const {
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const std::vector<PhraseDictionaryFeature*> &phraseDictionaries = staticData.GetPhraseDictionaries();
|
||||
|
||||
for (vector<PhraseDictionaryFeature*>::const_iterator i = phraseDictionaries.begin();
|
||||
i != phraseDictionaries.end(); ++i) {
|
||||
(*i)->InitDictionary(this,source);
|
||||
}
|
||||
|
||||
const std::vector<LexicalReordering*> &reorderingTables = StaticData::Instance().GetReorderModels();
|
||||
for(size_t i=0;i<reorderingTables.size();++i) {
|
||||
reorderingTables[i]->InitializeForInput(source);
|
||||
}
|
||||
|
||||
/*
|
||||
for(size_t i=0;i<m_globalLexicalModels.size();++i) {
|
||||
m_globalLexicalModels[i]->InitializeForInput((Sentence const&)source);
|
||||
}
|
||||
*/
|
||||
|
||||
LMList lmList = StaticData::Instance().GetLMList();
|
||||
lmList.InitializeBeforeSentenceProcessing();
|
||||
}
|
||||
|
||||
void TranslationSystem::CleanUpAfterSentenceProcessing(const InputType& source) const {
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const std::vector<PhraseDictionaryFeature*> &phraseDictionaries = staticData.GetPhraseDictionaries();
|
||||
const std::vector<GenerationDictionary*> &generationDictionaries = staticData.GetGenerationDictionaries();
|
||||
|
||||
for(size_t i=0;i<phraseDictionaries.size();++i)
|
||||
{
|
||||
PhraseDictionaryFeature &phraseDictionaryFeature = *phraseDictionaries[i];
|
||||
PhraseDictionary* phraseDictionary = const_cast<PhraseDictionary*>(phraseDictionaryFeature.GetDictionary());
|
||||
phraseDictionary->CleanUp(source);
|
||||
|
||||
}
|
||||
|
||||
for(size_t i=0;i<generationDictionaries.size();++i)
|
||||
generationDictionaries[i]->CleanUp(source);
|
||||
|
||||
LMList lmList = StaticData::Instance().GetLMList();
|
||||
lmList.CleanUpAfterSentenceProcessing(source);
|
||||
}
|
||||
};
|
||||
|
@ -57,12 +57,6 @@ class TranslationSystem {
|
||||
|
||||
|
||||
const std::string& GetId() const {return m_id;}
|
||||
|
||||
//Lists of tables relevant to this system.
|
||||
|
||||
//sentence (and thread) specific initialisationn and cleanup
|
||||
void InitializeBeforeSentenceProcessing(const InputType& source) const;
|
||||
void CleanUpAfterSentenceProcessing(const InputType& source) const;
|
||||
|
||||
static const std::string DEFAULT;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user