def parse_owl_rdf(url):
"""Downloads and parses an OWL resource in OWL/RDF format
:param str url: The URL to the OWL resource
:return: A directional graph representing the OWL document's hierarchy
:rtype: networkx.DiGraph
"""
g = nx.DiGraph(IRI=url)
o = Ontospy(url)
for cls in o.classes:
g.add_node(cls.locale, type='Class')
for parent in cls.parents():
g.add_edge(cls.locale, parent.locale, type='SubClassOf')
for instance in cls.instances():
_, frag = urldefrag(instance)
g.add_edge(frag, cls.locale, type='ClassAssertion')
return g
评论列表
文章目录