Skip to content

Commit 15bbd20

Browse files
Famlamfrodrigo
authored andcommitted
Accept names from NSI with connected initials
1 parent 10dbd49 commit 15bbd20

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

plugins/Name_Initials.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
from modules.OsmoseTranslation import T_
2323
from plugins.Plugin import Plugin
24+
from plugins.modules.name_suggestion_index import whitelist_from_nsi
25+
import re
2426

2527

2628
class Name_Initials(Plugin):
@@ -30,15 +32,19 @@ def init(self, logger):
3032
self.errors[902] = self.def_class(item = 5010, level = 3, tags = ['name', 'fix:chair'],
3133
title = T_('Initial stuck to the name'))
3234

33-
import re
3435
self.ReInitColleNom = re.compile(r"^(.*[A-Z]\.)([A-Z][a-z].*)$")
3536

37+
self.whitelist = []
38+
if "country" in self.father.config.options:
39+
country = self.father.config.options.get("country")
40+
self.whitelist = list(filter(lambda name: "." in name.replace(". ", ""), whitelist_from_nsi(country)))
41+
3642
def node(self, data, tags):
3743
if "name" in tags:
38-
name = tags[u"name"]
44+
name = tags["name"]
3945
r = self.ReInitColleNom.match(name)
40-
if r: # and not u"E.Leclerc" in self._DataTags[u"name"]:
41-
return {"class":902, "subclass": 0, "text":{"en":tags[u"name"]}, "fix":{"name": "{0} {1}".format(r.group(1), r.group(2))}}
46+
if r and not any(map(lambda whitelist: whitelist in name, self.whitelist)):
47+
return {"class":902, "subclass": 0, "text":{"en":tags["name"]}, "fix":{"name": "{0} {1}".format(r.group(1), r.group(2))}}
4248

4349
def way(self, data, tags, nds):
4450
return self.node(data, tags)
@@ -50,14 +56,19 @@ def relation(self, data, tags, members):
5056
from plugins.Plugin import TestPluginCommon
5157

5258
class Test(TestPluginCommon):
53-
def setUp(self):
54-
TestPluginCommon.setUp(self)
55-
self.p = Name_Initials(None)
56-
self.p.init(None)
57-
5859
def test(self):
59-
self.check_err(self.p.node(None, {"name": "A.Bsuaeuae"}))
60-
self.check_err(self.p.way(None, {"name": "C.Dkuaeu"}, None))
61-
assert not self.p.relation(None, {"name": "E. Fiuaeuie"}, None)
62-
assert not self.p.node(None, {"name": "G.H."})
63-
assert not self.p.node(None, {"name": "GeHaueue"})
60+
a = Name_Initials(None)
61+
class _config:
62+
options = {"country": "NL"}
63+
class father:
64+
config = _config()
65+
a.father = father()
66+
a.init(None)
67+
68+
self.check_err(a.node(None, {"name": "A.Bsuaeuae"}))
69+
self.check_err(a.way(None, {"name": "C.Dkuaeu"}, None))
70+
assert not a.relation(None, {"name": "E. Fiuaeuie"}, None)
71+
assert not a.node(None, {"name": "G.H."})
72+
assert not a.node(None, {"name": "GeHaueue"})
73+
assert not a.node(None, {"name": "Station Service E.Leclerc"}) # NSI-whitelisted (global)
74+
assert not a.node(None, {"name": "Station Service E.Leclerc Paris"}) # NSI-whitelisted with suffix

0 commit comments

Comments
 (0)