Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2015-01-04 16:40:48 +0300
committerHieu Hoang <hieuhoang@gmail.com>2015-01-04 16:40:48 +0300
commit1e0a2835bfd5b27ba11d586583ddf599f94a0904 (patch)
tree1e33fecd37bc4e6db465098de24c7d3e42fcfe85
parentb526efea2361f936a8a04c3e1ee1a5dd5b94982b (diff)
add oovpt
-rw-r--r--contrib/other-builds/moses/.project10
-rw-r--r--moses/FF/Factory.cpp2
-rw-r--r--moses/TranslationModel/OOVPT.cpp84
-rw-r--r--moses/TranslationModel/OOVPT.h36
4 files changed, 132 insertions, 0 deletions
diff --git a/contrib/other-builds/moses/.project b/contrib/other-builds/moses/.project
index 6020f4be5..bf55b0f12 100644
--- a/contrib/other-builds/moses/.project
+++ b/contrib/other-builds/moses/.project
@@ -1996,6 +1996,16 @@
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/DynSuffixArray.h</locationURI>
</link>
<link>
+ <name>TranslationModel/OOVPT.cpp</name>
+ <type>1</type>
+ <locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/OOVPT.cpp</locationURI>
+ </link>
+ <link>
+ <name>TranslationModel/OOVPT.h</name>
+ <type>1</type>
+ <locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/OOVPT.h</locationURI>
+ </link>
+ <link>
<name>TranslationModel/PhraseDictionary.cpp</name>
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/PhraseDictionary.cpp</locationURI>
diff --git a/moses/FF/Factory.cpp b/moses/FF/Factory.cpp
index 73f1ada0f..a89930b19 100644
--- a/moses/FF/Factory.cpp
+++ b/moses/FF/Factory.cpp
@@ -9,6 +9,7 @@
#include "moses/TranslationModel/PhraseDictionaryScope3.h"
#include "moses/TranslationModel/PhraseDictionaryTransliteration.h"
#include "moses/TranslationModel/PhraseDictionaryDynamicCacheBased.h"
+#include "moses/TranslationModel/OOVPT.h"
#include "moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.h"
#include "moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.h"
@@ -183,6 +184,7 @@ FeatureRegistry::FeatureRegistry()
MOSES_FNAME(PhraseDictionaryDynamicCacheBased);
MOSES_FNAME(PhraseDictionaryFuzzyMatch);
MOSES_FNAME2("RuleTable", Syntax::RuleTableFF);
+ MOSES_FNAME(OOVPT);
MOSES_FNAME(GlobalLexicalModel);
//MOSES_FNAME(GlobalLexicalModelUnlimited); This was commented out in the original
diff --git a/moses/TranslationModel/OOVPT.cpp b/moses/TranslationModel/OOVPT.cpp
new file mode 100644
index 000000000..c66e6ba1b
--- /dev/null
+++ b/moses/TranslationModel/OOVPT.cpp
@@ -0,0 +1,84 @@
+// vim:tabstop=2
+#include "OOVPT.h"
+
+using namespace std;
+
+namespace Moses
+{
+OOVPT::OOVPT(const std::string &line)
+ : PhraseDictionary(line)
+{
+ ReadParameters();
+}
+
+void OOVPT::Load()
+{
+ SetFeaturesToApply();
+}
+
+void OOVPT::InitializeForInput(InputType const& source)
+{
+ ReduceCache();
+}
+
+void OOVPT::GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const
+{
+ CacheColl &cache = GetCache();
+
+ InputPathList::const_iterator iter;
+ for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) {
+ InputPath &inputPath = **iter;
+ const Phrase &sourcePhrase = inputPath.GetPhrase();
+
+ TargetPhrase *tp = CreateTargetPhrase(sourcePhrase);
+ TargetPhraseCollection *tpColl = new TargetPhraseCollection();
+ tpColl->Add(tp);
+
+ // add target phrase to phrase-table cache
+ size_t hash = hash_value(sourcePhrase);
+ std::pair<const TargetPhraseCollection*, clock_t> value(tpColl, clock());
+ cache[hash] = value;
+
+ inputPath.SetTargetPhrases(*this, tpColl, NULL);
+ }
+}
+
+TargetPhrase *OOVPT::CreateTargetPhrase(const Phrase &sourcePhrase) const
+{
+ // create a target phrase from the 1st word of the source, prefix with 'OOVPT:'
+ assert(sourcePhrase.GetSize());
+ assert(m_output.size() == 1);
+
+ string str = sourcePhrase.GetWord(0).GetFactor(0)->GetString().as_string();
+
+ TargetPhrase *tp = new TargetPhrase(this);
+ Word &word = tp->AddWord();
+ word.CreateFromString(Output, m_output, str, false);
+
+ // score for this phrase table
+ vector<float> scores(m_numScoreComponents, 1.3);
+ tp->GetScoreBreakdown().PlusEquals(this, scores);
+
+ // score of all other ff when this rule is being loaded
+ tp->EvaluateInIsolation(sourcePhrase, GetFeaturesToApply());
+
+ return tp;
+}
+
+ChartRuleLookupManager* OOVPT::CreateRuleLookupManager(const ChartParser &parser,
+ const ChartCellCollectionBase &cellCollection,
+ std::size_t /*maxChartSpan*/)
+{
+ assert(false);
+ return NULL;
+}
+
+TO_STRING_BODY(OOVPT);
+
+// friend
+ostream& operator<<(ostream& out, const OOVPT& phraseDict)
+{
+ return out;
+}
+
+}
diff --git a/moses/TranslationModel/OOVPT.h b/moses/TranslationModel/OOVPT.h
new file mode 100644
index 000000000..04e53c6ec
--- /dev/null
+++ b/moses/TranslationModel/OOVPT.h
@@ -0,0 +1,36 @@
+
+#pragma once
+
+#include "PhraseDictionary.h"
+
+namespace Moses
+{
+class ChartParser;
+class ChartCellCollectionBase;
+class ChartRuleLookupManager;
+
+class OOVPT : public PhraseDictionary
+{
+ friend std::ostream& operator<<(std::ostream&, const OOVPT&);
+
+public:
+ OOVPT(const std::string &line);
+
+ void Load();
+
+ void InitializeForInput(InputType const& source);
+
+ // for phrase-based model
+ void GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const;
+
+ // for syntax/hiero model (CKY+ decoding)
+ ChartRuleLookupManager* CreateRuleLookupManager(const ChartParser&, const ChartCellCollectionBase&, std::size_t);
+
+ TO_STRING();
+
+
+protected:
+ TargetPhrase *CreateTargetPhrase(const Phrase &sourcePhrase) const;
+};
+
+} // namespace Moses