Relating one class to another class by object properties or relations (equivalent of SWRL rules in Owlready)

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

Relating one class to another class by object properties or relations (equivalent of SWRL rules in Owlready)

rahul_raj
Hello,
Defining rules is an important aspect of ontologies. Say I have two sub-classes 'CustomerA' and 'ProductA'. Here, 'CustomerA' is a sub-class of 'Customer' and 'ProductA' is a sub-class of 'Product'. Customer class has several instances with their data properties and some of them do belong to CustomerA as well, so is the case with Product and ProductA class. Now, I have an object property named 'should_be_given' which has 'Customer' as domain and 'Product' as range. Now, I wish to connect 'CustomerA' to 'ProductA' through this object property. While making this connection, it's desired that not only these two classes get connected to each other but also the instances of these two classes get connected to each other. For example, CustomerA has cust1 and cust2 as its instances. ProductA has pdt7 and pdt8 as its instances. So when I connect CustomerA class to ProductA class using object property 'should_be_given', I wish the instances to also get connected (their mutual cross product) i.e.,
cust1 should_be_given pdt7
cust1 should_be_given pdt8
cust2 should_be_given pdt7
cust2 should_be_given pdt8

To implement this (or other such rules), we have SWRL rules in Protege. And this SWRL rule would do this desired operation and give the same results as stated above.
CustomerA(?x) ^ ProductA(?y) -> should_be_given(?x, ?y)

I tried to implement in Owlready by using this code:
with onto:
    for i in CustomerA.instances():
        for j in ProductA.instances():
            i.should_be_given.append(j)

This gives me the desired output. But being a non functional property (should_be_given), I needed to use .append. So, when my rules get changed i.e., CustomerA should be given ProductB instead of ProductA, I will have to delete the list (should_be_appended) for each instances in CustomerA and start afresh by running the same code again with slight modification (replacing ProductA with ProductB). But this approach is more like hard coding and isn't much flexible when the rules change.

So, I wish to have such an implementation where we can just change the name of classes that are to be connected by an object property and we will get the cross product of their instances connected by that property. In SWRL rules for Protege, you can easily do that y changing that rule.
So, is there any functionality available in Owlready so as to implement something similar to SWRL rules or SWRL rule itself? Also, is there any alternative to get those kind of cross producted relationship established between instances of two classes by an object property?
Reply | Threaded
Open this post in threaded view
|

Re: Relating one class to another class by object properties or relations (equivalent of SWRL rules in Owlready)

Jiba
Administrator
Hello,

Owlready does not support SWRL rules yet.

In you situation, maybe you can assert the relations at the class level (i.e. between Customer and Product classes, rather that on their instances).

However, OWL cannot relate all instances of a class to all instances of another (it only support "some" or "only", not "all"). But this can be achieved by reifying the relation (i.e. turning should be given to a class).

Another solution is to store each set of "should_be_given" relations in a separate ontology. You can then destroy the ontology to remove the relations it contains.

Best regards,
Jiba