Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch recognizer #668

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
80cd700
Update release-ci.yml
shewer Jan 20, 2023
b779750
Merge branch 'rime:master' into master
shewer Jan 26, 2023
24a35e2
Merge branch 'rime:master' into master
shewer Feb 3, 2023
d6511eb
Merge branch 'rime:master' into master
shewer Feb 20, 2023
9a7414c
Merge branch 'rime:master' into master
shewer Apr 3, 2023
b2377f1
Merge branch 'rime:master' into master
shewer Jun 11, 2023
9029305
Merge branch 'rime:master' into master
shewer Jun 25, 2023
2a2c88b
recognizer/patterns 增加循序檢查 patterns 機制
shewer Jun 29, 2023
b286d2e
fixed clang-format
shewer Jun 29, 2023
4dba93c
Delete release-ci.yml
shewer Jun 30, 2023
1572c81
Update recognizer.cc
shewer Jun 30, 2023
64e626f
Merge branch 'rime:master' into master
shewer Aug 14, 2023
a5638b7
Merge remote-tracking branch 'fork/master'
shewer Aug 24, 2023
297df0d
Merge branch 'rime:master' into master
shewer Sep 6, 2023
2a622d2
Merge branch 'rime:master' into master
shewer Sep 18, 2023
a32d31d
Merge branch 'rime:master' into master
shewer Oct 4, 2023
034c84f
Merge branch 'rime:master' into master
shewer Oct 5, 2023
35da4ba
Merge remote-tracking branch 'fork/master'
shewer Oct 19, 2023
78a29e0
Merge remote-tracking branch 'fork/master'
shewer Oct 24, 2023
3d55f69
Merge remote-tracking branch 'fork/master'
shewer Dec 2, 2023
30e3b82
Merge remote-tracking branch 'fork/master'
shewer Dec 12, 2023
90d9a6a
Merge remote-tracking branch 'fork/master'
shewer Dec 14, 2023
457455d
reset release-ci.yml
shewer Dec 15, 2023
532c347
Merge remote-tracking branch 'fork/master'
shewer Apr 23, 2024
3d1c86c
merged master
shewer Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions .github/workflows/release-ci.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

This file was deleted.

2 changes: 1 addition & 1 deletion src/rime/gear/matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Matcher : public Segmentor {
virtual bool Proceed(Segmentation* segmentation);

protected:
RecognizerPatterns patterns_;
RecognizerPatternsOfVector patterns_;
};

} // namespace rime
Expand Down
31 changes: 29 additions & 2 deletions src/rime/gear/recognizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ static void load_patterns(RecognizerPatterns* patterns, an<ConfigMap> map) {
}
}

void RecognizerPatterns::LoadConfig(Config* config) {
load_patterns(this, config->GetMap("recognizer/patterns"));
void RecognizerPatterns::LoadConfig(Config* config, const string& path) {
load_patterns(this, config->GetMap(path));
}

RecognizerMatch RecognizerPatterns::GetMatch(
Expand Down Expand Up @@ -69,6 +69,33 @@ RecognizerMatch RecognizerPatterns::GetMatch(
return RecognizerMatch();
}

void RecognizerPatternsOfVector::LoadConfig(Config* config) {
this->clear();
string path = "recognizer/patterns";
if (config->IsMap(path)) {
this->assign(1, RecognizerPatterns());
(*this)[0].LoadConfig(config, path);
} else if (config->IsList(path)) {
size_t size = config->GetListSize(path);
this->assign(size, RecognizerPatterns());
for (size_t i = 0; i < size; ++i) {
(*this)[i].LoadConfig(config, path + "/@" + std::to_string(i));
}
}
}

RecognizerMatch RecognizerPatternsOfVector::GetMatch(
const string& input,
const Segmentation& segmentation) const {
for (auto it : *this) {
auto res = it.GetMatch(input, segmentation);
if (res.found()) {
return res;
}
}
return RecognizerMatch();
}

Recognizer::Recognizer(const Ticket& ticket) : Processor(ticket) {
if (!ticket.schema)
return;
Expand Down
10 changes: 8 additions & 2 deletions src/rime/gear/recognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,25 @@ struct RecognizerMatch {

class RecognizerPatterns : public map<string, boost::regex> {
public:
void LoadConfig(Config* config);
void LoadConfig(Config* config, const string& path = "recognizer/patterns");
RecognizerMatch GetMatch(const string& input,
const Segmentation& segmentation) const;
};

class RecognizerPatternsOfVector : public vector<RecognizerPatterns> {
public:
void LoadConfig(Config* config);
RecognizerMatch GetMatch(const string& input,
const Segmentation& segmentation) const;
};
class Recognizer : public Processor {
public:
Recognizer(const Ticket& ticket);

virtual ProcessResult ProcessKeyEvent(const KeyEvent& key_event);

protected:
RecognizerPatterns patterns_;
RecognizerPatternsOfVector patterns_;
bool use_space_ = false;
};

Expand Down