]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/tokenizer/sanitizers/clean_housenumbers.py
clean_housenumbers: make kinds and delimiters configurable
[nominatim.git] / nominatim / tokenizer / sanitizers / clean_housenumbers.py
index 5b592bcf8d76ae37db53196c85107d23097d5dd7..b65880c38e5179e167b8a2711e31b079e900d8ab 100644 (file)
@@ -6,13 +6,19 @@
 # For a full list of authors see the git log.
 """
 Sanitizer that cleans and normalizes housenumbers.
 # For a full list of authors see the git log.
 """
 Sanitizer that cleans and normalizes housenumbers.
+
+Arguments:
+    delimiters: Define the set of characters to be used for
+                splitting a list of housenumbers into parts. (default: ',;')
+
 """
 """
-import re
+from nominatim.tokenizer.sanitizers.helpers import create_split_regex
 
 class _HousenumberSanitizer:
 
     def __init__(self, config):
 
 class _HousenumberSanitizer:
 
     def __init__(self, config):
-        pass
+        self.kinds = config.get('filter-kind', ('housenumber', ))
+        self.split_regexp = create_split_regex(config)
 
 
     def __call__(self, obj):
 
 
     def __call__(self, obj):
@@ -21,7 +27,7 @@ class _HousenumberSanitizer:
 
         new_address = []
         for item in obj.address:
 
         new_address = []
         for item in obj.address:
-            if item.kind in ('housenumber', 'streetnumber', 'conscriptionnumber'):
+            if item.kind in self.kinds:
                 new_address.extend(item.clone(kind='housenumber', name=n) for n in self.sanitize(item.name))
             else:
                 # Don't touch other address items.
                 new_address.extend(item.clone(kind='housenumber', name=n) for n in self.sanitize(item.name))
             else:
                 # Don't touch other address items.
@@ -36,13 +42,9 @@ class _HousenumberSanitizer:
             The function works as a generator that yields all valid housenumbers
             that can be created from the value.
         """
             The function works as a generator that yields all valid housenumbers
             that can be created from the value.
         """
-        for hnr in self._split_number(value):
-            yield from self._regularize(hnr)
-
-
-    def _split_number(self, hnr):
-        for part in re.split(r'[;,]', hnr):
-            yield part.strip()
+        for hnr in self.split_regexp.split(value):
+            if hnr:
+                yield from self._regularize(hnr)
 
 
     def _regularize(self, hnr):
 
 
     def _regularize(self, hnr):