SWRL rules and instances/individuals made from loaded ontology classes

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

SWRL rules and instances/individuals made from loaded ontology classes

Bluer
This post was updated on .
Hi everyone,

I've been using owlready2 for some time now to try to get reasoning working with my ontology I made in Protege. Over time I've figured out little issues and solutions to them that are related to creating SWRL rules from loaded ontologies, and now I'm at the point of creating individuals/instances from those imported classes to try to perform reasoning with the SWRL rules.

I've noticed that the when I create an individual from the classes in my ontology, Pellet isn't creating the relation in the head from the rule on the individuals, but if I make a fresh ontology through owlready2, save it, load it back in the same way I would with my normal ontology and then apply the rule across it, it manages to create the relation on those individuals. Is there something specific that I may be missing or need to change on my normal ontology that owlready2's classes include with them?

The only thing I've noticed myself is that when I print out the IRI of the classes, the fresh ontology has "file:" at the beginning, but my normal ontology doesn't. I'm not sure if that's important...? and my ontology is several of them merged/imported together, so I have wondered if it's something specific about the IRIs.

I've already noticed that it works fine if I use individuals created from classes I defined in the code itself, but that does not solve the problem of me needing to use a loaded ontology.

Here is an idea of what my code is like: https://pastebin.com/1sHAkAF2

Edit: I've tested a little more and the only differences I can tell are: 1. My loaded classes don't seem to include their domains or ranges, and 2. My original class's "is_functional_for" property is different. I'm not sure if that affects anything.

Thank you in advance!

Daniel
Reply | Threaded
Open this post in threaded view
|

Re: SWRL rules and instances/individuals made from loaded ontology classes

isukura
Hello,

I'm having similar issues.
I defined a class using owlready2 and created an instance. Then I saved this ontology, but when I open it in Protégé, the created instance is a member of another class of the same name.
As Bluer mentioned, IRIs don't match. In my case, the defined class has "file:" at the beginning, but that other class (which my instance is member of) doesn't.

Another problem: all properties are saved as Annotations and not as Data/Object properties and because of that rules which I defined don't infer the values they should!

Code: https://pastebin.com/xRFCV8Xw
Reply | Threaded
Open this post in threaded view
|

Re: SWRL rules and instances/individuals made from loaded ontology classes

Jiba
Administrator
Hello,

The problem is that you create a new ontology without a full IRI (= "new.owl").

You need to replace it by a full IRI, for example:

onto = get_ontology("http://test.org/new.owl")

Your example works as expected after using a full IRI. Notice that you don't need to have access to http://test.org, nor to put you ontology online at that address.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: SWRL rules and instances/individuals made from loaded ontology classes

isukura
Hello,

thank you very much, I didn't know that! It was very confusing why everyone uses some non-existing links as an argument :)
Is there some more elegant way of creating ontologies than creating "fake" IRI?

I appreciate your help!
Reply | Threaded
Open this post in threaded view
|

Re: SWRL rules and instances/individuals made from loaded ontology classes

Jiba
Administrator
Hello,

No, using "fake" IRI is a common practice, e.g. Protégé automatically create a fake IRI for any new ontology.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: SWRL rules and instances/individuals made from loaded ontology classes

Bluer
Hi Jiba,

Thanks for the replies! I've renamed the IRI in my ontology from protege, and the atoms I made myself, however I'm still not getting the rules to work. Is there a way I can determine what is a real IRI vs a fake one? I could theoretically just remake the atoms using owlready instead, however I just want to make sure I understand what's going on so I'm learning properly.

Daniel
Reply | Threaded
Open this post in threaded view
|

Re: SWRL rules and instances/individuals made from loaded ontology classes

Jiba
Administrator
Hi,

The only way to distinguish fake IRI from real one is to try to download the IRI content. IRI are used as identifiers in ontology, and, when the entity cannot be accessed otherwise, the IRI is used to download the entity definition. If the corresponding ontology is available from a local file, the IRI is never used for download.

Jiba