explicit export for functions in flex-base

This commit is contained in:
Sarah Hoffmann 2022-12-15 17:48:00 +01:00
parent de3c28104c
commit a915815e4d
3 changed files with 50 additions and 43 deletions

View File

@ -1,6 +1,7 @@
-- Core functions for Nominatim import flex style. -- Core functions for Nominatim import flex style.
-- --
local module = {}
-- The single place table. -- The single place table.
place_table = osm2pgsql.define_table{ place_table = osm2pgsql.define_table{
@ -135,14 +136,17 @@ function Place:grab_address_parts(data)
for k, v in pairs(self.object.tags) do for k, v in pairs(self.object.tags) do
local atype = data.groups(k, v) local atype = data.groups(k, v)
if atype == 'main' then if atype ~= nil then
self.has_name = true if atype == 'main' then
self.address[strip_address_prefix(k)] = v self.has_name = true
count = count + 1 self.address[strip_address_prefix(k)] = v
elseif atype == 'extra' then count = count + 1
self.address[strip_address_prefix(k)] = v elseif atype == 'extra' then
elseif atype ~= nil then self.address[strip_address_prefix(k)] = v
self.address[atype] = v else
self.address[atype] = v
end
self.object.tags[k] = nil
end end
end end
end end
@ -277,7 +281,7 @@ function Place:write_row(k, v, save_extra_mains)
end end
function tag_match(data) function module.tag_match(data)
if data == nil or next(data) == nil then if data == nil or next(data) == nil then
return nil return nil
end end
@ -339,7 +343,7 @@ function tag_match(data)
end end
function key_group(data) function module.tag_group(data)
if data == nil or next(data) == nil then if data == nil or next(data) == nil then
return nil return nil
end end
@ -401,7 +405,7 @@ function osm2pgsql.process_node(object)
return o:as_point() return o:as_point()
end end
process_tags(Place.new(object, geom_func)) module.process_tags(Place.new(object, geom_func))
end end
function osm2pgsql.process_way(object) function osm2pgsql.process_way(object)
@ -416,27 +420,27 @@ function osm2pgsql.process_way(object)
return geom return geom
end end
process_tags(Place.new(object, geom_func)) module.process_tags(Place.new(object, geom_func))
end end
function relation_as_multipolygon(o) function module.relation_as_multipolygon(o)
return o:as_multipolygon() return o:as_multipolygon()
end end
function relation_as_multiline(o) function module.relation_as_multiline(o)
return o:as_multilinestring():line_merge() return o:as_multilinestring():line_merge()
end end
function osm2pgsql.process_relation(object) function osm2pgsql.process_relation(object)
local geom_func = RELATION_TYPES[object.tags.type] local geom_func = module.RELATION_TYPES[object.tags.type]
if geom_func ~= nil then if geom_func ~= nil then
process_tags(Place.new(object, geom_func)) module.process_tags(Place.new(object, geom_func))
end end
end end
function process_tags(o) function module.process_tags(o)
o:clean{delete = PRE_DELETE, extra = PRE_EXTRAS} o:clean{delete = module.PRE_DELETE, extra = module.PRE_EXTRAS}
-- Exception for boundary/place double tagging -- Exception for boundary/place double tagging
if o.object.tags.boundary == 'administrative' then if o.object.tags.boundary == 'administrative' then
@ -446,10 +450,10 @@ function process_tags(o)
end end
-- name keys -- name keys
local fallback = o:grab_name_parts{groups=NAMES} local fallback = o:grab_name_parts{groups=module.NAMES}
-- address keys -- address keys
if o:grab_address_parts{groups=ADDRESS_TAGS} > 0 and fallback == nil then if o:grab_address_parts{groups=module.ADDRESS_TAGS} > 0 and fallback == nil then
fallback = {'place', 'house', 'always'} fallback = {'place', 'house', 'always'}
end end
if o.address.country ~= nil and #o.address.country ~= 2 then if o.address.country ~= nil and #o.address.country ~= 2 then
@ -460,27 +464,36 @@ function process_tags(o)
end end
if o.address.interpolation ~= nil then if o.address.interpolation ~= nil then
o:write_place('place', 'houses', 'always', SAVE_EXTRA_MAINS) o:write_place('place', 'houses', 'always', module.SAVE_EXTRA_MAINS)
return return
end end
o:clean{delete = POST_DELETE, extra = POST_EXTRAS} o:clean{delete = module.POST_DELETE, extra = module.POST_EXTRAS}
-- collect main keys -- collect main keys
for k, v in pairs(o.object.tags) do for k, v in pairs(o.object.tags) do
local ktype = MAIN_KEYS[k] local ktype = module.MAIN_KEYS[k]
if ktype == 'fallback' then if ktype == 'fallback' then
if o.has_name then if o.has_name then
fallback = {k, v, 'named'} fallback = {k, v, 'named'}
end end
elseif ktype ~= nil then elseif ktype ~= nil then
o:write_place(k, v, MAIN_KEYS[k], SAVE_EXTRA_MAINS) o:write_place(k, v,module.MAIN_KEYS[k], module.SAVE_EXTRA_MAINS)
end end
end end
if fallback ~= nil and o.num_entries == 0 then if fallback ~= nil and o.num_entries == 0 then
o:write_place(fallback[1], fallback[2], fallback[3], SAVE_EXTRA_MAINS) o:write_place(fallback[1], fallback[2], fallback[3], module.SAVE_EXTRA_MAINS)
end end
end end
------ defaults --------------
module.RELATION_TYPES = {
multipolygon = module.relation_as_multipolygon,
boundary = module.relation_as_multipolygon,
waterway = module.relation_as_multiline
}
return module

View File

@ -1,12 +1,6 @@
require('flex-base') flex = require('flex-base')
RELATION_TYPES = { flex.MAIN_KEYS = {
multipolygon = relation_as_multipolygon,
boundary = relation_as_multipolygon,
waterway = relation_as_multiline
}
MAIN_KEYS = {
building = 'fallback', building = 'fallback',
emergency = 'always', emergency = 'always',
healthcare = 'fallback', healthcare = 'fallback',
@ -52,7 +46,7 @@ MAIN_KEYS = {
} }
PRE_DELETE = tag_match{keys = {'note', 'note:*', 'source', 'source*', 'attribution', flex.PRE_DELETE = flex.tag_match{keys = {'note', 'note:*', 'source', 'source*', 'attribution',
'comment', 'fixme', 'FIXME', 'created_by', 'NHD:*', 'comment', 'fixme', 'FIXME', 'created_by', 'NHD:*',
'nhd:*', 'gnis:*', 'geobase:*', 'KSJ2:*', 'yh:*', 'nhd:*', 'gnis:*', 'geobase:*', 'KSJ2:*', 'yh:*',
'osak:*', 'naptan:*', 'CLC:*', 'import', 'it:fvg:*', 'osak:*', 'naptan:*', 'CLC:*', 'import', 'it:fvg:*',
@ -83,15 +77,15 @@ PRE_DELETE = tag_match{keys = {'note', 'note:*', 'source', 'source*', 'attributi
boundary = {'place'}} boundary = {'place'}}
} }
POST_DELETE = tag_match{keys = {'tiger:*'}} flex.POST_DELETE = flex.tag_match{keys = {'tiger:*'}}
PRE_EXTRAS = tag_match{keys = {'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*', flex.PRE_EXTRAS = flex.tag_match{keys = {'*:prefix', '*:suffix', 'name:prefix:*', 'name:suffix:*',
'name:etymology', 'name:signed', 'name:botanical', 'name:etymology', 'name:signed', 'name:botanical',
'wikidata', '*:wikidata', 'wikidata', '*:wikidata',
'addr:street:name', 'addr:street:type'} 'addr:street:name', 'addr:street:type'}
} }
NAMES = key_group{main = {'name', 'name:*', flex.NAMES = flex.tag_group{main = {'name', 'name:*',
'int_name', 'int_name:*', 'int_name', 'int_name:*',
'nat_name', 'nat_name:*', 'nat_name', 'nat_name:*',
'reg_name', 'reg_name:*', 'reg_name', 'reg_name:*',
@ -107,7 +101,7 @@ NAMES = key_group{main = {'name', 'name:*',
house = {'addr:housename'} house = {'addr:housename'}
} }
ADDRESS_TAGS = key_group{main = {'addr:housenumber', flex.ADDRESS_TAGS = flex.tag_group{main = {'addr:housenumber',
'addr:conscriptionnumber', 'addr:conscriptionnumber',
'addr:streetnumber'}, 'addr:streetnumber'},
extra = {'addr:*', 'is_in:*', 'tiger:county'}, extra = {'addr:*', 'is_in:*', 'tiger:county'},
@ -119,5 +113,5 @@ ADDRESS_TAGS = key_group{main = {'addr:housenumber',
interpolation = {'addr:interpolation'} interpolation = {'addr:interpolation'}
} }
SAVE_EXTRA_MAINS = true flex.SAVE_EXTRA_MAINS = true

View File

@ -122,10 +122,10 @@ Feature: Tag evaluation
n8003 Tshop=shoes,name:source=survey n8003 Tshop=shoes,name:source=survey
""" """
Then place contains exactly Then place contains exactly
| object | class | extratags | | object | class | name | extratags |
| N8001 | shop | 'xx': 'yy' | | N8001 | shop | - | 'xx': 'yy' |
| N8002 | shop | 'ele': '234' | | N8002 | shop | - | 'ele': '234' |
| N8003 | shop | - | | N8003 | shop | - | - |
Scenario: Admin levels Scenario: Admin levels