Accessing the axioms (and axiom closure) of an ontology

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

Accessing the axioms (and axiom closure) of an ontology

Bijan Parsia
Hi ho,

Neither in the docs nor in the source (looking in the unfortunately named "namespace.py" at World, Ontology, and the like) do I see a way to iterate over the axioms (preferably the axiom closure) of an ontology. Now, it does seem that there are building blocks that might be useful, but it feels like I'm breaking abstraction (e.g., self.add_triple(bnode, rdf_type, owl_axiom) is suggestive). I was sorta expecting something similar to the "classes" method. (There seem to be lots of stuff for entities but nothing for axioms).

Pointers or advice gratefully accepted!

Cheers,
Bijan.
bijan.parsia@manchester.ac.uk
Reply | Threaded
Open this post in threaded view
|

Re: Accessing the axioms (and axiom closure) of an ontology

Jiba
Administrator
Hi,

Owlready is Class-oriented rather than axiom-oriented, so most functions are class oriented. Ontology and World object have .disjoint_classes() method (and disjoint_properties(), etc) for obtaining AllDisjoint axiom. However, there is nothing for other axioms.

By "closure axiom", do you mean restriction like "only A" or "some B"?

I think you can directly query the quadstore to obtain such axioms, and then use _parse_bnode() to load the restriction in Python object, for example:

for s in default_world.get_triples_po(rdf_type, owl_restriction):
      restriction = default_world._parse_bnode(s)

Best regards,
Jean-Baptiste Lamy
MCF, LIMICS, Université Paris 13
Reply | Threaded
Open this post in threaded view
|

Re: Accessing the axioms (and axiom closure) of an ontology

bparsia
Jiba wrote
Owlready is Class-oriented rather than axiom-oriented,
I was afraid of this.

Jiba wrote
By "closure axiom", do you mean restriction like "only A" or "some B"?
"Axiom closure" not "closure axiom". Confusing, I know! The axiom closure of an ontology is the union of the axioms of the ontology and all the ontologies in its import closure. Closure axiom refers to, as you indicate, "closing a role" (usually by adding a universal to the corresponding existential, i.e., adding (p only B) to  (p some B).

Jiba wrote
I think you can directly query the quadstore to obtain such axioms, and then use _parse_bnode() to load the restriction in Python object, for example:

for s in default_world.get_triples_po(rdf_type, owl_restriction):
      restriction = default_world._parse_bnode(s)
Would this yield an enumeration of the axioms? How do you serialise out constructed ontologies?

Thanks for your help.

Cheers,
Bijan.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing the axioms (and axiom closure) of an ontology

Jiba
Administrator
> Would this yield an enumeration of the axioms? How do you serialise out
> constructed ontologies?

It yields the "store-ID" corresponding to blank nodes that are restrictions (e.g. Some, Only restriction).

If you also want other axiom, I think you can chain several iterator, one for each type of axiom:

import itertools

for s in itertools.chain( default_world.get_triples_po(rdf_type, owl_restriction), default_world.get_triples_po(rdf_type, owl_axiom), default_world.get_triples_po(rdf_type, owl_propertychain) )


For serialization, I think you can easily produce NTriples format. For other format, I fear that Owlready has no way to serialize only a subpart of an ontology.

Best regards,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Accessing the axioms (and axiom closure) of an ontology

bparsia
Jiba wrote
> Would this yield an enumeration of the axioms? How do you serialise out
> constructed ontologies?

It yields the "store-ID" corresponding to blank nodes that are restrictions (e.g. Some, Only restriction).
But restrictions are class expressions, not axioms. Cf:

https://www.w3.org/TR/owl2-syntax/#Object_Property_Restrictions

https://www.w3.org/TR/owl2-syntax/#Axioms

If you also want other axiom, I think you can chain several iterator, one for each type of axiom:

import itertools

for s in itertools.chain( default_world.get_triples_po(rdf_type, owl_restriction), default_world.get_triples_po(rdf_type, owl_axiom), default_world.get_triples_po(rdf_type, owl_propertychain) )
Does the triple store just contain the RDF serialisation of the document?

For serialization, I think you can easily produce NTriples format. For other format, I fear that Owlready has no way to serialize only a subpart of an ontology.
But it can serialise the whole ontology? How can it do that without looping over the axioms?

If I have (p some C) subClassOf not(p only C) I need to know that it's a subclass axiom and not an equivalent classes axiom.

Cheers,
Bijan.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing the axioms (and axiom closure) of an ontology

Jiba
Administrator
Now I understand better what you mean by "axioms": it include SubclassOf axioms, etc.

There is not axiom-level in OwlReady, so you cannot iterate over axioms. I think the only solution is to iterate over RDF triples in the quadstore, and to "rebuild" axioms from triples.

Serialization is done at the ontology or the entity level (which is better for "pretty-printing" RDF), but not at the axiom-level.

The object-level is usually more intuitive (especially for Python programmers). What are you exactly trying to do with axioms? Maybe there is another, easier, way to do that ?

Best regards,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Accessing the axioms (and axiom closure) of an ontology

bparsia
On 6 Apr 2018, at 18:20, Jiba [via Owlready] <[hidden email]> wrote:
>
> Now I understand better what you mean by "axioms": it include SubclassOf axioms, etc.

Yes, as defined by the recommendation.

> There is not axiom-level in OwlReady, so you cannot iterate over axioms. I think the only solution is to iterate over RDF triples in the quadstore, and to "rebuild" axioms from triples.

I was guessing.

> Serialization is done at the ontology or the entity level (which is better for "pretty-printing" RDF), but not at the axiom-level.
>
> The object-level is usually more intuitive (especially for Python programmers). What are you exactly trying to do with axioms? Maybe there is another, easier, way to do that ?

Nope. For any ontology engineering services, the axiom level is essential. It’s also, in a key sense, primary. That’s why we pushed to move the standard (and the OWL API) from a frame like view to an axiom view. The frame view works for lots of things and, as you say, is more intuitive. But it’s also misleading in a lot of ways and makes lots of things a nightmare (reasoners, GCIs, modularity, etc.)

I appreciate your time and willingness to help. I’ll probably have to make a separate API (or just hack some XML for the time being). It’d be interesting to consider whether OWLReady could have a reasonable axiomatic view. Having RDF as the core representation makes things harder, though.

Cheers,
Bijan.