From 15ee63e87526be50431de2d98f298deb7789d0ae Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 5 Aug 2021 16:59:07 -0400 Subject: [PATCH 1/2] Improve code for keeping only interesting key/value pairs Before it was not actually checking that the osmvalue was in the vmap, so we were testing a bunch of pairs like `highway/crossing` and `highway/residential` that would never match a NSI category. --- modules/services/nsi.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/services/nsi.js b/modules/services/nsi.js index 99e63dcb6..509eaabed 100644 --- a/modules/services/nsi.js +++ b/modules/services/nsi.js @@ -163,7 +163,7 @@ function loadNsiData() { // and fallbacks like // "amenity/yes" // excluding things like -// "highway", "surface", "ref", etc. +// "tiger:reviewed", "surface", "ref", etc. // // Arguments // `tags`: `Object` containing the feature's OSM tags @@ -183,12 +183,12 @@ function gatherKVs(tags) { if (!osmvalue) return; const vmap = _nsi.kvt.get(osmkey); - if (!vmap) return; + if (!vmap) return; // not an interesting key - if (osmvalue !== 'yes') { - primary.add(`${osmkey}/${osmvalue}`); - } else { - alternate.add(`${osmkey}/${osmvalue}`); + if (vmap.get(osmvalue)) { // Matched a category in NSI + primary.add(`${osmkey}/${osmvalue}`); // interesting key/value + } else if (osmvalue === 'yes') { + alternate.add(`${osmkey}/${osmvalue}`); // fallback key/yes } }); From 0f913113c779a5de4698aefe36f4a91df3ef8b43 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 5 Aug 2021 22:05:11 -0400 Subject: [PATCH 2/2] Match a 'route_master' as if it were a 'route' This code just treats `type=route_master` relations as if they were `type=route` so they will match the transit networks in NSI. (closes https://github.com/osmlab/name-suggestion-index/issues/5184) --- modules/services/nsi.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/services/nsi.js b/modules/services/nsi.js index 509eaabed..d3094ef29 100644 --- a/modules/services/nsi.js +++ b/modules/services/nsi.js @@ -182,6 +182,9 @@ function gatherKVs(tags) { const osmvalue = tags[osmkey]; if (!osmvalue) return; + // Match a 'route_master' as if it were a 'route' - name-suggestion-index#5184 + if (osmkey === 'route_master') osmkey = 'route'; + const vmap = _nsi.kvt.get(osmkey); if (!vmap) return; // not an interesting key @@ -228,6 +231,9 @@ function identifyTree(tags) { const osmvalue = tags[osmkey]; if (!osmvalue) return; + // Match a 'route_master' as if it were a 'route' - name-suggestion-index#5184 + if (osmkey === 'route_master') osmkey = 'route'; + const vmap = _nsi.kvt.get(osmkey); if (!vmap) return; // this key is not in nsi @@ -427,6 +433,8 @@ function _upgradeTags(tags, loc) { } }); + // Match a 'route_master' as if it were a 'route' - name-suggestion-index#5184 + const isRouteMaster = (tags.type === 'route_master'); // Gather key/value tag pairs to try to match const tryKVs = gatherKVs(tags); @@ -521,6 +529,12 @@ function _upgradeTags(tags, loc) { // Do the tag upgrade Object.assign(newTags, item.tags, keepTags); + // Swap `route` back to `route_master` - name-suggestion-index#5184 + if (isRouteMaster) { + newTags.route_master = newTags.route; + delete newTags.route; + } + // Special `branch` splitting rules - IF.. // - NSI is suggesting to replace `name`, AND // - `branch` doesn't already contain something, AND