-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_doc.py
80 lines (70 loc) · 3.33 KB
/
build_doc.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
from pylode.profiles.vocpub import VocPub
import os
from bs4 import BeautifulSoup, formatter
source_ontology_path = './ontology/0.1/BadmintONTO.ttl'
onto_json_path = './BadmintONTO.json'
html_path = './docs/0.1/index.html'
webvowl_json_path = './docs/0.1/webvowl/data/BadmintONTO.json'
def generate_webvowl():
cmd = "java --add-opens java.base/java.lang=ALL-UNNAMED -jar owl2vowl.jar -file {onto} -output {output}".format(onto=source_ontology_path, output=webvowl_json_path)
os.system(cmd)
def generate_html():
onto_doc = VocPub(ontology=source_ontology_path)
onto_doc.make_html(destination=html_path)
def add_webvowl_to_html():
with open(html_path, encoding="utf-8") as f:
soup = BeautifulSoup(f, "html.parser")
download_overview = BeautifulSoup(
f"""
<div class="section" id="download">
<dl>
<div>
<dt>
<strong>
Download Serialization
</strong>
</dt>
<dd>
<span><a style="text-decoration:none" href="BadmintONTO.ttl" target="_blank"><img src="https://img.shields.io/badge/Format-TTL-blue.svg" alt="TTL"></a></span>
<span><a style="text-decoration:none" href="BadmintONTO.owl" target="_blank"><img src="https://img.shields.io/badge/Format-OWL-blue.svg" alt="OWL"></a></span>
<span><a style="text-decoration:none" href="BadmintONTO.rdf" target="_blank"><img src="https://img.shields.io/badge/Format-RDF/XML-blue.svg" alt="RDF/XML"></a></span>
<span><a style="text-decoration:none" href="BadmintONTO.jsonld" target="_blank"><img src="https://img.shields.io/badge/Format-JSON_LD-blue.svg" alt="JSON-LD"></a></span>
</dd>
</div>
</dl>
</div>
<div class="section" id="overview">
<h2>Overview</h2>
<div class="figure">
<iframe width="100%" height ="800px" src="webvowl/index.html#BadmintONTO"></iframe>
<div class="caption">
<strong>Figure 1:</strong>
Ontology Overview
</div>
</div>
</div>
""", "html.parser")
overview = BeautifulSoup(
f"""
<div class="section" id="overview">
<h2>Overview</h2>
<div class="figure">
<iframe width="100%" height ="800px" src="webvowl/index.html#BadmintONTO"></iframe>
<div class="caption">
<strong>Figure 1:</strong>
Ontology Overview
</div>
</div>
</div>
""", "html.parser")
tag = soup.find(id='classes')
tag.insert_before(download_overview)
html_formatter = formatter.HTMLFormatter(indent=4)
with open(html_path, "w") as f:
f.write(soup.prettify(formatter=html_formatter))
def main():
generate_html()
generate_webvowl()
add_webvowl_to_html()
if __name__ == "__main__":
main()