summaryrefslogtreecommitdiff
path: root/decoder/scfg_translator.cc
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2010-12-12 15:32:19 -0500
committerChris Dyer <cdyer@cs.cmu.edu>2010-12-12 15:32:19 -0500
commit8c16b9384e8b85abf9e51bc670e548bf5cd4a0c5 (patch)
tree83cb68bb8c884fcf14aa33eddf88f428ad60f807 /decoder/scfg_translator.cc
parentb8f314dddda3d440164e4772830e3c951ba06ee4 (diff)
facility for adding programmitically generated grammars
Diffstat (limited to 'decoder/scfg_translator.cc')
-rw-r--r--decoder/scfg_translator.cc19
1 files changed, 19 insertions, 0 deletions
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<GrammarPtr> 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<string, string>& 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";
+}
+