From 0bb59b2e225d9015462cbf069f83d6ed75eaaf3a Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 15 Feb 2022 14:38:03 +0100 Subject: [PATCH] handle unknown analyzer When changing something in the default configuration of the sanatizers that refers to an analyzer that is not yet loaded, there shouldn't be any errors. --- nominatim/tokenizer/icu_token_analysis.py | 7 +++++++ nominatim/tokenizer/icu_tokenizer.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/nominatim/tokenizer/icu_token_analysis.py b/nominatim/tokenizer/icu_token_analysis.py index ee3144a8..68fc82e3 100644 --- a/nominatim/tokenizer/icu_token_analysis.py +++ b/nominatim/tokenizer/icu_token_analysis.py @@ -27,3 +27,10 @@ class ICUTokenAnalysis: self.analysis = {name: arules.create(self.normalizer, self.to_ascii, arules.config) for name, arules in analysis_rules.items()} + + + def get_analyzer(self, name): + """ Return the given named analyzer. If no analyzer with that + name exists, return the default analyzer. + """ + return self.analysis.get(name) or self.analysis[None] diff --git a/nominatim/tokenizer/icu_tokenizer.py b/nominatim/tokenizer/icu_tokenizer.py index b89180ae..05c5a3ea 100644 --- a/nominatim/tokenizer/icu_tokenizer.py +++ b/nominatim/tokenizer/icu_tokenizer.py @@ -561,7 +561,7 @@ class LegacyICUNameAnalyzer(AbstractAnalyzer): for name in names: analyzer_id = name.get_attr('analyzer') - analyzer = self.token_analysis.analysis[analyzer_id] + analyzer = self.token_analysis.get_analyzer(analyzer_id) norm_name = analyzer.normalize(name.name) if analyzer_id is None: token_id = norm_name -- 2.39.5