Extracting/saving ontology subset

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

Extracting/saving ontology subset

Jayne
Hello,
I'm attempting to use owlready to load an ontology, then extract a node and all of its descendants and save this subset as a new ontology.

So far I have:

onto = get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl").load()
topping_desc = onto.Topping.descendants()

which creates topping_desc as a set of class names. It seems like a simple problem but I looked at the documentation and I'm not seeing how to extract all classes in topping_desc from onto in a format that I can save with save().

Thank you in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting/saving ontology subset

Jiba
Administrator
Hello,

I'm sorry, but Owlready has currently no methods for automatic extraction...

However, if you have a list of entities to extract, you can extract the triples using RDFlib, as follows:

import rdflib
g = default_world.as_rdflib_graph()
triples = list(g.triples((my_entity.iri, None, None))

and then write the triples in NTriple format.


Best regards,
Jiba