-
-
Notifications
You must be signed in to change notification settings - Fork 650
feat: Generate stores taxonomy from name-suggestion-index #9607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CloCkWeRX
wants to merge
27
commits into
openfoodfacts:main
Choose a base branch
from
CloCkWeRX:feature/7632-stores-taxinomy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18,346
−0
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2754512
Add a snapshot of https://raw.githubusercontent.com/osmlab/name-sugge…
CloCkWeRX 1f028eb
Add a generator
CloCkWeRX e4d3bb6
Comment out debugging for the moment
CloCkWeRX 19380cc
Add initially generated stores from OSM NSI
CloCkWeRX c9893a0
Unify naming
CloCkWeRX d0d0ee2
Append generated
CloCkWeRX b4eae74
Deal with english speakers vs country
CloCkWeRX 793992e
Fix script
CloCkWeRX 6863091
Append generated stores
CloCkWeRX 9cf7066
Only render country if available
CloCkWeRX af49be9
Only render wikidata if available
CloCkWeRX 94f0f09
English in the UK
CloCkWeRX c157240
Regenerated list
CloCkWeRX de13ba8
Merge lists
CloCkWeRX 2db44a8
Merge lists
CloCkWeRX 030f451
Merge branch 'main' into feature/7632-stores-taxinomy
CloCkWeRX e54359a
Merge branch 'main' into feature/7632-stores-taxinomy
CloCkWeRX 382bd70
Merge branch 'main' into feature/7632-stores-taxinomy
CloCkWeRX a945a09
Merge branch 'main' into feature/7632-stores-taxinomy
teolemon cb5fa75
Merge branch 'main' into feature/7632-stores-taxinomy
CloCkWeRX 9fcb62a
Merge branch 'main' into feature/7632-stores-taxinomy
CloCkWeRX cada148
Merge branch 'main' into feature/7632-stores-taxinomy
teolemon e3decb0
chore: Update NSI supermarkets to commit a86dd15d303126f8cfc7831aa395…
hangy 836c86f
typo
hangy 164d837
fix: enhance country code validation and language code handling in su…
hangy ebe5279
fix regexes and rerun script
hangy ea3c536
chore(taxonomies): resolve merge conflict in stores.txt keeping NSI r…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
298 changes: 298 additions & 0 deletions
298
taxonomies/external/name-suggestion-index/shop/supermarket.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,298 @@ | ||
| // A nodejs script to parse NameSuggestionIndex formatted JSON data and attempt to output valid taxonomy data. | ||
| // Do not use results without careful review | ||
| const data = require('./supermarket.json'); | ||
|
|
||
| // A quick ISO 3601 to human labels (english) mapping. | ||
| // TODO: Ensure this matches exactly with countries.txt | ||
| // TODO: Replace with a better lookup | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this utilise the |
||
| var iso3601 = { | ||
| "ad": "Andorra", | ||
| "ae": "United Arab Emirates", | ||
| "af": "Afghanistan", | ||
| "ag": "Antigua & Barbuda", | ||
| "ai": "Anguilla", | ||
| "al": "Albania", | ||
| "am": "Armenia", | ||
| "an": "Netherlands Antilles", | ||
| "ao": "Angola", | ||
| "aq": "Antarctica", | ||
| "ar": "Argentina", | ||
| "as": "American Samoa", | ||
| "at": "Austria", | ||
| "au": "Australia", | ||
| "aw": "Aruba", | ||
| "az": "Azerbaijan", | ||
| "ba": "Bosnia & Herzegovina", | ||
| "bb": "Barbados", | ||
| "bd": "Bangladesh", | ||
| "be": "Belgium", | ||
| "bf": "Burkina Faso", | ||
| "bg": "Bulgaria", | ||
| "bh": "Bahrain", | ||
| "bi": "Burundi", | ||
| "bj": "Benin", | ||
| "bm": "Bermuda", | ||
| "bn": "Brunei Darussalam", | ||
| "bo": "Bolivia", | ||
| "br": "Brazil", | ||
| "bs": "Bahamas", | ||
| "bt": "Bhutan", | ||
| "bv": "Bouvet Island", | ||
| "bw": "Botswana", | ||
| "by": "Belarus", | ||
| "bz": "Belize", | ||
| "ca": "Canada", | ||
| "cc": "Cocos (Keeling) Islands", | ||
| "cd": "Zaire", | ||
| "cf": "Central African Republic", | ||
| "cg": "Congo", | ||
| "ch": "Switzerland", | ||
| "ci": "Cote D'ivoire (Ivory Coast)", | ||
| "ck": "Cook Islands", | ||
| "cl": "Chile", | ||
| "cm": "Cameroon", | ||
| "cn": "China", | ||
| "co": "Colombia", | ||
| "cr": "Costa Rica", | ||
| "cu": "Cuba", | ||
| "cv": "Cape Verde", | ||
| "cx": "Christmas Island", | ||
| "cy": "Cyprus", | ||
| "cz": "Czech Republic", | ||
| "de": "Germany", | ||
| "dj": "Djibouti", | ||
| "dk": "Denmark", | ||
| "dm": "Dominica", | ||
| "do": "Dominican Republic", | ||
| "dz": "Algeria", | ||
| "ec": "Ecuador", | ||
| "ee": "Estonia", | ||
| "eg": "Egypt", | ||
| "eh": "Western Sahara", | ||
| "er": "Eritrea", | ||
| "es": "Spain", | ||
| "et": "Ethiopia", | ||
| "fi": "Finland", | ||
| "fj": "Fiji", | ||
| "fk": "Falkland Islands (Malvinas)", | ||
| "fm": "Micronesia", | ||
| "fo": "Faroe Islands", | ||
| "fr": "France", | ||
| "ga": "Gabon", | ||
| "gb": "United Kingdom", | ||
| "gd": "Grenada", | ||
| "ge": "Georgia", | ||
| "gf": "French Guiana", | ||
| "gh": "Ghana", | ||
| "gi": "Gibraltar", | ||
| "gl": "Greenland", | ||
| "gm": "Gambia", | ||
| "gn": "Guinea", | ||
| "gp": "Guadeloupe", | ||
| "gq": "Equatorial Guinea", | ||
| "gr": "Greece", | ||
| "gs": "S.Georgia & S.Sandwich Islands", | ||
| "gt": "Guatemala", | ||
| "gu": "Guam", | ||
| "gw": "Guinea-Bissau", | ||
| "gy": "Guyana", | ||
| "hk": "Hong Kong", | ||
| "hm": "Heard & McDonald Islands", | ||
| "hn": "Honduras", | ||
| "hr": "Croatia (Hrvatska)", | ||
| "ht": "Haiti", | ||
| "hu": "Hungary", | ||
| "id": "Indonesia", | ||
| "ie": "Ireland", | ||
| "il": "Israel", | ||
| "in": "India", | ||
| "io": "British Indian Ocean Territory", | ||
| "iq": "Iraq", | ||
| "ir": "Iran", | ||
| "is": "Iceland", | ||
| "it": "Italy", | ||
| "jm": "Jamaica", | ||
| "jo": "Jordan", | ||
| "jp": "Japan", | ||
| "ke": "Kenya", | ||
| "kg": "Kyrgyzstan", | ||
| "kh": "Cambodia", | ||
| "ki": "Kiribati", | ||
| "km": "Comoros", | ||
| "kn": "Saint Kitts & Nevis", | ||
| "kp": "Korea (North)", | ||
| "kr": "Korea (South)", | ||
| "kw": "Kuwait", | ||
| "ky": "Cayman Islands", | ||
| "kz": "Kazakhstan", | ||
| "la": "Laos", | ||
| "lb": "Lebanon", | ||
| "lc": "Saint Lucia", | ||
| "li": "Liechtenstein", | ||
| "lk": "Sri Lanka", | ||
| "lr": "Liberia", | ||
| "ls": "Lesotho", | ||
| "lt": "Lithuania", | ||
| "lu": "Luxembourg", | ||
| "lv": "Latvia", | ||
| "ly": "Libya", | ||
| "ma": "Morocco", | ||
| "mc": "Monaco", | ||
| "md": "Moldova", | ||
| "mg": "Madagascar", | ||
| "mh": "Marshall Islands", | ||
| "mk": "Macedonia", | ||
| "ml": "Mali", | ||
| "mm": "Myanmar", | ||
| "mn": "Mongolia", | ||
| "mo": "Macau", | ||
| "mp": "Northern Mariana Islands", | ||
| "mq": "Martinique", | ||
| "mr": "Mauritania", | ||
| "ms": "Montserrat", | ||
| "mt": "Malta", | ||
| "mu": "Mauritius", | ||
| "mv": "Maldives", | ||
| "mw": "Malawi", | ||
| "mx": "Mexico", | ||
| "my": "Malaysia", | ||
| "mz": "Mozambique", | ||
| "na": "Namibia", | ||
| "nc": "New Caledonia", | ||
| "ne": "Niger", | ||
| "nf": "Norfolk Island", | ||
| "ng": "Nigeria", | ||
| "ni": "Nicaragua", | ||
| "nl": "Netherlands", | ||
| "no": "Norway", | ||
| "np": "Nepal", | ||
| "nr": "Nauru", | ||
| "nu": "Niue", | ||
| "nz": "New Zealand", | ||
| "om": "Oman", | ||
| "pa": "Panama", | ||
| "pe": "Peru", | ||
| "pf": "French Polynesia", | ||
| "pg": "Papua New Guinea", | ||
| "ph": "Philippines", | ||
| "pk": "Pakistan", | ||
| "pl": "Poland", | ||
| "pm": "St. Pierre & Miquelon", | ||
| "pn": "Pitcairn", | ||
| "pr": "Puerto Rico", | ||
| "pt": "Portugal", | ||
| "pw": "Palau", | ||
| "py": "Paraguay", | ||
| "qa": "Qatar", | ||
| "re": "Reunion", | ||
| "ro": "Romania", | ||
| "ru": "Russian Federation", | ||
| "rw": "Rwanda", | ||
| "sa": "Saudi Arabia", | ||
| "sb": "Solomon Islands", | ||
| "sc": "Seychelles", | ||
| "sd": "Sudan", | ||
| "se": "Sweden", | ||
| "sg": "Singapore", | ||
| "sh": "St. Helena", | ||
| "si": "Slovenia", | ||
| "sj": "Svalbard & Jan Mayen Islands", | ||
| "sk": "Slovak Republic", | ||
| "sl": "Sierra Leone", | ||
| "sm": "San Marino", | ||
| "sn": "Senegal", | ||
| "so": "Somalia", | ||
| "sr": "Suriname", | ||
| "st": "Sao Tome & Principe", | ||
| "sv": "El Salvador", | ||
| "sy": "Syria", | ||
| "sz": "Swaziland", | ||
| "tc": "Turks & Caicos Islands", | ||
| "td": "Chad", | ||
| "tf": "French Southern Territories", | ||
| "tg": "Togo", | ||
| "th": "Thailand", | ||
| "tj": "Tajikistan", | ||
| "tk": "Tokelau", | ||
| "tm": "Turkmenistan", | ||
| "tn": "Tunisia", | ||
| "to": "Tonga", | ||
| "tp": "East Timor", | ||
| "tr": "Turkey", | ||
| "tt": "Trinidad & Tobago", | ||
| "tv": "Tuvalu", | ||
| "tw": "Taiwan", | ||
| "tz": "Tanzania", | ||
| "ua": "Ukraine", | ||
| "ug": "Uganda", | ||
| "us": "United States of America", | ||
| "uy": "Uruguay", | ||
| "uz": "Uzbekistan", | ||
| "va": "Vatican City (Holy See)", | ||
| "vc": "St. Vincent & the Grenadines", | ||
| "ve": "Venezuela", | ||
| "vg": "Virgin Islands (British)", | ||
| "vi": "Virgin Islands (U.S.)", | ||
| "vn": "Viet Nam", | ||
| "vu": "Vanuatu", | ||
| "wf": "Wallis & Futuna Islands", | ||
| "ws": "Samoa", | ||
| "ye": "Yemen", | ||
| "yt": "Mayotte", | ||
| "yu": "Yugoslavia", | ||
| "za": "South Africa", | ||
| "zm": "Zambia", | ||
| "zw": "Zimbabwe", | ||
| "fx": "France (Metropolitan)" | ||
| } | ||
|
|
||
| // Overrides for the language codes/mappings inferred by country code. | ||
| // TODO: This list is far, far from accurate or complete and should be replaced with any internal/authoritative mappings | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to use the language property from the |
||
| var iso3601_to_language_mappings = { | ||
| "ca": "en", | ||
| "au": "en", | ||
| "us": "en", | ||
| "gb": "en" | ||
| }; | ||
|
|
||
| data["items"].forEach(function (record) { | ||
| var countryCodes = record.locationSet["include"]; | ||
| var countryNames = []; | ||
|
|
||
| const languageMatcher = /^(?<language>[a-z]{2})$/i; | ||
| const countryMatcher = /^(?<country>[a-z]{2})(?:-.+)?$/i; | ||
| countryCodes.forEach(function (code) { | ||
| if (code == "001" || typeof code !== 'string') { | ||
| console.debug("Incompatible code type", code, typeof code); | ||
| return; | ||
| } | ||
|
|
||
| const isoMatch = code.match(countryMatcher); | ||
| if (!iso3601[isoMatch?.groups?.country]) { | ||
| console.debug("Unmapped ISO3601 code", code, isoMatch); | ||
| return; | ||
| } else { | ||
| countryNames.push("en:" + iso3601[isoMatch.groups.country]); | ||
| } | ||
| }); | ||
|
|
||
| var primaryCountryCode = countryCodes[0].toString().split("-")[0]; | ||
| var primaryLanguageCode = primaryCountryCode; | ||
| if (iso3601_to_language_mappings[primaryCountryCode]) { | ||
| primaryLanguageCode = iso3601_to_language_mappings[primaryCountryCode] | ||
| } | ||
|
|
||
| if (!languageMatcher.test(primaryLanguageCode)) { | ||
| console.debug("Unmapped language code", primaryLanguageCode); | ||
| primaryLanguageCode = "xx"; | ||
| } | ||
|
|
||
| process.stdout.write([primaryLanguageCode, record.displayName].join(":") + "\n"); | ||
| if (record.tags["brand:wikidata"]) { | ||
| process.stdout.write(["wikidata:en", record.tags["brand:wikidata"]].join(":") + "\n"); | ||
| } | ||
| if (countryNames.length > 0) { | ||
| process.stdout.write(["country:en:", countryNames.join(",")].join(" ") + "\n"); | ||
| } | ||
| process.stdout.write("\n"); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a big fan of the idea of leveraging NSI 👍
fyi I'm regularly contributing to the project, see openfoodfacts/open-prices#467 (comment)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe store a
nsi_id: carrefour-c622afto know that it comes from NSI ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to split these out into an stores-nsi.txt or something of that nature to more clearly split it; I feel like at the time I did this manually.
Script likely needs to be re-run since it's been ~2 years.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can have a look later this week and try to re-run the script myself.
if we switch to
xx:then the country mapping could be removed ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think country mapping could still be useful, esp. for cases where store-brands may have identical or near-identical names in different regions (see e.g. the 50 or so “COOP”s). (Mappings like
country:en: en:United States of America,en:United States of America,en:United States of America,en:United States of America,en:United States of Americaare probably a bit excessive though…). Maybe this is too much “preemptive optimisation(/complication)” though, and could be easily solved with a human-addedcomment:en:key or similar where it’s actually needed.Definitely +1 to using
xx:similar to ourbrands.txttaxonomy though, with possible locale specific overrides for locales with scripts other than the first/primaryxx:alias where relevant.