mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 14:32:38 +03:00
move decodeGraph to staticData
This commit is contained in:
parent
8799e721ac
commit
ea647fc658
@ -123,7 +123,7 @@ void ChartParserUnknown::Process(const Word &sourceWord, const WordsRange &range
|
|||||||
|
|
||||||
ChartParser::ChartParser(InputType const &source, const TranslationSystem &system, ChartCellCollectionBase &cells) :
|
ChartParser::ChartParser(InputType const &source, const TranslationSystem &system, ChartCellCollectionBase &cells) :
|
||||||
m_unknown(system),
|
m_unknown(system),
|
||||||
m_decodeGraphList(system.GetDecodeGraphs()),
|
m_decodeGraphList(StaticData::Instance().GetDecodeGraphs()),
|
||||||
m_source(source) {
|
m_source(source) {
|
||||||
const StaticData &staticData = StaticData::Instance();
|
const StaticData &staticData = StaticData::Instance();
|
||||||
|
|
||||||
|
@ -608,13 +608,6 @@ bool StaticData::LoadData(Parameter *parameter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t k = 0; k < m_decodeGraphs.size(); ++k) {
|
|
||||||
if (!tableIds.size() || tableIds.find(k) != tableIds.end()) {
|
|
||||||
VERBOSE(2,"Adding decoder graph " << k << " to translation system " << config[0] << endl);
|
|
||||||
m_translationSystems.find(config[0])->second.AddDecodeGraph(m_decodeGraphs[k],m_decodeGraphBackoff[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t lmid = 0;
|
size_t lmid = 0;
|
||||||
for (LMList::const_iterator k = m_languageModel.begin(); k != m_languageModel.end(); ++k, ++lmid) {
|
for (LMList::const_iterator k = m_languageModel.begin(); k != m_languageModel.end(); ++k, ++lmid) {
|
||||||
if (!tableIds.size() || tableIds.find(lmid) != tableIds.end()) {
|
if (!tableIds.size() || tableIds.find(lmid) != tableIds.end()) {
|
||||||
@ -630,7 +623,7 @@ bool StaticData::LoadData(Parameter *parameter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Instigate dictionary loading
|
//Instigate dictionary loading
|
||||||
m_translationSystems.find(config[0])->second.ConfigDictionaries();
|
ConfigDictionaries();
|
||||||
|
|
||||||
for (int i = 0; i < m_phraseDictionary.size(); i++)
|
for (int i = 0; i < m_phraseDictionary.size(); i++)
|
||||||
cerr << m_phraseDictionary[i] << " ";
|
cerr << m_phraseDictionary[i] << " ";
|
||||||
@ -2016,6 +2009,25 @@ float StaticData::GetWeightDistortion() const {
|
|||||||
return StaticData::Instance().GetWeight(m_distortionScoreProducer);
|
return StaticData::Instance().GetWeight(m_distortionScoreProducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StaticData::ConfigDictionaries() {
|
||||||
|
for (vector<DecodeGraph*>::const_iterator i = m_decodeGraphs.begin();
|
||||||
|
i != m_decodeGraphs.end(); ++i) {
|
||||||
|
for (DecodeGraph::const_iterator j = (*i)->begin(); j != (*i)->end(); ++j) {
|
||||||
|
const DecodeStep* step = *j;
|
||||||
|
PhraseDictionaryFeature* pdict = const_cast<PhraseDictionaryFeature*>(step->GetPhraseDictionaryFeature());
|
||||||
|
if (pdict) {
|
||||||
|
StaticData::InstanceNonConst().AddFeatureFunction(pdict);
|
||||||
|
pdict->InitDictionary(NULL);
|
||||||
|
}
|
||||||
|
GenerationDictionary* gdict = const_cast<GenerationDictionary*>(step->GetGenerationDictionaryFeature());
|
||||||
|
if (gdict) {
|
||||||
|
StaticData::InstanceNonConst().AddFeatureFunction(gdict);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
@ -783,6 +783,12 @@ public:
|
|||||||
return weights;
|
return weights;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<DecodeGraph*>& GetDecodeGraphs() const {return m_decodeGraphs;}
|
||||||
|
const std::vector<size_t>& GetDecodeGraphBackoff() const {return m_decodeGraphBackoff;}
|
||||||
|
|
||||||
|
//Called after adding the tables in order to set up the dictionaries
|
||||||
|
void ConfigDictionaries();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ void TranslationOptionCollection::Prune()
|
|||||||
|
|
||||||
void TranslationOptionCollection::ProcessUnknownWord()
|
void TranslationOptionCollection::ProcessUnknownWord()
|
||||||
{
|
{
|
||||||
const vector<DecodeGraph*>& decodeGraphList = m_system->GetDecodeGraphs();
|
const vector<DecodeGraph*>& decodeGraphList = StaticData::Instance().GetDecodeGraphs();
|
||||||
size_t size = m_source.GetSize();
|
size_t size = m_source.GetSize();
|
||||||
// try to translation for coverage with no trans by expanding table limit
|
// try to translation for coverage with no trans by expanding table limit
|
||||||
for (size_t graphInd = 0 ; graphInd < decodeGraphList.size() ; graphInd++) {
|
for (size_t graphInd = 0 ; graphInd < decodeGraphList.size() ; graphInd++) {
|
||||||
@ -367,8 +367,8 @@ void TranslationOptionCollection::CreateTranslationOptions()
|
|||||||
// for all phrases
|
// for all phrases
|
||||||
|
|
||||||
// there may be multiple decoding graphs (factorizations of decoding)
|
// there may be multiple decoding graphs (factorizations of decoding)
|
||||||
const vector <DecodeGraph*> &decodeGraphList = m_system->GetDecodeGraphs();
|
const vector <DecodeGraph*> &decodeGraphList = StaticData::Instance().GetDecodeGraphs();
|
||||||
const vector <size_t> &decodeGraphBackoff = m_system->GetDecodeGraphBackoff();
|
const vector <size_t> &decodeGraphBackoff = StaticData::Instance().GetDecodeGraphBackoff();
|
||||||
|
|
||||||
// length of the sentence
|
// length of the sentence
|
||||||
size_t size = m_source.GetSize();
|
size_t size = m_source.GetSize();
|
||||||
|
@ -53,31 +53,6 @@ namespace Moses {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Insert core 'big' features
|
|
||||||
void TranslationSystem::AddDecodeGraph(DecodeGraph* decodeGraph, size_t backoff) {
|
|
||||||
m_decodeGraphs.push_back(decodeGraph);
|
|
||||||
m_decodeGraphBackoff.push_back(backoff);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TranslationSystem::ConfigDictionaries() {
|
|
||||||
for (vector<DecodeGraph*>::const_iterator i = m_decodeGraphs.begin();
|
|
||||||
i != m_decodeGraphs.end(); ++i) {
|
|
||||||
for (DecodeGraph::const_iterator j = (*i)->begin(); j != (*i)->end(); ++j) {
|
|
||||||
const DecodeStep* step = *j;
|
|
||||||
PhraseDictionaryFeature* pdict = const_cast<PhraseDictionaryFeature*>(step->GetPhraseDictionaryFeature());
|
|
||||||
if (pdict) {
|
|
||||||
StaticData::InstanceNonConst().AddFeatureFunction(pdict);
|
|
||||||
const_cast<PhraseDictionaryFeature*>(pdict)->InitDictionary(this);
|
|
||||||
}
|
|
||||||
GenerationDictionary* gdict = const_cast<GenerationDictionary*>(step->GetGenerationDictionaryFeature());
|
|
||||||
if (gdict) {
|
|
||||||
StaticData::InstanceNonConst().AddFeatureFunction(gdict);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void TranslationSystem::InitializeBeforeSentenceProcessing(const InputType& source) const {
|
void TranslationSystem::InitializeBeforeSentenceProcessing(const InputType& source) const {
|
||||||
const StaticData &staticData = StaticData::Instance();
|
const StaticData &staticData = StaticData::Instance();
|
||||||
const std::vector<PhraseDictionaryFeature*> &phraseDictionaries = staticData.GetPhraseDictionaries();
|
const std::vector<PhraseDictionaryFeature*> &phraseDictionaries = staticData.GetPhraseDictionaries();
|
||||||
|
@ -54,18 +54,11 @@ class TranslationSystem {
|
|||||||
const UnknownWordPenaltyProducer* uwpProducer,
|
const UnknownWordPenaltyProducer* uwpProducer,
|
||||||
const DistortionScoreProducer* distortionProducer);
|
const DistortionScoreProducer* distortionProducer);
|
||||||
|
|
||||||
//Insert core 'big' features
|
|
||||||
void AddDecodeGraph(DecodeGraph* decodeGraph, size_t backoff);
|
|
||||||
|
|
||||||
//Called after adding the tables in order to set up the dictionaries
|
|
||||||
void ConfigDictionaries();
|
|
||||||
|
|
||||||
|
|
||||||
const std::string& GetId() const {return m_id;}
|
const std::string& GetId() const {return m_id;}
|
||||||
|
|
||||||
//Lists of tables relevant to this system.
|
//Lists of tables relevant to this system.
|
||||||
const std::vector<DecodeGraph*>& GetDecodeGraphs() const {return m_decodeGraphs;}
|
|
||||||
const std::vector<size_t>& GetDecodeGraphBackoff() const {return m_decodeGraphBackoff;}
|
|
||||||
|
|
||||||
//sentence (and thread) specific initialisationn and cleanup
|
//sentence (and thread) specific initialisationn and cleanup
|
||||||
void InitializeBeforeSentenceProcessing(const InputType& source) const;
|
void InitializeBeforeSentenceProcessing(const InputType& source) const;
|
||||||
@ -76,10 +69,7 @@ class TranslationSystem {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_id;
|
std::string m_id;
|
||||||
|
|
||||||
std::vector<DecodeGraph*> m_decodeGraphs;
|
|
||||||
std::vector<size_t> m_decodeGraphBackoff;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user