diff options
author | redpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-06-22 05:12:27 +0000 |
---|---|---|
committer | redpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-06-22 05:12:27 +0000 |
commit | 0172721855098ca02b207231a654dffa5e4eb1c9 (patch) | |
tree | 8069c3a62e2d72bd64a2cdeee9724b2679c8a56b /decoder/translator.cc | |
parent | 37728b8be4d0b3df9da81fdda2198ff55b4b2d91 (diff) |
initial checkin
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@2 ec762483-ff6d-05da-a07a-a48fb63a330f
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() {} + |