]> git.openstreetmap.org Git - nominatim.git/commitdiff
handle unknown analyzer
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 15 Feb 2022 13:38:03 +0000 (14:38 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 1 Mar 2022 08:34:32 +0000 (09:34 +0100)
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
nominatim/tokenizer/icu_tokenizer.py

index ee3144a8eeec107e2dce41203efc36c1ac8e80dd..68fc82e333b6a44de6eb9d42ed06a2d4ae17da58 100644 (file)
@@ -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()}
 
         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]
index b89180aefe11f681033b367362cb5e7517e7e83c..05c5a3ea3fb62b2e54d9e713604d7e25e8f0c5a3 100644 (file)
@@ -561,7 +561,7 @@ class LegacyICUNameAnalyzer(AbstractAnalyzer):
 
         for name in names:
             analyzer_id = name.get_attr('analyzer')
 
         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
             norm_name = analyzer.normalize(name.name)
             if analyzer_id is None:
                 token_id = norm_name