From ebdfd55f5c664a62a0ec93705c09018e7f9dd12b Mon Sep 17 00:00:00 2001 From: Shewer Lu Date: Wed, 19 Jun 2024 06:53:58 +0800 Subject: [PATCH] Recognizer ns (#691) Signed-off-by: shewer --- src/rime/gear/matcher.cc | 5 ++++- src/rime/gear/recognizer.cc | 11 +++++++---- src/rime/gear/recognizer.h | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/rime/gear/matcher.cc b/src/rime/gear/matcher.cc index 22968c642d..adf5eb1003 100644 --- a/src/rime/gear/matcher.cc +++ b/src/rime/gear/matcher.cc @@ -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) { diff --git a/src/rime/gear/recognizer.cc b/src/rime/gear/recognizer.cc index 6ceffd6036..86f36ad962 100644 --- a/src/rime/gear/recognizer.cc +++ b/src/rime/gear/recognizer.cc @@ -32,8 +32,8 @@ static void load_patterns(RecognizerPatterns* patterns, an 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( @@ -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_); } } diff --git a/src/rime/gear/recognizer.h b/src/rime/gear/recognizer.h index d9a6eff5a3..64567b8f10 100644 --- a/src/rime/gear/recognizer.h +++ b/src/rime/gear/recognizer.h @@ -29,7 +29,7 @@ struct RecognizerMatch { class RecognizerPatterns : public map { public: - void LoadConfig(Config* config); + void LoadConfig(Config* config, const string& name_space); RecognizerMatch GetMatch(const string& input, const Segmentation& segmentation) const; };