Skip to content

Commit

Permalink
Make format out of OSM
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Jan 17, 2025
1 parent 8a3c641 commit b3c5d66
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
28 changes: 14 additions & 14 deletions ontology-build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
if row["#{theme}_color_icon"]
current_superclasses = row["#{theme}_superclass"]
superclasses[current_superclasses] = {
label: { en: current_superclasses, fr: row["#{theme}_superclass:name:fr"] },
label: { en_GB: current_superclasses, fr_FR: row["#{theme}_superclass:name:fr"] },
color_fill: row["#{theme}_color_icon"].downcase,
color_line: row["#{theme}_color_text"].downcase,
attributes: row['attributes_superclass'].split,
Expand Down Expand Up @@ -51,7 +51,7 @@
plus_groups[tag[1..]] = current_group
elsif !tag.nil?
current_tag = {
label: { fr: row['name:fr'] },
label: { fr_FR: row['name:fr'] },
is_array: !row['array'].nil? && row['array'] != '',
values: row['value'] == '*' ? nil : [],
}
Expand All @@ -60,13 +60,13 @@
if current_tag[:values].nil?
puts "Error: value for non enum key: #{row['value']}"
end
current_tag[:values] << { value: row['value'], label: { fr: row['name:fr'] } }
current_tag[:values] << { value: row['value'], label: { fr_FR: row['name:fr'] } }
end
}
plus_groups.each{ |group_id, group|
group.each{ |tag, ct|
if !ct[:values].nil? && ct[:values].empty?
puts "Error: osm_tags_extra \"#{tag}\" with no values"
puts "Error: properties_extra \"#{tag}\" with no values"
ct[:values] = nil
end
}
Expand Down Expand Up @@ -122,35 +122,35 @@
rr['attributes'].any?{ |a| a == '' } and raise "Error: invalid attribute: #{rr['attributes'].inspect}"
value = rr['name_over_value'] || rr['value']
[value, {
label: { en: value, fr: rr['name:fr'] },
label: { en_GB: value, fr_FR: rr['name:fr'] },
zoom: rr["#{theme}_zoom"].to_i,
style: rr["#{theme}_style"],
priority: rr["#{theme}_priority"].to_i,
osm_tags: rr['overpass'].split(';'),
osm_tags_extra: rr['attributes'],
osm_selector: rr['overpass'].split(';'),
properties_extra: rr['attributes'],
}]
}.to_h
if sc
[classs, {
label: { en: classs, fr: sc0["#{theme}_class:name:fr"] },
subclass: sc,
label: { en_GB: classs, fr_FR: sc0["#{theme}_class:name:fr"] },
group: sc,
}]
else
[classs, {
label: { en: classs, fr: sc0["#{theme}_class:name:fr"] },
label: { en_GB: classs, fr_FR: sc0["#{theme}_class:name:fr"] },
zoom: sc0["#{theme}_zoom"].to_i,
style: sc0["#{theme}_style"],
priority: sc0["#{theme}_priority"].to_i,
}]
end
}.to_h
pop = c.delete(nil)
pop = pop[:subclass] if pop
pop = pop[:group] if pop
[superclass, {
label: superclasses[superclass][:label],
color_fill: superclasses[superclass][:color_fill],
color_line: superclasses[superclass][:color_line],
class: c.merge(pop || {}),
group: c.merge(pop || {}),
}]
}.to_h

Expand All @@ -162,6 +162,6 @@
file = File.open(ontology_json, 'w')
file.write(JSON.pretty_generate({
name: name,
superclass: hierarchy,
osm_tags_extra: plus_groups,
group: hierarchy,
properties_extra: plus_groups,
}))
8 changes: 4 additions & 4 deletions ontology-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ ruby ontology-build.rb tourism 'Ontology Tourism' \
ontology-tourism-superclass.csv \
ontology-tourism.csv \
ontology-tourism-extra_tags.csv \
build/teritorio-tourism-ontology-1.0.json
build/teritorio-tourism-ontology-2.0.json

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

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

ruby ontology2html.rb build/teritorio-city-ontology-1.0.json > build/teritorio-city-ontology-1.0.html
ruby ontology2html.rb build/teritorio-city-ontology-2.0.json > build/teritorio-city-ontology-2.0.html
12 changes: 6 additions & 6 deletions ontology2html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def leaf(color_fill, color_line, font, id, c)
<td>#{c["style"]}</td>
<td>#{c["zoom"]}</td>
<td>#{c["priority"]}</td>
<td>#{c["osm_tags"].join(' or</br>')}</td>
<td>#{c["osm_tags_extra"].join(', ')}</td>
<td>#{c["osm_selector"].join(' or</br>')}</td>
<td>#{c["properties_extra"].join(', ')}</td>
</tr>"
end

Expand All @@ -47,13 +47,13 @@ def leaf(color_fill, color_line, font, id, c)
<th>Overpass</th>
<th>Extra tags</th>
</tr>"
ontology["superclass"].each { |superclass_id, superclass|
ontology['group'].each { |superclass_id, superclass|
color_fill = superclass["color_fill"]
html += "<tr>#{icon(color_fill, superclass_id)}<td>#{superclass_id}</td><td colspan='99'>#{i18n(superclass["label"])}</td></tr>"
superclass["class"].each { |class_id, classs|
if classs["subclass"]
superclass['group'].each { |class_id, classs|
if classs['group']
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>"
classs["subclass"].each { |subclass_id, subclass|
classs['group'].each { |subclass_id, subclass|
html += leaf(
color_fill,
superclass["color_line"],
Expand Down

0 comments on commit b3c5d66

Please sign in to comment.