adapt taginfo script to new configuration structure

This commit is contained in:
Sarah Hoffmann
2024-12-06 15:11:16 +01:00
parent 59bce26afe
commit e1e8182c72
2 changed files with 70 additions and 28 deletions

View File

@@ -7,13 +7,31 @@ function osm2pgsql.define_table(...) end
-- provide path to flex-style lua file -- provide path to flex-style lua file
package.path = arg[0]:match("(.*/)") .. "?.lua;" .. package.path package.path = arg[0]:match("(.*/)") .. "?.lua;" .. package.path
local flex = require('import-extratags') local flex = require('import-' .. (arg[1] or 'extratags'))
local json = require ('dkjson') local json = require ('dkjson')
local NAME_DESCRIPTIONS = {
'Searchable auxiliary name of the place',
main = 'Searchable primary name of the place',
house = 'House name part of an address, searchable'
}
local ADDRESS_DESCRIPTIONS = {
'Used to determine the address of a place',
main = 'Primary key for an address point',
postcode = 'Used to determine the postcode of a place',
country = 'Used to determine country of a place (only if written as two-letter code)',
interpolation = 'Primary key for an address interpolation line'
}
------------ helper functions --------------------- ------------ helper functions ---------------------
-- Sets the key order for the resulting JSON table
local function set_keyorder(table, order)
setmetatable(table, {
__jsonorder = order
})
end
function get_key_description(key, description) local function get_key_description(key, description)
local desc = {} local desc = {}
desc.key = key desc.key = key
desc.description = description desc.description = description
@@ -21,35 +39,60 @@ function get_key_description(key, description)
return desc return desc
end end
-- Sets the key order for the resulting JSON table local function get_key_value_description(key, value, description)
function set_keyorder(table, order) local desc = {key = key, value = value, description = description}
setmetatable(table, { set_keyorder(desc, {'key', 'value', 'description'})
__jsonorder = order return desc
})
end end
local function group_table_to_keys(tags, data, descriptions)
for group, values in pairs(data) do
local desc = descriptions[group] or descriptions[1]
for _, key in pairs(values) do
if key:sub(1, 1) ~= '*' and key:sub(#key, #key) ~= '*' then
table.insert(tags, get_key_description(key, desc))
end
end
end
end
-- Prints the collected tags in the required format in JSON -- Prints the collected tags in the required format in JSON
function print_taginfo() local function print_taginfo()
local taginfo = flex.get_taginfo()
local tags = {} local tags = {}
for _, k in ipairs(flex.TAGINFO_MAIN.keys) do for k, values in pairs(taginfo.main) do
local desc = get_key_description(k, 'POI/feature in the search database') if values[1] == nil or values[1] == 'delete' or values[1] == 'extra' then
if flex.TAGINFO_MAIN.delete_tags[k] ~= nil then for v, group in pairs(values) do
desc.description = string.format('%s (except for values: %s).', desc.description, if type(v) == 'string' and group ~= 'delete' and group ~= 'extra' then
table.concat(flex.TAGINFO_MAIN.delete_tags[k], ', ')) local text = 'POI/feature in the search database'
if type(group) ~= 'function' then
text = 'Fallback ' .. text
end
table.insert(tags, get_key_value_description(k, v, text))
end
end
elseif type(values[1]) == 'function' or values[1] == 'fallback' then
local desc = 'POI/feature in the search database'
if values[1] == 'fallback' then
desc = 'Fallback ' .. desc
end
local excp = {}
for v, group in pairs(values) do
if group == 'delete' or group == 'extra' then
table.insert(excp, v)
end
end
if next(excp) ~= nil then
desc = desc .. string.format(' (except for values: %s)',
table.concat(excp, ', '))
end
table.insert(tags, get_key_description(k, desc))
end end
table.insert(tags, desc)
end end
for k, _ in pairs(flex.TAGINFO_NAME_KEYS) do group_table_to_keys(tags, taginfo.name, NAME_DESCRIPTIONS)
local desc = get_key_description(k, 'Searchable name of the place.') group_table_to_keys(tags, taginfo.address, ADDRESS_DESCRIPTIONS)
table.insert(tags, desc)
end
for k, _ in pairs(flex.TAGINFO_ADDRESS_KEYS) do
local desc = get_key_description(k, 'Used to determine the address of a place.')
table.insert(tags, desc)
end
local format = { local format = {
data_format = 1, data_format = 1,

View File

@@ -40,12 +40,6 @@ if type(themepark) ~= 'table' then
themepark = nil themepark = nil
end end
-- tables required for taginfo
module.TAGINFO_MAIN = {keys = {}, delete_tags = {}}
module.TAGINFO_NAME_KEYS = {}
module.TAGINFO_ADDRESS_KEYS = {}
-- The single place table. -- The single place table.
local place_table_definition = { local place_table_definition = {
name = "place", name = "place",
@@ -904,4 +898,9 @@ function module.set_relation_types(data)
end end
end end
function module.get_taginfo()
return {main = MAIN_KEYS, name = NAMES, address = ADDRESS_TAGS}
end
return module return module