vote up 1 vote down
star

During our work with a triple store we noticed a strange behaviour related to inheritance chaining and linking properties to classes.

Consider the following example:

3 types defined - GrandParent, Parent and Child.
3 properties defined - GrandParentsProp, ParentsProp and ChildsProp.
Parent inherits GrandParent, Child inherits Parent.
GrandParentsProp has domain GrandParent.
ParentsProp has domain Parent.
ChildsProp has domain Child.

We are asking for properties related to each of these types. I am expecting to get result similar to result in OOP. Like

Child has GrandParentProp, ParentProp and ChildProp
GradnParent has GrandParentProp.

Unfortunately this was not what I got when testing reasoning in the triple store. I got exactly the opposite:

Child has ChildProp
GrandParent has GrandParentProp, ParentProp and ChildProp

In order to speak the same language I am providing the sample RDF data that was used.

# baseURI: http://sample/data

@prefix :        <http://sample/data#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://sample/data>
      a       owl:Ontology .

:Child
      a       owl:Class ;
      rdfs:label "Child"^^xsd:string ;
      rdfs:subClassOf :Parent .

:ChildProp
      a       rdf:Property ;
      rdfs:domain :Child ;
      rdfs:label "Child prop"^^xsd:string .

:GrandParent
      a       owl:Class ;
      rdfs:label "Grand parent"^^xsd:string .

:GrandParentProp
      a       rdf:Property ;
      rdfs:domain :GrandParent ;
      rdfs:label "Grand parent prop"^^xsd:string .

:Parent
      a       owl:Class ;
      rdfs:label "Parent"^^xsd:string ;
      rdfs:subClassOf :GrandParent .

:ParentProp
      a       rdf:Property ;
      rdfs:domain :Parent ;
      rdfs:label "Parent prop"^^xsd:string .

I am querying the data using these SPARQL query:

select * where 
{
  ?s <http://www.w3.org/2000/01/rdf-schema#domain> <http://sample/data#GrandParent>
} 
select * where 
{
  ?s <http://www.w3.org/2000/01/rdf-schema#domain> <http://sample/data#Child>
}

I am wondering whether I am expecting something that is strange in semantic world or there is some problem with my statements or there is a problem with the reasoning in the triple store?

flag

2 Answers

vote up 4 vote down
check

This one of the most common mistakes that developers make when moving from traditional object oriented technologies to OWL.

Domain in OWL is not a schematic restriction on the property. It does NOT mean; "the domain of the property is the only type of thing that can be assigned that property".

Instead Domain in OWL is a reasoning hint that means; "if this property exists on an instance that instance can be inferred to be of type [Domain]".

If you inserted the following data into a graph that contained your ontology:

<s1> a rdfs:Resource;
    :ChildProp "ABC".

An OWL reasoner would infer additional data about <s1> based on your ontology and you would get the following description (describe <s1>):

<s1> a :GrandParent, 
    :Parent, 
    :Child, 
    rdfs:Resource; 
    :ChildProp "ABC".

What happening is that because <s1> has :ChildProp, <s1> is inferred to be of type :Child which is rdfs:subClassOf :Parent which is rdfs:subClassOf :GrandParent so <s1> is inferred to be of all three of those types.

This is correct behavior and becomes very powerful when you think about creating ontologies which describe objects that haven't been classified in terms of that ontology.

Here are some different examples of input/output that might help to fully realize how an OWL reasoner will work with your ontology.

Input

<s2> a rdfs:Resource;
    :ParentProp "ABC".

Output

<s2> :ParentProp "ABC"; 
    a :GrandParent, 
        :Parent, 
        rdfs:Resource.

Input

<s3> a rdfs:Resource; 
    :GrandParentProp "ABC".

Output

<s3> a :GrandParent, 
    rdfs:Resource; 
    :GrandParentProp "ABC".

Input

<s4>
    a rdfs:Resource;
    a :Child.

Output

<s4> a :GrandParent, 
    :Parent, 
    :Child, 
    :Resource.

Input

<s5>
    a rdfs:Resource;
    a :Parent.

Output

<s5> a :GrandParent, 
    :Parent, 
    rdfs:Resource.

Input

<s6>
    a rdfs:Resource;
    a :GrandParent.

Output

<s6> a :GrandParent, 
    rdfs:Resource.
link|flag
Thank you very much for the detailed examples and descriptions! Now I have to fix my code and rethink the strategy based on these wrong assumptions. Thanks again! – ViktorZ Nov 5 at 9:26
vote up 8 vote down

The inference rules of OWL are a bit different to OO inheritance, so it can be a bit counter-intuitive at times if your brain is used to the OO approach. I think your statements and reasoner are correct.

(I don't know much about which types of inference different triple stores actually apply - if you let us know which triple store you are using, someone more knowledgeable than me might be able to help on the details of that).

Let me simplify your example a little (we only need two classes) and avoid the potentially confusing parent/child names.

Let's have classes Car and MeansOfTransport. Car is a subclass of MeansOfTransport

The main owl inference rule here is: if A is a Car, then A is also a MeansOfTransport.

Now introduce some properties: engineSize with domain Car and maximumSpeed with domain MeansOfTransport.

The owl inference rule for domains is: if (A engineSize B) then because the domain of engineSize is Car, then A is a Car.

And we know that if A is a Car, then A is also a MeansOfTransport. So it is correct to say that the domain of engineSize is (also) MeansOfTransport: because if we know (A engineSize B) it is correct to conclude that A is a MeansOfTransport. If later you want to ask for all things in the class MeansOfTransport, you want the results to include A.

if (C maximumSpeed D), then by the domain of maximumSpeed, we can infer that C is a MeansOfTransport. We can't say that C is a car - it might be some other kind of thing, like a bicycle.

I think it is the direction of the inference that makes this confusing. In OWL, knowing the domain of the property lets you conclude things about the subjects. In Object Oriented programming, knowing the class of an object lets you conclude something about the methods it supports.

Hope that helps! I agree it isn't obvious - I did some head-scratching to try to make sure I got this example right.

link|flag
Thank you very much! I was expecting something like this, but my OO background played on the bad side in this. Thanks for clearing things out! – ViktorZ Nov 5 at 9:24
You're welcome! I recommend reading Allemang and Hendler "Semantic web for the working ontologist". They explain this stuff very well. – billroberts Nov 5 at 14:07

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.