librime: recognizer.h Source File

| librime 1.2 Rime Input Method Engine, the core library

recognizer.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2012-01-01 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_RECOGNIZER_H_
8#define RIME_RECOGNIZER_H_
9
10#include <boost/regex.hpp>
11#include <rime/common.h>
12#include <rime/processor.h>
13
14namespace rime {
15
16class Config;
17class Segmentation;
18
19 struct RecognizerMatch {
20 string tag;
21 size_t start = 0, end = 0;
22
23 RecognizerMatch() = default;
24 RecognizerMatch(const string& a_tag, size_t a_start, size_t an_end)
25 : tag(a_tag), start(a_start), end(an_end) {}
26
27 bool found() const { return start < end; }
28};
29
30 class RecognizerPatterns : public map<string, boost::regex> {
31 public:
32 void LoadConfig(Config* config, const string& name_space);
33 RecognizerMatch GetMatch(const string& input,
34 const Segmentation& segmentation) const;
35};
36
37 class Recognizer : public Processor {
38 public:
39 Recognizer(const Ticket& ticket);
40
41 virtual ProcessResult ProcessKeyEvent(const KeyEvent& key_event);
42
43 protected:
44 RecognizerPatterns patterns_;
45 bool use_space_ = false;
46};
47
48} // namespace rime
49
50#endif // RIME_RECOGNIZER_H_
processor.h
common.h
rime
Definition algebra.cc:12
rime::ProcessResult
ProcessResult
Definition processor.h:18
rime::Config
Definition config_component.h:21
rime::RecognizerMatch
Definition recognizer.h:19
rime::RecognizerMatch::RecognizerMatch
RecognizerMatch()=default
rime::RecognizerMatch::end
size_t end
Definition recognizer.h:21
rime::RecognizerMatch::start
size_t start
Definition recognizer.h:21
rime::RecognizerMatch::tag
string tag
Definition recognizer.h:20
rime::RecognizerMatch::found
bool found() const
Definition recognizer.h:27
rime::RecognizerMatch::RecognizerMatch
RecognizerMatch(const string &a_tag, size_t a_start, size_t an_end)
Definition recognizer.h:24
rime::RecognizerPatterns
Definition recognizer.h:30
rime::RecognizerPatterns::GetMatch
RecognizerMatch GetMatch(const string &input, const Segmentation &segmentation) const
Definition recognizer.cc:39
rime::RecognizerPatterns::LoadConfig
void LoadConfig(Config *config, const string &name_space)
Definition recognizer.cc:35
rime::Recognizer::use_space_
bool use_space_
Definition recognizer.h:45
rime::Recognizer::patterns_
RecognizerPatterns patterns_
Definition recognizer.h:44
rime::Recognizer::Recognizer
Recognizer(const Ticket &ticket)
Definition recognizer.cc:72
rime::Recognizer::ProcessKeyEvent
virtual ProcessResult ProcessKeyEvent(const KeyEvent &key_event)
Definition recognizer.cc:84
rime::KeyEvent
Definition key_event.h:17
rime::Processor::Processor
Processor(const Ticket &ticket)
Definition processor.h:26
rime::Segmentation
Definition segmentation.h:60
rime::Ticket
Definition ticket.h:17