partial code cleanup (not working)

This commit is contained in:
Nicola Bertoldi 2014-01-14 18:27:11 +01:00
parent 326d3bd508
commit c13bb8f8e8
4 changed files with 54 additions and 36 deletions

View File

@ -10,7 +10,7 @@ namespace Moses
DynamicCacheBasedLanguageModel::DynamicCacheBasedLanguageModel(const std::string &line)
: StatelessFeatureFunction("DynamicCacheBasedLanguageModel", line)
{
std::cerr << "Initializing DynamicCacheBasedLanguageModel feature..." << std::endl;
VERBOSE(2,"Initializing DynamicCacheBasedLanguageModel feature..." << std::endl);
m_query_type = CBLM_QUERY_TYPE_ALLSUBSTRINGS;
m_score_type = CBLM_SCORE_TYPE_HYPERBOLA;
@ -57,7 +57,7 @@ float DynamicCacheBasedLanguageModel::GetPreComputedScores(const unsigned int ag
void DynamicCacheBasedLanguageModel::SetParameter(const std::string& key, const std::string& value)
{
std::cerr << "DynamicCacheBasedLanguageModel::SetParameter" << std::endl;
VERBOSE(2, "DynamicCacheBasedLanguageModel::SetParameter key:|" << key << "| value:|" << value << "|" << std::endl);
if (key == "cblm-query-type") {
SetQueryType(Scan<size_t>(value));
} else if (key == "cblm-score-type") {

View File

@ -901,7 +901,7 @@ void StaticData::LoadFeatureFunctions()
if (PhraseDictionary *ffCast = dynamic_cast<PhraseDictionary*>(ff)) {
cerr << "m_phraseDictionary here" << endl;
m_phraseDictionary.push_back(ffCast);
// m_phraseDictionary.push_back(ffCast);
doLoad = false;
if (PhraseDictionaryDynamicCacheBased *ffCast2 = dynamic_cast<PhraseDictionaryDynamicCacheBased*>(ff)){
CHECK(m_dynamicPDCB == NULL); // max 1 PhraseDictionaryDynamicCacheBased
@ -910,6 +910,15 @@ void StaticData::LoadFeatureFunctions()
if (m_dynamicPDCB_MaxAge > 0) m_dynamicPDCB->SetMaxAge(m_dynamicPDCB_MaxAge);
if (m_dynamicPDCB_ScoreType != CBTM_SCORE_TYPE_UNDEFINED) m_dynamicPDCB->SetScoreType(m_dynamicPDCB_ScoreType);
}
} else if (DynamicCacheBasedLanguageModel *ffCast = dynamic_cast<DynamicCacheBasedLanguageModel*>(ff)) {
CHECK(m_dynamicCBLM == NULL); // max 1 DynamicCacheBasedLanguageModel;
cerr << "m_dynamicCBLM here" << endl;
m_dynamicCBLM = ffCast;
if (m_dynamicCBLM_MaxAge > 0) m_dynamicCBLM->SetMaxAge(m_dynamicCBLM_MaxAge);
if (m_dynamicCBLM_ScoreType != CBLM_SCORE_TYPE_UNDEFINED) m_dynamicCBLM->SetScoreType(m_dynamicCBLM_ScoreType);
if (m_dynamicCBLM_QueryType != CBLM_QUERY_TYPE_UNDEFINED) m_dynamicCBLM->SetQueryType(m_dynamicCBLM_QueryType);
}
/*
} else if (const GenerationDictionary *ffCast = dynamic_cast<const GenerationDictionary*>(ff)) {
cerr << "m_generationDictionary here" << endl;
m_generationDictionary.push_back(ffCast);
@ -925,24 +934,28 @@ void StaticData::LoadFeatureFunctions()
CHECK(m_inputFeature == NULL); // max 1 input feature;
cerr << "m_inputFeature here" << endl;
m_inputFeature = ffCast;
} else if (DynamicCacheBasedLanguageModel *ffCast = dynamic_cast<DynamicCacheBasedLanguageModel*>(ff)) {
CHECK(m_dynamicCBLM == NULL); // max 1 DynamicCacheBasedLanguageModel;
cerr << "m_dynamicCBLM here" << endl;
m_dynamicCBLM = ffCast;
if (m_dynamicCBLM_MaxAge > 0) m_dynamicCBLM->SetMaxAge(m_dynamicCBLM_MaxAge);
if (m_dynamicCBLM_ScoreType != CBLM_SCORE_TYPE_UNDEFINED) m_dynamicCBLM->SetScoreType(m_dynamicCBLM_ScoreType);
if (m_dynamicCBLM_QueryType != CBLM_QUERY_TYPE_UNDEFINED) m_dynamicCBLM->SetQueryType(m_dynamicCBLM_QueryType);
}
*/
if (doLoad) {
VERBOSE(1, "Loading " << ff->GetScoreProducerDescription() << endl);
ff->Load();
}
}
for (size_t i = 0; i < m_phraseDictionary.size(); ++i) {
PhraseDictionary *pt = m_phraseDictionary[i];
const std::vector<PhraseDictionary*> &pts = PhraseDictionary::GetColl();
for (size_t i = 0; i < pts.size(); ++i) {
PhraseDictionary *pt = pts[i];
VERBOSE(1, "Loading " << pt->GetScoreProducerDescription() << endl);
pt->Load();
}
/* for (size_t i = 0; i < m_phraseDictionary.size(); ++i) {
PhraseDictionary *pt = m_phraseDictionary[i];
pt->Load();
}
*/
CheckLEGACYPT();
}
bool StaticData::CheckWeights() const
@ -1122,5 +1135,19 @@ void StaticData::ForcedDecoding()
}
void StaticData::CheckLEGACYPT()
{
const std::vector<PhraseDictionary*> &pts = PhraseDictionary::GetColl();
for (size_t i = 0; i < pts.size(); ++i) {
const PhraseDictionary *phraseDictionary = pts[i];
if (dynamic_cast<const PhraseDictionaryTreeAdaptor*>(phraseDictionary) != NULL) {
m_useLegacyPT = true;
return;
}
}
m_useLegacyPT = false;
}
} // namespace

View File

@ -52,12 +52,8 @@ namespace Moses
{
class InputType;
class PhraseDictionary;
class GenerationDictionary;
class DecodeGraph;
class DecodeStep;
class WordPenaltyProducer;
class UnknownWordPenaltyProducer;
class InputFeature;
class DynamicCacheBasedLanguageModel;
class PhraseDictionaryDynamicCacheBased;
@ -75,15 +71,12 @@ private:
static StaticData s_instance;
protected:
std::map<long,Phrase> m_constraints;
std::vector<PhraseDictionary*> m_phraseDictionary;
std::vector<const GenerationDictionary*> m_generationDictionary;
Parameter *m_parameter;
std::vector<FactorType> m_inputFactorOrder, m_outputFactorOrder;
mutable ScoreComponentCollection m_allWeights;
std::vector<DecodeGraph*> m_decodeGraphs;
std::vector<size_t> m_decodeGraphBackoff;
// Initial = 0 = can be used when creating poss trans
// Other = 1 = used to calculate LM score once all steps have been processed
float
@ -110,11 +103,8 @@ protected:
, m_maxNoPartTransOpt
, m_maxPhraseLength;
std::string
m_constraintFileName;
std::string m_nBestFilePath, m_latticeSamplesFilePath;
bool m_labeledNBestList,m_nBestIncludesSegmentation;
std::string m_nBestFilePath, m_latticeSamplesFilePath;
bool m_labeledNBestList,m_nBestIncludesSegmentation;
bool m_dropUnknown; //! false = treat unknown words as unknowns, and translate them as themselves; true = drop (ignore) them
bool m_markUnknown; //! false = treat unknown words as unknowns, and translate them as themselves; true = mark and (ignore) them
bool m_wordDeletionEnabled;
@ -127,15 +117,10 @@ protected:
bool m_recoverPath;
bool m_outputHypoScore;
ParsingAlgorithm m_parsingAlgorithm;
SearchAlgorithm m_searchAlgorithm;
InputTypeEnum m_inputType;
mutable size_t m_verboseLevel;
WordPenaltyProducer* m_wpProducer;
UnknownWordPenaltyProducer *m_unknownWordPenaltyProducer;
const InputFeature *m_inputFeature;
DynamicCacheBasedLanguageModel* m_dynamicCBLM;
PhraseDictionaryDynamicCacheBased* m_dynamicPDCB;
@ -225,7 +210,10 @@ protected:
std::map< std::string, std::set< std::string > > m_weightSettingIgnoreFF; // feature function
std::map< std::string, std::set< size_t > > m_weightSettingIgnoreDP; // decoding path
std::pair<FactorType, FactorType> m_placeHolderFactor;
FactorType m_placeHolderFactor;
bool m_useLegacyPT;
FeatureRegistry m_registry;
StaticData();
@ -238,7 +226,10 @@ protected:
//! load decoding steps
bool LoadDecodeGraphs();
void ForcedDecoding();
void NoCache();
bool m_continuePartialTranslation;
std::string m_binPath;
bool m_continuePartialTranslation;
std::string m_binPath;
@ -780,7 +771,7 @@ public:
const std::vector<const GenerationDictionary*>& GetGenerationDictionaries() const {
return m_generationDictionary;
}
const PhraseDictionary*GetTranslationScoreProducer(size_t index) const {
const PhraseDictionary* GetTranslationScoreProducer(size_t index) const {
return GetPhraseDictionaries().at(index);
}
std::vector<float> GetTranslationWeights(size_t index) const {

View File

@ -83,7 +83,7 @@ void PhraseDictionaryDynamicCacheBased::Load_Single_File(const std::string file)
void PhraseDictionaryDynamicCacheBased::SetParameter(const std::string& key, const std::string& value)
{
VERBOSE(2,"PhraseDictionaryDynamicCacheBased::SetParameter" << std::endl);
VERBOSE(2, "PhraseDictionaryDynamicCacheBased::SetParameter key:|" << key << "| value:|" << value << "|" << std::endl);
if(key == "cbtm-score-type") {
SetScoreType(Scan<size_t>(value));