mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 12:52:29 +03:00
redo parsing of feature function parameters
This commit is contained in:
parent
dc33fa3d3d
commit
24d2edd790
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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.. ";
|
||||
|
@ -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)
|
||||
|
@ -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 =
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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.. ";
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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(
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user