forked from balrog-kun/osm-addr-tools
-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate_inconsistent_symul.py
69 lines (63 loc) · 2.05 KB
/
generate_inconsistent_symul.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
from converters import teryt
from utils import mapping
import re
shorts = re.compile(r"(\w+\. )")
def main():
ulic = teryt.UlicCache().get_cache()
names_with_dots = []
objects = []
for (symul, names) in mapping.get_inconsistent_symul():
ulic_entry = ulic.get(symul)
ulic_name = ulic_entry.nazwa if ulic_entry else "N/A"
ulic_name = (
ulic_name[len("Ulica ") :] if "ULICA" in ulic_name.upper() else ulic_name
)
ulic_name = mapping.mapstreet(ulic_name, "")
most_popular_osm = max(names.items(), key=lambda x: x[1])[0]
if ulic_name == most_popular_osm:
pass
elif ulic_name in most_popular_osm:
ulic_name = most_popular_osm
elif shorts.sub("", ulic_name).replace(" ", " ") in most_popular_osm:
ulic_name = most_popular_osm
if "." not in ulic_name:
objects.append(
"""// TERYT: {teryt} OSM: {osm_names}
node["addr:street:sym_ul"="{symul}"]["addr:street"!="{street}"];
way["addr:street:sym_ul"="{symul}"]["addr:street"!="{street}"];
relation["addr:street:sym_ul"="{symul}"]["addr:street"!="{street}"];
""".format(
teryt=ulic_entry.nazwa if ulic_entry else "N/A",
osm_names=", ".join(
k
for k, _ in sorted(
names.items(), key=lambda x: x[1], reverse=True
)
),
symul=symul,
street=ulic_name.replace('"', '\\"'),
)
)
if "." in ulic_name:
names_with_dots.append(
"{} {:<40s} {}".format(symul, ulic_name, ", ".join(names))
)
print(
"""
[out:json][timeout:25];
// gather results
(
{}
);
// print results
out body;
>;
out skel qt;
""".format(
"".join(objects)
)
)
print("Names with dots:\n" + "\n".join(names_with_dots))
print(len(names_with_dots))
if __name__ == "__main__":
main()