Skip to content

Commit

Permalink
Name_UpperCase: Add whitelist of some names (osm-fr#537)
Browse files Browse the repository at this point in the history
Some names are meant to be in uppercase. Instead of complaining, just whitelist them per country.
  • Loading branch information
bilboed authored and frodrigo committed Jun 17, 2019
1 parent 3d288dd commit ee3bd19
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions plugins/Name_UpperCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
from plugins.Plugin import Plugin
import regex as re

# Whitelist of allowed capitals by country code
UpperCase_WhiteList = {
"FR": ["CNFPT", "COSEC", "EHPAD", "MACIF", "MEDEF", "URSSAF"]
}

class Name_UpperCase(Plugin):

Expand All @@ -32,11 +36,21 @@ def init(self, logger):
self.errors[803] = { "item": 5010, "level": 1, "tag": ["name", "fix:chair"], "desc": T_(u"Name with uppercase") }
self.UpperTitleCase = re.compile(u".*[\p{Lu}\p{Lt}]{5,}")
self.RomanNumber = re.compile(u".*[IVXCDLM]{5,}")
country = self.father.config.options.get("country")[:2]
self.whitelist = UpperCase_WhiteList.get(country, None)

def node(self, data, tags):
err = []
if u"name" in tags and self.UpperTitleCase.match(tags[u"name"]) and not self.RomanNumber.match(tags[u"name"]):
err.append({"class": 803})
if u"name" in tags:
# first check if the name *might* match
if self.UpperTitleCase.match(tags[u"name"]) and not self.RomanNumber.match(tags[u"name"]):
if self.whitelist is None:
err.append({"class": 803, "text":{"en":tags[u"name"]}})
else:
# Check if we match the whitelist and if so re-try
name = " ".join(i for i in tags[u"name"].split() if not i in self.whitelist)
if self.UpperTitleCase.match(name) and not self.RomanNumber.match(name):
err.append({"class": 803, "text":{"en":tags[u"name"]}})
return err

def way(self, data, tags, nds):
Expand All @@ -49,14 +63,21 @@ def way(self, data, tags, nds):
class Test(TestPluginCommon):
def test(self):
a = Name_UpperCase(None)
class _config:
options = {"country": "FR"}
class father:
config = _config()
a.father = father()
a.init(None)
for t in [{u"name": u"COL TRÈS HAUTTT"},
{u"name": u"EHPAD MAGEUSCULE"},
{u"name": u"AÇDZÞΣSSὩΙST"},
]:
self.check_err(a.node(None, t), t)
self.check_err(a.way(None, t, None), t)

for t in [{u"name": u"Col des Champs XIIVVVIM"},
{u"name": u"EHPAD La Madelon"},
{u"name": u"ƻאᎯᚦ京"},
]:
assert not a.node(None, t), t

0 comments on commit ee3bd19

Please sign in to comment.