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:
authorUlrich Germann <Ulrich.Germann@gmail.com>2015-12-10 06:17:36 +0300
committerUlrich Germann <Ulrich.Germann@gmail.com>2015-12-10 06:17:36 +0300
commit831dc83778f4594375e9de6a4e2831a02b3e1314 (patch)
treefdeb1aa98f940a073d7d5e197ce58b67db0418d1 /moses/Syntax
parent240b88c6834c9c94e8a6448a34dc4ad33bdf3fbd (diff)
Code cleanup and refactoring.
Diffstat (limited to 'moses/Syntax')
-rw-r--r--moses/Syntax/F2S/GlueRuleSynthesizer.cpp24
-rw-r--r--moses/Syntax/F2S/GlueRuleSynthesizer.h7
-rw-r--r--moses/Syntax/F2S/Manager-inl.h3
-rw-r--r--moses/Syntax/T2S/GlueRuleSynthesizer.cpp21
-rw-r--r--moses/Syntax/T2S/GlueRuleSynthesizer.h8
-rw-r--r--moses/Syntax/T2S/Manager-inl.h3
6 files changed, 37 insertions, 29 deletions
diff --git a/moses/Syntax/F2S/GlueRuleSynthesizer.cpp b/moses/Syntax/F2S/GlueRuleSynthesizer.cpp
index c8d867650..930138750 100644
--- a/moses/Syntax/F2S/GlueRuleSynthesizer.cpp
+++ b/moses/Syntax/F2S/GlueRuleSynthesizer.cpp
@@ -3,9 +3,8 @@
#include <sstream>
#include "moses/FF/UnknownWordPenaltyProducer.h"
-#include "moses/StaticData.h"
#include "util/string_stream.hh"
-
+#include "moses/parameters/AllOptions.h"
namespace Moses
{
namespace Syntax
@@ -14,13 +13,13 @@ namespace F2S
{
GlueRuleSynthesizer::
-GlueRuleSynthesizer(HyperTree &trie, const std::vector<FactorType> &iFactors)
- : m_hyperTree(trie)
+GlueRuleSynthesizer(Moses::AllOptions const& opts, HyperTree &trie)
+ : m_input_default_nonterminal(opts.syntax.input_default_non_terminal)
+ , m_output_default_nonterminal(opts.syntax.output_default_non_terminal)
+ , m_hyperTree(trie)
{
- // const std::vector<FactorType> &inputFactorOrder =
- // StaticData::Instance().GetInputFactorOrder();
Word *lhs = NULL;
- m_dummySourcePhrase.CreateFromString(Input, iFactors, "hello", &lhs);
+ m_dummySourcePhrase.CreateFromString(Input, opts.input.factor_order, "hello", &lhs);
delete lhs;
}
@@ -47,11 +46,10 @@ void GlueRuleSynthesizer::SynthesizeHyperPath(const Forest::Hyperedge &e,
}
}
-TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase(
- const Forest::Hyperedge &e)
+TargetPhrase*
+GlueRuleSynthesizer::
+SynthesizeTargetPhrase(const Forest::Hyperedge &e)
{
- const StaticData &staticData = StaticData::Instance();
-
const UnknownWordPenaltyProducer &unknownWordPenaltyProducer =
UnknownWordPenaltyProducer::Instance();
@@ -61,7 +59,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase(
for (std::size_t i = 0; i < e.tail.size(); ++i) {
const Word &symbol = e.tail[i]->pvertex.symbol;
if (symbol.IsNonTerminal()) {
- targetPhrase->AddWord(staticData.GetOutputDefaultNonTerminal());
+ targetPhrase->AddWord(m_output_default_nonterminal);
} else {
// TODO Check this
Word &targetWord = targetPhrase->AddWord();
@@ -75,7 +73,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase(
float score = LOWEST_SCORE;
targetPhrase->GetScoreBreakdown().Assign(&unknownWordPenaltyProducer, score);
targetPhrase->EvaluateInIsolation(m_dummySourcePhrase);
- Word *targetLhs = new Word(staticData.GetOutputDefaultNonTerminal());
+ Word *targetLhs = new Word(m_output_default_nonterminal);
targetPhrase->SetTargetLHS(targetLhs);
targetPhrase->SetAlignmentInfo(alignmentSS.str());
diff --git a/moses/Syntax/F2S/GlueRuleSynthesizer.h b/moses/Syntax/F2S/GlueRuleSynthesizer.h
index c66fb0ff8..b4128c5d7 100644
--- a/moses/Syntax/F2S/GlueRuleSynthesizer.h
+++ b/moses/Syntax/F2S/GlueRuleSynthesizer.h
@@ -9,6 +9,7 @@
namespace Moses
{
+ class AllOptions;
namespace Syntax
{
namespace F2S
@@ -16,9 +17,11 @@ namespace F2S
class GlueRuleSynthesizer : public HyperTreeCreator
{
+ Word m_input_default_nonterminal;
+ Word m_output_default_nonterminal;
public:
- GlueRuleSynthesizer(HyperTree &, std::vector<FactorType> const& iFactors);
-
+ GlueRuleSynthesizer(Moses::AllOptions const& opts, HyperTree &);
+
// Synthesize the minimal, monotone rule that can be applied to the given
// hyperedge and add it to the rule trie.
void SynthesizeRule(const Forest::Hyperedge &);
diff --git a/moses/Syntax/F2S/Manager-inl.h b/moses/Syntax/F2S/Manager-inl.h
index 77d4e0d58..59e48ab13 100644
--- a/moses/Syntax/F2S/Manager-inl.h
+++ b/moses/Syntax/F2S/Manager-inl.h
@@ -74,8 +74,7 @@ void Manager<RuleMatcher>::Decode()
RuleMatcherCallback callback(m_stackMap, ruleLimit);
// Create a glue rule synthesizer.
- GlueRuleSynthesizer glueRuleSynthesizer(*m_glueRuleTrie,
- options()->input.factor_order);
+ GlueRuleSynthesizer glueRuleSynthesizer(*options(), *m_glueRuleTrie);
// Sort the input forest's vertices into bottom-up topological order.
std::vector<const Forest::Vertex *> sortedVertices;
diff --git a/moses/Syntax/T2S/GlueRuleSynthesizer.cpp b/moses/Syntax/T2S/GlueRuleSynthesizer.cpp
index f50f84629..04b5da4e7 100644
--- a/moses/Syntax/T2S/GlueRuleSynthesizer.cpp
+++ b/moses/Syntax/T2S/GlueRuleSynthesizer.cpp
@@ -3,7 +3,7 @@
#include <sstream>
#include "moses/FF/UnknownWordPenaltyProducer.h"
-#include "moses/StaticData.h"
+#include <boost/scoped_ptr.hpp>
namespace Moses
{
@@ -12,7 +12,9 @@ namespace Syntax
namespace T2S
{
-void GlueRuleSynthesizer::SynthesizeRule(const InputTree::Node &node)
+void
+GlueRuleSynthesizer::
+SynthesizeRule(const InputTree::Node &node)
{
const Word &sourceLhs = node.pvertex.symbol;
boost::scoped_ptr<Phrase> sourceRhs(SynthesizeSourcePhrase(node));
@@ -22,7 +24,9 @@ void GlueRuleSynthesizer::SynthesizeRule(const InputTree::Node &node)
tpc->Add(tp);
}
-Phrase *GlueRuleSynthesizer::SynthesizeSourcePhrase(const InputTree::Node &node)
+Phrase*
+GlueRuleSynthesizer::
+SynthesizeSourcePhrase(const InputTree::Node &node)
{
Phrase *phrase = new Phrase(node.children.size());
for (std::vector<InputTree::Node*>::const_iterator p = node.children.begin();
@@ -37,11 +41,10 @@ Phrase *GlueRuleSynthesizer::SynthesizeSourcePhrase(const InputTree::Node &node)
return phrase;
}
-TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase(
- const InputTree::Node &node, const Phrase &sourceRhs)
+TargetPhrase*
+GlueRuleSynthesizer::
+SynthesizeTargetPhrase(const InputTree::Node &node, const Phrase &sourceRhs)
{
- const StaticData &staticData = StaticData::Instance();
-
const UnknownWordPenaltyProducer &unknownWordPenaltyProducer =
UnknownWordPenaltyProducer::Instance();
@@ -51,7 +54,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase(
for (std::size_t i = 0; i < node.children.size(); ++i) {
const Word &symbol = node.children[i]->pvertex.symbol;
if (symbol.IsNonTerminal()) {
- targetPhrase->AddWord(staticData.GetOutputDefaultNonTerminal());
+ targetPhrase->AddWord(m_output_default_nonterminal);
} else {
// TODO Check this
Word &targetWord = targetPhrase->AddWord();
@@ -65,7 +68,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase(
float score = LOWEST_SCORE;
targetPhrase->GetScoreBreakdown().Assign(&unknownWordPenaltyProducer, score);
targetPhrase->EvaluateInIsolation(sourceRhs);
- Word *targetLhs = new Word(staticData.GetOutputDefaultNonTerminal());
+ Word *targetLhs = new Word(m_output_default_nonterminal);
targetPhrase->SetTargetLHS(targetLhs);
targetPhrase->SetAlignmentInfo(alignmentSS.str());
diff --git a/moses/Syntax/T2S/GlueRuleSynthesizer.h b/moses/Syntax/T2S/GlueRuleSynthesizer.h
index 3e51c08a4..3d9e4f8f9 100644
--- a/moses/Syntax/T2S/GlueRuleSynthesizer.h
+++ b/moses/Syntax/T2S/GlueRuleSynthesizer.h
@@ -16,9 +16,13 @@ namespace T2S
class GlueRuleSynthesizer : public RuleTrieCreator
{
+ Word m_output_default_nonterminal;
public:
- GlueRuleSynthesizer(RuleTrie &trie) : m_ruleTrie(trie) {}
-
+ GlueRuleSynthesizer(RuleTrie &trie, Word dflt_nonterm)
+ : m_ruleTrie(trie)
+ , m_output_default_nonterminal(dflt_nonterm)
+ {}
+
// Synthesize the minimal, montone rule that can be applied to the given node
// and add it to the rule trie.
void SynthesizeRule(const InputTree::Node &);
diff --git a/moses/Syntax/T2S/Manager-inl.h b/moses/Syntax/T2S/Manager-inl.h
index 76aae54a8..88b87c014 100644
--- a/moses/Syntax/T2S/Manager-inl.h
+++ b/moses/Syntax/T2S/Manager-inl.h
@@ -111,7 +111,8 @@ void Manager<RuleMatcher>::Decode()
F2S::RuleMatcherCallback callback(m_stackMap, ruleLimit);
// Create a glue rule synthesizer.
- GlueRuleSynthesizer glueRuleSynthesizer(*m_glueRuleTrie);
+ Word dflt_nonterm = options()->syntax.output_default_non_terminal;
+ GlueRuleSynthesizer glueRuleSynthesizer(*m_glueRuleTrie, dflt_nonterm);
// Visit each node of the input tree in post-order.
for (std::vector<InputTree::Node>::const_iterator p =