-
Notifications
You must be signed in to change notification settings - Fork 0
/
ontology2html.rb
77 lines (72 loc) · 2.13 KB
/
ontology2html.rb
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
require 'json'
ontology = ARGV[0]
ontology = JSON.parse(File.read(ontology))
def i18n(label)
label.collect{ |key, text| "#{key}: #{text}" }.join(', ')
end
def icon(color_fill, font)
"<td style='background: #{color_fill}; color: white; font-size: 200%; padding: 5px'>
<center><i class='teritorio teritorio-#{font}'></i></center>
</td>"
end
def leaf(color_fill, color_line, font, id, c)
"<tr><td></td><td></td><td></td><td></td><td></td><td></td>
#{icon(color_fill, font)}
<td>#{id}</td>
<td>#{i18n(c["label"])}</td>
<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>
</tr>"
end
title = ontology["name"]
html = "<html><head>
<title>#{title}</title>
<link rel='stylesheet' href='https://unpkg.com/@teritorio/font-teritorio/teritorio/teritorio.css'>
<style>
table, td, th {
border: 1px solid black;
border-collapse: collapse;
padding: 2px;
}
</style>
</head>
<body><h1>#{title}</h1><table>"
html += "<tr>
<th></th><th>superclass_id</th><th>superclass label</th>
<th></th><th>class_id</th><th>class label</th>
<th></th><th>subclass_id</th><th>subclass label</th>
<th>i</th><th>z</th><th>p</th>
<th>Overpass</th>
<th>Extra tags</th>
</tr>"
ontology["superclass"].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"]
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|
html += leaf(
color_fill,
superclass["color_line"],
subclass_id,
subclass_id,
subclass,
)
}
else
html += leaf(
color_fill,
superclass["color_line"],
class_id,
class_id,
classs,
)
end
}
}
html += "</table></body></html>"
puts html