Import whole Ontology from rdflib-Graph

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Import whole Ontology from rdflib-Graph

cknoll
Hi,

I want to combine owlready2 with the reasoner https://github.com/gtfierro/reasonable.

Therefore it would be useful to create an owlready2-Ontology-instance from a rdflib-Graph-instance. This would be the inverse direction of onto.default_world.as_rdflib_graph().

Is this functionality implemented?
If not: is there an easy way to achieve this?

Best,
Carsten
Reply | Threaded
Open this post in threaded view
|

Re: Import whole Ontology from rdflib-Graph

Jiba
Administrator
Hi,

I think you can use "as_rdflib_graph" to call reasonable, as follows:

# Load any ontology
onto = get_ontology("/home/jiba/src/owlready2/test/pizza_onto.owl").load()

import rdflib

g = default_world.as_rdflib_graph()

import reasonable

r = reasonable.PyReasoner()
r.from_graph(g)
triples = r.reason()
print("from rdflib:", len(triples))


The inverse operation (using an RDF graph as an Owlready quadstore) is currently not possible, and has little interest (Owlready quadstore is much faster that RDFlib).

Beware that, after calling the reasoner, Owlready2 object may not be updated if they where loaded before reasoning.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Import whole Ontology from rdflib-Graph

cknoll
Thank you for your response

Jiba wrote
...
The inverse operation (using an RDF graph as an Owlready quadstore) is currently not possible, and has little interest (Owlready quadstore is much faster that RDFlib).
I see. Anyway I would be interested in importing an RDF graph as (or into) an Owlready ontology an  to be able to compare the reasoning results with both approaches. Is that possible?
Reply | Threaded
Open this post in threaded view
|

Re: Import whole Ontology from rdflib-Graph

Jiba
Administrator
I think the easier approach is to serialize the RDFlib graph in a temporary NTriple file, and then to load that file with Owlready2.

Jiba