summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
Diffstat (limited to 'decoder')
-rw-r--r--decoder/decoder.cc4
-rw-r--r--decoder/decoder.h1
-rw-r--r--decoder/ff_klm.cc19
-rw-r--r--decoder/hg.h2
-rw-r--r--decoder/scfg_translator.cc19
-rw-r--r--decoder/translator.h3
6 files changed, 48 insertions, 0 deletions
diff --git a/decoder/decoder.cc b/decoder/decoder.cc
index 3b53fd6b..b93925d1 100644
--- a/decoder/decoder.cc
+++ b/decoder/decoder.cc
@@ -734,6 +734,10 @@ void Decoder::SetSupplementalGrammar(const std::string& grammar_string) {
assert(pimpl_->translator->GetDecoderType() == "SCFG");
static_cast<SCFGTranslator&>(*pimpl_->translator).SetSupplementalGrammar(grammar_string);
}
+void Decoder::SetSentenceGrammarFromString(const std::string& grammar_str) {
+ assert(pimpl_->translator->GetDecoderType() == "SCFG");
+ static_cast<SCFGTranslator&>(*pimpl_->translator).SetSentenceGrammarFromString(grammar_str);
+}
bool DecoderImpl::Decode(const string& input, DecoderObserver* o) {
diff --git a/decoder/decoder.h b/decoder/decoder.h
index 9d009ffa..6b2f7b16 100644
--- a/decoder/decoder.h
+++ b/decoder/decoder.h
@@ -55,6 +55,7 @@ struct Decoder {
// that will be used on subsequent calls to Decode. rules should be in standard
// text format. This function does NOT read from a file.
void SetSupplementalGrammar(const std::string& grammar);
+ void SetSentenceGrammarFromString(const std::string& grammar_str);
private:
boost::program_options::variables_map conf;
boost::shared_ptr<DecoderImpl> pimpl_;
diff --git a/decoder/ff_klm.cc b/decoder/ff_klm.cc
index ed6f731e..28bcb6b9 100644
--- a/decoder/ff_klm.cc
+++ b/decoder/ff_klm.cc
@@ -392,3 +392,22 @@ std::string KLanguageModelFactory::usage(bool params,bool verbose) const {
return KLanguageModel<lm::ngram::Model>::usage(params, verbose);
}
+ switch (m) {
+ case HASH_PROBING:
+ return CreateModel<ProbingModel>(param);
+ case TRIE_SORTED:
+ return CreateModel<TrieModel>(param);
+ case ARRAY_TRIE_SORTED:
+ return CreateModel<ArrayTrieModel>(param);
+ case QUANT_TRIE_SORTED:
+ return CreateModel<QuantTrieModel>(param);
+ case QUANT_ARRAY_TRIE_SORTED:
+ return CreateModel<QuantArrayTrieModel>(param);
+ default:
+ UTIL_THROW(util::Exception, "Unrecognized kenlm binary file type " << (unsigned)m);
+ }
+}
+
+std::string KLanguageModelFactory::usage(bool params,bool verbose) const {
+ return KLanguageModel<lm::ngram::Model>::usage(params, verbose);
+}
diff --git a/decoder/hg.h b/decoder/hg.h
index f0ddbb76..52a18601 100644
--- a/decoder/hg.h
+++ b/decoder/hg.h
@@ -397,6 +397,8 @@ public:
template <class V>
void Reweight(const V& weights) {
for (int i = 0; i < edges_.size(); ++i) {
+ SparseVector<double> v;
+ //v.set_value(FD::Convert("use_shell"), 1000);
Edge& e = edges_[i];
e.edge_prob_.logeq(e.feature_values_.dot(weights));
}
diff --git a/decoder/scfg_translator.cc b/decoder/scfg_translator.cc
index d978d8b9..646d67fa 100644
--- a/decoder/scfg_translator.cc
+++ b/decoder/scfg_translator.cc
@@ -103,6 +103,21 @@ 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 SetSentenceGrammarFromString(const std::string& grammar_str) {
+ assert( grammar_str != "" );
+ if (!SILENT) cerr << "Setting sentence grammar" << endl;
+ usingSentenceGrammar = true;
+ istringstream in( grammar_str );
+ 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 +319,10 @@ void SCFGTranslator::SetSupplementalGrammar(const std::string& grammar) {
pimpl_->SetSupplementalGrammar(grammar);
}
+void SCFGTranslator::SetSentenceGrammarFromString(const std::string& grammar_str) {
+ pimpl_->SetSentenceGrammarFromString(grammar_str);
+}
+
void SCFGTranslator::SentenceCompleteImpl() {
if(usingSentenceGrammar) // Drop the last sentence grammar from the list of grammars
diff --git a/decoder/translator.h b/decoder/translator.h
index 9d6dd97d..cfd3b08a 100644
--- a/decoder/translator.h
+++ b/decoder/translator.h
@@ -7,6 +7,8 @@
#include <boost/shared_ptr.hpp>
#include <boost/program_options/variables_map.hpp>
+#include "grammar.h"
+
class Hypergraph;
class SentenceMetadata;
@@ -57,6 +59,7 @@ class SCFGTranslator : public Translator {
public:
SCFGTranslator(const boost::program_options::variables_map& conf);
void SetSupplementalGrammar(const std::string& grammar);
+ void SetSentenceGrammarFromString(const std::string& grammar);
virtual std::string GetDecoderType() const;
protected:
bool TranslateImpl(const std::string& src,