]> git.openstreetmap.org Git - nominatim.git/blob - settings/taginfo.lua
Merge pull request #3178 from lonvia/library-documentation
[nominatim.git] / settings / taginfo.lua
1 -- Prints taginfo project description in the standard output
2 --
3
4 -- create fake "osm2pgsql" table for flex-base, originally created by the main C++ program
5 osm2pgsql = {}
6 function osm2pgsql.define_table(...) end
7
8 -- provide path to flex-style lua file
9 flex = require('import-extratags')
10 local json = require ('dkjson')
11
12
13 ------------ helper functions ---------------------
14
15 function get_key_description(key, description)
16     local desc = {}
17     desc.key = key
18     desc.description = description
19     set_keyorder(desc, {'key', 'description'})
20     return desc
21 end
22
23 -- Sets the key order for the resulting JSON table
24 function set_keyorder(table, order)
25     setmetatable(table, {
26         __jsonorder = order
27     })
28 end
29
30
31 -- Prints the collected tags in the required format in JSON
32 function print_taginfo()
33     local tags = {}
34
35     for _, k in ipairs(flex.TAGINFO_MAIN.keys) do
36         local desc = get_key_description(k, 'POI/feature in the search database')
37         if flex.TAGINFO_MAIN.delete_tags[k] ~= nil then
38             desc.description = string.format('%s(except for values: %s).', desc.description,
39                                 table.concat(flex.TAGINFO_MAIN.delete_tags[k], ', '))
40         end
41         table.insert(tags, desc)
42     end
43
44     for k, _ in pairs(flex.TAGINFO_NAME_KEYS) do
45         local desc = get_key_description(k, 'Searchable name of the place.')
46         table.insert(tags, desc)
47     end
48     for k, _ in pairs(flex.TAGINFO_ADDRESS_KEYS) do
49         local desc = get_key_description(k, 'Used to determine the address of a place.')
50         table.insert(tags, desc)
51     end
52
53     local format = {
54         data_format = 1,
55         data_url = 'https://nominatim.openstreetmap.org/taginfo.json',
56         project = {
57             name = 'Nominatim',
58             description = 'OSM search engine.',
59             project_url = 'https://nominatim.openstreetmap.org',
60             doc_url = 'https://nominatim.org/release-docs/develop/',
61             contact_name = 'Sarah Hoffmann',
62             contact_email = 'lonvia@denofr.de'
63         }
64     }
65     format.tags = tags
66
67     set_keyorder(format, {'data_format', 'data_url', 'project', 'tags'})
68     set_keyorder(format.project, {'name', 'description', 'project_url', 'doc_url',
69                     'contact_name', 'contact_email'})
70
71     print(json.encode(format))
72 end
73
74 print_taginfo()