From 354561ec7006b6a67884227e0a37465608a01152 Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Sun, 24 Jul 2011 20:46:22 +0200
Subject: added dtrain, implemented psg setting in decoder/translator,
implemented psmetrics, ngram statistics, main carcass
---
decoder/decoder.cc | 4 ++++
decoder/decoder.h | 1 +
decoder/scfg_translator.cc | 18 ++++++++++++++++++
decoder/translator.h | 1 +
4 files changed, 24 insertions(+)
(limited to 'decoder')
diff --git a/decoder/decoder.cc b/decoder/decoder.cc
index ff068be9..434109c2 100644
--- a/decoder/decoder.cc
+++ b/decoder/decoder.cc
@@ -708,6 +708,10 @@ void Decoder::SetSupplementalGrammar(const std::string& grammar_string) {
assert(pimpl_->translator->GetDecoderType() == "SCFG");
static_cast(*pimpl_->translator).SetSupplementalGrammar(grammar_string);
}
+void Decoder::SetSentenceGrammar(const std::string& grammar_string) {
+ assert(pimpl_->translator->GetDecoderType() == "SCFG");
+ static_cast(*pimpl_->translator).SetSentenceGrammar(grammar_string);
+}
bool DecoderImpl::Decode(const string& input, DecoderObserver* o) {
diff --git a/decoder/decoder.h b/decoder/decoder.h
index 813400e3..6eca12c1 100644
--- a/decoder/decoder.h
+++ b/decoder/decoder.h
@@ -34,6 +34,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 SetSentenceGrammar(const std::string& grammar);
private:
boost::program_options::variables_map conf;
boost::shared_ptr pimpl_;
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& 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
diff --git a/decoder/translator.h b/decoder/translator.h
index 9d6dd97d..5abf9fd6 100644
--- a/decoder/translator.h
+++ b/decoder/translator.h
@@ -57,6 +57,7 @@ class SCFGTranslator : public Translator {
public:
SCFGTranslator(const boost::program_options::variables_map& conf);
void SetSupplementalGrammar(const std::string& grammar);
+ void SetSentenceGrammar(const std::string& grammar);
virtual std::string GetDecoderType() const;
protected:
bool TranslateImpl(const std::string& src,
--
cgit v1.2.3