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
11class 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_
Definition algebra.cc:12
Definition component.h:21
Definition config_component.h:21
Definition grammar.h:11
virtual ~Grammar()
Definition grammar.h:13
virtual double Query(const string &context, const string &word, bool is_rear)=0
static double Evaluate(const string &context, const string &entry_text, double entry_weight, bool is_rear, Grammar *grammar)
Definition grammar.h:18