librime: punctuator.h Source File

| librime 1.2 Rime Input Method Engine, the core library

punctuator.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2011-11-21 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_PUNCTUATOR_H_
8#define RIME_PUNCTUATOR_H_
9
10#include <rime/common.h>
11#include <rime/component.h>
12#include <rime/config.h>
13#include <rime/processor.h>
14#include <rime/segmentor.h>
15#include <rime/translator.h>
16#include <rime/gear/shape.h>
17
18namespace rime {
19
20class Engine;
21
22 class PunctConfig {
23 public:
24 void LoadConfig(Engine* engine, bool load_symbols = false);
25 an<ConfigItem> GetPunctDefinition(const string key);
26
27 bool has_digit_separators() const { return !digit_separators_.empty(); }
28 bool is_digit_separator(char ch) const {
29 return digit_separators_.find(ch) != string::npos;
30 }
31 bool digit_separator_commit() const { return digit_separator_commit_; }
32
33 protected:
34 string shape_;
35 an<ConfigMap> mapping_;
36 an<ConfigMap> symbols_;
37
38 string digit_separators_ = ".:";
39 bool digit_separator_commit_ = false;
40};
41
42 class Punctuator : public Processor {
43 public:
44 Punctuator(const Ticket& ticket);
45 virtual ProcessResult ProcessKeyEvent(const KeyEvent& key_event);
46
47 protected:
48 bool ConvertDigitSeparator(char ch);
49 bool ReconvertDigitSeparatorAsPunct(const string& key);
50 bool AlternatePunct(const string& key, const an<ConfigItem>& definition);
51 bool ConfirmUniquePunct(const an<ConfigItem>& definition);
52 bool AutoCommitPunct(const an<ConfigItem>& definition);
53 bool PairPunct(const an<ConfigItem>& definition);
54
55 PunctConfig config_;
56 bool use_space_ = false;
57 map<an<ConfigItem>, int> oddness_;
58};
59
60 class PunctSegmentor : public Segmentor {
61 public:
62 PunctSegmentor(const Ticket& ticket);
63 virtual bool Proceed(Segmentation* segmentation);
64
65 protected:
66 PunctConfig config_;
67};
68
69 class PunctTranslator : public Translator {
70 public:
71 PunctTranslator(const Ticket& ticket);
72 virtual an<Translation> Query(const string& input, const Segment& segment);
73
74 protected:
75 an<Translation> TranslateUniquePunct(const string& key,
76 const Segment& segment,
77 const an<ConfigValue>& definition);
78 an<Translation> TranslateAlternatingPunct(const string& key,
79 const Segment& segment,
80 const an<ConfigList>& definition);
81 an<Translation> TranslateAutoCommitPunct(const string& key,
82 const Segment& segment,
83 const an<ConfigMap>& definition);
84 an<Translation> TranslatePairedPunct(const string& key,
85 const Segment& segment,
86 const an<ConfigMap>& definition);
87
88 ShapeFormatter formatter_;
89 PunctConfig config_;
90};
91
92} // namespace rime
93
94#endif // RIME_PUNCTUATOR_H_
translator.h
processor.h
segmentor.h
shape.h
common.h
component.h
config.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::ProcessResult
ProcessResult
Definition processor.h:18
rime::Engine
Definition engine.h:20
rime::PunctConfig
Definition punctuator.h:22
rime::PunctConfig::digit_separator_commit
bool digit_separator_commit() const
Definition punctuator.h:31
rime::PunctConfig::digit_separators_
string digit_separators_
Definition punctuator.h:38
rime::PunctConfig::LoadConfig
void LoadConfig(Engine *engine, bool load_symbols=false)
Definition punctuator.cc:23
rime::PunctConfig::GetPunctDefinition
an< ConfigItem > GetPunctDefinition(const string key)
Definition punctuator.cc:51
rime::PunctConfig::is_digit_separator
bool is_digit_separator(char ch) const
Definition punctuator.h:28
rime::PunctConfig::has_digit_separators
bool has_digit_separators() const
Definition punctuator.h:27
rime::PunctConfig::shape_
string shape_
Definition punctuator.h:34
rime::PunctConfig::mapping_
an< ConfigMap > mapping_
Definition punctuator.h:35
rime::PunctConfig::symbols_
an< ConfigMap > symbols_
Definition punctuator.h:36
rime::PunctConfig::digit_separator_commit_
bool digit_separator_commit_
Definition punctuator.h:39
rime::Punctuator::use_space_
bool use_space_
Definition punctuator.h:56
rime::Punctuator::ReconvertDigitSeparatorAsPunct
bool ReconvertDigitSeparatorAsPunct(const string &key)
Definition punctuator.cc:154
rime::Punctuator::AlternatePunct
bool AlternatePunct(const string &key, const an< ConfigItem > &definition)
Definition punctuator.cc:178
rime::Punctuator::ConfirmUniquePunct
bool ConfirmUniquePunct(const an< ConfigItem > &definition)
Definition punctuator.cc:202
rime::Punctuator::config_
PunctConfig config_
Definition punctuator.h:55
rime::Punctuator::AutoCommitPunct
bool AutoCommitPunct(const an< ConfigItem > &definition)
Definition punctuator.cc:209
rime::Punctuator::oddness_
map< an< ConfigItem >, int > oddness_
Definition punctuator.h:57
rime::Punctuator::ProcessKeyEvent
virtual ProcessResult ProcessKeyEvent(const KeyEvent &key_event)
Definition punctuator.cc:94
rime::Punctuator::ConvertDigitSeparator
bool ConvertDigitSeparator(char ch)
Definition punctuator.cc:139
rime::Punctuator::Punctuator
Punctuator(const Ticket &ticket)
Definition punctuator.cc:56
rime::Punctuator::PairPunct
bool PairPunct(const an< ConfigItem > &definition)
Definition punctuator.cc:217
rime::PunctSegmentor::PunctSegmentor
PunctSegmentor(const Ticket &ticket)
Definition punctuator.cc:241
rime::PunctSegmentor::config_
PunctConfig config_
Definition punctuator.h:66
rime::PunctSegmentor::Proceed
virtual bool Proceed(Segmentation *segmentation)
Definition punctuator.cc:245
rime::PunctTranslator::config_
PunctConfig config_
Definition punctuator.h:89
rime::PunctTranslator::formatter_
ShapeFormatter formatter_
Definition punctuator.h:88
rime::PunctTranslator::TranslateAutoCommitPunct
an< Translation > TranslateAutoCommitPunct(const string &key, const Segment &segment, const an< ConfigMap > &definition)
Definition punctuator.cc:396
rime::PunctTranslator::PunctTranslator
PunctTranslator(const Ticket &ticket)
Definition punctuator.cc:278
rime::PunctTranslator::TranslateUniquePunct
an< Translation > TranslateUniquePunct(const string &key, const Segment &segment, const an< ConfigValue > &definition)
Definition punctuator.cc:362
rime::PunctTranslator::TranslateAlternatingPunct
an< Translation > TranslateAlternatingPunct(const string &key, const Segment &segment, const an< ConfigList > &definition)
Definition punctuator.cc:372
rime::PunctTranslator::Query
virtual an< Translation > Query(const string &input, const Segment &segment)
Definition punctuator.cc:325
rime::PunctTranslator::TranslatePairedPunct
an< Translation > TranslatePairedPunct(const string &key, const Segment &segment, const an< ConfigMap > &definition)
Definition punctuator.cc:410
rime::ShapeFormatter
Definition shape.h:16
rime::KeyEvent
Definition key_event.h:17
rime::Processor::Processor
Processor(const Ticket &ticket)
Definition processor.h:26
rime::Segment
Definition segmentation.h:18
rime::Segmentation
Definition segmentation.h:60
rime::Segmentor::Segmentor
Segmentor(const Ticket &ticket)
Definition segmentor.h:20
rime::Ticket
Definition ticket.h:17
rime::Translator::Translator
Translator(const Ticket &ticket)
Definition translator.h:24