Different reasoning results between Stardog and Protege

Hello,

I’m bringing a question I posted a yesterday in Stack Overflow (https://stackoverflow.com/questions/43373587/different-reasoning-results-between-stardog-and-protege).

The problem I’m having is the following: I have designed a ontology using Protege, and added all the tuples in Stardog, but I’m getting different results between the reasoning of both tools.

Let me show you the ontology:

Number

Class: Number

Number DisjointUnionOf OddNumber,EvenNumber

OddNumber

OddNumber subClassOf Number

EvenNumber

EvenNumber subClassOf Number

EvenNumber EquivalentTo hasValue {"2", "4", "6" }

hasValue

DataProperty: hasValue

hasValue Range xsd:string

hasValue SubPropertyOf: owl:topDataProperty

hasValue Domain Number

Functional: hasValue

Then I create two instances called num1 and num2 which are defined as follows:

num1

num1 hasValue "1"^^xsd:string

individual: num1

num1 Type Number

num2

num2 hasValue "2"^^xsd:string

individual: num2

num2 Type Number

When applying reasoning in Protege and Stardog, both reasoners show that num2 is an instance of EvenNumber and Number. When applying the reasoners with num1, Protege says num1 is an instance of OddNumber and Number, while Stardog says num1 is just an instance of Number.

I need Stardog to classify num1 as an OddNumber too. Am I missing some restriction/axiom in order to achieve this behavior? Is it possible to configure Stardog to behave like this?

As I was told in one of the answers, the following axiom is invalid in Protege:
EvenNumber EquivalentTo hasValue {"2", "4", "6" }
and I should be getting an error message in stardog log file. The thing is I’m not getting any error related to this in the log file, and this axiom seem to be working as expected when classifying num2 as a EvenNumber. Again, the problem occurs when Stardog isn’t showing num1 as a OddNumber instance.

Any further help about how to resolve this problem would be much appreciated.

Note: I’m using a default installation of Stardog (version 4.2.3) and Protege (version 5.1.0) by default with reasoner Hermit 1.3.8.

Thanks in advance.

Hi,

As it turns out, and if you check stardog.log you’ll see this is the case, the axiom being rejected by Stardog in this instance is actually the disjointUnionOf axiom, as it is DL and Stardog does not support DL reasoning over the ABox.

However, what you’re trying to accomplish is very doable with Stardog Rules. I went ahead and used the SWRL built-in mod function to make the EvenNumber/OddNumber more complete, but you can of course use any BGPs/Filters you want:

@prefix swrlb: <http://www.w3.org/2003/11/swrlb#> .
@prefix rule: <tag:stardog:api:rule:> .

[] a rule:SPARQLRule ;
	rule:content """ 
	IF {
		?n a :Number ;
			:hasValue ?v .
		FILTER (swrlb:mod(xsd:integer(?v), 2) = 0)
	}
	THEN {
		?n a :EvenNumber
	}
""" .

[] a rule:SPARQLRule ;
	rule:content """ 
	IF {
		?n a :Number ;
			:hasValue ?v .
		FILTER (swrlb:mod(xsd:integer(?v), 2) = 1)
	}
	THEN {
		?n a :OddNumber
	}
""" .

Hello Stephen,

Thanks for you answer. I’ve been trying to accomplish this with SPARQL rules as you suggested. This number ontology was just an example, so I won’t be assuming the SWRL built-in mod function (thanks anyway for this information).

The situation I’m trying to describe through my sparql rules is a bit different from yours. Your rules behave like this

  • any number which is dividable by 2, is an even number.
  • any number which is not dividable by 2, is an odd number.

What I’m trying to achieve is something as follows:-

  • any number which is dividable by 2, is an even number.
  • any number, which is not an even number, is an odd number.

This is the sparql rule I’m inserting in my Stardog instance:

prefix swrlb: <http://www.w3.org/2003/11/swrlb#>
prefix rule: <tag:stardog:api:rule:>

insert data {
  graph <MY_GRAPH> {
  [] a rule:SPARQLRule ;
  rule:content """
  IF {
		?n a :Number .
		?n rdf:type ?class .
		?class rdfs:subClassOf+ :Number .
		filter (?class != :EvenNumber)
	}
	THEN {
		?n a :OddNumber .
	}
  """ .
  }
}

while EvenNumber is described as showed in original question (EvenNumber subClassOf Number, EvenNumber EquivalentTo hasValue {“2”, “4”, “6” }).

When running this following query, Stardog shows 0 results:

select ?n where {
	?n a :OddNumber. 
}

I don’t understand why Stardog isn’t showing num1 as an instance of OddNumber.

The following query actually is showing num1 as an instance of Number and not an instance of EvenNumber:

select ?n where {
	?n a :Number .
	?n rdf:type ?class .
	?class rdfs:subClassOf+ :Number .
	filter (?class != :EvenNumber)
}

Any help or comments about how to achieve this behaviour would be very much appreciated.

Thanks in advance.

Can you include the actual files you’re using?

Zachary, thanks for your help. This is the actual file I’m using, which was created with Protege.

This is the behaviour I’m trying to achieve:

  • The instance “expectedInstance” should be classified as a “ExpectedHTTPResponseCode” instance. (which is working as expected in Stardog).
  • The instance “unexpectedInstance” should be classified as a “UnexpectedHTTPResponseCode”, which Protege classifies this way but Stardog doesn’t.

Thanks for your help.

<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#"
     xml:base="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     xmlns:untitled-ontology-3="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3"/>
    


    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Data properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    


    <!-- http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#hasStatusCode -->

    <owl:DatatypeProperty rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#hasStatusCode">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>
        <rdfs:domain rdf:resource="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#HTTPResponse"/>
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    </owl:DatatypeProperty>
    


    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Classes
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    


    <!-- http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#ExpectedHTTPResponseCode -->

    <owl:Class rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#ExpectedHTTPResponseCode">
        <owl:equivalentClass>
            <owl:Restriction>
                <owl:onProperty rdf:resource="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#hasStatusCode"/>
                <owl:someValuesFrom>
                    <rdfs:Datatype>
                        <owl:oneOf>
                            <rdf:Description>
                                <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"/>
                                <rdf:first>200</rdf:first>
                                <rdf:rest>
                                    <rdf:Description>
                                        <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"/>
                                        <rdf:first>300</rdf:first>
                                        <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
                                    </rdf:Description>
                                </rdf:rest>
                            </rdf:Description>
                        </owl:oneOf>
                    </rdfs:Datatype>
                </owl:someValuesFrom>
            </owl:Restriction>
        </owl:equivalentClass>
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#HTTPResponse"/>
        <owl:disjointWith rdf:resource="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#UnexpectedHTTPResponseCode"/>
    </owl:Class>
    


    <!-- http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#HTTPResponse -->

    <owl:Class rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#HTTPResponse">
        <owl:disjointUnionOf rdf:parseType="Collection">
            <rdf:Description rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#ExpectedHTTPResponseCode"/>
            <rdf:Description rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#UnexpectedHTTPResponseCode"/>
        </owl:disjointUnionOf>
    </owl:Class>
    


    <!-- http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#UnexpectedHTTPResponseCode -->

    <owl:Class rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#UnexpectedHTTPResponseCode">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#HTTPResponse"/>
    </owl:Class>
    


    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Individuals
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    


    <!-- http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#expectedInstance -->

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#expectedInstance">
        <rdf:type rdf:resource="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#HTTPResponse"/>
        <hasStatusCode rdf:datatype="http://www.w3.org/2001/XMLSchema#string">200</hasStatusCode>
    </owl:NamedIndividual>
    


    <!-- http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#unexpectedInstance -->

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#unexpectedInstance">
        <rdf:type rdf:resource="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#HTTPResponse"/>
        <hasStatusCode rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ASDFASDF</hasStatusCode>
    </owl:NamedIndividual>
    


    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // General axioms
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    <rdf:Description>
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AllDifferent"/>
        <owl:distinctMembers rdf:parseType="Collection">
            <rdf:Description rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#expectedInstance"/>
            <rdf:Description rdf:about="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3#unexpectedInstance"/>
        </owl:distinctMembers>
    </rdf:Description>
</rdf:RDF>



<!-- Generated by the OWL API (version 4.2.6.20160910-2108) https://github.com/owlcs/owlapi -->

When running the queries with SL I get the warningg “Not a valid SL axiom: DisjointUniont(…” as mentioned earlier. When running it with DL I do not get any warnings but curiously I get a result when querying for UnexpectedHTTPResponseCode and no repose for ExpectedHTTPResponseCode, the exact opposite of what you’re reporting. Can you confirm that you didn’t actually mix them up when typing your response?

Here is something odd as well

Query for UnexpectedHTTPResponseCode instances

"select * where { ?s a :UnexpectedHttpResponseCode }

I get :unexpectedInstance

Query for ExpectedHttpResponseCode instances

"select * where {?s a :ExpectedHttpResponseCode }

I get nothing

When I query for all properties on :unexpectedInstance

"select * where {:unexpectedInstance ?p ?o}

I get :unexpectedInstance a :UnexpectedHTTPResponseCode

but here’s where it gets strange

When I query for all properties on :expectedInstance

"select * where {:expectedInstance ?p ?o}

I get :expectedInstance a :UnexpectedHTTPResponseCode ???

I’ll have to double check that I don’t have any typos. There was some manual typing involved in trying out your example.

I’m running on Startdog 4.2.1 but that’s the best I can do at the moment.

Hey zachary, thanks for your answer.

I can confirm you I didn’t mistype the results I told you before. Let me show you the results I’m getting:

USING SL reasoning:

select ?s where { 
?s a :ExpectedHTTPResponseCode 
}

Returns :expectedInstance

select ?s where { ?s a :UnexpectedHTTPResponseCode }

Returns no results.

I just tested this same queries using DL reasoning as you mention it and it’s working the way I wanted!!!

USING DL reasoning:

select ?s where { ?s a :UnexpectedHTTPResponseCode }

returns :unexpectedInstance

and

select ?s where { ?s a :ExpectedHTTPResponseCode }

returns :expectedInstance

I would say this wasn’t working in SL reasoning because of what Stephen mentioned about an invalid axiom, but DL reasoning seems to work as I was expecting.

Thank you very much Stephen and Zachary for your time and patience.

Some additional feedback…

If I execute the query from the CLI I only get back owl:Thing for both unexpectedInstance and expectedInstance

select * where {:expectedInstance ?p ?o}

select * where {:unexpectedInstance ?p ?o}

but if I execute the query through the webconsole I get additional bindings even without reasoning enabled.

My pleasure. I’m glad I could help. Now I’m wondering what the problems I was seeing were all about and why you weren’t seeing the error in the logs when using SL about unsupported axioms. I’ll have to have to give it a try with 4.2.4 and see what happens.

@zachary.whitley: I think your CLI issue is because of the way the base namespace is defined. In the provided file it’s xml:base="http://www.semanticweb.org/gubuntu/ontologies/2017/3/untitled-ontology-3", which is missing the required # at the end to make things like :expectedinstance work.

@SemanticUY1: I’m glad you got it running with DL reasoning. Just be aware that the SL axioms (EL, DL, RL, Stardog Rules) will not work in conjunction with DL.

But I would never expect the result from the CLI to ever be different from the Webconsole. I had to convert it to ttl and type it back in so I could easily have made a mistake in there somewhere.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.