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.h | |
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.h')
-rw-r--r-- | decoder/translator.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/decoder/translator.h b/decoder/translator.h new file mode 100644 index 00000000..6b0a02e4 --- /dev/null +++ b/decoder/translator.h @@ -0,0 +1,82 @@ +#ifndef _TRANSLATOR_H_ +#define _TRANSLATOR_H_ + +#include <string> +#include <vector> +#include <map> +#include <boost/shared_ptr.hpp> +#include <boost/program_options/variables_map.hpp> + +class Hypergraph; +class SentenceMetadata; + +// Workflow: for each sentence to be translated +// 1) call ProcessMarkupHints(markup) +// 2) call Translate(...) +// 3) call SentenceComplete() +class Translator { + public: + Translator() : state_(kUninitialized) {} + virtual ~Translator(); + // returns true if goal reached, false otherwise + // minus_lm_forest will contain the unpruned forest. the + // feature values from the phrase table / grammar / etc + // should be in the forest already - the "late" features + // should not just copy values that are available without + // any context or computation. + // SentenceMetadata contains information about the sentence, + // but it is an input/output parameter since the Translator + // is also responsible for setting the value of src_len. + bool Translate(const std::string& src, + SentenceMetadata* smeta, + const std::vector<double>& weights, + Hypergraph* minus_lm_forest); + + // This is called before Translate(...) with the sentence- + // level markup passed in. This can be used to set sentence- + // specific behavior of the translator. + void ProcessMarkupHints(const std::map<std::string, std::string>& kv); + + // Free any sentence-specific resources + void SentenceComplete(); + protected: + virtual bool TranslateImpl(const std::string& src, + SentenceMetadata* smeta, + const std::vector<double>& weights, + Hypergraph* minus_lm_forest) = 0; + virtual void ProcessMarkupHintsImpl(const std::map<std::string, std::string>& kv); + virtual void SentenceCompleteImpl(); + private: + enum State { kUninitialized, kReadyToTranslate, kTranslated }; + State state_; +}; + +class SCFGTranslatorImpl; +class SCFGTranslator : public Translator { + public: + SCFGTranslator(const boost::program_options::variables_map& conf); + protected: + bool TranslateImpl(const std::string& src, + SentenceMetadata* smeta, + const std::vector<double>& weights, + Hypergraph* minus_lm_forest); + void ProcessMarkupHintsImpl(const std::map<std::string, std::string>& kv); + void SentenceCompleteImpl(); + private: + boost::shared_ptr<SCFGTranslatorImpl> pimpl_; +}; + +class FSTTranslatorImpl; +class FSTTranslator : public Translator { + public: + FSTTranslator(const boost::program_options::variables_map& conf); + private: + bool TranslateImpl(const std::string& src, + SentenceMetadata* smeta, + const std::vector<double>& weights, + Hypergraph* minus_lm_forest); + private: + boost::shared_ptr<FSTTranslatorImpl> pimpl_; +}; + +#endif |