mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
flex: simplify address configuration
This commit is contained in:
@@ -102,8 +102,39 @@ function Place:grab_address(data)
|
|||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
function Place:set_address(key, value)
|
local function strip_address_prefix(k)
|
||||||
self.address[key] = value
|
if k:sub(1, 5) == 'addr:' then
|
||||||
|
return k:sub(6)
|
||||||
|
end
|
||||||
|
|
||||||
|
if k:sub(1, 6) == 'is_in:' then
|
||||||
|
return k:sub(7)
|
||||||
|
end
|
||||||
|
|
||||||
|
return k
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Place:grab_address_parts(data)
|
||||||
|
local count = 0
|
||||||
|
|
||||||
|
if data.groups ~= nil then
|
||||||
|
for k, v in pairs(self.object.tags) do
|
||||||
|
local atype = data.groups(k, v)
|
||||||
|
|
||||||
|
if atype == 'main' then
|
||||||
|
self.has_name = true
|
||||||
|
self.address[strip_address_prefix(k)] = v
|
||||||
|
count = count + 1
|
||||||
|
elseif atype == 'extra' then
|
||||||
|
self.address[strip_address_prefix(k)] = v
|
||||||
|
elseif atype ~= nil then
|
||||||
|
self.address[atype] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
function Place:grab_name(data)
|
function Place:grab_name(data)
|
||||||
@@ -129,10 +160,6 @@ function Place:grab_tag(key)
|
|||||||
return self.object:grab_tag(key)
|
return self.object:grab_tag(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Place:tags()
|
|
||||||
return self.object.tags
|
|
||||||
end
|
|
||||||
|
|
||||||
function Place:write_place(k, v, mtype, save_extra_mains)
|
function Place:write_place(k, v, mtype, save_extra_mains)
|
||||||
if mtype == nil then
|
if mtype == nil then
|
||||||
return 0
|
return 0
|
||||||
@@ -277,6 +304,61 @@ function tag_match(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function key_group(data)
|
||||||
|
if data == nil or next(data) == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local fullmatches = {}
|
||||||
|
local key_prefixes = {}
|
||||||
|
local key_suffixes = {}
|
||||||
|
|
||||||
|
for group, tags in pairs(data) do
|
||||||
|
for _, key in pairs(tags) do
|
||||||
|
if key:sub(1, 1) == '*' then
|
||||||
|
if #key > 1 then
|
||||||
|
if key_suffixes[#key - 1] == nil then
|
||||||
|
key_suffixes[#key - 1] = {}
|
||||||
|
end
|
||||||
|
key_suffixes[#key - 1][key:sub(2)] = group
|
||||||
|
end
|
||||||
|
elseif key:sub(#key, #key) == '*' then
|
||||||
|
if key_prefixes[#key - 1] == nil then
|
||||||
|
key_prefixes[#key - 1] = {}
|
||||||
|
end
|
||||||
|
key_prefixes[#key - 1][key:sub(1, #key - 1)] = group
|
||||||
|
else
|
||||||
|
fullmatches[key] = group
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return function (k, v)
|
||||||
|
local val = fullmatches[k]
|
||||||
|
if val ~= nil then
|
||||||
|
return val
|
||||||
|
end
|
||||||
|
|
||||||
|
for slen, slist in pairs(key_suffixes) do
|
||||||
|
if #k >= slen then
|
||||||
|
val = slist[k:sub(-slen)]
|
||||||
|
if val ~= nil then
|
||||||
|
return val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for slen, slist in pairs(key_prefixes) do
|
||||||
|
if #k >= slen then
|
||||||
|
val = slist[k:sub(1, slen)]
|
||||||
|
if val ~= nil then
|
||||||
|
return val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Process functions for all data types
|
-- Process functions for all data types
|
||||||
function osm2pgsql.process_node(object)
|
function osm2pgsql.process_node(object)
|
||||||
|
|
||||||
@@ -332,25 +414,20 @@ function process_tags(o)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- address keys
|
-- address keys
|
||||||
o:grab_address{match=COUNTRY_TAGS, out_key='country'}
|
if o:grab_name{match=HOUSENAME_TAGS} > 0 then
|
||||||
|
fallback = {'place', 'house', 'always'}
|
||||||
|
end
|
||||||
|
if o:grab_address_parts{groups=ADDRESS_TAGS} > 0 and fallback == nil then
|
||||||
|
fallback = {'place', 'house', 'always'}
|
||||||
|
end
|
||||||
if o.address.country ~= nil and #o.address.country ~= 2 then
|
if o.address.country ~= nil and #o.address.country ~= 2 then
|
||||||
o.address['country'] = nil
|
o.address['country'] = nil
|
||||||
end
|
end
|
||||||
if o:grab_name{match=HOUSENAME_TAGS} > 0 then
|
if fallback == nil and o.address.postcode ~= nil then
|
||||||
fallback = {'place', 'house'}
|
fallback = {'place', 'postcode', 'always'}
|
||||||
end
|
|
||||||
if o:grab_address{match=HOUSENUMBER_TAGS, include_on_name = true} > 0 and fallback == nil then
|
|
||||||
fallback = {'place', 'house'}
|
|
||||||
end
|
|
||||||
if o:grab_address{match=POSTCODES, out_key='postcode'} > 0 and fallback == nil then
|
|
||||||
fallback = {'place', 'postcode'}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local is_interpolation = o:grab_address{match=INTERPOLATION_TAGS} > 0
|
if o.address.interpolation ~= nil then
|
||||||
|
|
||||||
o:grab_address{match=ADDRESS_TAGS}
|
|
||||||
|
|
||||||
if is_interpolation then
|
|
||||||
o:write_place('place', 'houses', 'always', SAVE_EXTRA_MAINS)
|
o:write_place('place', 'houses', 'always', SAVE_EXTRA_MAINS)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -363,21 +440,19 @@ function process_tags(o)
|
|||||||
o:grab_extratags{match = POST_EXTRAS}
|
o:grab_extratags{match = POST_EXTRAS}
|
||||||
|
|
||||||
-- collect main keys
|
-- collect main keys
|
||||||
local num_mains = 0
|
for k, v in pairs(o.object.tags) do
|
||||||
for k, v in pairs(o:tags()) do
|
local ktype = MAIN_KEYS[k]
|
||||||
num_mains = num_mains + o:write_place(k, v, MAIN_KEYS[k], SAVE_EXTRA_MAINS)
|
if ktype == 'fallback' then
|
||||||
|
if o.has_name then
|
||||||
|
fallback = {k, v, 'named'}
|
||||||
|
end
|
||||||
|
elseif ktype ~= nil then
|
||||||
|
o:write_place(k, v, MAIN_KEYS[k], SAVE_EXTRA_MAINS)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if num_mains == 0 then
|
if fallback ~= nil and o.num_entries == 0 then
|
||||||
for tag, mtype in pairs(MAIN_FALLBACK_KEYS) do
|
o:write_place(fallback[1], fallback[2], fallback[3], SAVE_EXTRA_MAINS)
|
||||||
if o:write_place(tag, nil, mtype, SAVE_EXTRA_MAINS) > 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if fallback ~= nil then
|
|
||||||
o:write_place(fallback[1], fallback[2], 'always', SAVE_EXTRA_MAINS)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ RELATION_TYPES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MAIN_KEYS = {
|
MAIN_KEYS = {
|
||||||
|
building = 'fallback',
|
||||||
emergency = 'always',
|
emergency = 'always',
|
||||||
|
healthcare = 'fallback',
|
||||||
historic = 'always',
|
historic = 'always',
|
||||||
military = 'always',
|
military = 'always',
|
||||||
natural = 'named',
|
natural = 'named',
|
||||||
@@ -36,6 +38,8 @@ MAIN_KEYS = {
|
|||||||
amenity = 'always',
|
amenity = 'always',
|
||||||
club = 'always',
|
club = 'always',
|
||||||
craft = 'always',
|
craft = 'always',
|
||||||
|
junction = 'fallback',
|
||||||
|
landuse = 'fallback',
|
||||||
leisure = 'always',
|
leisure = 'always',
|
||||||
office = 'always',
|
office = 'always',
|
||||||
mountain_pass = 'always',
|
mountain_pass = 'always',
|
||||||
@@ -47,13 +51,6 @@ MAIN_KEYS = {
|
|||||||
place = 'always'
|
place = 'always'
|
||||||
}
|
}
|
||||||
|
|
||||||
MAIN_FALLBACK_KEYS = {
|
|
||||||
building = 'named',
|
|
||||||
landuse = 'named',
|
|
||||||
junction = 'named',
|
|
||||||
healthcare = 'named'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PRE_DELETE = tag_match{keys = {'note', 'note:*', 'source', 'source*', 'attribution',
|
PRE_DELETE = tag_match{keys = {'note', 'note:*', 'source', 'source*', 'attribution',
|
||||||
'comment', 'fixme', 'FIXME', 'created_by', 'NHD:*',
|
'comment', 'fixme', 'FIXME', 'created_by', 'NHD:*',
|
||||||
@@ -109,21 +106,19 @@ NAMES = tag_match{keys = {'name', 'name:*',
|
|||||||
REFS = tag_match{keys = {'ref', 'int_ref', 'nat_ref', 'reg_ref', 'loc_ref', 'old_ref',
|
REFS = tag_match{keys = {'ref', 'int_ref', 'nat_ref', 'reg_ref', 'loc_ref', 'old_ref',
|
||||||
'iata', 'icao', 'pcode', 'pcode:*', 'ISO3166-2'}}
|
'iata', 'icao', 'pcode', 'pcode:*', 'ISO3166-2'}}
|
||||||
|
|
||||||
POSTCODES = tag_match{keys = {'postal_code', 'postcode', 'addr:postcode',
|
|
||||||
'tiger:zip_left', 'tiger:zip_right'}}
|
|
||||||
|
|
||||||
COUNTRY_TAGS = tag_match{keys = {'country_code', 'ISO3166-1',
|
|
||||||
'addr:country_code', 'is_in:country_code',
|
|
||||||
'addr:country', 'is_in:country'}}
|
|
||||||
|
|
||||||
HOUSENAME_TAGS = tag_match{keys = {'addr:housename'}}
|
HOUSENAME_TAGS = tag_match{keys = {'addr:housename'}}
|
||||||
|
|
||||||
HOUSENUMBER_TAGS = tag_match{keys = {'addr:housenumber', 'addr:conscriptionnumber',
|
ADDRESS_TAGS = key_group{main = {'addr:housenumber',
|
||||||
'addr:streetnumber'}}
|
'addr:conscriptionnumber',
|
||||||
|
'addr:streetnumber'},
|
||||||
INTERPOLATION_TAGS = tag_match{keys = {'addr:interpolation'}}
|
extra = {'addr:*', 'is_in:*', 'tiger:county'},
|
||||||
|
postcode = {'postal_code', 'postcode', 'addr:postcode',
|
||||||
ADDRESS_TAGS = tag_match{keys = {'addr:*', 'is_in:*', 'tiger:county'}}
|
'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'}
|
||||||
|
}
|
||||||
|
|
||||||
SAVE_EXTRA_MAINS = true
|
SAVE_EXTRA_MAINS = true
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user