diff options
Diffstat (limited to 'decoder/translator.cc')
-rw-r--r-- | decoder/translator.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/decoder/translator.cc b/decoder/translator.cc new file mode 100644 index 00000000..e6c282e1 --- /dev/null +++ b/decoder/translator.cc @@ -0,0 +1,57 @@ +#include "translator.h" + +#include <iostream> +#include <vector> + +using namespace std; + +Translator::~Translator() {} + +void Translator::ProcessMarkupHints(const map<string, string>& kv) { + if (state_ != kUninitialized) { + cerr << "Translator::ProcessMarkupHints in wrong state: " << state_ << endl; + abort(); + } + ProcessMarkupHintsImpl(kv); + state_ = kReadyToTranslate; +} + +bool Translator::Translate(const std::string& src, + SentenceMetadata* smeta, + const std::vector<double>& weights, + Hypergraph* minus_lm_forest) { + if (state_ == kUninitialized) { + cerr << "Translator::Translate(...) must not be in uninitialized state!\n"; + abort(); + } + const bool result = TranslateImpl(src, smeta, weights, minus_lm_forest); + state_ = kTranslated; + return result; +} + +void Translator::SentenceComplete() { + if (state_ != kTranslated) { + cerr << "Translator::Complete in unexpected state: " << state_ << endl; + // not fatal + } + SentenceCompleteImpl(); + state_ = kUninitialized; // return to start state +} + +// this may be overridden by translators that want to accept +// metadata +void Translator::ProcessMarkupHintsImpl(const map<string, string>& kv) { + int unprocessed = kv.size() - kv.count("id"); + cerr << "Inside translator process hints\n"; + if (unprocessed > 0) { + cerr << "Sentence markup contains unprocessed data:\n"; + for (map<string, string>::const_iterator it = kv.begin(); it != kv.end(); ++it) { + if (it->first == "id") continue; + cerr << " KEY[" << it->first << "] --> " << it->second << endl; + } + abort(); + } +} + +void Translator::SentenceCompleteImpl() {} + |