add program to create ini file. Replace train-model.perl step=9

This commit is contained in:
Hieu Hoang 2013-02-07 19:14:26 +00:00
parent dd20bbabf7
commit c0b92c1ddb

View File

@ -1,3 +1,4 @@
#include <typeinfo>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@ -30,6 +31,8 @@ public:
{ {
toks = Tokenize(line, ":"); toks = Tokenize(line, ":");
} }
virtual string ffType() const= 0;
}; };
class LM : public FF class LM : public FF
@ -56,10 +59,14 @@ public:
case 9: implementation = "KENLM"; otherArgs = "lazyken=1"; break; case 9: implementation = "KENLM"; otherArgs = "lazyken=1"; break;
} }
} }
string ffType() const
{ return "LM"; }
}; };
class RO : public FF class RO : public FF
{ {
public:
RO(const string &line) RO(const string &line)
:FF(line) :FF(line)
{ {
@ -67,10 +74,14 @@ class RO : public FF
numFeatures = 6; numFeatures = 6;
path = toks[0]; path = toks[0];
} }
string ffType() const
{ return "RO"; }
}; };
class Pt : public FF class Pt : public FF
{ {
public:
int numFeatures; int numFeatures;
Pt(const string &line) Pt(const string &line)
@ -80,10 +91,13 @@ class Pt : public FF
numFeatures = 5; numFeatures = 5;
path = toks[0]; path = toks[0];
} }
string ffType() const
{ return "Pt"; }
}; };
string iniPath; string iniPath;
vector<FF> ffVec; vector<FF*> ffVec;
void OutputWeights(stringstream &weightStrme, const FF &ff) void OutputWeights(stringstream &weightStrme, const FF &ff)
{ {
@ -107,17 +121,30 @@ void Output()
strme << "[feature]" << endl; strme << "[feature]" << endl;
for (size_t i = 0; i < ffVec.size(); ++i) { for (size_t i = 0; i < ffVec.size(); ++i) {
const FF &ff = ffVec[i]; const FF &ff = *ffVec[i];
const LM *lm = dynamic_cast<const LM*>(&ff); if (ff.ffType() == "LM") {
if (lm) { const LM &model = static_cast<const LM&>(ff);
strme << lm->implementation << i << " " strme << model.implementation << i << " "
<< " order=" << lm->order << " order=" << model.order
<< " factor=" << lm->factor << " factor=" << model.factor
<< " path=" << lm->path << " path=" << model.path
<< " " << lm->otherArgs << " " << model.otherArgs
<< endl; << endl;
} }
else if (ff.ffType() == "Pt") {
const Pt &model = static_cast<const Pt&>(ff);
strme << model.implementation << i << " "
<< " path=" << model.path
<< endl;
}
else if (ff.ffType() == "RO") {
const RO &model = static_cast<const RO&>(ff);
strme << model.implementation << i << " "
<< " path=" << model.path
<< endl;
}
OutputWeights(weightStrme, ff); OutputWeights(weightStrme, ff);
} }
@ -151,19 +178,18 @@ int main(int argc, char **argv)
if (key == "-phrase-translation-table") { if (key == "-phrase-translation-table") {
++i; ++i;
string path = argv[i]; Pt *model = new Pt(argv[i]);
ffVec.push_back(path); ffVec.push_back(model);
} }
else if (key == "-reordering-table") { else if (key == "-reordering-table") {
++i; ++i;
string path = argv[i]; RO *model = new RO(argv[i]);
ffVec.push_back(path); ffVec.push_back(model);
} }
else if (key == "-lm") { else if (key == "-lm") {
++i; ++i;
string line = argv[i]; LM *model = new LM(argv[i]);
LM lm(line); ffVec.push_back(model);
ffVec.push_back(lm);
} }
else if (key == "-config") { else if (key == "-config") {
++i; ++i;