mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
move collection of phrase-table from Staticdata to PhraseDictionary
This commit is contained in:
parent
79fb8a1df4
commit
2f00ae936b
@ -79,7 +79,6 @@
|
||||
<listOptionValue builtIn="false" value="RandLM"/>
|
||||
<listOptionValue builtIn="false" value="OnDiskPt"/>
|
||||
<listOptionValue builtIn="false" value="lm"/>
|
||||
<listOptionValue builtIn="false" value="rt"/>
|
||||
<listOptionValue builtIn="false" value="util"/>
|
||||
<listOptionValue builtIn="false" value="boost_iostreams-mt"/>
|
||||
<listOptionValue builtIn="false" value="boost_system-mt"/>
|
||||
@ -89,6 +88,7 @@
|
||||
<listOptionValue builtIn="false" value="z"/>
|
||||
<listOptionValue builtIn="false" value="bz2"/>
|
||||
<listOptionValue builtIn="false" value="dl"/>
|
||||
<listOptionValue builtIn="false" value="rt"/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.128214028" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
|
@ -530,7 +530,7 @@ void OutputFeatureWeightsForHypergraph(std::ostream &outputSearchGraphStream)
|
||||
featureIndex = OutputFeatureWeightsForHypergraph(featureIndex, slf[i], outputSearchGraphStream);
|
||||
}
|
||||
}
|
||||
const vector<PhraseDictionary*>& pds = staticData.GetPhraseDictionaries();
|
||||
const vector<PhraseDictionary*>& pds = PhraseDictionary::GetColl();
|
||||
for( size_t i=0; i<pds.size(); i++ ) {
|
||||
featureIndex = OutputFeatureWeightsForHypergraph(featureIndex, pds[i], outputSearchGraphStream);
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ ChartParser::ChartParser(InputType const &source, ChartCellCollectionBase &cells
|
||||
staticData.InitializeForInput(source);
|
||||
CreateInputPaths(m_source);
|
||||
|
||||
const std::vector<PhraseDictionary*> &dictionaries = staticData.GetPhraseDictionaries();
|
||||
const std::vector<PhraseDictionary*> &dictionaries = PhraseDictionary::GetColl();
|
||||
m_ruleLookupManagers.reserve(dictionaries.size());
|
||||
for (std::vector<PhraseDictionary*>::const_iterator p = dictionaries.begin();
|
||||
p != dictionaries.end(); ++p) {
|
||||
|
@ -19,8 +19,7 @@ InputFeature::InputFeature(const std::string &line)
|
||||
|
||||
void InputFeature::Load()
|
||||
{
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const PhraseDictionary *pt = staticData.GetTranslationScoreProducer(0);
|
||||
const PhraseDictionary *pt = PhraseDictionary::GetColl()[0];
|
||||
const PhraseDictionaryTreeAdaptor *ptBin = dynamic_cast<const PhraseDictionaryTreeAdaptor*>(pt);
|
||||
|
||||
m_legacy = (ptBin != NULL);
|
||||
|
@ -464,7 +464,7 @@ void OutputWordGraph(std::ostream &outputWordGraphStream, const Hypothesis *hypo
|
||||
|
||||
// phrase table scores
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const std::vector<PhraseDictionary*> &phraseTables = staticData.GetPhraseDictionaries();
|
||||
const std::vector<PhraseDictionary*> &phraseTables = PhraseDictionary::GetColl();
|
||||
std::vector<PhraseDictionary*>::const_iterator iterPhraseTable;
|
||||
for (iterPhraseTable = phraseTables.begin() ; iterPhraseTable != phraseTables.end() ; ++iterPhraseTable) {
|
||||
const PhraseDictionary *phraseTable = *iterPhraseTable;
|
||||
@ -687,7 +687,7 @@ void Manager::OutputFeatureWeightsForSLF(std::ostream &outputSearchGraphStream)
|
||||
featureIndex = OutputFeatureWeightsForSLF(featureIndex, slf[i], outputSearchGraphStream);
|
||||
}
|
||||
}
|
||||
const vector<PhraseDictionary*>& pds = staticData.GetPhraseDictionaries();
|
||||
const vector<PhraseDictionary*>& pds = PhraseDictionary::GetColl();
|
||||
for( size_t i=0; i<pds.size(); i++ ) {
|
||||
featureIndex = OutputFeatureWeightsForSLF(featureIndex, pds[i], outputSearchGraphStream);
|
||||
}
|
||||
@ -726,7 +726,7 @@ void Manager::OutputFeatureValuesForSLF(const Hypothesis* hypo, bool zeros, std:
|
||||
featureIndex = OutputFeatureValuesForSLF(featureIndex, zeros, hypo, slf[i], outputSearchGraphStream);
|
||||
}
|
||||
}
|
||||
const vector<PhraseDictionary*>& pds = staticData.GetPhraseDictionaries();
|
||||
const vector<PhraseDictionary*>& pds = PhraseDictionary::GetColl();
|
||||
for( size_t i=0; i<pds.size(); i++ ) {
|
||||
featureIndex = OutputFeatureValuesForSLF(featureIndex, zeros, hypo, pds[i], outputSearchGraphStream);
|
||||
}
|
||||
@ -760,7 +760,7 @@ void Manager::OutputFeatureValuesForHypergraph(const Hypothesis* hypo, std::ostr
|
||||
featureIndex = OutputFeatureValuesForHypergraph(featureIndex, hypo, slf[i], outputSearchGraphStream);
|
||||
}
|
||||
}
|
||||
const vector<PhraseDictionary*>& pds = staticData.GetPhraseDictionaries();
|
||||
const vector<PhraseDictionary*>& pds = PhraseDictionary::GetColl();
|
||||
for( size_t i=0; i<pds.size(); i++ ) {
|
||||
featureIndex = OutputFeatureValuesForHypergraph(featureIndex, hypo, pds[i], outputSearchGraphStream);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ protected:
|
||||
m_inputFeature = staticData.GetInputFeature();
|
||||
|
||||
if (m_inputFeature) {
|
||||
const PhraseDictionary *firstPt = staticData.GetPhraseDictionaries()[0];
|
||||
const PhraseDictionary *firstPt = PhraseDictionary::GetColl()[0];
|
||||
if (firstPt == m_obj) {
|
||||
m_numInputScores = m_inputFeature->GetNumScoreComponents();
|
||||
}
|
||||
|
@ -650,6 +650,7 @@ bool StaticData::LoadDecodeGraphs()
|
||||
{
|
||||
const vector<string> &mappingVector = m_parameter->GetParam("mapping");
|
||||
const vector<size_t> &maxChartSpans = Scan<size_t>(m_parameter->GetParam("max-chart-span"));
|
||||
const vector<PhraseDictionary*>& pts = PhraseDictionary::GetColl();
|
||||
|
||||
const std::vector<FeatureFunction*> *featuresRemaining = &FeatureFunction::GetFeatureFunctions();
|
||||
DecodeStep *prev = 0;
|
||||
@ -687,14 +688,14 @@ bool StaticData::LoadDecodeGraphs()
|
||||
DecodeStep* decodeStep = NULL;
|
||||
switch (decodeType) {
|
||||
case Translate:
|
||||
if(index>=m_phraseDictionary.size()) {
|
||||
if(index>=pts.size()) {
|
||||
stringstream strme;
|
||||
strme << "No phrase dictionary with index "
|
||||
<< index << " available!";
|
||||
UserMessage::Add(strme.str());
|
||||
CHECK(false);
|
||||
}
|
||||
decodeStep = new DecodeStepTranslation(m_phraseDictionary[index], prev, *featuresRemaining);
|
||||
decodeStep = new DecodeStepTranslation(pts[index], prev, *featuresRemaining);
|
||||
break;
|
||||
case Generate:
|
||||
if(index>=m_generationDictionary.size()) {
|
||||
@ -897,7 +898,6 @@ void StaticData::LoadFeatureFunctions()
|
||||
bool doLoad = true;
|
||||
|
||||
if (PhraseDictionary *ffCast = dynamic_cast<PhraseDictionary*>(ff)) {
|
||||
m_phraseDictionary.push_back(ffCast);
|
||||
doLoad = false;
|
||||
} else if (const GenerationDictionary *ffCast
|
||||
= dynamic_cast<const GenerationDictionary*>(ff)) {
|
||||
@ -920,8 +920,9 @@ void StaticData::LoadFeatureFunctions()
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
pt->Load();
|
||||
}
|
||||
|
||||
@ -1078,8 +1079,9 @@ void StaticData::OverrideFeatures()
|
||||
|
||||
void StaticData::CheckLEGACYPT()
|
||||
{
|
||||
for (size_t i = 0; i < m_phraseDictionary.size(); ++i) {
|
||||
const PhraseDictionary *phraseDictionary = m_phraseDictionary[i];
|
||||
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;
|
||||
|
@ -47,7 +47,6 @@ namespace Moses
|
||||
{
|
||||
|
||||
class InputType;
|
||||
class PhraseDictionary;
|
||||
class GenerationDictionary;
|
||||
class DecodeGraph;
|
||||
class DecodeStep;
|
||||
@ -67,7 +66,6 @@ class StaticData
|
||||
private:
|
||||
static StaticData s_instance;
|
||||
protected:
|
||||
std::vector<PhraseDictionary*> m_phraseDictionary;
|
||||
std::vector<const GenerationDictionary*> m_generationDictionary;
|
||||
Parameter *m_parameter;
|
||||
std::vector<FactorType> m_inputFactorOrder, m_outputFactorOrder;
|
||||
@ -723,15 +721,9 @@ public:
|
||||
float GetWeightWordPenalty() const;
|
||||
float GetWeightUnknownWordPenalty() const;
|
||||
|
||||
const std::vector<PhraseDictionary*>& GetPhraseDictionaries() const {
|
||||
return m_phraseDictionary;
|
||||
}
|
||||
const std::vector<const GenerationDictionary*>& GetGenerationDictionaries() const {
|
||||
return m_generationDictionary;
|
||||
}
|
||||
const PhraseDictionary*GetTranslationScoreProducer(size_t index) const {
|
||||
return GetPhraseDictionaries().at(index);
|
||||
}
|
||||
|
||||
const std::vector<DecodeGraph*>& GetDecodeGraphs() const {
|
||||
return m_decodeGraphs;
|
||||
|
@ -152,7 +152,7 @@ void TargetPhrase::Evaluate(const InputType &input, const InputPath &inputPath)
|
||||
void TargetPhrase::SetXMLScore(float score)
|
||||
{
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const FeatureFunction* prod = staticData.GetPhraseDictionaries()[0];
|
||||
const FeatureFunction* prod = PhraseDictionary::GetColl()[0];
|
||||
size_t numScores = prod->GetNumScoreComponents();
|
||||
vector <float> scoreVector(numScores,score/numScores);
|
||||
|
||||
|
@ -31,12 +31,14 @@ using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
std::vector<PhraseDictionary*> PhraseDictionary::s_staticColl;
|
||||
|
||||
PhraseDictionary::PhraseDictionary(const std::string &line)
|
||||
:DecodeFeature(line)
|
||||
,m_tableLimit(20) // default
|
||||
,m_maxCacheSize(DEFAULT_MAX_TRANS_OPT_CACHE_SIZE)
|
||||
{
|
||||
s_staticColl.push_back(this);
|
||||
}
|
||||
|
||||
const TargetPhraseCollection *PhraseDictionary::GetTargetPhraseCollectionLEGACY(const Phrase& src) const
|
||||
|
@ -59,6 +59,10 @@ class ChartParser;
|
||||
class PhraseDictionary : public DecodeFeature
|
||||
{
|
||||
public:
|
||||
static const std::vector<PhraseDictionary*>& GetColl() {
|
||||
return s_staticColl;
|
||||
}
|
||||
|
||||
PhraseDictionary(const std::string &line);
|
||||
|
||||
virtual ~PhraseDictionary() {
|
||||
@ -110,6 +114,8 @@ public:
|
||||
virtual const TargetPhraseCollectionWithSourcePhrase* GetTargetPhraseCollectionLEGACY(InputType const& src,WordsRange const& range) const;
|
||||
|
||||
protected:
|
||||
static std::vector<PhraseDictionary*> s_staticColl;
|
||||
|
||||
size_t m_tableLimit;
|
||||
std::string m_filePath;
|
||||
|
||||
|
@ -464,8 +464,7 @@ double CrossEntropy::operator() ( const dlib::matrix<double,0,1>& arg) const
|
||||
|
||||
PhraseDictionary *FindPhraseDictionary(const string &ptName)
|
||||
{
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const std::vector<PhraseDictionary*> &pts = staticData.GetPhraseDictionaries();
|
||||
const std::vector<PhraseDictionary*> &pts = PhraseDictionary::GetColl();
|
||||
|
||||
PhraseDictionary *pt = NULL;
|
||||
std::vector<PhraseDictionary*>::const_iterator iter;
|
||||
|
Loading…
Reference in New Issue
Block a user