00001 #ifndef LM_FACADE__
00002 #define LM_FACADE__
00003
00004 #include "lm/virtual_interface.hh"
00005 #include "util/string_piece.hh"
00006
00007 #include <string>
00008
00009 namespace lm {
00010 namespace base {
00011
00012
00013
00014 template <class Child, class StateT, class VocabularyT> class ModelFacade : public Model {
00015 public:
00016 typedef StateT State;
00017 typedef VocabularyT Vocabulary;
00018
00019
00020 float Score(const State &in_state, const WordIndex new_word, State &out_state) const {
00021 return static_cast<const Child*>(this)->FullScore(in_state, new_word, out_state).prob;
00022 }
00023
00024
00025 FullScoreReturn FullScore(const void *in_state, const WordIndex new_word, void *out_state) const {
00026 return static_cast<const Child*>(this)->FullScore(
00027 *reinterpret_cast<const State*>(in_state),
00028 new_word,
00029 *reinterpret_cast<State*>(out_state));
00030 }
00031 float Score(const void *in_state, const WordIndex new_word, void *out_state) const {
00032 return static_cast<const Child*>(this)->Score(
00033 *reinterpret_cast<const State*>(in_state),
00034 new_word,
00035 *reinterpret_cast<State*>(out_state));
00036 }
00037
00038 const State &BeginSentenceState() const { return begin_sentence_; }
00039 const State &NullContextState() const { return null_context_; }
00040 const Vocabulary &GetVocabulary() const { return *static_cast<const Vocabulary*>(&BaseVocabulary()); }
00041
00042 protected:
00043 ModelFacade() : Model(sizeof(State)) {}
00044
00045 virtual ~ModelFacade() {}
00046
00047
00048 void Init(const State &begin_sentence, const State &null_context, const Vocabulary &vocab, unsigned char order) {
00049 begin_sentence_ = begin_sentence;
00050 null_context_ = null_context;
00051 begin_sentence_memory_ = &begin_sentence_;
00052 null_context_memory_ = &null_context_;
00053 base_vocab_ = &vocab;
00054 order_ = order;
00055 }
00056
00057 private:
00058 State begin_sentence_, null_context_;
00059 };
00060
00061 }
00062 }
00063
00064 #endif // LM_FACADE__