librime: grammar.h Source File

| librime 1.2 Rime Input Method Engine, the core library

grammar.h
Go to the documentation of this file.
1#ifndef RIME_GRAMMAR_H_
2#define RIME_GRAMMAR_H_
3
4#include <rime/common.h>
5#include <rime/component.h>
6
7namespace rime {
8
9class Config;
10
11 class Grammar : public Class<Grammar, Config*> {
12 public:
13 virtual ~Grammar() {}
14 virtual double Query(const string& context,
15 const string& word,
16 bool is_rear) = 0;
17
18 inline static double Evaluate(const string& context,
19 const string& entry_text,
20 double entry_weight,
21 bool is_rear,
22 Grammar* grammar) {
23 // log(1e-6) ≈ -13.81
24 const double kPenalty = -13.815510557964274;
25 return entry_weight +
26 (grammar ? grammar->Query(context, entry_text, is_rear) : kPenalty);
27 }
28};
29
30} // namespace rime
31
32#endif // RIME_GRAMMAR_H_
common.h
component.h
rime
Definition algebra.cc:12
rime::Class
Definition component.h:21
rime::Config
Definition config_component.h:21
rime::Grammar
Definition grammar.h:11
rime::Grammar::~Grammar
virtual ~Grammar()
Definition grammar.h:13
rime::Grammar::Query
virtual double Query(const string &context, const string &word, bool is_rear)=0
rime::Grammar::Evaluate
static double Evaluate(const string &context, const string &entry_text, double entry_weight, bool is_rear, Grammar *grammar)
Definition grammar.h:18