From be3fbba090775aaa8c557951120ebfa1609979ef Mon Sep 17 00:00:00 2001 From: Famlam Date: Fri, 15 Nov 2024 23:24:43 +0100 Subject: [PATCH] 'Support' some geojson files In case the geojson file of NSI is named like an Osmose extract (e.g. like US Iowa, or Quebec (CA), it'll support include/exclude statements for those subregions. --- plugins/TagFix_Brand.py | 37 ++++++++++++++++++++++++ plugins/modules/name_suggestion_index.py | 8 +++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/plugins/TagFix_Brand.py b/plugins/TagFix_Brand.py index d574bafba..35c02d7f3 100644 --- a/plugins/TagFix_Brand.py +++ b/plugins/TagFix_Brand.py @@ -153,4 +153,41 @@ class father: a.father = father() a.init(None) + # Include CA, exclude CA-QC assert a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"}) + + def test_CA_ON(self): + a = TagFix_Brand(None) + class _config: + options = {"country": "CA-ON"} + class father: + config = _config() + a.father = father() + a.init(None) + + # Include CA, exclude CA-QC + assert a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"}) + + def test_CA_QC_LAN(self): + a = TagFix_Brand(None) + class _config: + options = {"country": "CA-QC-LAN"} + class father: + config = _config() + a.father = father() + a.init(None) + + # Include CA, exclude CA-QC + assert not a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"}) + + def test_CA_QC(self): + a = TagFix_Brand(None) + class _config: + options = {"country": "CA-QC"} + class father: + config = _config() + a.father = father() + a.init(None) + + # Include CA, exclude CA-QC + assert not a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"}) diff --git a/plugins/modules/name_suggestion_index.py b/plugins/modules/name_suggestion_index.py index b4f448a90..777415f83 100644 --- a/plugins/modules/name_suggestion_index.py +++ b/plugins/modules/name_suggestion_index.py @@ -39,13 +39,15 @@ def download_nsi(): def nsi_rule_applies(locationSet, country): if not "include" in locationSet and not "exclude" in locationSet: return True + incl = set(map(lambda c: str(c).lower().replace('.geojson', '', 1), locationSet["include"] if "include" in locationSet else [])) + excl = set(map(lambda c: str(c).lower().replace('.geojson', '', 1), locationSet["exclude"] if "exclude" in locationSet else [])) # For extract with country="AB-CD-EF", check "AB-CD-EF", then "AB-CD", then "AB", then worldwide ("001") for c in ['-'.join(country.lower().split("-")[:i]) for i in range(country.count("-")+1, 0, -1)]: - if "exclude" in locationSet and c in locationSet["exclude"]: + if c in excl: return False - if "include" in locationSet and c in locationSet["include"]: + if c in incl: return True - return not "include" in locationSet or "001" in locationSet["include"] + return len(incl) == 0 or "001" in locationSet["include"] # Gets all valid (shop, amenity, ...) names that exist within a certain country