diff options
-rw-r--r-- | contrib/moses2/TranslationModel/PhraseTable.cpp | 2 | ||||
-rw-r--r-- | contrib/moses2/TranslationModel/UnknownWordPenalty.cpp | 33 | ||||
-rw-r--r-- | contrib/moses2/TranslationModel/UnknownWordPenalty.h | 4 |
3 files changed, 34 insertions, 5 deletions
diff --git a/contrib/moses2/TranslationModel/PhraseTable.cpp b/contrib/moses2/TranslationModel/PhraseTable.cpp index c9ee75f80..6c2d6eaf2 100644 --- a/contrib/moses2/TranslationModel/PhraseTable.cpp +++ b/contrib/moses2/TranslationModel/PhraseTable.cpp @@ -26,8 +26,6 @@ PhraseTable::PhraseTable(size_t startInd, const std::string &line) : , m_maxCacheSize(DEFAULT_MAX_TRANS_OPT_CACHE_SIZE) { m_input.push_back(0); - - ReadParameters(); } PhraseTable::~PhraseTable() diff --git a/contrib/moses2/TranslationModel/UnknownWordPenalty.cpp b/contrib/moses2/TranslationModel/UnknownWordPenalty.cpp index 46d6b0f9d..f08b31d4a 100644 --- a/contrib/moses2/TranslationModel/UnknownWordPenalty.cpp +++ b/contrib/moses2/TranslationModel/UnknownWordPenalty.cpp @@ -37,6 +37,19 @@ UnknownWordPenalty::~UnknownWordPenalty() // TODO Auto-generated destructor stub } +void UnknownWordPenalty::SetParameter(const std::string& key, const std::string& value) +{ + if (key == "prefix") { + m_prefix = value; + } + else if (key == "suffix") { + m_suffix = value; + } + else { + PhraseTable::SetParameter(key, value); + } +} + void UnknownWordPenalty::ProcessXML( const Manager &mgr, MemPool &pool, @@ -111,9 +124,23 @@ TargetPhrases *UnknownWordPenalty::Lookup(const Manager &mgr, MemPool &pool, system, 1); Moses2::Word &word = (*target)[0]; - //FactorCollection &fc = system.vocab; - //const Factor *factor = fc.AddFactor("SSS", false); - word[0] = factor; + if (m_prefix.empty() && m_suffix.empty()) { + word[0] = factor; + } + else { + stringstream strm; + if (!m_prefix.empty()) { + strm << m_prefix; + } + strm << factor->GetString(); + if (!m_suffix.empty()) { + strm << m_suffix; + } + + FactorCollection &fc = system.GetVocab(); + const Factor *targetFactor = fc.AddFactor(strm.str(), system, false); + word[0] = targetFactor; + } Scores &scores = target->GetScores(); scores.PlusEquals(mgr.system, *this, -100); diff --git a/contrib/moses2/TranslationModel/UnknownWordPenalty.h b/contrib/moses2/TranslationModel/UnknownWordPenalty.h index 0e8ec6a56..3adb5bbc2 100644 --- a/contrib/moses2/TranslationModel/UnknownWordPenalty.h +++ b/contrib/moses2/TranslationModel/UnknownWordPenalty.h @@ -21,6 +21,8 @@ public: UnknownWordPenalty(size_t startInd, const std::string &line); virtual ~UnknownWordPenalty(); + virtual void SetParameter(const std::string& key, const std::string& value); + void Lookup(const Manager &mgr, InputPathsBase &inputPaths) const; virtual TargetPhrases *Lookup(const Manager &mgr, MemPool &pool, InputPath &inputPath) const; @@ -78,6 +80,8 @@ protected: const Moses2::Hypotheses *hypos, const Moses2::Range &subPhraseRange, SCFG::InputPath &outPath) const; +protected: + std::string m_prefix, m_suffix; }; } |