File: punctuator.h

package info (click to toggle)
librime 1.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,608 kB
  • ctags: 25,041
  • sloc: cpp: 119,202; sh: 21,794; ansic: 7,346; python: 4,372; makefile: 863; perl: 288; ruby: 50
file content (89 lines) | stat: -rw-r--r-- 2,465 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// Copyleft RIME Developers
// License: GPLv3
//
// 2011-11-21 GONG Chen <chen.sst@gmail.com>
//
#ifndef RIME_PUNCTUATOR_H_
#define RIME_PUNCTUATOR_H_

#include <map>
#include <rime/common.h>
#include <rime/component.h>
#include <rime/config.h>
#include <rime/processor.h>
#include <rime/segmentor.h>
#include <rime/translator.h>

namespace rime {

class Engine;

class PunctConfig {
 public:
  void LoadConfig(Engine *engine, bool load_symbols = false);
  ConfigItemPtr GetPunctDefinition(const std::string key);
 protected:
  ConfigMapPtr mapping_;
  ConfigMapPtr preset_mapping_;
  std::string shape_;
  ConfigMapPtr symbols_;
  ConfigMapPtr preset_symbols_;
};

class Punctuator : public Processor {
 public:
  Punctuator(const Ticket& ticket);
  virtual ProcessResult ProcessKeyEvent(const KeyEvent &key_event);

 protected:
  bool ConfirmUniquePunct(const ConfigItemPtr &definition);
  bool AlternatePunct(const std::string &key, const ConfigItemPtr &definition);
  bool AutoCommitPunct(const ConfigItemPtr &definition);
  bool PairPunct(const ConfigItemPtr &definition);

  PunctConfig config_;
  bool use_space_;
  std::map<ConfigItemPtr, int> oddness_;
};

class PunctSegmentor : public Segmentor {
 public:
  PunctSegmentor(const Ticket& ticket);
  virtual bool Proceed(Segmentation *segmentation);

 protected:
  PunctConfig config_;
};

class PunctTranslator : public Translator {
 public:
  PunctTranslator(const Ticket& ticket);
  virtual shared_ptr<Translation> Query(const std::string &input,
                                        const Segment &segment,
                                        std::string* prompt);

 protected:
  shared_ptr<Translation>
  TranslateUniquePunct(const std::string &key,
                       const Segment &segment,
                       const ConfigValuePtr &definition);
  shared_ptr<Translation>
  TranslateAlternatingPunct(const std::string &key,
                            const Segment &segment,
                            const ConfigListPtr &definition);
  shared_ptr<Translation>
  TranslateAutoCommitPunct(const std::string &key,
                           const Segment &segment,
                           const ConfigMapPtr &definition);
  shared_ptr<Translation>
  TranslatePairedPunct(const std::string &key,
                       const Segment &segment,
                       const ConfigMapPtr &definition);

  PunctConfig config_;
};

}  // namespace rime

#endif  // RIME_PUNCTUATOR_H_