Skip to content

Commit

Permalink
Recognizer ns (#691)
Browse files Browse the repository at this point in the history
Signed-off-by: shewer <[email protected]>
  • Loading branch information
shewer authored Jun 18, 2024
1 parent 1e14721 commit ebdfd55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/rime/gear/matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ Matcher::Matcher(const Ticket& ticket) : Segmentor(ticket) {
// read schema settings
if (!ticket.schema)
return;
if (name_space_ == "segmentor") {
name_space_ = "recognizer";
}
Config* config = ticket.schema->config();
patterns_.LoadConfig(config);
patterns_.LoadConfig(config, name_space_);
}

bool Matcher::Proceed(Segmentation* segmentation) {
Expand Down
11 changes: 7 additions & 4 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& name_space) {
load_patterns(this, config->GetMap(name_space + "/patterns"));
}

RecognizerMatch RecognizerPatterns::GetMatch(
Expand Down Expand Up @@ -72,9 +72,12 @@ RecognizerMatch RecognizerPatterns::GetMatch(
Recognizer::Recognizer(const Ticket& ticket) : Processor(ticket) {
if (!ticket.schema)
return;
if (name_space_ == "processor") {
name_space_ = "recognizer";
}
if (Config* config = ticket.schema->config()) {
patterns_.LoadConfig(config);
config->GetBool("recognizer/use_space", &use_space_);
patterns_.LoadConfig(config, name_space_);
config->GetBool(name_space_ + "/use_space", &use_space_);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rime/gear/recognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct RecognizerMatch {

class RecognizerPatterns : public map<string, boost::regex> {
public:
void LoadConfig(Config* config);
void LoadConfig(Config* config, const string& name_space);
RecognizerMatch GetMatch(const string& input,
const Segmentation& segmentation) const;
};
Expand Down

0 comments on commit ebdfd55

Please sign in to comment.