diff options
author | Patrick Simianer <p@simianer.de> | 2014-02-06 10:26:29 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-02-06 10:26:29 +0100 |
commit | 7bfe96c2a706d375362c054619f28dd40c7c33e8 (patch) | |
tree | fb0698a3bcb4b38d99d7a07b87a573a571dd7be2 /decoder | |
parent | c83f665cb7efbbfb0fdfa12203b09ba60e365d25 (diff) | |
parent | 3798fb9a43c27c3dfe0db5ee0dd0ef04bf5ee5f5 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'decoder')
-rw-r--r-- | decoder/scfg_translator.cc | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/decoder/scfg_translator.cc b/decoder/scfg_translator.cc index 236d7c90..159a1d60 100644 --- a/decoder/scfg_translator.cc +++ b/decoder/scfg_translator.cc @@ -2,6 +2,7 @@ #include <vector> #include <boost/foreach.hpp> #include <boost/functional/hash.hpp> +#include "fast_lexical_cast.hpp" #include "hash.h" #include "translator.h" #include "hg.h" @@ -353,15 +354,31 @@ bool SCFGTranslator::TranslateImpl(const string& input, return pimpl_->Translate(input, smeta, weights, minus_lm_forest); } -/* -Check for grammar pointer in the sentence markup, for use with sentence specific grammars - */ +// +// Check for extra grammars in the sentence markup, for use with sentence specific grammars +// void SCFGTranslator::ProcessMarkupHintsImpl(const map<string, string>& kv) { - map<string,string>::const_iterator it = kv.find("grammar"); - if (it != kv.end()) { - TextGrammar* sentGrammar = new TextGrammar(it->second); + if (kv.find("grammar0") != kv.end()) { + cerr << "SGML tag grammar0 is not expected (order is: grammar, grammar1, grammar2, ...)\n"; + abort(); + } + unsigned gc = 0; + set<string> loaded; + while(true) { + string gkey = "grammar"; + if (gc > 0) gkey += boost::lexical_cast<string>(gc); + ++gc; + map<string,string>::const_iterator it = kv.find(gkey); + if (it == kv.end()) break; + const string& gfile = it->second; + if (loaded.count(gfile) == 1) { + cerr << "Attempting to load " << gfile << " twice!\n"; + abort(); + } + loaded.insert(gfile); + TextGrammar* sentGrammar = new TextGrammar(gfile); sentGrammar->SetMaxSpan(pimpl_->max_span_limit); - sentGrammar->SetGrammarName(it->second); + sentGrammar->SetGrammarName(gfile); pimpl_->AddSupplementalGrammar(GrammarPtr(sentGrammar)); } } |