]> git.openstreetmap.org Git - nominatim.git/commitdiff
flex: switch to functions for substyles
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 15 Dec 2022 21:10:19 +0000 (22:10 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 18 Dec 2022 09:10:58 +0000 (10:10 +0100)
This gives us a bit more flexibility about the implementation
in the future.

settings/flex-base.lua
settings/import-extratags.lua

index f508b98a123342b64b9b438c61d0f51932580b02..904401cee4e1a64dd27b4f077772050e831267c4 100644 (file)
@@ -46,14 +46,12 @@ function Place.new(object, geom_func)
 end
 
 function Place:clean(data)
 end
 
 function Place:clean(data)
-    if data.delete ~= nil or data.extra ~= nil then
-        for k, v in pairs(self.object.tags) do
-            if data.delete ~= nil and data.delete(k, v) then
-                self.object.tags[k] = nil
-            elseif data.extra ~= nil and data.extra(k, v) then
-                self.extratags[k] = v
-                self.object.tags[k] = nil
-            end
+    for k, v in pairs(self.object.tags) do
+        if data.delete ~= nil and data.delete(k, v) then
+            self.object.tags[k] = nil
+        elseif data.extra ~= nil and data.extra(k, v) then
+            self.extratags[k] = v
+            self.object.tags[k] = nil
         end
     end
 end
         end
     end
 end
@@ -182,6 +180,7 @@ function Place:grab_name_parts(data)
 
             if atype ~= nil then
                 self.names[k] = v
 
             if atype ~= nil then
                 self.names[k] = v
+                self.object.tags[k] = nil
                 if atype == 'main' then
                     self.has_name = true
                 elseif atype == 'house' then
                 if atype == 'main' then
                     self.has_name = true
                 elseif atype == 'house' then
@@ -487,6 +486,40 @@ function module.process_tags(o)
     end
 end
 
     end
 end
 
+--------- Convenience functions for simple style configuration -----------------
+
+function module.set_prefilters(data)
+    module.PRE_DELETE = module.tag_match{keys = data.delete_keys, tags = data.delete_tags}
+    module.PRE_EXTRAS = module.tag_match{keys = data.extratag_keys,
+                                         tags = data.extratag_tags}
+end
+
+function module.set_main_tags(data)
+    module.MAIN_KEYS = data
+end
+
+function module.set_name_tags(data)
+    module.NAMES = module.tag_group(data)
+end
+
+function module.set_address_tags(data)
+    module.ADDRESS_TAGS = module.tag_group(data)
+end
+
+function module.set_unused_handling(data)
+    if data.extra_keys == nil and data.extra_tags == nil then
+        module.POST_DELETE = module.tag_match{data.delete_keys, tags = data.delete_tags}
+        module.POST_EXTRAS = nil
+        module.SAVE_EXTRA_MAINS = true
+    elseif data.delete_keys == nil and data.delete_tags == nil then
+        module.POST_DELETE = nil
+        module.POST_EXTRAS = module.tag_match{data.extra_keys, tags = data.extra_tags}
+        module.SAVE_EXTRA_MAINS = false
+    else
+        error("unused handler can have only 'extra_keys' or 'delete_keys' set.")
+    end
+end
+
 ------ defaults --------------
 
 module.RELATION_TYPES = {
 ------ defaults --------------
 
 module.RELATION_TYPES = {
index fabc4aa1f1b4b7268d415db05a8aabfada5a89c6..22c3d9c8392803192950fe5291387991efd7b747 100644 (file)
@@ -1,6 +1,6 @@
 flex = require('flex-base')
 
 flex = require('flex-base')
 
-flex.MAIN_KEYS = {
+flex.set_main_tags{
     building = 'fallback',
     emergency = 'always',
     healthcare = 'fallback',
     building = 'fallback',
     emergency = 'always',
     healthcare = 'fallback',
@@ -45,47 +45,42 @@ flex.MAIN_KEYS = {
     place = 'always'
 }
 
     place = 'always'
 }
 
-
-flex.PRE_DELETE = flex.tag_match{keys = {'note', 'note:*', 'source', 'source*', 'attribution',
-                               'comment', 'fixme', 'FIXME', 'created_by', 'NHD:*',
-                               'nhd:*', 'gnis:*', 'geobase:*', 'KSJ2:*', 'yh:*',
-                               'osak:*', 'naptan:*', 'CLC:*', 'import', 'it:fvg:*',
-                               'type', 'lacounty:*', 'ref:ruian:*', 'building:ruian:type',
-                               'ref:linz:*', 'is_in:postcode'},
-                       tags = {emergency = {'yes', 'no', 'fire_hydrant'},
-                               historic = {'yes', 'no'},
-                               military = {'yes', 'no'},
-                               natural = {'yes', 'no', 'coastline'},
-                               highway = {'no', 'turning_circle', 'mini_roundabout',
-                                          'noexit', 'crossing', 'give_way', 'stop'},
-                               railway = {'level_crossing', 'no', 'rail'},
-                               man_made = {'survey_point', 'cutline'},
-                               aerialway = {'pylon', 'no'},
-                               aeroway = {'no'},
-                               amenity = {'no'},
-                               club = {'no'},
-                               craft = {'no'},
-                               leisure = {'no'},
-                               office = {'no'},
-                               mountain_pass = {'no'},
-                               shop = {'no'},
-                               tourism = {'yes', 'no'},
-                               bridge = {'no'},
-                               tunnel = {'no'},
-                               waterway = {'riverbank'},
-                               building = {'no'},
-                               boundary = {'place'}}
-                      }
-
-flex.POST_DELETE = flex.tag_match{keys = {'tiger:*'}}
-
-flex.PRE_EXTRAS = flex.tag_match{keys = {'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
+flex.set_prefilters{delete_keys = {'note', 'note:*', 'source', '*source', 'attribution',
+                                   'comment', 'fixme', 'FIXME', 'created_by', 'NHD:*',
+                                   'nhd:*', 'gnis:*', 'geobase:*', 'KSJ2:*', 'yh:*',
+                                   'osak:*', 'naptan:*', 'CLC:*', 'import', 'it:fvg:*',
+                                   'type', 'lacounty:*', 'ref:ruian:*', 'building:ruian:type',
+                                   'ref:linz:*', 'is_in:postcode'},
+                    delete_tags = {emergency = {'yes', 'no', 'fire_hydrant'},
+                                   historic = {'yes', 'no'},
+                                   military = {'yes', 'no'},
+                                   natural = {'yes', 'no', 'coastline'},
+                                   highway = {'no', 'turning_circle', 'mini_roundabout',
+                                              'noexit', 'crossing', 'give_way', 'stop'},
+                                   railway = {'level_crossing', 'no', 'rail'},
+                                   man_made = {'survey_point', 'cutline'},
+                                   aerialway = {'pylon', 'no'},
+                                   aeroway = {'no'},
+                                   amenity = {'no'},
+                                   club = {'no'},
+                                   craft = {'no'},
+                                   leisure = {'no'},
+                                   office = {'no'},
+                                   mountain_pass = {'no'},
+                                   shop = {'no'},
+                                   tourism = {'yes', 'no'},
+                                   bridge = {'no'},
+                                   tunnel = {'no'},
+                                   waterway = {'riverbank'},
+                                   building = {'no'},
+                                   boundary = {'place'}},
+                    extratag_keys = {'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
                                'name:etymology', 'name:signed', 'name:botanical',
                                'wikidata', '*:wikidata',
                                'addr:street:name', 'addr:street:type'}
                                'name:etymology', 'name:signed', 'name:botanical',
                                'wikidata', '*:wikidata',
                                'addr:street:name', 'addr:street:type'}
-                      }
+                   }
 
 
-flex.NAMES = flex.tag_group{main = {'name', 'name:*',
+flex.set_name_tags{main = {'name', 'name:*',
                           'int_name', 'int_name:*',
                           'nat_name', 'nat_name:*',
                           'reg_name', 'reg_name:*',
                           'int_name', 'int_name:*',
                           'nat_name', 'nat_name:*',
                           'reg_name', 'reg_name:*',
@@ -101,17 +96,17 @@ flex.NAMES = flex.tag_group{main = {'name', 'name:*',
                    house = {'addr:housename'}
                   }
 
                    house = {'addr:housename'}
                   }
 
-flex.ADDRESS_TAGS = flex.tag_group{main = {'addr:housenumber',
-                                 'addr:conscriptionnumber',
-                                 'addr:streetnumber'},
-                         extra = {'addr:*', 'is_in:*', 'tiger:county'},
-                         postcode = {'postal_code', 'postcode', 'addr:postcode',
-                                     'tiger:zip_left', 'tiger:zip_right'},
-                         country = {'country_code', 'ISO3166-1',
-                                    'addr:country_code', 'is_in:country_code',
-                                    'addr:country', 'is_in:country'},
-                         interpolation = {'addr:interpolation'}
-                        }
+flex.set_address_tags{main = {'addr:housenumber',
+                              'addr:conscriptionnumber',
+                              'addr:streetnumber'},
+                      extra = {'addr:*', 'is_in:*', 'tiger:county'},
+                      postcode = {'postal_code', 'postcode', 'addr:postcode',
+                                  'tiger:zip_left', 'tiger:zip_right'},
+                      country = {'country_code', 'ISO3166-1',
+                                 'addr:country_code', 'is_in:country_code',
+                                 'addr:country', 'is_in:country'},
+                      interpolation = {'addr:interpolation'}
+                     }
 
 
-flex.SAVE_EXTRA_MAINS = true
 
 
+flex.set_unused_handling{delete_keys = {'tiger:*'}}