librime: table_translator.h Source File

| librime 1.2 Rime Input Method Engine, the core library

table_translator.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2011-07-10 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_TABLE_TRANSLATOR_H_
8#define RIME_TABLE_TRANSLATOR_H_
9
10#include <rime/common.h>
11#include <rime/config.h>
12#include <rime/translation.h>
13#include <rime/translator.h>
14#include <rime/algo/algebra.h>
15#include <rime/dict/dictionary.h>
16#include <rime/dict/user_dictionary.h>
17#include <rime/gear/memory.h>
18#include <rime/gear/translator_commons.h>
19
20namespace rime {
21
22class Poet;
23class UnityTableEncoder;
24
25 class TableTranslator : public Translator,
26 public Memory,
27 public TranslatorOptions {
28 public:
29 TableTranslator(const Ticket& ticket);
30
31 virtual an<Translation> Query(const string& input, const Segment& segment);
32 virtual bool Memorize(const CommitEntry& commit_entry);
33
34 an<Translation> MakeSentence(const string& input,
35 size_t start,
36 bool include_prefix_phrases = false);
37 string GetPrecedingText(size_t start) const;
38 UnityTableEncoder* encoder() const { return encoder_.get(); }
39
40 protected:
41 bool enable_charset_filter_ = false;
42 bool enable_encoder_ = false;
43 bool enable_sentence_ = true;
44 bool sentence_over_completion_ = false;
45 bool encode_commit_history_ = true;
46 int max_phrase_length_ = 5;
47 int max_homographs_ = 1;
48 the<Poet> poet_;
49 the<UnityTableEncoder> encoder_;
50};
51
52 class TableTranslation : public Translation {
53 public:
54 TableTranslation(TranslatorOptions* options,
55 const Language* language,
56 const string& input,
57 size_t start,
58 size_t end,
59 const string& preedit,
60 DictEntryIterator&& iter = {},
61 UserDictEntryIterator&& uter = {});
62
63 virtual bool Next();
64 virtual an<Candidate> Peek();
65
66 protected:
67 virtual bool FetchMoreUserPhrases() { return false; }
68 virtual bool FetchMoreTableEntries() { return false; }
69
70 bool CheckEmpty();
71 bool PreferUserPhrase();
72
73 an<DictEntry> PreferredEntry(bool prefer_user_phrase) {
74 return prefer_user_phrase ? uter_.Peek() : iter_.Peek();
75 }
76
77 TranslatorOptions* options_;
78 const Language* language_;
79 string input_;
80 size_t start_;
81 size_t end_;
82 string preedit_;
83 DictEntryIterator iter_;
84 UserDictEntryIterator uter_;
85};
86
87} // namespace rime
88
89#endif // RIME_TABLE_TRANSLATOR_H_
algebra.h
common.h
config.h
dictionary.h
user_dictionary.h
memory.h
translator_commons.h
translation.h
translator.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::the
std::unique_ptr< T > the
Definition common.h:58
rime::DictEntryIterator
Definition dictionary.h:26
rime::DictEntryIterator::Peek
an< DictEntry > Peek()
Definition dictionary.cc:153
rime::UserDictEntryIterator
Definition user_dictionary.h:18
rime::UserDictEntryIterator::Peek
an< DictEntry > Peek()
Definition user_dictionary.cc:126
rime::CommitEntry
Definition memory.h:24
rime::Memory::Memory
Memory(const Ticket &ticket)
Definition memory.cc:58
rime::Poet
Definition poet.h:26
rime::TableTranslator::enable_charset_filter_
bool enable_charset_filter_
Definition table_translator.h:41
rime::TableTranslator::MakeSentence
an< Translation > MakeSentence(const string &input, size_t start, bool include_prefix_phrases=false)
Definition table_translator.cc:543
rime::TableTranslator::sentence_over_completion_
bool sentence_over_completion_
Definition table_translator.h:44
rime::TableTranslator::max_homographs_
int max_homographs_
Definition table_translator.h:47
rime::TableTranslator::TableTranslator
TableTranslator(const Ticket &ticket)
Definition table_translator.cc:211
rime::TableTranslator::enable_sentence_
bool enable_sentence_
Definition table_translator.h:43
rime::TableTranslator::GetPrecedingText
string GetPrecedingText(size_t start) const
Definition table_translator.cc:358
rime::TableTranslator::Query
virtual an< Translation > Query(const string &input, const Segment &segment)
Definition table_translator.cc:244
rime::TableTranslator::max_phrase_length_
int max_phrase_length_
Definition table_translator.h:46
rime::TableTranslator::poet_
the< Poet > poet_
Definition table_translator.h:48
rime::TableTranslator::encoder
UnityTableEncoder * encoder() const
Definition table_translator.h:38
rime::TableTranslator::encode_commit_history_
bool encode_commit_history_
Definition table_translator.h:45
rime::TableTranslator::Memorize
virtual bool Memorize(const CommitEntry &commit_entry)
Definition table_translator.cc:311
rime::TableTranslator::enable_encoder_
bool enable_encoder_
Definition table_translator.h:42
rime::TableTranslator::encoder_
the< UnityTableEncoder > encoder_
Definition table_translator.h:49
rime::TableTranslation::PreferUserPhrase
bool PreferUserPhrase()
Definition table_translator.cc:102
rime::TableTranslation::uter_
UserDictEntryIterator uter_
Definition table_translator.h:84
rime::TableTranslation::iter_
DictEntryIterator iter_
Definition table_translator.h:83
rime::TableTranslation::end_
size_t end_
Definition table_translator.h:81
rime::TableTranslation::start_
size_t start_
Definition table_translator.h:80
rime::TableTranslation::FetchMoreUserPhrases
virtual bool FetchMoreUserPhrases()
Definition table_translator.h:67
rime::TableTranslation::language_
const Language * language_
Definition table_translator.h:78
rime::TableTranslation::FetchMoreTableEntries
virtual bool FetchMoreTableEntries()
Definition table_translator.h:68
rime::TableTranslation::PreferredEntry
an< DictEntry > PreferredEntry(bool prefer_user_phrase)
Definition table_translator.h:73
rime::TableTranslation::Next
virtual bool Next()
Definition table_translator.cc:54
rime::TableTranslation::preedit_
string preedit_
Definition table_translator.h:82
rime::TableTranslation::options_
TranslatorOptions * options_
Definition table_translator.h:77
rime::TableTranslation::input_
string input_
Definition table_translator.h:79
rime::TableTranslation::Peek
virtual an< Candidate > Peek()
Definition table_translator.cc:73
rime::TableTranslation::CheckEmpty
bool CheckEmpty()
Definition table_translator.cc:96
rime::TableTranslation::TableTranslation
TableTranslation(TranslatorOptions *options, const Language *language, const string &input, size_t start, size_t end, const string &preedit, DictEntryIterator &&iter={}, UserDictEntryIterator &&uter={})
Definition table_translator.cc:33
rime::TranslatorOptions
Definition translator_commons.h:143
rime::TranslatorOptions::TranslatorOptions
TranslatorOptions(const Ticket &ticket)
Definition translator_commons.cc:115
rime::UnityTableEncoder
Definition unity_table_encoder.h:19
rime::Language
Definition language.h:12
rime::Segment
Definition segmentation.h:18
rime::Ticket
Definition ticket.h:17
rime::Translation::Translation
Translation()=default
rime::Translator::Translator
Translator(const Ticket &ticket)
Definition translator.h:24