]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/tokenizer/icu_rule_loader.py
update unit tests for adapted abbreviation code
[nominatim.git] / nominatim / tokenizer / icu_rule_loader.py
index 3b7211691f72eed8ed18373be91bb714742cb732..a11b9bd86e0140b97d4fd189e2d44b6b79adc13b 100644 (file)
@@ -2,11 +2,11 @@
 Helper class to create ICU rules from a configuration file.
 """
 import io
-import yaml
 import logging
 from collections import defaultdict
 import itertools
 
+import yaml
 from icu import Transliterator
 
 from nominatim.errors import UsageError
@@ -20,6 +20,8 @@ class ICURuleLoader:
 
     def __init__(self, configfile):
         self.configfile = configfile
+        self.compound_suffixes = set()
+        self.abbreviations = defaultdict()
 
         if configfile.suffix == '.yaml':
             self._load_from_yaml()
@@ -28,7 +30,7 @@ class ICURuleLoader:
 
 
     def get_search_rules(self):
-        """ Returns the ICU rules to be used during search.
+        """ Return the ICU rules to be used during search.
             The rules combine normalization, compound decomposition (including
             abbreviated compounds) and transliteration.
         """
@@ -42,7 +44,7 @@ class ICURuleLoader:
             suffixes.add(suffix)
             suffixes.update(self.abbreviations.get(suffix, []))
 
-        for suffix in sorted(suffixes, key=lambda x:len(x), reverse=True):
+        for suffix in sorted(suffixes, key=len, reverse=True):
             rules.write("'{0} ' > ' {0} ';".format(suffix))
 
         # Finally add transliteration.
@@ -60,7 +62,7 @@ class ICURuleLoader:
         return self.transliteration_rules
 
     def get_replacement_pairs(self):
-        """ Returns the list of possible compound decompositions with
+        """ Return the list of possible compound decompositions with
             application of abbreviations included.
             The result is a list of pairs: the first item is the sequence to
             replace, the second is a list of replacements.
@@ -85,7 +87,7 @@ class ICURuleLoader:
                 synonyms[abbr + ' '].add(' ' + abbr + ' ')
 
         # sort the resulting list by descending length (longer matches are prefered).
-        sorted_keys = sorted(synonyms.keys(), key=lambda x: len(x), reverse=True)
+        sorted_keys = sorted(synonyms.keys(), key=len, reverse=True)
 
         return [(k, list(synonyms[k])) for k in sorted_keys]