From 8c16b9384e8b85abf9e51bc670e548bf5cd4a0c5 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Sun, 12 Dec 2010 15:32:19 -0500 Subject: facility for adding programmitically generated grammars --- decoder/scfg_translator.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'decoder/scfg_translator.cc') diff --git a/decoder/scfg_translator.cc b/decoder/scfg_translator.cc index afe796a5..a19e9d75 100644 --- a/decoder/scfg_translator.cc +++ b/decoder/scfg_translator.cc @@ -91,6 +91,17 @@ struct SCFGTranslatorImpl { bool show_tree_structure_; unsigned int ctf_iterations_; vector grammars; + GrammarPtr sup_grammar_; + + struct Equals { Equals(const GrammarPtr& v) : v_(v) {} + bool operator()(const GrammarPtr& x) const { return x == v_; } const GrammarPtr& v_; }; + + void SetSupplementalGrammar(const std::string& grammar_string) { + grammars.erase(remove_if(grammars.begin(), grammars.end(), Equals(sup_grammar_)), grammars.end()); + istringstream in(grammar_string); + sup_grammar_.reset(new TextGrammar(&in)); + grammars.push_back(sup_grammar_); + } bool Translate(const string& input, SentenceMetadata* smeta, @@ -290,6 +301,10 @@ void SCFGTranslator::ProcessMarkupHintsImpl(const map& kv) { } +void SCFGTranslator::SetSupplementalGrammar(const std::string& grammar) { + pimpl_->SetSupplementalGrammar(grammar); +} + void SCFGTranslator::SentenceCompleteImpl() { if(usingSentenceGrammar) // Drop the last sentence grammar from the list of grammars @@ -299,3 +314,7 @@ void SCFGTranslator::SentenceCompleteImpl() { } } +std::string SCFGTranslator::GetDecoderType() const { + return "SCFG"; +} + -- cgit v1.2.3