librime: calculus.h Source File

| librime 1.2 Rime Input Method Engine, the core library

calculus.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2012-01-17 GONG Chen <chen.sst@gmail.com>
6//
7
8#ifndef RIME_CALCULUS_H_
9#define RIME_CALCULUS_H_
10
11#include <stdint.h>
12#include <boost/regex.hpp>
13#include <rime_api.h>
14#include <rime/common.h>
15#include "spelling.h"
16
17namespace rime {
18
19 class Calculation {
20 public:
21 using Factory = Calculation*(const vector<string>& args);
22
23 Calculation() = default;
24 virtual ~Calculation() = default;
25 virtual bool Apply(Spelling* spelling) = 0;
26 virtual bool addition() { return true; }
27 virtual bool deletion() { return true; }
28};
29
30 class Calculus {
31 public:
32 RIME_DLL Calculus();
33 void Register(const string& token, Calculation::Factory* factory);
34 RIME_DLL Calculation* Parse(const string& definition);
35
36 private:
37 map<string, Calculation::Factory*> factories_;
38};
39
40// xlit/zyx/abc/
41 class Transliteration : public Calculation {
42 public:
43 static Factory Parse;
44 bool Apply(Spelling* spelling) override;
45
46 protected:
47 map<uint32_t, uint32_t> char_map_;
48};
49
50// xform/x/y/
51 class Transformation : public Calculation {
52 public:
53 static Factory Parse;
54 bool Apply(Spelling* spelling) override;
55
56 protected:
57 boost::regex pattern_;
58 string replacement_;
59};
60
61// erase/x/
62 class Erasion : public Calculation {
63 public:
64 static Factory Parse;
65 bool Apply(Spelling* spelling) override;
66 bool addition() override { return false; }
67
68 protected:
69 boost::regex pattern_;
70};
71
72// derive/x/X/
73 class Derivation : public Transformation {
74 public:
75 static Factory Parse;
76 bool deletion() override { return false; }
77};
78
79// fuzz/zyx/zx/
80 class Fuzzing : public Derivation {
81 public:
82 static Factory Parse;
83 bool Apply(Spelling* spelling) override;
84};
85
86// abbrev/zyx/z/
87 class Abbreviation : public Derivation {
88 public:
89 static Factory Parse;
90 bool Apply(Spelling* spelling) override;
91};
92
93// derive/zyx/zxy/correction
94 class Correction : public Derivation {
95 public:
96 bool Apply(Spelling* spelling) override;
97};
98
99} // namespace rime
100
101#endif // RIME_CALCULUS_H_
spelling.h
common.h
rime_api.h
RIME_DLL
#define RIME_DLL
Definition rime_api.h:33
rime
Definition algebra.cc:12
rime::Calculation
Definition calculus.h:19
rime::Calculation::Calculation
Calculation()=default
rime::Calculation::~Calculation
virtual ~Calculation()=default
rime::Calculation::Factory
Calculation *(const vector< string > &args) Factory
Definition calculus.h:21
rime::Calculation::Apply
virtual bool Apply(Spelling *spelling)=0
rime::Calculation::deletion
virtual bool deletion()
Definition calculus.h:27
rime::Calculation::addition
virtual bool addition()
Definition calculus.h:26
rime::Calculus::Calculus
RIME_DLL Calculus()
Definition calculus.cc:18
rime::Calculus::Register
void Register(const string &token, Calculation::Factory *factory)
Definition calculus.cc:27
rime::Calculus::Parse
RIME_DLL Calculation * Parse(const string &definition)
Definition calculus.cc:31
rime::Transliteration
Definition calculus.h:41
rime::Transliteration::char_map_
map< uint32_t, uint32_t > char_map_
Definition calculus.h:47
rime::Transliteration::Parse
static Factory Parse
Definition calculus.h:43
rime::Transliteration::Apply
bool Apply(Spelling *spelling) override
Definition calculus.cc:70
rime::Transformation
Definition calculus.h:51
rime::Transformation::Parse
static Factory Parse
Definition calculus.h:53
rime::Transformation::Apply
bool Apply(Spelling *spelling) override
Definition calculus.cc:112
rime::Transformation::replacement_
string replacement_
Definition calculus.h:58
rime::Transformation::pattern_
boost::regex pattern_
Definition calculus.h:57
rime::Erasion
Definition calculus.h:62
rime::Erasion::addition
bool addition() override
Definition calculus.h:66
rime::Erasion::Parse
static Factory Parse
Definition calculus.h:64
rime::Erasion::pattern_
boost::regex pattern_
Definition calculus.h:69
rime::Erasion::Apply
bool Apply(Spelling *spelling) override
Definition calculus.cc:135
rime::Derivation
Definition calculus.h:73
rime::Derivation::Parse
static Factory Parse
Definition calculus.h:75
rime::Derivation::deletion
bool deletion() override
Definition calculus.h:76
rime::Fuzzing
Definition calculus.h:80
rime::Fuzzing::Parse
static Factory Parse
Definition calculus.h:82
rime::Fuzzing::Apply
bool Apply(Spelling *spelling) override
Definition calculus.cc:202
rime::Abbreviation
Definition calculus.h:87
rime::Abbreviation::Parse
static Factory Parse
Definition calculus.h:89
rime::Abbreviation::Apply
bool Apply(Spelling *spelling) override
Definition calculus.cc:226
rime::Correction
Definition calculus.h:94
rime::Correction::Apply
bool Apply(Spelling *spelling) override
Definition calculus.cc:237
rime::Spelling
Definition spelling.h:37