build_brands.js
function checkBrands() {
    let warnMatched = [];
    let warnDuplicate = [];
    let warnFormatWikidata = [];
    let warnFormatWikipedia = [];
    let warnMissingWikidata = [];
    let warnMissingWikipedia = [];
    let warnMissingLogos = [];
    let warnMissingTag = [];
    let seen = {};

    Object.keys(brands).forEach(k => {
        let obj = brands[k];
        let parts = k.split('|', 2);
        let tag = parts[0];
        let name = parts[1];

        // Warn if the item is found in rIndex (i.e. some other item matches it)
        if (rIndex[k]) {
            warnMatched.push([rIndex[k], k]);
        }

        // Warn if the name appears to be a duplicate
        let stem = stemmer(name);
        let other = seen[stem];
        if (other) {
            // suppress warning?
            let suppress = false;
            if (brands[other].nomatch && brands[other].nomatch.indexOf(k) !== -1) {
                suppress = true;
            } else if (obj.nomatch && obj.nomatch.indexOf(other) !== -1) {
                suppress = true;
            }
            if (!suppress) {
                warnDuplicate.push([k, other]);
            }
        }
        seen[stem] = k;


        // Warn if `brand:wikidata` or `brand:wikipedia` tags are missing or look wrong..
        let wd = obj.tags['brand:wikidata'];
        if (!wd) {
            warnMissingWikidata.push(k);
        } else if (!/^Q\d+$/.test(wd)) {
            warnFormatWikidata.push([k, wd]);
        }
        let wp = obj.tags['brand:wikipedia'];
        if (!wp) {
            warnMissingWikipedia.push(k);
        } else if (!/^[a-z_]{2,}:[^_]*$/.test(wp)) {
            warnFormatWikipedia.push([k, wp]);
        }

        // Warn on missing logo
        let logos = (wd && _wikidata[wd] && _wikidata[wd].logos) || {};
        if (!Object.keys(logos).length) {
            warnMissingLogos.push(k);
        }

        // Warn on other missing tags
        switch (tag) {
            case 'amenity/fast_food':
            case 'amenity/restaurant':
                if (!obj.tags.cuisine) { warnMissingTag.push([k, 'cuisine']); }
                break;
            case 'amenity/vending_machine':
                if (!obj.tags.vending) { warnMissingTag.push([k, 'vending']); }
                break;
            case 'shop/beauty':
                if (!obj.tags.beauty) { warnMissingTag.push([k, 'beauty']); }
                break;
        }
    });

    if (warnMatched.length) {
        console.warn(colors.yellow('\nWarning - Brands matched to other brands:'));
        console.warn('To resolve these, remove the worse entry and add "match" property on the better entry.');
        warnMatched.forEach(w => console.warn(
            colors.yellow('  "' + w[0] + '"') + ' -> matches? -> ' + colors.yellow('"' + w[1] + '"')
        ));
        console.warn('total ' + warnMatched.length);
    }

    if (warnMissingTag.length) {
        console.warn(colors.yellow('\nWarning - Missing tags for brands:'));
        console.warn('To resolve these, add the missing tag.');
        warnMissingTag.forEach(w => console.warn(
            colors.yellow('  "' + w[0] + '"') + ' -> missing tag? -> ' + colors.yellow('"' + w[1] + '"')
        ));
        console.warn('total ' + warnMissingTag.length);
    }

    if (warnDuplicate.length) {
        console.warn(colors.yellow('\nWarning - Potential duplicate brand names:'));
        console.warn('To resolve these, remove the worse entry and add "match" property on the better entry.');
        console.warn('To suppress this warning for entries that really are different, add a "nomatch" property on both entries.');
        warnDuplicate.forEach(w => console.warn(
            colors.yellow('  "' + w[0] + '"') + ' -> duplicates? -> ' + colors.yellow('"' + w[1] + '"')
        ));
        console.warn('total ' + warnDuplicate.length);
    }

    // if (warnMissingWikidata.length) {
    //     console.warn(colors.yellow('\nWarning - Brand missing `brand:wikidata`:'));
    //     console.warn('To resolve these, make sure "brand:wikidata" tag looks like "Q191615".');
    //     warnMissingWikidata.forEach(w => console.warn(
    //         colors.yellow('  "' + w + '"') + ' -> missing -> "brand:wikidata"'
    //     ));
    //     console.warn('total ' + warnMissingWikidata.length);
    // }

    // if (warnMissingWikipedia.length) {
    //     console.warn(colors.yellow('\nWarning - Brand missing `brand:wikipedia`:'));
    //     console.warn('To resolve these, make sure "brand:wikipedia" tag looks like "en:Pizza Hut".');
    //     warnMissingWikipedia.forEach(w => console.warn(
    //         colors.yellow('  "' + w + '"') + ' -> missing -> "brand:wikipedia"'
    //     ));
    //     console.warn('total ' + warnMissingWikipedia.length);
    // }

    // if (warnMissingLogos.length) {
    //     console.warn(colors.yellow('\nWarning - Brand missing `logos`:'));
    //     console.warn('To resolve these, update the brands' entries on wikidata.org, then `npm run wikidata`.');
    //     warnMissingLogos.forEach(w => console.warn(
    //         colors.yellow('  "' + w + '"') + ' -> missing -> "logos"'
    //     ));
    //     console.warn('total ' + warnMissingLogos.length);
    // }

    if (warnFormatWikidata.length) {
        console.warn(colors.yellow('\nWarning - Brand with incorrect `brand:wikidata` format:'));
        console.warn('To resolve these, make sure "brand:wikidata" tag looks like "Q191615".');
        warnFormatWikidata.forEach(w => console.warn(
            colors.yellow('  "' + w[0] + '"') + ' -> "brand:wikidata": ' + '"' + w[1] + '"'
        ));
        console.warn('total ' + warnFormatWikidata.length);
    }

    if (warnFormatWikipedia.length) {
        console.warn(colors.yellow('\nWarning - Brand with incorrect `brand:wikipedia` format:'));
        console.warn('To resolve these, make sure "brand:wikipedia" tag looks like "en:Pizza Hut".');
        warnFormatWikipedia.forEach(w => console.warn(
            colors.yellow('  "' + w[0] + '"') + ' -> "brand:wikipedia": ' + '"' + w[1] + '"'
        ));
        console.warn('total ' + warnFormatWikipedia.length);
    }

    let total = Object.keys(brands).length;
    let hasWd = total - warnMissingWikidata.length;
    let pctWd = (hasWd * 100 / total).toFixed(1);
    let hasLogos = total - warnMissingLogos.length;
    let pctLogos = (hasLogos * 100 / total).toFixed(1);
    console.info(colors.blue.bold(`\nIndex completeness:`));
    console.info(colors.blue.bold(`  ${total} entries total.`));
    console.info(colors.blue.bold(`  ${hasWd} (${pctWd}%) with a 'brand:wikidata' tag.`));
    console.info(colors.blue.bold(`  ${hasLogos} (${pctLogos}%) with a logo.`));
}
function checkBrands() {
    let warnMatched = [];
    let warnDuplicate = [];
    let warnFormatWikidata = [];
    let warnFormatWikipedia = [];
    let warnMissingWikidata = [];
    let warnMissingWikipedia = [];
    let warnMissingLogos = [];
    let warnMissingTag = [];
    let seen = {};

    Object.keys(brands).forEach(k => {
        let obj = brands[k];
        let parts = k.split('|', 2);
        let tag = parts[0];
        let name = parts[1];

        // Warn if the item is found in rIndex (i.e. some other item matches it)
        if (rIndex[k]) {
            warnMatched.push([rIndex[k], k]);
        }

        // Warn if the name appears to be a duplicate
        let stem = stemmer(name);
        let other = seen[stem];
        if (other) {
            // suppress warning?
            let suppress = false;
            if (brands[other].nomatch && brands[other].nomatch.indexOf(k) !== -1) {
                suppress = true;
            } else if (obj.nomatch && obj.nomatch.indexOf(other) !== -1) {
                suppress = true;
            }
            if (!suppress) {
                warnDuplicate.push([k, other]);
            }
        }
        seen[stem] = k;


        // Warn if `brand:wikidata` or `brand:wikipedia` tags are missing or look wrong..
        let wd = obj.tags['brand:wikidata'];
        if (!wd) {
            warnMissingWikidata.push(k);
        } else if (!/^Q\d+$/.test(wd)) {
            warnFormatWikidata.push([k, wd]);
        }
        let wp = obj.tags['brand:wikipedia'];
        if (!wp) {
            warnMissingWikipedia.push(k);
        } else if (!/^[a-z_]{2,}:[^_]*$/.test(wp)) {
            warnFormatWikipedia.push([k, wp]);
        }

        // Warn on missing logo
        let logos = (wd && _wikidata[wd] && _wikidata[wd].logos) || {};
        if (!Object.keys(logos).length) {
            warnMissingLogos.push(k);
        }

        // Warn on other missing tags
        switch (tag) {
            case 'amenity/fast_food':
            case 'amenity/restaurant':
                if (!obj.tags.cuisine) { warnMissingTag.push([k, 'cuisine']); }
                break;
            case 'amenity/vending_machine':
                if (!obj.tags.vending) { warnMissingTag.push([k, 'vending']); }
                break;
            case 'shop/beauty':
                if (!obj.tags.beauty) { warnMissingTag.push([k, 'beauty']); }
                break;
        }
    });

    if (warnMatched.length) {
        console.warn(colors.yellow('\nWarning - Brands matched to other brands:'));
        console.warn('To resolve these, remove the worse entry and add "match" property on the better entry.');
        warnMatched.forEach(w => console.warn(
            colors.yellow('  "' + w[0] + '"') + ' -> matches? -> ' + colors.yellow('"' + w[1] + '"')
        ));
        console.warn('total ' + warnMatched.length);
    }

    if (warnMissingTag.length) {
        console.warn(colors.yellow('\nWarning - Missing tags for brands:'));
        console.warn('To resolve these, add the missing tag.');
        warnMissingTag.forEach(w => console.warn(
            colors.yellow('  "' + w[0] + '"') + ' -> missing tag? -> ' + colors.yellow('"' + w[1] + '"')
        ));
        console.warn('total ' + warnMissingTag.length);
    }

    if (warnDuplicate.length) {
        console.warn(colors.yellow('\nWarning - Potential duplicate brand names:'));
        console.warn('To resolve these, remove the worse entry and add "match" property on the better entry.');
        console.warn('To suppress this warning for entries that really are different, add a "nomatch" property on both entries.');
        warnDuplicate.forEach(w => console.warn(
            colors.yellow('  "' + w[0] + '"') + ' -> duplicates? -> ' + colors.yellow('"' + w[1] + '"')
        ));
        console.warn('total ' + warnDuplicate.length);
    }

    // if (warnMissingWikidata.length) {
    //     console.warn(colors.yellow('\nWarning - Brand missing `brand:wikidata`:'));
    //     console.warn('To resolve these, make sure "brand:wikidata" tag looks like "Q191615".');
    //     warnMissingWikidata.forEach(w => console.warn(
    //         colors.yellow('  "' + w + '"') + ' -> missing -> "brand:wikidata"'
    //     ));
    //     console.warn('total ' + warnMissingWikidata.length);
    // }

    // if (warnMissingWikipedia.length) {
    //     console.warn(colors.yellow('\nWarning - Brand missing `brand:wikipedia`:'));
    //     console.warn('To resolve these, make sure "brand:wikipedia" tag looks like "en:Pizza Hut".');
    //     warnMissingWikipedia.forEach(w => console.warn(
    //         colors.yellow('  "' + w + '"') + ' -> missing -> "brand:wikipedia"'
    //     ));
    //     console.warn('total ' + warnMissingWikipedia.length);
    // }

    // if (warnMissingLogos.length) {
    //     console.warn(colors.yellow('\nWarning - Brand missing `logos`:'));
    //     console.warn('To resolve these, update the brands' entries on wikidata.org, then `npm run wikidata`.');
    //     warnMissingLogos.forEach(w => console.warn(
    //         colors.yellow('  "' + w + '"') + ' -> missing -> "logos"'
    //     ));
    //     console.warn('total ' + warnMissingLogos.length);
    // }

    if (warnFormatWikidata.length) {
        console.warn(colors.yellow('\nWarning - Brand with incorrect `brand:wikidata` format:'));
        console.warn('To resolve these, make sure "brand:wikidata" tag looks like "Q191615".');
        warnFormatWikidata.forEach(w => console.warn(
            colors.yellow('  "' + w[0] + '"') + ' -> "brand:wikidata": ' + '"' + w[1] + '"'
        ));
        console.warn('total ' + warnFormatWikidata.length);
    }

    if (warnFormatWikipedia.length) {
        console.warn(colors.yellow('\nWarning - Brand with incorrect `brand:wikipedia` format:'));
        console.warn('To resolve these, make sure "brand:wikipedia" tag looks like "en:Pizza Hut".');
        warnFormatWikipedia.forEach(w => console.warn(
            colors.yellow('  "' + w[0] + '"') + ' -> "brand:wikipedia": ' + '"' + w[1] + '"'
        ));
        console.warn('total ' + warnFormatWikipedia.length);
    }

    let total = Object.keys(brands).length;
    let hasWd = total - warnMissingWikidata.length;
    let pctWd = (hasWd * 100 / total).toFixed(1);
    let hasLogos = total - warnMissingLogos.length;
    let pctLogos = (hasLogos * 100 / total).toFixed(1);
    console.info(colors.blue.bold(`\nIndex completeness:`));
    console.info(colors.blue.bold(`  ${total} entries total.`));
    console.info(colors.blue.bold(`  ${hasWd} (${pctWd}%) with a 'brand:wikidata' tag.`));
    console.info(colors.blue.bold(`  ${hasLogos} (${pctLogos}%) with a logo.`));
}
function checkBrands ( ) { let warnMatched = [ ] ; let warnDuplicate = [ ] ; let warnFormatWikidata = [ ] ; let warnFormatWikipedia = [ ] ; let warnMissingWikidata = [ ] ; let warnMissingWikipedia = [ ] ; let warnMissingLogos = [ ] ; let warnMissingTag = [ ] ; let seen = { } ; Object . keys ( brands ) . forEach ( k => { let obj = brands [ k ] ; let parts = k . split ( '|' , 2 ) ; let tag = parts [ 0 ] ; let name = parts [ 1 ] ; // Warn if the item is found in rIndex (i.e. some other item matches it) if ( rIndex [ k ] ) { warnMatched . push ( [ rIndex [ k ] , k ] ) ; } // Warn if the name appears to be a duplicate let stem = stemmer ( name ) ; let other = seen [ stem ] ; if ( other ) { // suppress warning? let suppress = false ; if ( brands [ other ] . nomatch && brands [ other ] . nomatch . indexOf ( k ) !== - 1 ) { suppress = true ; } else if ( obj . nomatch && obj . nomatch . indexOf ( other ) !== - 1 ) { suppress = true ; } if ( ! suppress ) { warnDuplicate . push ( [ k , other ] ) ; } } seen [ stem ] = k ; // Warn if `brand:wikidata` or `brand:wikipedia` tags are missing or look wrong.. let wd = obj . tags [ 'brand:wikidata' ] ; if ( ! wd ) { warnMissingWikidata . push ( k ) ; } else if ( ! / ^Q\d+$ / . test ( wd ) ) { warnFormatWikidata . push ( [ k , wd ] ) ; } let wp = obj . tags [ 'brand:wikipedia' ] ; if ( ! wp ) { warnMissingWikipedia . push ( k ) ; } else if ( ! / ^[a-z_]{2,}:[^_]*$ / . test ( wp ) ) { warnFormatWikipedia . push ( [ k , wp ] ) ; } // Warn on missing logo let logos = ( wd && _wikidata [ wd ] && _wikidata [ wd ] . logos ) || { } ; if ( ! Object . keys ( logos ) . length ) { warnMissingLogos . push ( k ) ; } // Warn on other missing tags switch ( tag ) { case 'amenity/fast_food' : case 'amenity/restaurant' : if ( ! obj . tags . cuisine ) { warnMissingTag . push ( [ k , 'cuisine' ] ) ; } break ; case 'amenity/vending_machine' : if ( ! obj . tags . vending ) { warnMissingTag . push ( [ k , 'vending' ] ) ; } break ; case 'shop/beauty' : if ( ! obj . tags . beauty ) { warnMissingTag . push ( [ k , 'beauty' ] ) ; } break ; } } ) ; if ( warnMatched . length ) { console . warn ( colors . yellow ( '\nWarning - Brands matched to other brands:' ) ) ; console . warn ( 'To resolve these, remove the worse entry and add "match" property on the better entry.' ) ; warnMatched . forEach ( w => console . warn ( colors . yellow ( '  "' + w [ 0 ] + '"' ) + ' -> matches? -> ' + colors . yellow ( '"' + w [ 1 ] + '"' ) ) ) ; console . warn ( 'total ' + warnMatched . length ) ; } if ( warnMissingTag . length ) { console . warn ( colors . yellow ( '\nWarning - Missing tags for brands:' ) ) ; console . warn ( 'To resolve these, add the missing tag.' ) ; warnMissingTag . forEach ( w => console . warn ( colors . yellow ( '  "' + w [ 0 ] + '"' ) + ' -> missing tag? -> ' + colors . yellow ( '"' + w [ 1 ] + '"' ) ) ) ; console . warn ( 'total ' + warnMissingTag . length ) ; } if ( warnDuplicate . length ) { console . warn ( colors . yellow ( '\nWarning - Potential duplicate brand names:' ) ) ; console . warn ( 'To resolve these, remove the worse entry and add "match" property on the better entry.' ) ; console . warn ( 'To suppress this warning for entries that really are different, add a "nomatch" property on both entries.' ) ; warnDuplicate . forEach ( w => console . warn ( colors . yellow ( '  "' + w [ 0 ] + '"' ) + ' -> duplicates? -> ' + colors . yellow ( '"' + w [ 1 ] + '"' ) ) ) ; console . warn ( 'total ' + warnDuplicate . length ) ; } // if (warnMissingWikidata.length) { //     console.warn(colors.yellow('\nWarning - Brand missing `brand:wikidata`:')); //     console.warn('To resolve these, make sure "brand:wikidata" tag looks like "Q191615".'); //     warnMissingWikidata.forEach(w => console.warn( //         colors.yellow('  "' + w + '"') + ' -> missing -> "brand:wikidata"' //     )); //     console.warn('total ' + warnMissingWikidata.length); // } // if (warnMissingWikipedia.length) { //     console.warn(colors.yellow('\nWarning - Brand missing `brand:wikipedia`:')); //     console.warn('To resolve these, make sure "brand:wikipedia" tag looks like "en:Pizza Hut".'); //     warnMissingWikipedia.forEach(w => console.warn( //         colors.yellow('  "' + w + '"') + ' -> missing -> "brand:wikipedia"' //     )); //     console.warn('total ' + warnMissingWikipedia.length); // } // if (warnMissingLogos.length) { //     console.warn(colors.yellow('\nWarning - Brand missing `logos`:')); //     console.warn('To resolve these, update the brands' entries on wikidata.org, then `npm run wikidata`.'); //     warnMissingLogos.forEach(w => console.warn( //         colors.yellow('  "' + w + '"') + ' -> missing -> "logos"' //     )); //     console.warn('total ' + warnMissingLogos.length); // } if ( warnFormatWikidata . length ) { console . warn ( colors . yellow ( '\nWarning - Brand with incorrect `brand:wikidata` format:' ) ) ; console . warn ( 'To resolve these, make sure "brand:wikidata" tag looks like "Q191615".' ) ; warnFormatWikidata . forEach ( w => console . warn ( colors . yellow ( '  "' + w [ 0 ] + '"' ) + ' -> "brand:wikidata": ' + '"' + w [ 1 ] + '"' ) ) ; console . warn ( 'total ' + warnFormatWikidata . length ) ; } if ( warnFormatWikipedia . length ) { console . warn ( colors . yellow ( '\nWarning - Brand with incorrect `brand:wikipedia` format:' ) ) ; console . warn ( 'To resolve these, make sure "brand:wikipedia" tag looks like "en:Pizza Hut".' ) ; warnFormatWikipedia . forEach ( w => console . warn ( colors . yellow ( '  "' + w [ 0 ] + '"' ) + ' -> "brand:wikipedia": ' + '"' + w [ 1 ] + '"' ) ) ; console . warn ( 'total ' + warnFormatWikipedia . length ) ; } let total = Object . keys ( brands ) . length ; let hasWd = total - warnMissingWikidata . length ; let pctWd = ( hasWd * 100 / total ) . toFixed ( 1 ) ; let hasLogos = total - warnMissingLogos . length ; let pctLogos = ( hasLogos * 100 / total ) . toFixed ( 1 ) ; console . info ( colors . blue . bold ( ` \n ` ) ) ; console . info ( colors . blue . bold ( ` ${ total } ` ) ) ; console . info ( colors . blue . bold ( ` ${ hasWd } ${ pctWd } ` ) ) ; console . info ( colors . blue . bold ( ` ${ hasLogos } ${ pctLogos } ` ) ) ; }
Checks all the brands for several kinds of issues
Checks all the brands for several kinds of issues