How to use name-suggestion-index - 6 common examples

To help you get started, we’ve selected a few name-suggestion-index examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstreetmap / iD / build_data.js View on Github external
function suggestionsToPresets(presets) {
  const brands = nsi.brands.brands;
  const wikidata = nsi.wikidata.wikidata;

  Object.keys(brands).forEach(kvnd => {
    const suggestion = brands[kvnd];
    const qid = suggestion.tags['brand:wikidata'];
    if (!qid || !/^Q\d+$/.test(qid)) return;   // wikidata tag missing or looks wrong..

    const parts = kvnd.split('|', 2);
    const kv = parts[0];
    const name = parts[1].replace('~', ' ');

    let presetID, preset;

    // sometimes we can choose a more specific preset then key/value..
    if (suggestion.tags.cuisine) {
      // cuisine can contain multiple values, so try them all in order
github openstreetmap / iD / modules / validations / suspicious_name.js View on Github external
export function validationSuspiciousName() {
    var type = 'suspicious_name';

    // known list of generic names (e.g. "bar")
    var discardNamesRegexes = filters.discardNames.map(function(discardName) {
        return new RegExp(discardName, 'i');
    });

    var keysToTestForGenericValues = ['amenity', 'building', 'leisure', 'man_made', 'shop', 'tourism'];

    function isDiscardedSuggestionName(lowercaseName) {
        for (var i = 0; i < discardNamesRegexes.length; i++) {
            if (discardNamesRegexes[i].test(lowercaseName)) {
                return true;
            }
        }
        return false;
    }

    // test if the name is just the key or tag value (e.g. "park")
    function nameMatchesRawTag(lowercaseName, tags) {
github openstreetmap / iD / build_data.js View on Github external
function suggestionsToPresets(presets) {
  const brands = nsi.brands.brands;
  const wikidata = nsi.wikidata.wikidata;

  Object.keys(brands).forEach(kvnd => {
    const suggestion = brands[kvnd];
    const qid = suggestion.tags['brand:wikidata'];
    if (!qid || !/^Q\d+$/.test(qid)) return;   // wikidata tag missing or looks wrong..

    const parts = kvnd.split('|', 2);
    const kv = parts[0];
    const name = parts[1].replace('~', ' ');

    let presetID, preset;

    // sometimes we can choose a more specific preset then key/value..
    if (suggestion.tags.cuisine) {
      // cuisine can contain multiple values, so try them all in order
      let cuisines = suggestion.tags.cuisine.split(';');
github openstreetmap / iD / modules / validations / outdated_tags.js View on Github external
export function validationOutdatedTags(context) {
    var type = 'outdated_tags';

    // initialize name-suggestion-index matcher
    var nsiMatcher = matcher();
    nsiMatcher.buildMatchIndex(brands.brands);
    var nsiKeys = ['amenity', 'shop', 'tourism', 'leisure', 'office'];

    var allWD = {};
    var allWP = {};
    Object.keys(brands.brands).forEach(function(kvnd) {
        var brand = brands.brands[kvnd];
        var wd = brand.tags['brand:wikidata'];
        var wp = brand.tags['brand:wikipedia'];
        if (wd) { allWD[wd] = kvnd; }
        if (wp) { allWP[wp] = kvnd; }
    });


    function oldTagIssues(entity, graph) {
        var oldTags = Object.assign({}, entity.tags);  // shallow copy
        var preset = context.presets().match(entity, graph);
github openstreetmap / iD / modules / validations / outdated_tags.js View on Github external
// try key/value|name match against name-suggestion-index
        if (newTags.name) {
            for (var i = 0; i < nsiKeys.length; i++) {
                var k = nsiKeys[i];
                if (!newTags[k]) continue;

                var center = entity.extent(graph).center();
                var countryCode = countryCoder.iso1A2Code(center);
                var match = nsiMatcher.matchKVN(k, newTags[k], newTags.name, countryCode && countryCode.toLowerCase());
                if (!match) continue;

                // for now skip ambiguous matches (like Target~(USA) vs Target~(Australia))
                if (match.d) continue;

                var brand = brands.brands[match.kvnd];
                if (brand && brand.tags['brand:wikidata'] &&
                    brand.tags['brand:wikidata'] !== entity.tags['not:brand:wikidata']) {
                    subtype = 'noncanonical_brand';

                    var keepTags = ['takeaway'].reduce(function(acc, k) {
                        if (newTags[k]) {
                            acc[k] = newTags[k];
                        }
                        return acc;
                    }, {});

                    nsiKeys.forEach(function(k) { delete newTags[k]; });
                    Object.assign(newTags, brand.tags, keepTags);
                    break;
                }
            }
github openstreetmap / iD / modules / validations / outdated_tags.js View on Github external
export function validationOutdatedTags(context) {
    var type = 'outdated_tags';

    // initialize name-suggestion-index matcher
    var nsiMatcher = matcher();
    nsiMatcher.buildMatchIndex(brands.brands);
    var nsiKeys = ['amenity', 'shop', 'tourism', 'leisure', 'office'];

    var allWD = {};
    var allWP = {};
    Object.keys(brands.brands).forEach(function(kvnd) {
        var brand = brands.brands[kvnd];
        var wd = brand.tags['brand:wikidata'];
        var wp = brand.tags['brand:wikipedia'];
        if (wd) { allWD[wd] = kvnd; }
        if (wp) { allWP[wp] = kvnd; }
    });


    function oldTagIssues(entity, graph) {
        var oldTags = Object.assign({}, entity.tags);  // shallow copy

name-suggestion-index

Canonical common brand names for OpenStreetMap

BSD-3-Clause
Latest version published 7 days ago

Package Health Score

88 / 100
Full package analysis