summaryrefslogtreecommitdiff
path: root/decoder/scfg_translator.cc
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2011-07-24 20:46:22 +0200
committerPatrick Simianer <p@simianer.de>2011-09-23 19:13:57 +0200
commit3da2d6bef3d6f6c0e1e0d8845003db59d5697c90 (patch)
treef76ba4bf59aabc8cce9837dbfb4bbe716e50e1ec /decoder/scfg_translator.cc
parent8e67ebda72410a84830b679db0c46251935e7892 (diff)
added dtrain, implemented psg setting in decoder/translator, implemented psmetrics, ngram statistics, main carcass
Diffstat (limited to 'decoder/scfg_translator.cc')
-rw-r--r--decoder/scfg_translator.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/decoder/scfg_translator.cc b/decoder/scfg_translator.cc
index d978d8b9..9ca11cd9 100644
--- a/decoder/scfg_translator.cc
+++ b/decoder/scfg_translator.cc
@@ -103,6 +103,20 @@ struct SCFGTranslatorImpl {
grammars.push_back(sup_grammar_);
}
+ struct NameEquals { NameEquals(const string name) : name_(name) {}
+ bool operator()(const GrammarPtr& x) const { return x->GetGrammarName() == name_; } const string name_; };
+
+ void SetSentenceGrammar(const std::string& grammar_string) {
+ if (!SILENT) cerr << "Setting sentence grammar" << endl;
+ usingSentenceGrammar = true;
+ istringstream in(grammar_string);
+ TextGrammar* sent_grammar = new TextGrammar(&in);
+ sent_grammar->SetMaxSpan(max_span_limit);
+ sent_grammar->SetGrammarName("__psg");
+ grammars.erase (remove_if(grammars.begin(), grammars.end(), NameEquals("__psg")), grammars.end());
+ grammars.push_back(GrammarPtr(sent_grammar));
+ }
+
bool Translate(const string& input,
SentenceMetadata* smeta,
const vector<double>& weights,
@@ -304,6 +318,10 @@ void SCFGTranslator::SetSupplementalGrammar(const std::string& grammar) {
pimpl_->SetSupplementalGrammar(grammar);
}
+void SCFGTranslator::SetSentenceGrammar(const std::string& grammar) {
+ pimpl_->SetSentenceGrammar(grammar);
+}
+
void SCFGTranslator::SentenceCompleteImpl() {
if(usingSentenceGrammar) // Drop the last sentence grammar from the list of grammars