Skip to content

Commit f1ab72f

Browse files
committed
Make format out of OSM
1 parent 8a3c641 commit f1ab72f

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

ontology-build.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
if row["#{theme}_color_icon"]
2222
current_superclasses = row["#{theme}_superclass"]
2323
superclasses[current_superclasses] = {
24-
label: { en: current_superclasses, fr: row["#{theme}_superclass:name:fr"] },
24+
label: { en_GB: current_superclasses, fr_FR: row["#{theme}_superclass:name:fr"] },
2525
color_fill: row["#{theme}_color_icon"].downcase,
2626
color_line: row["#{theme}_color_text"].downcase,
2727
attributes: row['attributes_superclass'].split,
@@ -51,7 +51,7 @@
5151
plus_groups[tag[1..]] = current_group
5252
elsif !tag.nil?
5353
current_tag = {
54-
label: { fr: row['name:fr'] },
54+
label: { fr_FR: row['name:fr'] },
5555
is_array: !row['array'].nil? && row['array'] != '',
5656
values: row['value'] == '*' ? nil : [],
5757
}
@@ -60,13 +60,13 @@
6060
if current_tag[:values].nil?
6161
puts "Error: value for non enum key: #{row['value']}"
6262
end
63-
current_tag[:values] << { value: row['value'], label: { fr: row['name:fr'] } }
63+
current_tag[:values] << { value: row['value'], label: { fr_FR: row['name:fr'] } }
6464
end
6565
}
6666
plus_groups.each{ |group_id, group|
6767
group.each{ |tag, ct|
6868
if !ct[:values].nil? && ct[:values].empty?
69-
puts "Error: osm_tags_extra \"#{tag}\" with no values"
69+
puts "Error: properties_extra \"#{tag}\" with no values"
7070
ct[:values] = nil
7171
end
7272
}
@@ -122,35 +122,39 @@
122122
rr['attributes'].any?{ |a| a == '' } and raise "Error: invalid attribute: #{rr['attributes'].inspect}"
123123
value = rr['name_over_value'] || rr['value']
124124
[value, {
125-
label: { en: value, fr: rr['name:fr'] },
125+
label: { en_GB: value, fr_FR: rr['name:fr'] },
126+
icon: value,
126127
zoom: rr["#{theme}_zoom"].to_i,
127128
style: rr["#{theme}_style"],
128129
priority: rr["#{theme}_priority"].to_i,
129-
osm_tags: rr['overpass'].split(';'),
130-
osm_tags_extra: rr['attributes'],
130+
osm_selector: rr['overpass'].split(';'),
131+
properties_extra: rr['attributes'],
131132
}]
132133
}.to_h
133134
if sc
134135
[classs, {
135-
label: { en: classs, fr: sc0["#{theme}_class:name:fr"] },
136-
subclass: sc,
136+
label: { en_GB: classs, fr_FR: sc0["#{theme}_class:name:fr"] },
137+
icon: classs,
138+
group: sc,
137139
}]
138140
else
139141
[classs, {
140-
label: { en: classs, fr: sc0["#{theme}_class:name:fr"] },
142+
label: { en_GB: classs, fr_FR: sc0["#{theme}_class:name:fr"] },
143+
icon: classs,
141144
zoom: sc0["#{theme}_zoom"].to_i,
142145
style: sc0["#{theme}_style"],
143146
priority: sc0["#{theme}_priority"].to_i,
144147
}]
145148
end
146149
}.to_h
147150
pop = c.delete(nil)
148-
pop = pop[:subclass] if pop
151+
pop = pop[:group] if pop
149152
[superclass, {
150153
label: superclasses[superclass][:label],
154+
icon: superclass,
151155
color_fill: superclasses[superclass][:color_fill],
152156
color_line: superclasses[superclass][:color_line],
153-
class: c.merge(pop || {}),
157+
group: c.merge(pop || {}),
154158
}]
155159
}.to_h
156160

