name-suggestion-index
Version:
Canonical common brand names for OpenStreetMap
4 lines • 105 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../node_modules/quickselect/quickselect.js", "../../node_modules/rbush/index.js", "../../node_modules/lineclip/index.js", "../../node_modules/which-polygon/index.js", "../../node_modules/diacritics/index.js", "../../index.mjs", "../../lib/matcher.js", "../../lib/simplify.js", "../../config/matchGroups.json", "../../config/genericWords.json", "../../config/trees.json", "../../lib/stemmer.js"],
"sourcesContent": ["(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n\ttypeof define === 'function' && define.amd ? define(factory) :\n\t(global.quickselect = factory());\n}(this, (function () { 'use strict';\n\nfunction quickselect(arr, k, left, right, compare) {\n quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);\n}\n\nfunction quickselectStep(arr, k, left, right, compare) {\n\n while (right > left) {\n if (right - left > 600) {\n var n = right - left + 1;\n var m = k - left + 1;\n var z = Math.log(n);\n var s = 0.5 * Math.exp(2 * z / 3);\n var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);\n var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));\n var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));\n quickselectStep(arr, k, newLeft, newRight, compare);\n }\n\n var t = arr[k];\n var i = left;\n var j = right;\n\n swap(arr, left, k);\n if (compare(arr[right], t) > 0) swap(arr, left, right);\n\n while (i < j) {\n swap(arr, i, j);\n i++;\n j--;\n while (compare(arr[i], t) < 0) i++;\n while (compare(arr[j], t) > 0) j--;\n }\n\n if (compare(arr[left], t) === 0) swap(arr, left, j);\n else {\n j++;\n swap(arr, j, right);\n }\n\n if (j <= k) left = j + 1;\n if (k <= j) right = j - 1;\n }\n}\n\nfunction swap(arr, i, j) {\n var tmp = arr[i];\n arr[i] = arr[j];\n arr[j] = tmp;\n}\n\nfunction defaultCompare(a, b) {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\nreturn quickselect;\n\n})));\n", "'use strict';\n\nmodule.exports = rbush;\nmodule.exports.default = rbush;\n\nvar quickselect = require('quickselect');\n\nfunction rbush(maxEntries, format) {\n if (!(this instanceof rbush)) return new rbush(maxEntries, format);\n\n // max entries in a node is 9 by default; min node fill is 40% for best performance\n this._maxEntries = Math.max(4, maxEntries || 9);\n this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4));\n\n if (format) {\n this._initFormat(format);\n }\n\n this.clear();\n}\n\nrbush.prototype = {\n\n all: function () {\n return this._all(this.data, []);\n },\n\n search: function (bbox) {\n\n var node = this.data,\n result = [],\n toBBox = this.toBBox;\n\n if (!intersects(bbox, node)) return result;\n\n var nodesToSearch = [],\n i, len, child, childBBox;\n\n while (node) {\n for (i = 0, len = node.children.length; i < len; i++) {\n\n child = node.children[i];\n childBBox = node.leaf ? toBBox(child) : child;\n\n if (intersects(bbox, childBBox)) {\n if (node.leaf) result.push(child);\n else if (contains(bbox, childBBox)) this._all(child, result);\n else nodesToSearch.push(child);\n }\n }\n node = nodesToSearch.pop();\n }\n\n return result;\n },\n\n collides: function (bbox) {\n\n var node = this.data,\n toBBox = this.toBBox;\n\n if (!intersects(bbox, node)) return false;\n\n var nodesToSearch = [],\n i, len, child, childBBox;\n\n while (node) {\n for (i = 0, len = node.children.length; i < len; i++) {\n\n child = node.children[i];\n childBBox = node.leaf ? toBBox(child) : child;\n\n if (intersects(bbox, childBBox)) {\n if (node.leaf || contains(bbox, childBBox)) return true;\n nodesToSearch.push(child);\n }\n }\n node = nodesToSearch.pop();\n }\n\n return false;\n },\n\n load: function (data) {\n if (!(data && data.length)) return this;\n\n if (data.length < this._minEntries) {\n for (var i = 0, len = data.length; i < len; i++) {\n this.insert(data[i]);\n }\n return this;\n }\n\n // recursively build the tree with the given data from scratch using OMT algorithm\n var node = this._build(data.slice(), 0, data.length - 1, 0);\n\n if (!this.data.children.length) {\n // save as is if tree is empty\n this.data = node;\n\n } else if (this.data.height === node.height) {\n // split root if trees have the same height\n this._splitRoot(this.data, node);\n\n } else {\n if (this.data.height < node.height) {\n // swap trees if inserted one is bigger\n var tmpNode = this.data;\n this.data = node;\n node = tmpNode;\n }\n\n // insert the small tree into the large tree at appropriate level\n this._insert(node, this.data.height - node.height - 1, true);\n }\n\n return this;\n },\n\n insert: function (item) {\n if (item) this._insert(item, this.data.height - 1);\n return this;\n },\n\n clear: function () {\n this.data = createNode([]);\n return this;\n },\n\n remove: function (item, equalsFn) {\n if (!item) return this;\n\n var node = this.data,\n bbox = this.toBBox(item),\n path = [],\n indexes = [],\n i, parent, index, goingUp;\n\n // depth-first iterative tree traversal\n while (node || path.length) {\n\n if (!node) { // go up\n node = path.pop();\n parent = path[path.length - 1];\n i = indexes.pop();\n goingUp = true;\n }\n\n if (node.leaf) { // check current node\n index = findItem(item, node.children, equalsFn);\n\n if (index !== -1) {\n // item found, remove the item and condense tree upwards\n node.children.splice(index, 1);\n path.push(node);\n this._condense(path);\n return this;\n }\n }\n\n if (!goingUp && !node.leaf && contains(node, bbox)) { // go down\n path.push(node);\n indexes.push(i);\n i = 0;\n parent = node;\n node = node.children[0];\n\n } else if (parent) { // go right\n i++;\n node = parent.children[i];\n goingUp = false;\n\n } else node = null; // nothing found\n }\n\n return this;\n },\n\n toBBox: function (item) { return item; },\n\n compareMinX: compareNodeMinX,\n compareMinY: compareNodeMinY,\n\n toJSON: function () { return this.data; },\n\n fromJSON: function (data) {\n this.data = data;\n return this;\n },\n\n _all: function (node, result) {\n var nodesToSearch = [];\n while (node) {\n if (node.leaf) result.push.apply(result, node.children);\n else nodesToSearch.push.apply(nodesToSearch, node.children);\n\n node = nodesToSearch.pop();\n }\n return result;\n },\n\n _build: function (items, left, right, height) {\n\n var N = right - left + 1,\n M = this._maxEntries,\n node;\n\n if (N <= M) {\n // reached leaf level; return leaf\n node = createNode(items.slice(left, right + 1));\n calcBBox(node, this.toBBox);\n return node;\n }\n\n if (!height) {\n // target height of the bulk-loaded tree\n height = Math.ceil(Math.log(N) / Math.log(M));\n\n // target number of root entries to maximize storage utilization\n M = Math.ceil(N / Math.pow(M, height - 1));\n }\n\n node = createNode([]);\n node.leaf = false;\n node.height = height;\n\n // split the items into M mostly square tiles\n\n var N2 = Math.ceil(N / M),\n N1 = N2 * Math.ceil(Math.sqrt(M)),\n i, j, right2, right3;\n\n multiSelect(items, left, right, N1, this.compareMinX);\n\n for (i = left; i <= right; i += N1) {\n\n right2 = Math.min(i + N1 - 1, right);\n\n multiSelect(items, i, right2, N2, this.compareMinY);\n\n for (j = i; j <= right2; j += N2) {\n\n right3 = Math.min(j + N2 - 1, right2);\n\n // pack each entry recursively\n node.children.push(this._build(items, j, right3, height - 1));\n }\n }\n\n calcBBox(node, this.toBBox);\n\n return node;\n },\n\n _chooseSubtree: function (bbox, node, level, path) {\n\n var i, len, child, targetNode, area, enlargement, minArea, minEnlargement;\n\n while (true) {\n path.push(node);\n\n if (node.leaf || path.length - 1 === level) break;\n\n minArea = minEnlargement = Infinity;\n\n for (i = 0, len = node.children.length; i < len; i++) {\n child = node.children[i];\n area = bboxArea(child);\n enlargement = enlargedArea(bbox, child) - area;\n\n // choose entry with the least area enlargement\n if (enlargement < minEnlargement) {\n minEnlargement = enlargement;\n minArea = area < minArea ? area : minArea;\n targetNode = child;\n\n } else if (enlargement === minEnlargement) {\n // otherwise choose one with the smallest area\n if (area < minArea) {\n minArea = area;\n targetNode = child;\n }\n }\n }\n\n node = targetNode || node.children[0];\n }\n\n return node;\n },\n\n _insert: function (item, level, isNode) {\n\n var toBBox = this.toBBox,\n bbox = isNode ? item : toBBox(item),\n insertPath = [];\n\n // find the best node for accommodating the item, saving all nodes along the path too\n var node = this._chooseSubtree(bbox, this.data, level, insertPath);\n\n // put the item into the node\n node.children.push(item);\n extend(node, bbox);\n\n // split on node overflow; propagate upwards if necessary\n while (level >= 0) {\n if (insertPath[level].children.length > this._maxEntries) {\n this._split(insertPath, level);\n level--;\n } else break;\n }\n\n // adjust bboxes along the insertion path\n this._adjustParentBBoxes(bbox, insertPath, level);\n },\n\n // split overflowed node into two\n _split: function (insertPath, level) {\n\n var node = insertPath[level],\n M = node.children.length,\n m = this._minEntries;\n\n this._chooseSplitAxis(node, m, M);\n\n var splitIndex = this._chooseSplitIndex(node, m, M);\n\n var newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex));\n newNode.height = node.height;\n newNode.leaf = node.leaf;\n\n calcBBox(node, this.toBBox);\n calcBBox(newNode, this.toBBox);\n\n if (level) insertPath[level - 1].children.push(newNode);\n else this._splitRoot(node, newNode);\n },\n\n _splitRoot: function (node, newNode) {\n // split root node\n this.data = createNode([node, newNode]);\n this.data.height = node.height + 1;\n this.data.leaf = false;\n calcBBox(this.data, this.toBBox);\n },\n\n _chooseSplitIndex: function (node, m, M) {\n\n var i, bbox1, bbox2, overlap, area, minOverlap, minArea, index;\n\n minOverlap = minArea = Infinity;\n\n for (i = m; i <= M - m; i++) {\n bbox1 = distBBox(node, 0, i, this.toBBox);\n bbox2 = distBBox(node, i, M, this.toBBox);\n\n overlap = intersectionArea(bbox1, bbox2);\n area = bboxArea(bbox1) + bboxArea(bbox2);\n\n // choose distribution with minimum overlap\n if (overlap < minOverlap) {\n minOverlap = overlap;\n index = i;\n\n minArea = area < minArea ? area : minArea;\n\n } else if (overlap === minOverlap) {\n // otherwise choose distribution with minimum area\n if (area < minArea) {\n minArea = area;\n index = i;\n }\n }\n }\n\n return index;\n },\n\n // sorts node children by the best axis for split\n _chooseSplitAxis: function (node, m, M) {\n\n var compareMinX = node.leaf ? this.compareMinX : compareNodeMinX,\n compareMinY = node.leaf ? this.compareMinY : compareNodeMinY,\n xMargin = this._allDistMargin(node, m, M, compareMinX),\n yMargin = this._allDistMargin(node, m, M, compareMinY);\n\n // if total distributions margin value is minimal for x, sort by minX,\n // otherwise it's already sorted by minY\n if (xMargin < yMargin) node.children.sort(compareMinX);\n },\n\n // total margin of all possible split distributions where each node is at least m full\n _allDistMargin: function (node, m, M, compare) {\n\n node.children.sort(compare);\n\n var toBBox = this.toBBox,\n leftBBox = distBBox(node, 0, m, toBBox),\n rightBBox = distBBox(node, M - m, M, toBBox),\n margin = bboxMargin(leftBBox) + bboxMargin(rightBBox),\n i, child;\n\n for (i = m; i < M - m; i++) {\n child = node.children[i];\n extend(leftBBox, node.leaf ? toBBox(child) : child);\n margin += bboxMargin(leftBBox);\n }\n\n for (i = M - m - 1; i >= m; i--) {\n child = node.children[i];\n extend(rightBBox, node.leaf ? toBBox(child) : child);\n margin += bboxMargin(rightBBox);\n }\n\n return margin;\n },\n\n _adjustParentBBoxes: function (bbox, path, level) {\n // adjust bboxes along the given tree path\n for (var i = level; i >= 0; i--) {\n extend(path[i], bbox);\n }\n },\n\n _condense: function (path) {\n // go through the path, removing empty nodes and updating bboxes\n for (var i = path.length - 1, siblings; i >= 0; i--) {\n if (path[i].children.length === 0) {\n if (i > 0) {\n siblings = path[i - 1].children;\n siblings.splice(siblings.indexOf(path[i]), 1);\n\n } else this.clear();\n\n } else calcBBox(path[i], this.toBBox);\n }\n },\n\n _initFormat: function (format) {\n // data format (minX, minY, maxX, maxY accessors)\n\n // uses eval-type function compilation instead of just accepting a toBBox function\n // because the algorithms are very sensitive to sorting functions performance,\n // so they should be dead simple and without inner calls\n\n var compareArr = ['return a', ' - b', ';'];\n\n this.compareMinX = new Function('a', 'b', compareArr.join(format[0]));\n this.compareMinY = new Function('a', 'b', compareArr.join(format[1]));\n\n this.toBBox = new Function('a',\n 'return {minX: a' + format[0] +\n ', minY: a' + format[1] +\n ', maxX: a' + format[2] +\n ', maxY: a' + format[3] + '};');\n }\n};\n\nfunction findItem(item, items, equalsFn) {\n if (!equalsFn) return items.indexOf(item);\n\n for (var i = 0; i < items.length; i++) {\n if (equalsFn(item, items[i])) return i;\n }\n return -1;\n}\n\n// calculate node's bbox from bboxes of its children\nfunction calcBBox(node, toBBox) {\n distBBox(node, 0, node.children.length, toBBox, node);\n}\n\n// min bounding rectangle of node children from k to p-1\nfunction distBBox(node, k, p, toBBox, destNode) {\n if (!destNode) destNode = createNode(null);\n destNode.minX = Infinity;\n destNode.minY = Infinity;\n destNode.maxX = -Infinity;\n destNode.maxY = -Infinity;\n\n for (var i = k, child; i < p; i++) {\n child = node.children[i];\n extend(destNode, node.leaf ? toBBox(child) : child);\n }\n\n return destNode;\n}\n\nfunction extend(a, b) {\n a.minX = Math.min(a.minX, b.minX);\n a.minY = Math.min(a.minY, b.minY);\n a.maxX = Math.max(a.maxX, b.maxX);\n a.maxY = Math.max(a.maxY, b.maxY);\n return a;\n}\n\nfunction compareNodeMinX(a, b) { return a.minX - b.minX; }\nfunction compareNodeMinY(a, b) { return a.minY - b.minY; }\n\nfunction bboxArea(a) { return (a.maxX - a.minX) * (a.maxY - a.minY); }\nfunction bboxMargin(a) { return (a.maxX - a.minX) + (a.maxY - a.minY); }\n\nfunction enlargedArea(a, b) {\n return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) *\n (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));\n}\n\nfunction intersectionArea(a, b) {\n var minX = Math.max(a.minX, b.minX),\n minY = Math.max(a.minY, b.minY),\n maxX = Math.min(a.maxX, b.maxX),\n maxY = Math.min(a.maxY, b.maxY);\n\n return Math.max(0, maxX - minX) *\n Math.max(0, maxY - minY);\n}\n\nfunction contains(a, b) {\n return a.minX <= b.minX &&\n a.minY <= b.minY &&\n b.maxX <= a.maxX &&\n b.maxY <= a.maxY;\n}\n\nfunction intersects(a, b) {\n return b.minX <= a.maxX &&\n b.minY <= a.maxY &&\n b.maxX >= a.minX &&\n b.maxY >= a.minY;\n}\n\nfunction createNode(children) {\n return {\n children: children,\n height: 1,\n leaf: true,\n minX: Infinity,\n minY: Infinity,\n maxX: -Infinity,\n maxY: -Infinity\n };\n}\n\n// sort an array so that items come in groups of n unsorted items, with groups sorted between each other;\n// combines selection algorithm with binary divide & conquer approach\n\nfunction multiSelect(arr, left, right, n, compare) {\n var stack = [left, right],\n mid;\n\n while (stack.length) {\n right = stack.pop();\n left = stack.pop();\n\n if (right - left <= n) continue;\n\n mid = left + Math.ceil((right - left) / n / 2) * n;\n quickselect(arr, mid, left, right, compare);\n\n stack.push(left, mid, mid, right);\n }\n}\n", "'use strict';\n\nmodule.exports = lineclip;\n\nlineclip.polyline = lineclip;\nlineclip.polygon = polygonclip;\n\n\n// Cohen-Sutherland line clippign algorithm, adapted to efficiently\n// handle polylines rather than just segments\n\nfunction lineclip(points, bbox, result) {\n\n var len = points.length,\n codeA = bitCode(points[0], bbox),\n part = [],\n i, a, b, codeB, lastCode;\n\n if (!result) result = [];\n\n for (i = 1; i < len; i++) {\n a = points[i - 1];\n b = points[i];\n codeB = lastCode = bitCode(b, bbox);\n\n while (true) {\n\n if (!(codeA | codeB)) { // accept\n part.push(a);\n\n if (codeB !== lastCode) { // segment went outside\n part.push(b);\n\n if (i < len - 1) { // start a new line\n result.push(part);\n part = [];\n }\n } else if (i === len - 1) {\n part.push(b);\n }\n break;\n\n } else if (codeA & codeB) { // trivial reject\n break;\n\n } else if (codeA) { // a outside, intersect with clip edge\n a = intersect(a, b, codeA, bbox);\n codeA = bitCode(a, bbox);\n\n } else { // b outside\n b = intersect(a, b, codeB, bbox);\n codeB = bitCode(b, bbox);\n }\n }\n\n codeA = lastCode;\n }\n\n if (part.length) result.push(part);\n\n return result;\n}\n\n// Sutherland-Hodgeman polygon clipping algorithm\n\nfunction polygonclip(points, bbox) {\n\n var result, edge, prev, prevInside, i, p, inside;\n\n // clip against each side of the clip rectangle\n for (edge = 1; edge <= 8; edge *= 2) {\n result = [];\n prev = points[points.length - 1];\n prevInside = !(bitCode(prev, bbox) & edge);\n\n for (i = 0; i < points.length; i++) {\n p = points[i];\n inside = !(bitCode(p, bbox) & edge);\n\n // if segment goes through the clip window, add an intersection\n if (inside !== prevInside) result.push(intersect(prev, p, edge, bbox));\n\n if (inside) result.push(p); // add a point if it's inside\n\n prev = p;\n prevInside = inside;\n }\n\n points = result;\n\n if (!points.length) break;\n }\n\n return result;\n}\n\n// intersect a segment against one of the 4 lines that make up the bbox\n\nfunction intersect(a, b, edge, bbox) {\n return edge & 8 ? [a[0] + (b[0] - a[0]) * (bbox[3] - a[1]) / (b[1] - a[1]), bbox[3]] : // top\n edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox[1] - a[1]) / (b[1] - a[1]), bbox[1]] : // bottom\n edge & 2 ? [bbox[2], a[1] + (b[1] - a[1]) * (bbox[2] - a[0]) / (b[0] - a[0])] : // right\n edge & 1 ? [bbox[0], a[1] + (b[1] - a[1]) * (bbox[0] - a[0]) / (b[0] - a[0])] : // left\n null;\n}\n\n// bit code reflects the point position relative to the bbox:\n\n// left mid right\n// top 1001 1000 1010\n// mid 0001 0000 0010\n// bottom 0101 0100 0110\n\nfunction bitCode(p, bbox) {\n var code = 0;\n\n if (p[0] < bbox[0]) code |= 1; // left\n else if (p[0] > bbox[2]) code |= 2; // right\n\n if (p[1] < bbox[1]) code |= 4; // bottom\n else if (p[1] > bbox[3]) code |= 8; // top\n\n return code;\n}\n", "'use strict';\n\nvar rbush = require('rbush');\nvar lineclip = require('lineclip');\n\nmodule.exports = whichPolygon;\n\nfunction whichPolygon(data) {\n var bboxes = [];\n for (var i = 0; i < data.features.length; i++) {\n var feature = data.features[i];\n\n // unlocated GeoJSON features can have null `geometry`\n if (!feature.geometry) continue;\n\n var coords = feature.geometry.coordinates;\n\n if (feature.geometry.type === 'Polygon') {\n bboxes.push(treeItem(coords, feature.properties));\n\n } else if (feature.geometry.type === 'MultiPolygon') {\n for (var j = 0; j < coords.length; j++) {\n bboxes.push(treeItem(coords[j], feature.properties));\n }\n }\n }\n\n var tree = rbush().load(bboxes);\n\n function query(p, multi) {\n var output = [],\n result = tree.search({\n minX: p[0],\n minY: p[1],\n maxX: p[0],\n maxY: p[1]\n });\n for (var i = 0; i < result.length; i++) {\n if (insidePolygon(result[i].coords, p)) {\n if (multi)\n output.push(result[i].props);\n else\n return result[i].props;\n }\n }\n return multi && output.length ? output : null;\n }\n\n query.tree = tree;\n query.bbox = function queryBBox(bbox) {\n var output = [];\n var result = tree.search({\n minX: bbox[0],\n minY: bbox[1],\n maxX: bbox[2],\n maxY: bbox[3]\n });\n for (var i = 0; i < result.length; i++) {\n if (polygonIntersectsBBox(result[i].coords, bbox)) {\n output.push(result[i].props);\n }\n }\n return output;\n };\n\n return query;\n}\n\nfunction polygonIntersectsBBox(polygon, bbox) {\n var bboxCenter = [\n (bbox[0] + bbox[2]) / 2,\n (bbox[1] + bbox[3]) / 2\n ];\n if (insidePolygon(polygon, bboxCenter)) return true;\n for (var i = 0; i < polygon.length; i++) {\n if (lineclip(polygon[i], bbox).length > 0) return true;\n }\n return false;\n}\n\n// ray casting algorithm for detecting if point is in polygon\nfunction insidePolygon(rings, p) {\n var inside = false;\n for (var i = 0, len = rings.length; i < len; i++) {\n var ring = rings[i];\n for (var j = 0, len2 = ring.length, k = len2 - 1; j < len2; k = j++) {\n if (rayIntersect(p, ring[j], ring[k])) inside = !inside;\n }\n }\n return inside;\n}\n\nfunction rayIntersect(p, p1, p2) {\n return ((p1[1] > p[1]) !== (p2[1] > p[1])) && (p[0] < (p2[0] - p1[0]) * (p[1] - p1[1]) / (p2[1] - p1[1]) + p1[0]);\n}\n\nfunction treeItem(coords, props) {\n var item = {\n minX: Infinity,\n minY: Infinity,\n maxX: -Infinity,\n maxY: -Infinity,\n coords: coords,\n props: props\n };\n\n for (var i = 0; i < coords[0].length; i++) {\n var p = coords[0][i];\n item.minX = Math.min(item.minX, p[0]);\n item.minY = Math.min(item.minY, p[1]);\n item.maxX = Math.max(item.maxX, p[0]);\n item.maxY = Math.max(item.maxY, p[1]);\n }\n return item;\n}\n", "exports.remove = removeDiacritics;\n\nvar replacementList = [\n {\n base: ' ',\n chars: \"\\u00A0\",\n }, {\n base: '0',\n chars: \"\\u07C0\",\n }, {\n base: 'A',\n chars: \"\\u24B6\\uFF21\\u00C0\\u00C1\\u00C2\\u1EA6\\u1EA4\\u1EAA\\u1EA8\\u00C3\\u0100\\u0102\\u1EB0\\u1EAE\\u1EB4\\u1EB2\\u0226\\u01E0\\u00C4\\u01DE\\u1EA2\\u00C5\\u01FA\\u01CD\\u0200\\u0202\\u1EA0\\u1EAC\\u1EB6\\u1E00\\u0104\\u023A\\u2C6F\",\n }, {\n base: 'AA',\n chars: \"\\uA732\",\n }, {\n base: 'AE',\n chars: \"\\u00C6\\u01FC\\u01E2\",\n }, {\n base: 'AO',\n chars: \"\\uA734\",\n }, {\n base: 'AU',\n chars: \"\\uA736\",\n }, {\n base: 'AV',\n chars: \"\\uA738\\uA73A\",\n }, {\n base: 'AY',\n chars: \"\\uA73C\",\n }, {\n base: 'B',\n chars: \"\\u24B7\\uFF22\\u1E02\\u1E04\\u1E06\\u0243\\u0181\",\n }, {\n base: 'C',\n chars: \"\\u24b8\\uff23\\uA73E\\u1E08\\u0106\\u0043\\u0108\\u010A\\u010C\\u00C7\\u0187\\u023B\",\n }, {\n base: 'D',\n chars: \"\\u24B9\\uFF24\\u1E0A\\u010E\\u1E0C\\u1E10\\u1E12\\u1E0E\\u0110\\u018A\\u0189\\u1D05\\uA779\",\n }, {\n base: 'Dh',\n chars: \"\\u00D0\",\n }, {\n base: 'DZ',\n chars: \"\\u01F1\\u01C4\",\n }, {\n base: 'Dz',\n chars: \"\\u01F2\\u01C5\",\n }, {\n base: 'E',\n chars: \"\\u025B\\u24BA\\uFF25\\u00C8\\u00C9\\u00CA\\u1EC0\\u1EBE\\u1EC4\\u1EC2\\u1EBC\\u0112\\u1E14\\u1E16\\u0114\\u0116\\u00CB\\u1EBA\\u011A\\u0204\\u0206\\u1EB8\\u1EC6\\u0228\\u1E1C\\u0118\\u1E18\\u1E1A\\u0190\\u018E\\u1D07\",\n }, {\n base: 'F',\n chars: \"\\uA77C\\u24BB\\uFF26\\u1E1E\\u0191\\uA77B\",\n }, {\n base: 'G',\n chars: \"\\u24BC\\uFF27\\u01F4\\u011C\\u1E20\\u011E\\u0120\\u01E6\\u0122\\u01E4\\u0193\\uA7A0\\uA77D\\uA77E\\u0262\",\n }, {\n base: 'H',\n chars: \"\\u24BD\\uFF28\\u0124\\u1E22\\u1E26\\u021E\\u1E24\\u1E28\\u1E2A\\u0126\\u2C67\\u2C75\\uA78D\",\n }, {\n base: 'I',\n chars: \"\\u24BE\\uFF29\\xCC\\xCD\\xCE\\u0128\\u012A\\u012C\\u0130\\xCF\\u1E2E\\u1EC8\\u01CF\\u0208\\u020A\\u1ECA\\u012E\\u1E2C\\u0197\",\n }, {\n base: 'J',\n chars: \"\\u24BF\\uFF2A\\u0134\\u0248\\u0237\",\n }, {\n base: 'K',\n chars: \"\\u24C0\\uFF2B\\u1E30\\u01E8\\u1E32\\u0136\\u1E34\\u0198\\u2C69\\uA740\\uA742\\uA744\\uA7A2\",\n }, {\n base: 'L',\n chars: \"\\u24C1\\uFF2C\\u013F\\u0139\\u013D\\u1E36\\u1E38\\u013B\\u1E3C\\u1E3A\\u0141\\u023D\\u2C62\\u2C60\\uA748\\uA746\\uA780\",\n }, {\n base: 'LJ',\n chars: \"\\u01C7\",\n }, {\n base: 'Lj',\n chars: \"\\u01C8\",\n }, {\n base: 'M',\n chars: \"\\u24C2\\uFF2D\\u1E3E\\u1E40\\u1E42\\u2C6E\\u019C\\u03FB\",\n }, {\n base: 'N',\n chars: \"\\uA7A4\\u0220\\u24C3\\uFF2E\\u01F8\\u0143\\xD1\\u1E44\\u0147\\u1E46\\u0145\\u1E4A\\u1E48\\u019D\\uA790\\u1D0E\",\n }, {\n base: 'NJ',\n chars: \"\\u01CA\",\n }, {\n base: 'Nj',\n chars: \"\\u01CB\",\n }, {\n base: 'O',\n chars: \"\\u24C4\\uFF2F\\xD2\\xD3\\xD4\\u1ED2\\u1ED0\\u1ED6\\u1ED4\\xD5\\u1E4C\\u022C\\u1E4E\\u014C\\u1E50\\u1E52\\u014E\\u022E\\u0230\\xD6\\u022A\\u1ECE\\u0150\\u01D1\\u020C\\u020E\\u01A0\\u1EDC\\u1EDA\\u1EE0\\u1EDE\\u1EE2\\u1ECC\\u1ED8\\u01EA\\u01EC\\xD8\\u01FE\\u0186\\u019F\\uA74A\\uA74C\",\n }, {\n base: 'OE',\n chars: \"\\u0152\",\n }, {\n base: 'OI',\n chars: \"\\u01A2\",\n }, {\n base: 'OO',\n chars: \"\\uA74E\",\n }, {\n base: 'OU',\n chars: \"\\u0222\",\n }, {\n base: 'P',\n chars: \"\\u24C5\\uFF30\\u1E54\\u1E56\\u01A4\\u2C63\\uA750\\uA752\\uA754\",\n }, {\n base: 'Q',\n chars: \"\\u24C6\\uFF31\\uA756\\uA758\\u024A\",\n }, {\n base: 'R',\n chars: \"\\u24C7\\uFF32\\u0154\\u1E58\\u0158\\u0210\\u0212\\u1E5A\\u1E5C\\u0156\\u1E5E\\u024C\\u2C64\\uA75A\\uA7A6\\uA782\",\n }, {\n base: 'S',\n chars: \"\\u24C8\\uFF33\\u1E9E\\u015A\\u1E64\\u015C\\u1E60\\u0160\\u1E66\\u1E62\\u1E68\\u0218\\u015E\\u2C7E\\uA7A8\\uA784\",\n }, {\n base: 'T',\n chars: \"\\u24C9\\uFF34\\u1E6A\\u0164\\u1E6C\\u021A\\u0162\\u1E70\\u1E6E\\u0166\\u01AC\\u01AE\\u023E\\uA786\",\n }, {\n base: 'Th',\n chars: \"\\u00DE\",\n }, {\n base: 'TZ',\n chars: \"\\uA728\",\n }, {\n base: 'U',\n chars: \"\\u24CA\\uFF35\\xD9\\xDA\\xDB\\u0168\\u1E78\\u016A\\u1E7A\\u016C\\xDC\\u01DB\\u01D7\\u01D5\\u01D9\\u1EE6\\u016E\\u0170\\u01D3\\u0214\\u0216\\u01AF\\u1EEA\\u1EE8\\u1EEE\\u1EEC\\u1EF0\\u1EE4\\u1E72\\u0172\\u1E76\\u1E74\\u0244\",\n }, {\n base: 'V',\n chars: \"\\u24CB\\uFF36\\u1E7C\\u1E7E\\u01B2\\uA75E\\u0245\",\n }, {\n base: 'VY',\n chars: \"\\uA760\",\n }, {\n base: 'W',\n chars: \"\\u24CC\\uFF37\\u1E80\\u1E82\\u0174\\u1E86\\u1E84\\u1E88\\u2C72\",\n }, {\n base: 'X',\n chars: \"\\u24CD\\uFF38\\u1E8A\\u1E8C\",\n }, {\n base: 'Y',\n chars: \"\\u24CE\\uFF39\\u1EF2\\xDD\\u0176\\u1EF8\\u0232\\u1E8E\\u0178\\u1EF6\\u1EF4\\u01B3\\u024E\\u1EFE\",\n }, {\n base: 'Z',\n chars: \"\\u24CF\\uFF3A\\u0179\\u1E90\\u017B\\u017D\\u1E92\\u1E94\\u01B5\\u0224\\u2C7F\\u2C6B\\uA762\",\n }, {\n base: 'a',\n chars: \"\\u24D0\\uFF41\\u1E9A\\u00E0\\u00E1\\u00E2\\u1EA7\\u1EA5\\u1EAB\\u1EA9\\u00E3\\u0101\\u0103\\u1EB1\\u1EAF\\u1EB5\\u1EB3\\u0227\\u01E1\\u00E4\\u01DF\\u1EA3\\u00E5\\u01FB\\u01CE\\u0201\\u0203\\u1EA1\\u1EAD\\u1EB7\\u1E01\\u0105\\u2C65\\u0250\\u0251\",\n }, {\n base: 'aa',\n chars: \"\\uA733\",\n }, {\n base: 'ae',\n chars: \"\\u00E6\\u01FD\\u01E3\",\n }, {\n base: 'ao',\n chars: \"\\uA735\",\n }, {\n base: 'au',\n chars: \"\\uA737\",\n }, {\n base: 'av',\n chars: \"\\uA739\\uA73B\",\n }, {\n base: 'ay',\n chars: \"\\uA73D\",\n }, {\n base: 'b',\n chars: \"\\u24D1\\uFF42\\u1E03\\u1E05\\u1E07\\u0180\\u0183\\u0253\\u0182\",\n }, {\n base: 'c',\n chars: \"\\uFF43\\u24D2\\u0107\\u0109\\u010B\\u010D\\u00E7\\u1E09\\u0188\\u023C\\uA73F\\u2184\",\n }, {\n base: 'd',\n chars: \"\\u24D3\\uFF44\\u1E0B\\u010F\\u1E0D\\u1E11\\u1E13\\u1E0F\\u0111\\u018C\\u0256\\u0257\\u018B\\u13E7\\u0501\\uA7AA\",\n }, {\n base: 'dh',\n chars: \"\\u00F0\",\n }, {\n base: 'dz',\n chars: \"\\u01F3\\u01C6\",\n }, {\n base: 'e',\n chars: \"\\u24D4\\uFF45\\u00E8\\u00E9\\u00EA\\u1EC1\\u1EBF\\u1EC5\\u1EC3\\u1EBD\\u0113\\u1E15\\u1E17\\u0115\\u0117\\u00EB\\u1EBB\\u011B\\u0205\\u0207\\u1EB9\\u1EC7\\u0229\\u1E1D\\u0119\\u1E19\\u1E1B\\u0247\\u01DD\",\n }, {\n base: 'f',\n chars: \"\\u24D5\\uFF46\\u1E1F\\u0192\",\n }, {\n base: 'ff',\n chars: \"\\uFB00\",\n }, {\n base: 'fi',\n chars: \"\\uFB01\",\n }, {\n base: 'fl',\n chars: \"\\uFB02\",\n }, {\n base: 'ffi',\n chars: \"\\uFB03\",\n }, {\n base: 'ffl',\n chars: \"\\uFB04\",\n }, {\n base: 'g',\n chars: \"\\u24D6\\uFF47\\u01F5\\u011D\\u1E21\\u011F\\u0121\\u01E7\\u0123\\u01E5\\u0260\\uA7A1\\uA77F\\u1D79\",\n }, {\n base: 'h',\n chars: \"\\u24D7\\uFF48\\u0125\\u1E23\\u1E27\\u021F\\u1E25\\u1E29\\u1E2B\\u1E96\\u0127\\u2C68\\u2C76\\u0265\",\n }, {\n base: 'hv',\n chars: \"\\u0195\",\n }, {\n base: 'i',\n chars: \"\\u24D8\\uFF49\\xEC\\xED\\xEE\\u0129\\u012B\\u012D\\xEF\\u1E2F\\u1EC9\\u01D0\\u0209\\u020B\\u1ECB\\u012F\\u1E2D\\u0268\\u0131\",\n }, {\n base: 'j',\n chars: \"\\u24D9\\uFF4A\\u0135\\u01F0\\u0249\",\n }, {\n base: 'k',\n chars: \"\\u24DA\\uFF4B\\u1E31\\u01E9\\u1E33\\u0137\\u1E35\\u0199\\u2C6A\\uA741\\uA743\\uA745\\uA7A3\",\n }, {\n base: 'l',\n chars: \"\\u24DB\\uFF4C\\u0140\\u013A\\u013E\\u1E37\\u1E39\\u013C\\u1E3D\\u1E3B\\u017F\\u0142\\u019A\\u026B\\u2C61\\uA749\\uA781\\uA747\\u026D\",\n }, {\n base: 'lj',\n chars: \"\\u01C9\",\n }, {\n base: 'm',\n chars: \"\\u24DC\\uFF4D\\u1E3F\\u1E41\\u1E43\\u0271\\u026F\",\n }, {\n base: 'n',\n chars: \"\\u24DD\\uFF4E\\u01F9\\u0144\\xF1\\u1E45\\u0148\\u1E47\\u0146\\u1E4B\\u1E49\\u019E\\u0272\\u0149\\uA791\\uA7A5\\u043B\\u0509\",\n }, {\n base: 'nj',\n chars: \"\\u01CC\",\n }, {\n base: 'o',\n chars: \"\\u24DE\\uFF4F\\xF2\\xF3\\xF4\\u1ED3\\u1ED1\\u1ED7\\u1ED5\\xF5\\u1E4D\\u022D\\u1E4F\\u014D\\u1E51\\u1E53\\u014F\\u022F\\u0231\\xF6\\u022B\\u1ECF\\u0151\\u01D2\\u020D\\u020F\\u01A1\\u1EDD\\u1EDB\\u1EE1\\u1EDF\\u1EE3\\u1ECD\\u1ED9\\u01EB\\u01ED\\xF8\\u01FF\\uA74B\\uA74D\\u0275\\u0254\\u1D11\",\n }, {\n base: 'oe',\n chars: \"\\u0153\",\n }, {\n base: 'oi',\n chars: \"\\u01A3\",\n }, {\n base: 'oo',\n chars: \"\\uA74F\",\n }, {\n base: 'ou',\n chars: \"\\u0223\",\n }, {\n base: 'p',\n chars: \"\\u24DF\\uFF50\\u1E55\\u1E57\\u01A5\\u1D7D\\uA751\\uA753\\uA755\\u03C1\",\n }, {\n base: 'q',\n chars: \"\\u24E0\\uFF51\\u024B\\uA757\\uA759\",\n }, {\n base: 'r',\n chars: \"\\u24E1\\uFF52\\u0155\\u1E59\\u0159\\u0211\\u0213\\u1E5B\\u1E5D\\u0157\\u1E5F\\u024D\\u027D\\uA75B\\uA7A7\\uA783\",\n }, {\n base: 's',\n chars: \"\\u24E2\\uFF53\\u015B\\u1E65\\u015D\\u1E61\\u0161\\u1E67\\u1E63\\u1E69\\u0219\\u015F\\u023F\\uA7A9\\uA785\\u1E9B\\u0282\",\n }, {\n base: 'ss',\n chars: \"\\xDF\",\n }, {\n base: 't',\n chars: \"\\u24E3\\uFF54\\u1E6B\\u1E97\\u0165\\u1E6D\\u021B\\u0163\\u1E71\\u1E6F\\u0167\\u01AD\\u0288\\u2C66\\uA787\",\n }, {\n base: 'th',\n chars: \"\\u00FE\",\n }, {\n base: 'tz',\n chars: \"\\uA729\",\n }, {\n base: 'u',\n chars: \"\\u24E4\\uFF55\\xF9\\xFA\\xFB\\u0169\\u1E79\\u016B\\u1E7B\\u016D\\xFC\\u01DC\\u01D8\\u01D6\\u01DA\\u1EE7\\u016F\\u0171\\u01D4\\u0215\\u0217\\u01B0\\u1EEB\\u1EE9\\u1EEF\\u1EED\\u1EF1\\u1EE5\\u1E73\\u0173\\u1E77\\u1E75\\u0289\",\n }, {\n base: 'v',\n chars: \"\\u24E5\\uFF56\\u1E7D\\u1E7F\\u028B\\uA75F\\u028C\",\n }, {\n base: 'vy',\n chars: \"\\uA761\",\n }, {\n base: 'w',\n chars: \"\\u24E6\\uFF57\\u1E81\\u1E83\\u0175\\u1E87\\u1E85\\u1E98\\u1E89\\u2C73\",\n }, {\n base: 'x',\n chars: \"\\u24E7\\uFF58\\u1E8B\\u1E8D\",\n }, {\n base: 'y',\n chars: \"\\u24E8\\uFF59\\u1EF3\\xFD\\u0177\\u1EF9\\u0233\\u1E8F\\xFF\\u1EF7\\u1E99\\u1EF5\\u01B4\\u024F\\u1EFF\",\n }, {\n base: 'z',\n chars: \"\\u24E9\\uFF5A\\u017A\\u1E91\\u017C\\u017E\\u1E93\\u1E95\\u01B6\\u0225\\u0240\\u2C6C\\uA763\",\n }\n];\n\nvar diacriticsMap = {};\nfor (var i = 0; i < replacementList.length; i += 1) {\n var chars = replacementList[i].chars;\n for (var j = 0; j < chars.length; j += 1) {\n diacriticsMap[chars[j]] = replacementList[i].base;\n }\n}\n\nfunction removeDiacritics(str) {\n return str.replace(/[^\\u0000-\\u007e]/g, function(c) {\n return diacriticsMap[c] || c;\n });\n}\n\nexports.replacementList = replacementList;\nexports.diacriticsMap = diacriticsMap;\n", "export { Matcher } from './lib/matcher.js';\nexport { simplify } from './lib/simplify.js';\nexport { stemmer } from './lib/stemmer.js';\n", "// External\nimport whichPolygon from 'which-polygon';\n\n// Internal\nimport { simplify } from './simplify.js';\n\n// JSON\nimport matchGroupsJSON from '../config/matchGroups.json' with {type: 'json'};\nimport genericWordsJSON from '../config/genericWords.json' with {type: 'json'};\nimport treesJSON from '../config/trees.json' with {type: 'json'};\n\nconst matchGroups = matchGroupsJSON.matchGroups;\nconst trees = treesJSON.trees;\n\n\nexport class Matcher {\n //\n // `constructor`\n // initialize the genericWords regexes\n constructor() {\n // The `matchIndex` is a specialized structure that allows us to quickly answer\n // _\"Given a [key/value tagpair, name, location], what canonical items (brands etc) can match it?\"_\n //\n // The index contains all valid combinations of k/v tagpairs and names\n // matchIndex:\n // {\n // 'k/v': {\n // 'primary': Map (String 'nsimple' -> Set (itemIDs\u2026), // matches for tags like `name`, `name:xx`, etc.\n // 'alternate': Map (String 'nsimple' -> Set (itemIDs\u2026), // matches for tags like `alt_name`, `brand`, etc.\n // 'excludeNamed': Map (String 'pattern' -> RegExp),\n // 'excludeGeneric': Map (String 'pattern' -> RegExp)\n // },\n // }\n //\n // {\n // 'amenity/bank': {\n // 'primary': {\n // 'firstbank': Set (\"firstbank-978cca\", \"firstbank-9794e6\", \"firstbank-f17495\", \u2026),\n // \u2026\n // },\n // 'alternate': {\n // '1stbank': Set (\"firstbank-f17495\"),\n // \u2026\n // }\n // },\n // 'shop/supermarket': {\n // 'primary': {\n // 'coop': Set (\"coop-76454b\", \"coop-ebf2d9\", \"coop-36e991\", \u2026),\n // 'coopfood': Set (\"coopfood-a8278b\", \u2026),\n // \u2026\n // },\n // 'alternate': {\n // 'coop': Set (\"coopfood-a8278b\", \u2026),\n // 'federatedcooperatives': Set (\"coop-76454b\", \u2026),\n // 'thecooperative': Set (\"coopfood-a8278b\", \u2026),\n // \u2026\n // }\n // }\n // }\n //\n this.matchIndex = undefined;\n\n // The `genericWords` structure matches the contents of genericWords.json to instantiated RegExp objects\n // Map (String 'pattern' -> RegExp),\n this.genericWords = new Map();\n (genericWordsJSON.genericWords || []).forEach(s => this.genericWords.set(s, new RegExp(s, 'i')));\n\n // The `itemLocation` structure maps itemIDs to locationSetIDs:\n // {\n // 'firstbank-f17495': '+[first_bank_western_us.geojson]',\n // 'firstbank-978cca': '+[first_bank_carolinas.geojson]',\n // 'coop-76454b': '+[Q16]',\n // 'coopfood-a8278b': '+[Q23666]',\n // \u2026\n // }\n this.itemLocation = undefined;\n\n // The `locationSets` structure maps locationSetIDs to *resolved* locationSets:\n // {\n // '+[first_bank_western_us.geojson]': GeoJSON {\u2026},\n // '+[first_bank_carolinas.geojson]': GeoJSON {\u2026},\n // '+[Q16]': GeoJSON {\u2026},\n // '+[Q23666]': GeoJSON {\u2026},\n // \u2026\n // }\n this.locationSets = undefined;\n\n // The `locationIndex` is an instance of which-polygon spatial index for the locationSets.\n this.locationIndex = undefined;\n\n // Array of match conflict pairs (currently unused)\n this.warnings = [];\n }\n\n\n //\n // `buildMatchIndex()`\n // Call this to prepare the matcher for use\n //\n // `data` needs to be an Object indexed on a 'tree/key/value' path.\n // (e.g. cache filled by `fileTree.read` or data found in `dist/nsi.json`)\n // {\n // 'brands/amenity/bank': { properties: {}, items: [ {}, {}, \u2026 ] },\n // 'brands/amenity/bar': { properties: {}, items: [ {}, {}, \u2026 ] },\n // \u2026\n // }\n //\n buildMatchIndex(data) {\n const that = this;\n if (that.matchIndex) return; // it was built already\n that.matchIndex = new Map();\n\n const seenTree = new Map(); // warn if the same [k, v, nsimple] appears in multiple trees - #5625\n\n Object.keys(data).forEach(tkv => {\n const category = data[tkv];\n const parts = tkv.split('/', 3); // tkv = \"tree/key/value\"\n const t = parts[0];\n const k = parts[1];\n const v = parts[2];\n const thiskv = `${k}/${v}`;\n const tree = trees[t];\n\n let branch = that.matchIndex.get(thiskv);\n if (!branch) {\n branch = {\n primary: new Map(),\n alternate: new Map(),\n excludeGeneric: new Map(),\n excludeNamed: new Map()\n };\n that.matchIndex.set(thiskv, branch);\n }\n\n // ADD EXCLUSIONS\n const properties = category.properties || {};\n const exclude = properties.exclude || {};\n (exclude.generic || []).forEach(s => branch.excludeGeneric.set(s, new RegExp(s, 'i')));\n (exclude.named || []).forEach(s => branch.excludeNamed.set(s, new RegExp(s, 'i')));\n const excludeRegexes = [...branch.excludeGeneric.values(), ...branch.excludeNamed.values()];\n\n\n // ADD ITEMS\n let items = category.items;\n if (!Array.isArray(items) || !items.length) return;\n\n\n // Primary name patterns, match tags to take first\n // e.g. `name`, `name:ru`\n const primaryName = new RegExp(tree.nameTags.primary, 'i');\n\n // Alternate name patterns, match tags to consider after primary\n // e.g. `alt_name`, `short_name`, `brand`, `brand:ru`, etc..\n const alternateName = new RegExp(tree.nameTags.alternate, 'i');\n\n // There are a few exceptions to the name matching regexes.\n // Usually a tag suffix contains a language code like `name:en`, `name:ru`\n // but we want to exclude things like `operator:type`, `name:etymology`, etc..\n const notName = /:(colou?r|type|forward|backward|left|right|etymology|pronunciation|signed|wikipedia)$/i;\n\n // For certain categories we do not want to match generic KV pairs like `building/yes` or `amenity/yes`\n const skipGenericKV = skipGenericKVMatches(t, k, v);\n\n // We will collect the generic KV pairs anyway (for the purpose of filtering them out of matchTags)\n const genericKV = new Set([`${k}/yes`, `building/yes`]);\n\n // Collect alternate tagpairs for this kv category from matchGroups.\n // We might also pick up a few more generic KVs (like `shop/yes`)\n const matchGroupKV = new Set();\n Object.values(matchGroups).forEach(matchGroup => {\n const inGroup = matchGroup.some(otherkv => otherkv === thiskv);\n if (!inGroup) return;\n\n matchGroup.forEach(otherkv => {\n if (otherkv === thiskv) return; // skip self\n matchGroupKV.add(otherkv);\n\n const otherk = otherkv.split('/', 2)[0]; // we might pick up a `shop/yes`\n genericKV.add(`${otherk}/yes`);\n });\n });\n\n // For each item, insert all [key, value, name] combinations into the match index\n items.forEach(item => {\n if (!item.id) return;\n\n // Automatically remove redundant `matchTags` - #3417, #8137\n // (i.e. This kv is already covered by matchGroups, so it doesn't need to be in `item.matchTags`\n // or this kv is the primary kv, so it doesn't need to be duplicated in `item.matchTags`)\n if (Array.isArray(item.matchTags) && item.matchTags.length) {\n item.matchTags = item.matchTags\n .filter(matchTag => !matchGroupKV.has(matchTag) && (matchTag !== thiskv) && !genericKV.has(matchTag));\n\n if (!item.matchTags.length) delete item.matchTags;\n }\n\n // key/value tagpairs to insert into the match index..\n let kvTags = [`${thiskv}`]\n .concat(item.matchTags || []);\n\n if (!skipGenericKV) {\n kvTags = kvTags\n .concat(Array.from(genericKV)); // #3454 - match some generic tags\n }\n\n // Index all the namelike tag values\n Object.keys(item.tags).forEach(osmkey => {\n if (notName.test(osmkey)) return; // osmkey is not a namelike tag, skip\n const osmvalue = item.tags[osmkey];\n if (!osmvalue || excludeRegexes.some(regex => regex.test(osmvalue))) return; // osmvalue missing or excluded\n\n if (primaryName.test(osmkey)) {\n kvTags.forEach(kv => insertName('primary', t, kv, simplify(osmvalue), item.id));\n } else if (alternateName.test(osmkey)) {\n kvTags.forEach(kv => insertName('alternate', t, kv, simplify(osmvalue), item.id));\n }\n });\n\n // Index `matchNames` after indexing all other names..\n let keepMatchNames = new Set();\n (item.matchNames || []).forEach(matchName => {\n // If this matchname isn't already indexed, add it to the alternate index\n const nsimple = simplify(matchName);\n kvTags.forEach(kv => {\n const branch = that.matchIndex.get(kv);\n const primaryLeaf = branch && branch.primary.get(nsimple);\n const alternateLeaf = branch && branch.alternate.get(nsimple);\n const inPrimary = primaryLeaf && primaryLeaf.has(item.id);\n const inAlternate = alternateLeaf && alternateLeaf.has(item.id);\n\n if (!inPrimary && !inAlternate) {\n insertName('alternate', t, kv, nsimple, item.id);\n keepMatchNames.add(matchName);\n }\n });\n });\n\n // Automatically remove redundant `matchNames` - #3417\n // (i.e. This name got indexed some other way, so it doesn't need to be in `item.matchNames`)\n if (keepMatchNames.size) {\n item.matchNames = Array.from(keepMatchNames);\n } else {\n delete item.matchNames;\n }\n\n }); // each item\n }); // each tkv\n\n\n // Insert this item into the matchIndex\n function insertName(which, t, kv, nsimple, itemID) {\n if (!nsimple) {\n that.warnings.push(`Warning: skipping empty ${which} name for item ${t}/${kv}: ${itemID}`);\n return;\n }\n\n let branch = that.matchIndex.get(kv);\n if (!branch) {\n branch = {\n primary: new Map(),\n alternate: new Map(),\n excludeGeneric: new Map(),\n excludeNamed: new Map()\n };\n that.matchIndex.set(kv, branch);\n }\n\n let leaf = branch[which].get(nsimple);\n if (!leaf) {\n leaf = new Set();\n branch[which].set(nsimple, leaf);\n }\n\n leaf.add(itemID); // insert\n\n // check for duplicates - #5625\n if (!/yes$/.test(kv)) { // ignore genericKV like amenity/yes, building/yes, etc\n const kvnsimple = `${kv}/${nsimple}`;\n const existing = seenTree.get(kvnsimple);\n if (existing && existing !== t) {\n const items = Array.from(leaf);\n that.warnings.push(`Duplicate cache key \"${kvnsimple}\" in trees \"${t}\" and \"${existing}\", check items: ${items}`);\n return;\n }\n seenTree.set(kvnsimple, t);\n }\n }\n\n // For certain categories we do not want to match generic KV pairs like `building/yes` or `amenity/yes`\n function skipGenericKVMatches(t, k, v) {\n return (\n t === 'flags' ||\n t === 'transit' ||\n k === 'landuse' ||\n v === 'atm' ||\n v === 'bicycle_parking' ||\n v === 'car_sharing' ||\n v === 'caravan_site' ||\n v === 'charging_station' ||\n v === 'dog_park' ||\n v === 'parking' ||\n v === 'phone' ||\n v === 'playground' ||\n v === 'post_box' ||\n v === 'public_bookcase' ||\n v === 'recycling' ||\n v === 'vending_machine'\n );\n }\n }\n\n\n //\n // `buildLocationIndex()`\n // Call this to prepare a which-polygon location index.\n // This *resolves* all the locationSets into GeoJSON, which takes some time.\n // You can skip this step if you don't care about matching within a location.\n //\n // `data` needs to be an Object indexed on a 'tree/key/value' path.\n // (e.g. cache filled by `fileTree.read` or data found in `dist/nsi.json`)\n // {\n // 'brands/amenity/bank': { properties: {}, items: [ {}, {}, \u2026 ] },\n // 'brands/amenity/bar': { properties: {}, items: [ {}, {}, \u2026 ] },\n // \u2026\n // }\n //\n buildLocationIndex(data, loco) {\n const that = this;\n if (that.locationIndex) return; // it was built already\n\n that.itemLocation = new Map();\n that.locationSets = new Map();\n\n Object.keys(data).forEach(tkv => {\n const items = data[tkv].items;\n if (!Array.isArray(items) || !items.length) return;\n\n items.forEach(item => {\n if (that.itemLocation.has(item.id)) return; // we've seen item id already - shouldn't be possible?\n\n let resolved;\n try {\n resolved = loco.resolveLocationSet(item.locationSet); // resolve