forked from AleSteB/Reac4Cat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOntoPlot.py
More file actions
37 lines (31 loc) · 1.26 KB
/
Copy pathOntoPlot.py
File metadata and controls
37 lines (31 loc) · 1.26 KB
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
import rdflib
from pyvis.network import Network
# Load the OWL file
owl_file = './Reac4Cat.owl'
g = rdflib.Graph()
g.parse(owl_file)
# Initialize a pyvis Network for visualization
nt = Network(notebook=True)
# Extract class hierarchy
for s, p, o in g.triples((None, rdflib.RDFS.subClassOf, None)):
if isinstance(s, rdflib.URIRef) and isinstance(o, rdflib.URIRef):
nt.add_node(str(s), label=str(s))
nt.add_node(str(o), label=str(o))
nt.add_edge(str(s), str(o))
# Extract individuals
for s, p, o in g.triples((None, None, None)):
if isinstance(s, rdflib.URIRef) and isinstance(o, rdflib.URIRef):
nt.add_node(str(s), label=str(s))
nt.add_node(str(o), label=str(o))
nt.add_edge(str(s), str(o))
# Extract object properties
for s, p, o in g.triples((None, None, None)):
if isinstance(s, rdflib.URIRef) and isinstance(p, rdflib.URIRef) and isinstance(o, rdflib.URIRef):
nt.add_node(str(s), label=str(s))
nt.add_node(str(o), label=str(o))
nt.add_edge(str(s), str(o), label=str(p))
# Save the interactive visualization to an HTML file
nt.show_buttons(filter_=['physics'])
html_file_path = 'ontology_interactive.html'
nt.save_graph(html_file_path)
print(f"Interactive visualization saved to '{html_file_path}'")