-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grammar): compare homophones/homographs in sentence
add inteface to grammar plugin; fall back to naive formula if missing "grammar" module
- Loading branch information
Showing
10 changed files
with
156 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef RIME_GRAMMAR_H_ | ||
#define RIME_GRAMMAR_H_ | ||
|
||
#include <rime/common.h> | ||
#include <rime/component.h> | ||
#include <rime/dict/vocabulary.h> | ||
|
||
namespace rime { | ||
|
||
class Config; | ||
|
||
class Grammar : public Class<Grammar, Config*> { | ||
public: | ||
virtual ~Grammar() {} | ||
virtual double Query(const string& context, | ||
const string& word, | ||
bool is_rear) = 0; | ||
|
||
inline static double Evaluate(const string& context, | ||
const DictEntry& entry, | ||
bool is_rear, | ||
Grammar* grammar) { | ||
const double kPenalty = -18.420680743952367; // log(1e-8) | ||
return entry.weight + | ||
(grammar ? grammar->Query(context, entry.text, is_rear) : kPenalty); | ||
} | ||
}; | ||
|
||
} // namespace rime | ||
|
||
#endif // RIME_GRAMMAR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.