-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__explore_ontology.py
62 lines (55 loc) · 2.19 KB
/
__explore_ontology.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
# explore_ontology.py
from owlready2 import *
# onto = get_ontology("jena_in.rdf").load()
onto = get_ontology("jena_out.n3").load()
from flask import Flask, url_for
app = Flask(__name__)
@app.route('/')
def ontology_page():
html = """<html><body>"""
html += """<h2>'%s' ontology</h2>""" % onto.base_iri
html += """<h3>Root classes</h3>"""
for Class in Thing.subclasses():
html += """<p><a href="%s">%s</a></p>""" % (url_for("class_page", iri = Class.iri), Class.name)
html += """</body></html>"""
return html
@app.route('/class/<path:iri>')
def class_page(iri):
Class = IRIS[iri]
html = """<html><body><h2>'%s' class</h2>""" % Class.name
html += """<h3>superclasses</h3>"""
for SuperClass in Class.is_a:
if isinstance(SuperClass, ThingClass):
html += """<p><a href="%s">%s</a></p>""" % (url_for("class_page", iri = SuperClass.iri), SuperClass.name)
else:
html += """<p>%s</p>""" % SuperClass
html += """<h3>equivalent classes</h3>"""
for EquivClass in Class.equivalent_to:
html += """<p>%s</p>""" % EquivClass
html += """<h3>Subclasses</h3>"""
for SubClass in Class.subclasses():
html += """<p><a href="%s">%s</a></p>""" % (url_for("class_page", iri = SubClass.iri), SubClass.name)
html += """<h3>Individuals</h3>"""
for individual in Class.instances():
html += """<p><a href="%s">%s</a></p>""" % (url_for("individual_page", iri = individual.iri), individual.name)
html += """</body></html>"""
return html
@app.route('/individual/<path:iri>')
def individual_page(iri):
individual = IRIS[iri]
html = """<html><body><h2>'%s' individual</h2>""" % individual.name
html += """<h3>Classes</h3>"""
for Class in individual.is_a:
html += """<p><a href="%s">%s</a></p>""" % (url_for("class_page", iri = Class.iri), Class.name)
html += """<h3>Relations</h3>"""
# if isinstance(individual, onto.Bacterium):
# html += """<p>shape = %s</p>""" % individual.has_shape
# html += """<p>grouping = %s</p>""" % individual.has_grouping
# if individual.gram_positive == True:
# html += """<p>Gram +</p>"""
# elif individual.gram_positive == False:
# html += """<p>Gram -</p>"""
html += """</body></html>"""
return html
import werkzeug.serving
werkzeug.serving.run_simple("localhost", 5000, app)