@@ -162,6 +166,6 @@
162166
file = File.open(ontology_json, 'w')
163167
file.write(JSON.pretty_generate({
164168
name: name,
165-
superclass: hierarchy,
166-
osm_tags_extra: plus_groups,
169+
group: hierarchy,
170+
properties_extra: plus_groups,
167171
}))

ontology-build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ ruby ontology-build.rb tourism 'Ontology Tourism' \
1616
ontology-tourism-superclass.csv \
1717
ontology-tourism.csv \
1818
ontology-tourism-extra_tags.csv \
19-
build/teritorio-tourism-ontology-1.0.json
19+
build/teritorio-tourism-ontology-2.0.json
2020

21-
ruby ontology2html.rb build/teritorio-tourism-ontology-1.0.json > build/teritorio-tourism-ontology-1.0.html
21+
ruby ontology2html.rb build/teritorio-tourism-ontology-2.0.json > build/teritorio-tourism-ontology-2.0.html
2222

2323
# City
2424
curl -L "${DOC_CITY}/export?format=csv&gid=2097204395" > ontology-city-superclass.csv
@@ -29,6 +29,6 @@ ruby ontology-build.rb city 'Ontology City' \
2929
ontology-city-superclass.csv \
3030
ontology-city.csv \
3131
ontology-city-extra_tags.csv \
32-
build/teritorio-city-ontology-1.0.json
32+
build/teritorio-city-ontology-2.0.json
3333

34-
ruby ontology2html.rb build/teritorio-city-ontology-1.0.json > build/teritorio-city-ontology-1.0.html
34+
ruby ontology2html.rb build/teritorio-city-ontology-2.0.json > build/teritorio-city-ontology-2.0.html

ontology2html.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def leaf(color_fill, color_line, font, id, c)
2121
<td>#{c["style"]}</td>
2222
<td>#{c["zoom"]}</td>
2323
<td>#{c["priority"]}</td>
24-
<td>#{c["osm_tags"].join(' or</br>')}</td>
25-
<td>#{c["osm_tags_extra"].join(', ')}</td>
24+
<td>#{c["osm_selector"].join(' or</br>')}</td>
25+
<td>#{c["properties_extra"].join(', ')}</td>
2626
</tr>"
2727
end
2828

@@ -47,17 +47,17 @@ def leaf(color_fill, color_line, font, id, c)
4747
<th>Overpass</th>
4848
<th>Extra tags</th>
4949
</tr>"
50-
ontology["superclass"].each { |superclass_id, superclass|
50+
ontology["group"].each { |superclass_id, superclass|
5151
color_fill = superclass["color_fill"]
52-
html += "<tr>#{icon(color_fill, superclass_id)}<td>#{superclass_id}</td><td colspan='99'>#{i18n(superclass["label"])}</td></tr>"
53-
superclass["class"].each { |class_id, classs|
54-
if classs["subclass"]
55-
html += "<tr><td></td><td></td><td></td>#{icon(color_fill, class_id)}<td>#{class_id}</td><td colspan='99'>#{i18n(classs["label"])}</td></tr>"
56-
classs["subclass"].each { |subclass_id, subclass|
52+
html += "<tr>#{icon(color_fill, superclass["icon"])}<td>#{superclass_id}</td><td colspan='99'>#{i18n(superclass["label"])}</td></tr>"
53+
superclass["group"].each { |class_id, classs|
54+
if classs["group"]
55+
html += "<tr><td></td><td></td><td></td>#{icon(color_fill, classs["icon"])}<td>#{class_id}</td><td colspan='99'>#{i18n(classs["label"])}</td></tr>"
56+
classs["group"].each { |subclass_id, subclass|
5757
html += leaf(
5858
color_fill,
5959
superclass["color_line"],
60-
subclass_id,
60+
subclass["icon"],
6161
subclass_id,
6262
subclass,
6363
)
@@ -66,7 +66,7 @@ def leaf(color_fill, color_line, font, id, c)
6666
html += leaf(
6767
color_fill,
6868
superclass["color_line"],
69-
class_id,
69+
classs["icon"],
7070
class_id,
7171
classs,
7272
)

0 commit comments

Comments
 (0)