redo parsing of feature function parameters

This commit is contained in:
Hieu Hoang 2013-06-20 13:06:03 +01:00
parent dc33fa3d3d
commit 24d2edd790
22 changed files with 35 additions and 223 deletions

View File

@ -23,16 +23,7 @@ struct DistortionState_traditional : public FFState {
DistortionScoreProducer::DistortionScoreProducer(const std::string &line)
: StatefulFeatureFunction("Distortion", 1, line) {
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
ReadParameters();
}
const FFState* DistortionScoreProducer::EmptyHypothesisState(const InputType &input) const

View File

@ -107,5 +107,19 @@ void FeatureFunction::OverrideParameter(const std::string& key, const std::strin
UTIL_THROW_IF(!ret, util::Exception, "Unknown argument" << key);
}
void FeatureFunction::ReadParameters()
{
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
}
}

View File

@ -108,6 +108,7 @@ public:
virtual bool SetParameter(const std::string& key, const std::string& value);
virtual void OverrideParameter(const std::string& key, const std::string& value);
virtual void ReadParameters();
};
}

View File

@ -13,18 +13,7 @@ GlobalLexicalModel::GlobalLexicalModel(const std::string &line)
: StatelessFeatureFunction("GlobalLexicalModel",1, line)
{
std::cerr << "Creating global lexical model...\n";
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
// define bias word
FactorCollection &factorCollection = FactorCollection::Instance();

View File

@ -19,19 +19,7 @@ PhraseBoundaryFeature::PhraseBoundaryFeature(const std::string &line)
: StatefulFeatureFunction("PhraseBoundaryFeature", 0, line)
{
std::cerr << "Initializing source word deletion feature.." << std::endl;
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
}
bool PhraseBoundaryFeature::SetParameter(const std::string& key, const std::string& value)

View File

@ -12,16 +12,7 @@ using namespace std;
PhraseLengthFeature::PhraseLengthFeature(const std::string &line)
:StatelessFeatureFunction("PhraseLengthFeature", 0, line)
{
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
ReadParameters();
}
void PhraseLengthFeature::Evaluate(const Phrase &source

View File

@ -17,18 +17,7 @@ PhrasePairFeature::PhrasePairFeature(const std::string &line)
:StatelessFeatureFunction("PhrasePairFeature", 0, line)
{
std::cerr << "Initializing PhrasePairFeature.." << std::endl;
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
if (m_simple == 1) std::cerr << "using simple phrase pairs.. ";
if (m_sourceContext == 1) std::cerr << "using source context.. ";

View File

@ -22,18 +22,7 @@ SourceWordDeletionFeature::SourceWordDeletionFeature(const std::string &line)
m_unrestricted(true)
{
std::cerr << "Initializing source word deletion feature.." << std::endl;
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
}
bool SourceWordDeletionFeature::SetParameter(const std::string& key, const std::string& value)

View File

@ -21,18 +21,7 @@ TargetBigramFeature::TargetBigramFeature(const std::string &line)
:StatefulFeatureFunction("TargetBigramFeature", 0, line)
{
std::cerr << "Initializing target bigram feature.." << std::endl;
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
FactorCollection& factorCollection = FactorCollection::Instance();
const Factor* bosFactor =

View File

@ -41,19 +41,7 @@ TargetNgramFeature::TargetNgramFeature(const std::string &line)
:StatefulFeatureFunction("TargetNgramFeature", 0, line)
{
std::cerr << "Initializing target ngram feature.." << std::endl;
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
}
bool TargetNgramFeature::SetParameter(const std::string& key, const std::string& value)

View File

@ -20,18 +20,7 @@ TargetWordInsertionFeature::TargetWordInsertionFeature(const std::string &line)
m_unrestricted(true)
{
std::cerr << "Initializing target word insertion feature.." << std::endl;
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
}
bool TargetWordInsertionFeature::SetParameter(const std::string& key, const std::string& value)

View File

@ -9,17 +9,7 @@ namespace Moses
UnknownWordPenaltyProducer::UnknownWordPenaltyProducer(const std::string &line)
: StatelessFeatureFunction("UnknownWordPenalty",1, line) {
m_tuneable = false;
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
ReadParameters();
}
}

View File

@ -8,16 +8,7 @@ namespace Moses
{
WordPenaltyProducer::WordPenaltyProducer(const std::string &line)
: StatelessFeatureFunction("WordPenalty",1, line) {
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
ReadParameters();
}
void WordPenaltyProducer::Evaluate(const Phrase &source

View File

@ -26,18 +26,7 @@ WordTranslationFeature::WordTranslationFeature(const std::string &line)
,m_domainTrigger(false)
{
std::cerr << "Initializing word translation feature.. " << endl;
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
if (m_simple == 1) std::cerr << "using simple word translations.. ";
if (m_sourceContext == 1) std::cerr << "using source context.. ";

View File

@ -38,16 +38,7 @@ namespace Moses
GenerationDictionary::GenerationDictionary(const std::string &line)
: DecodeFeature("Generation", line)
{
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
ReadParameters();
}
void GenerationDictionary::Load()

View File

@ -49,16 +49,7 @@ PhraseDictionaryCompact::PhraseDictionaryCompact(const std::string &line)
,m_phraseDecoder(0)
,m_weight(0)
{
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
ReadParameters();
}
void PhraseDictionaryCompact::Load()

View File

@ -12,18 +12,7 @@ PhraseDictionaryDynSuffixArray::PhraseDictionaryDynSuffixArray(const std::string
:PhraseDictionary("PhraseDictionaryDynSuffixArray", line)
,m_biSA(new BilingualDynSuffixArray())
{
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
}
PhraseDictionaryDynSuffixArray::~PhraseDictionaryDynSuffixArray()

View File

@ -42,16 +42,7 @@ namespace Moses
PhraseDictionaryMemory::PhraseDictionaryMemory(const std::string &line)
: RuleTableTrie("PhraseDictionaryMemory", line)
{
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
ReadParameters();
}
TargetPhraseCollection &PhraseDictionaryMemory::GetOrCreateTargetPhraseCollection(

View File

@ -28,17 +28,7 @@ namespace Moses
PhraseDictionaryMultiModel::PhraseDictionaryMultiModel(const std::string &line)
:PhraseDictionary("PhraseDictionaryMultiModel", line)
{
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
if (m_mode != "interpolate") {
ostringstream msg;

View File

@ -68,17 +68,7 @@ PhraseDictionaryMultiModelCounts::PhraseDictionaryMultiModelCounts(const std::st
//m_mode = "interpolate";
//m_combineFunction = LinearInterpolationFromCounts;
cerr << "m_args=" << m_args.size() << endl;
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
ReadParameters();
CHECK(m_targetTable.size() == m_pdStr.size());

View File

@ -29,16 +29,7 @@ PhraseDictionaryTreeAdaptor::
PhraseDictionaryTreeAdaptor(const std::string &line)
: PhraseDictionary("PhraseDictionaryBinary", line)
{
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
ReadParameters();
}
PhraseDictionaryTreeAdaptor::~PhraseDictionaryTreeAdaptor()

View File

@ -32,16 +32,7 @@ namespace Moses
{
PhraseDictionaryOnDisk::PhraseDictionaryOnDisk(const std::string &line)
: MyBase("PhraseDictionaryOnDisk", line) {
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
ReadParameters();
}
PhraseDictionaryOnDisk::~PhraseDictionaryOnDisk()