-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathJosm_territories.py
188 lines (159 loc) · 11.8 KB
/
Josm_territories.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#-*- coding: utf-8 -*-
import modules.mapcss_lib as mapcss
import regex as re # noqa
from plugins.Plugin import with_options # noqa
from plugins.PluginMapCSS import PluginMapCSS
class Josm_territories(PluginMapCSS):
MAPCSS_URL = 'https://josm.openstreetmap.de/browser/josm/trunk/resources/data/validator/territories.mapcss'
def init(self, logger):
super().init(logger)
tags = capture_tags = {} # noqa
self.errors[9009001] = self.def_class(item = 9009, level = 3, tags = ["tag"], title = mapcss.tr('deprecated tagging'))
self.errors[9009002] = self.def_class(item = 9009, level = 2, tags = ["tag"], title = mapcss.tr('street name contains ss'))
self.errors[9009003] = self.def_class(item = 9009, level = 2, tags = ["tag"], title = mapcss.tr('street name contains ß'))
self.re_1596ad87 = re.compile(r'(?i).*spannungstrasse.*')
self.re_3d3faeb5 = re.compile(r'(?i).*Straße.*')
self.re_559797c8 = re.compile(r'(?i).*Strasser.*')
self.re_5b84a257 = re.compile(r'(?i).*Strasse.*')
def node(self, data, tags):
capture_tags = {}
keys = tags.keys()
err = []
# *[addr:street=~/(?i).*Strasse.*/][addr:street!~/(?i).*Strasser.*/][inside("DE,AT")]
# *[name=~/(?i).*Strasse.*/][name!~/(?i).*Strasser.*/][name!~/(?i).*spannungstrasse.*/][inside("DE,AT")]
if ('addr:street' in keys) or ('name' in keys):
match = False
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_5b84a257), mapcss._tag_capture(capture_tags, 0, tags, 'addr:street'))) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 1, self.re_559797c8, '(?i).*Strasser.*'), mapcss._tag_capture(capture_tags, 1, tags, 'addr:street'))) and (mapcss.inside(self.father.config.options, 'DE,AT')))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_5b84a257), mapcss._tag_capture(capture_tags, 0, tags, 'name'))) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 1, self.re_559797c8, '(?i).*Strasser.*'), mapcss._tag_capture(capture_tags, 1, tags, 'name'))) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 2, self.re_1596ad87, '(?i).*spannungstrasse.*'), mapcss._tag_capture(capture_tags, 2, tags, 'name'))) and (mapcss.inside(self.father.config.options, 'DE,AT')))
except mapcss.RuleAbort: pass
if match:
# throwError:tr("street name contains ss")
err.append({'class': 9009002, 'subclass': 1817721249, 'text': mapcss.tr('street name contains ss')})
# *[addr:street=~/(?i).*Straße.*/][inside("LI,CH")]
# *[name=~/(?i).*Straße.*/][inside("LI,CH")]
if ('addr:street' in keys) or ('name' in keys):
match = False
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_3d3faeb5), mapcss._tag_capture(capture_tags, 0, tags, 'addr:street'))) and (mapcss.inside(self.father.config.options, 'LI,CH')))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_3d3faeb5), mapcss._tag_capture(capture_tags, 0, tags, 'name'))) and (mapcss.inside(self.father.config.options, 'LI,CH')))
except mapcss.RuleAbort: pass
if match:
# throwError:tr("street name contains ß")
err.append({'class': 9009003, 'subclass': 610086334, 'text': mapcss.tr('street name contains ß')})
return err
def way(self, data, tags, nds):
capture_tags = {}
keys = tags.keys()
err = []
# *[addr:street=~/(?i).*Strasse.*/][addr:street!~/(?i).*Strasser.*/][inside("DE,AT")]
# *[name=~/(?i).*Strasse.*/][name!~/(?i).*Strasser.*/][name!~/(?i).*spannungstrasse.*/][inside("DE,AT")]
if ('addr:street' in keys) or ('name' in keys):
match = False
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_5b84a257), mapcss._tag_capture(capture_tags, 0, tags, 'addr:street'))) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 1, self.re_559797c8, '(?i).*Strasser.*'), mapcss._tag_capture(capture_tags, 1, tags, 'addr:street'))) and (mapcss.inside(self.father.config.options, 'DE,AT')))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_5b84a257), mapcss._tag_capture(capture_tags, 0, tags, 'name'))) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 1, self.re_559797c8, '(?i).*Strasser.*'), mapcss._tag_capture(capture_tags, 1, tags, 'name'))) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 2, self.re_1596ad87, '(?i).*spannungstrasse.*'), mapcss._tag_capture(capture_tags, 2, tags, 'name'))) and (mapcss.inside(self.father.config.options, 'DE,AT')))
except mapcss.RuleAbort: pass
if match:
# throwError:tr("street name contains ss")
# assertMatch:"way name=Hauptstrasse"
# assertNoMatch:"way name=Hauptstraße"
# assertNoMatch:"way name=Hochspannungstrasse"
# assertNoMatch:"way name=Kapitän-Strasser-Straße"
# assertNoMatch:"way name=Peter-Strasser-Platz"
err.append({'class': 9009002, 'subclass': 1817721249, 'text': mapcss.tr('street name contains ss')})
# *[addr:street=~/(?i).*Straße.*/][inside("LI,CH")]
# *[name=~/(?i).*Straße.*/][inside("LI,CH")]
if ('addr:street' in keys) or ('name' in keys):
match = False
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_3d3faeb5), mapcss._tag_capture(capture_tags, 0, tags, 'addr:street'))) and (mapcss.inside(self.father.config.options, 'LI,CH')))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_3d3faeb5), mapcss._tag_capture(capture_tags, 0, tags, 'name'))) and (mapcss.inside(self.father.config.options, 'LI,CH')))
except mapcss.RuleAbort: pass
if match:
# throwError:tr("street name contains ß")
# assertNoMatch:"way name=Hauptstrasse"
# assertMatch:"way name=Hauptstraße"
err.append({'class': 9009003, 'subclass': 610086334, 'text': mapcss.tr('street name contains ß')})
return err
def relation(self, data, tags, members):
capture_tags = {}
keys = tags.keys()
err = []
# *[addr:street=~/(?i).*Strasse.*/][addr:street!~/(?i).*Strasser.*/][inside("DE,AT")]
# *[name=~/(?i).*Strasse.*/][name!~/(?i).*Strasser.*/][name!~/(?i).*spannungstrasse.*/][inside("DE,AT")]
if ('addr:street' in keys) or ('name' in keys):
match = False
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_5b84a257), mapcss._tag_capture(capture_tags, 0, tags, 'addr:street'))) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 1, self.re_559797c8, '(?i).*Strasser.*'), mapcss._tag_capture(capture_tags, 1, tags, 'addr:street'))) and (mapcss.inside(self.father.config.options, 'DE,AT')))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_5b84a257), mapcss._tag_capture(capture_tags, 0, tags, 'name'))) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 1, self.re_559797c8, '(?i).*Strasser.*'), mapcss._tag_capture(capture_tags, 1, tags, 'name'))) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 2, self.re_1596ad87, '(?i).*spannungstrasse.*'), mapcss._tag_capture(capture_tags, 2, tags, 'name'))) and (mapcss.inside(self.father.config.options, 'DE,AT')))
except mapcss.RuleAbort: pass
if match:
# throwError:tr("street name contains ss")
err.append({'class': 9009002, 'subclass': 1817721249, 'text': mapcss.tr('street name contains ss')})
# *[addr:street=~/(?i).*Straße.*/][inside("LI,CH")]
# *[name=~/(?i).*Straße.*/][inside("LI,CH")]
if ('addr:street' in keys) or ('name' in keys):
match = False
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_3d3faeb5), mapcss._tag_capture(capture_tags, 0, tags, 'addr:street'))) and (mapcss.inside(self.father.config.options, 'LI,CH')))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = ((mapcss.regexp_test(mapcss._value_capture(capture_tags, 0, self.re_3d3faeb5), mapcss._tag_capture(capture_tags, 0, tags, 'name'))) and (mapcss.inside(self.father.config.options, 'LI,CH')))
except mapcss.RuleAbort: pass
if match:
# throwError:tr("street name contains ß")
err.append({'class': 9009003, 'subclass': 610086334, 'text': mapcss.tr('street name contains ß')})
# relation[type=associatedStreet][inside("DE")]
if ('type' in keys):
match = False
if not match:
capture_tags = {}
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'type') == mapcss._value_capture(capture_tags, 0, 'associatedStreet')) and (mapcss.inside(self.father.config.options, 'DE')))
except mapcss.RuleAbort: pass
if match:
# group:tr("deprecated tagging")
# throwWarning:tr("{0} is deprecated in {1}","{0.tag}","Deutschland")
# suggestAlternative:"addr:street"
err.append({'class': 9009001, 'subclass': 746730328, 'text': mapcss.tr('{0} is deprecated in {1}', mapcss._tag_uncapture(capture_tags, '{0.tag}'), 'Deutschland')})
return err
from plugins.PluginMapCSS import TestPluginMapcss
class Test(TestPluginMapcss):
def test(self):
n = Josm_territories(None)
class _config:
options = {"country": None, "language": None}
class father:
config = _config()
n.father = father()
n.init(None)
data = {'id': 0, 'lat': 0, 'lon': 0}
self.check_err(n.way(data, {'name': 'Hauptstrasse'}, [0]), expected={'class': 9009002, 'subclass': 1817721249})
self.check_not_err(n.way(data, {'name': 'Hauptstraße'}, [0]), expected={'class': 9009002, 'subclass': 1817721249})
self.check_not_err(n.way(data, {'name': 'Hochspannungstrasse'}, [0]), expected={'class': 9009002, 'subclass': 1817721249})
self.check_not_err(n.way(data, {'name': 'Kapitän-Strasser-Straße'}, [0]), expected={'class': 9009002, 'subclass': 1817721249})
self.check_not_err(n.way(data, {'name': 'Peter-Strasser-Platz'}, [0]), expected={'class': 9009002, 'subclass': 1817721249})
self.check_not_err(n.way(data, {'name': 'Hauptstrasse'}, [0]), expected={'class': 9009003, 'subclass': 610086334})
self.check_err(n.way(data, {'name': 'Hauptstraße'}, [0]), expected={'class': 9009003, 'subclass': 610086334})