mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-18 14:45:12 +02:00
Upgrade code for name-suggestion-index v1
- we now import all the name suggestions - get rid of the code to pick a single name based on count - get rid of "hacky" code to set healthcare tags - we now actually match on brand:wikidata tag, not name
This commit is contained in:
+21
-50
@@ -1,7 +1,6 @@
|
||||
/* eslint-disable no-console */
|
||||
const requireESM = require('esm')(module);
|
||||
const _cloneDeep = requireESM('lodash-es/cloneDeep').default;
|
||||
const _extend = requireESM('lodash-es/extend').default;
|
||||
const _forEach = requireESM('lodash-es/forEach').default;
|
||||
const _isEmpty = requireESM('lodash-es/isEmpty').default;
|
||||
const _merge = requireESM('lodash-es/merge').default;
|
||||
@@ -18,7 +17,7 @@ const YAML = require('js-yaml');
|
||||
|
||||
const fieldSchema = require('./data/presets/schema/field.json');
|
||||
const presetSchema = require('./data/presets/schema/preset.json');
|
||||
const suggestions = require('name-suggestion-index/name-suggestions.json');
|
||||
const suggestions = require('name-suggestion-index').names;
|
||||
|
||||
// fontawesome icons
|
||||
const fontawesome = require('@fortawesome/fontawesome-svg-core');
|
||||
@@ -46,9 +45,7 @@ module.exports = function buildData() {
|
||||
|
||||
for (var target of Object.keys(symlinks)) {
|
||||
if (!shell.test('-L', target)) {
|
||||
console.log(
|
||||
`Creating symlink: ${target} -> ${symlinks[target]}`
|
||||
);
|
||||
console.log(`Creating symlink: ${target} -> ${symlinks[target]}`);
|
||||
shell.ln('-sf', symlinks[target], target);
|
||||
}
|
||||
}
|
||||
@@ -191,64 +188,38 @@ function generateFields(tstrings, faIcons) {
|
||||
|
||||
|
||||
function suggestionsToPresets(presets) {
|
||||
var existing = {};
|
||||
|
||||
for (var key in suggestions) {
|
||||
for (var value in suggestions[key]) {
|
||||
for (var name in suggestions[key][value]) {
|
||||
var item = key + '/' + value + '/' + name;
|
||||
var tags = {};
|
||||
var count = suggestions[key][value][name].count;
|
||||
|
||||
if (existing[name] && count > existing[name].count) {
|
||||
delete presets[existing[name].category];
|
||||
delete existing[name];
|
||||
}
|
||||
if (!existing[name]) {
|
||||
tags = _extend({name: name.replace(/"/g, '')}, suggestions[key][value][name].tags);
|
||||
addSuggestion(item, tags, name.replace(/"/g, ''), count);
|
||||
}
|
||||
addSuggestion(key, value, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function addSuggestion(category, tags, name, count) {
|
||||
var tag = category.split('/');
|
||||
var parent = presets[tag[0] + '/' + tag[1]];
|
||||
|
||||
// Hacky code to add healthcare tagging not yet present in name-suggestion-index
|
||||
// This will be fixed by https://github.com/osmlab/name-suggestion-index/issues/57
|
||||
if (tag[0] === 'amenity') {
|
||||
var healthcareTags = {
|
||||
clinic: 'clinic',
|
||||
dentist: 'dentist',
|
||||
doctors: 'doctor',
|
||||
hospital: 'hospital',
|
||||
pharmacy: 'pharmacy'
|
||||
};
|
||||
if (healthcareTags.hasOwnProperty(tag[1])) {
|
||||
tags.healthcare = healthcareTags[tag[1]];
|
||||
}
|
||||
}
|
||||
|
||||
if (!parent) {
|
||||
console.log('WARN: no preset for suggestion = ' + tag);
|
||||
function addSuggestion(key, value, name) {
|
||||
var presetID = key + '/' + value;
|
||||
var preset = presets[presetID];
|
||||
if (!preset) {
|
||||
console.log('Warning: No preset "' + presetID + '" for name-suggestion "' + name + '"');
|
||||
return;
|
||||
}
|
||||
|
||||
presets[category.replace(/"/g, '')] = {
|
||||
tags: parent.tags ? _merge(tags, parent.tags) : tags,
|
||||
name: name,
|
||||
icon: parent.icon,
|
||||
geometry: parent.geometry,
|
||||
fields: parent.fields,
|
||||
suggestion: true
|
||||
};
|
||||
var suggestionID = key + '/' + value + '/' + name;
|
||||
var suggestion = suggestions[key][value][name];
|
||||
var wikidataTag = { 'brand:wikidata': suggestion.tags['brand:wikidata'] };
|
||||
|
||||
existing[name] = {
|
||||
category: category,
|
||||
count: count
|
||||
presets[suggestionID] = {
|
||||
name: name,
|
||||
icon: preset.icon,
|
||||
fields: preset.fields,
|
||||
geometry: preset.geometry,
|
||||
tags: _merge({}, preset.tags, wikidataTag),
|
||||
addTags: suggestion.tags,
|
||||
removeTags: suggestion.tags,
|
||||
reference: preset.reference,
|
||||
suggestion: true
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1968
-3438
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user