You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Ed Swing <Ed...@sas.com> on 2013/05/14 16:20:12 UTC

Bug in SameAs

I discovered a significant bug when dealing with SameAs and functional properties. Here's the Java code:


import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.reasoner.ValidityReport;

public class SameAsTest {

    public static void main(String[] args) throws IOException {
        OntModel m =
            ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
        FileInputStream inStream = new FileInputStream("ontology/vehicle.owl");
        m.read(inStream, null);
        inStream.close();
        String uriBase = m.getNsPrefixURI("");
        OntClass vehCls = m.getOntClass(uriBase + "Vehicle");
        Individual myCar = vehCls.createIndividual(uriBase + "/data/myCar");
        DatatypeProperty wheels = m.getDatatypeProperty(uriBase + "numWheels");
        // state that myCar has 4 wheels
        myCar.addProperty(wheels, "4");
        // do the same for another vehicle
        Individual redCrv = vehCls.createIndividual(uriBase + "/data/redCrv");
        redCrv.addProperty(wheels, "4");
        // now add the fact that the redCrv and myCar are the same object
        myCar.addSameAs(redCrv);
        ValidityReport rept = m.validate();
        for (Iterator<ValidityReport.Report> riter = rept.getReports(); riter
            .hasNext();) {
            ValidityReport.Report rep = riter.next();
            System.out.println("ValRep: " + rep.getDescription());
        }
    }
}

The relevant ontology is attached to this message. The crucial thing is that numWheels is a datatype property, with a max cardinality of 1 for the Vehicle class.

When the two vehicles are linked via the SameAs property, the number of wheels are also linked because of cardinality. However, sameAs doesn't allow datatype values (literals) to be linked. It's even more annoying in this case since the two values are in fact the same.

This also occurs if I declare the numWheels property as a functional property, so that's no help.

Edward Swing
Applied Research Technologist
Vision Systems + Technology, Inc., a SAS Company
6021 University Boulevard * Suite 360 * Ellicott City * Maryland * 21043
Tel: 410.418.5555 Ext: 919 * Fax: 410.418.8580
Email: Ed.Swing@vsticorp.com<ma...@vsticorp.com>
Web: http://www.vsticorp.com<http://www.vsticorp.com/>


Re: Bug in SameAs

Posted by Dave Reynolds <da...@gmail.com>.
We can't see your ontology and you don't list the results of your test case.

However, the Jena rule reasoners are (fragments of) OWL full, not OWL 
DL. In OWL full then semantically you can state that two literals are 
sameas, you just can't directly express it syntactically in RDF. The 
reasoners work internally using graphs which remove that syntactic 
constraint.

There is no DL reasoner for Jena supplied out of the box. You may wish 
to look at commercial offerings such as Pellet.

Dave

On 14/05/13 15:20, Ed Swing wrote:
> I discovered a significant bug when dealing with SameAs and functional
> properties. Here’s the Java code:
>
> *import*java.io.FileInputStream;
>
> *import*java.io.IOException;
>
> *import*java.util.Iterator;
>
> *import*com.hp.hpl.jena.ontology.*;
>
> *import*com.hp.hpl.jena.rdf.model.ModelFactory;
>
> *import*com.hp.hpl.jena.reasoner.ValidityReport;
>
> *public**class*SameAsTest {
>
> *public**static**void*main(String[] args) *throws*IOException {
>
>          OntModel m =
>
>
> ModelFactory./createOntologyModel/(OntModelSpec./OWL_DL_MEM_RULE_INF/);
>
>          FileInputStream inStream =
> *new*FileInputStream("ontology/vehicle.owl");
>
>          m.read(inStream, *null*);
>
>          inStream.close();
>
>          String uriBase = m.getNsPrefixURI("");
>
>          OntClass vehCls = m.getOntClass(uriBase + "Vehicle");
>
>          Individual myCar = vehCls.createIndividual(uriBase +
> "/data/myCar");
>
>          DatatypeProperty wheels = m.getDatatypeProperty(uriBase +
> "numWheels");
>
> // state that myCar has 4 wheels
>
>          myCar.addProperty(wheels, "4");
>
> // do the same for another vehicle
>
>          Individual redCrv = vehCls.createIndividual(uriBase +
> "/data/redCrv");
>
>          redCrv.addProperty(wheels, "4");
>
> // now add the fact that the redCrv and myCar are the same object
>
>          myCar.addSameAs(redCrv);
>
>          ValidityReport rept = m.validate();
>
> *for*(Iterator<ValidityReport.Report> riter = rept.getReports(); riter
>
>              .hasNext();) {
>
>              ValidityReport.Report rep = riter.next();
>
>              System./out/.println("ValRep: "+ rep.getDescription());
>
>          }
>
>      }
>
> }
>
> The relevant ontology is attached to this message. The crucial thing is
> that numWheels is a datatype property, with a max cardinality of 1 for
> the Vehicle class.
>
> When the two vehicles are linked via the SameAs property, the number of
> wheels are also linked because of cardinality. However, sameAs doesn’t
> allow datatype values (literals) to be linked. It’s even more annoying
> in this case since the two values are in fact the same.
>
> This also occurs if I declare the numWheels property as a functional
> property, so that’s no help.
>
> *Edward Swing*
>
> *Applied Research Technologist*
>
> *Vision Systems + Technology, Inc., a SAS Company*
>
> 6021 University Boulevard • Suite 360 • Ellicott City • Maryland • 21043
>
> *Tel:*410.418.5555 *Ext:*919 • *Fax:*410.418.8580
>
> *Email*:Ed.Swing@vsticorp.com <ma...@vsticorp.com>
>
> *Web:*http://www.vsticorp.com <http://www.vsticorp.com/>
>


RE: Bug in SameAs

Posted by Ed Swing <Ed...@sas.com>.
OK - I fixed a minor bug, and retested. It seems the addProperty() method doesn't parse the "4" into an integer form, and this was causing a problem. I'm still seeing the other behavior, but not in this particular case. I'll repost with a better example.

-----Original Message-----
From: Joshua TAYLOR [mailto:joshuaaaron@gmail.com] 
Sent: Tuesday, May 14, 2013 10:46 AM
To: users@jena.apache.org
Subject: Re: Bug in SameAs

On Tue, May 14, 2013 at 10:20 AM, Ed Swing <Ed...@sas.com> wrote:
> I discovered a significant bug when dealing with SameAs and functional 
> properties. Here’s the Java code:
>
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.util.Iterator;
> import com.hp.hpl.jena.ontology.*;
> import com.hp.hpl.jena.rdf.model.ModelFactory;
> import com.hp.hpl.jena.reasoner.ValidityReport;
>
> public class SameAsTest {
>     public static void main(String[] args) throws IOException {
>         OntModel m =
> ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>         FileInputStream inStream = new 
> FileInputStream("ontology/vehicle.owl");
>         m.read(inStream, null);
>         inStream.close();
>         String uriBase = m.getNsPrefixURI("");
>         OntClass vehCls = m.getOntClass(uriBase + "Vehicle");
>         Individual myCar = vehCls.createIndividual(uriBase + "/data/myCar");
>         DatatypeProperty wheels = m.getDatatypeProperty(uriBase + 
> "numWheels");
>         // state that myCar has 4 wheels
>         myCar.addProperty(wheels, "4");
>         // do the same for another vehicle
>         Individual redCrv = vehCls.createIndividual(uriBase + 
> "/data/redCrv");
>         redCrv.addProperty(wheels, "4");
>         // now add the fact that the redCrv and myCar are the same object
>         myCar.addSameAs(redCrv);
>         ValidityReport rept = m.validate();
>         for (Iterator<ValidityReport.Report> riter = 
> rept.getReports(); riter
>             .hasNext();) {
>             ValidityReport.Report rep = riter.next();
>             System.out.println("ValRep: " + rep.getDescription());
>         }
>     }
> }
>
> The relevant ontology is attached to this message. The crucial thing 
> is that numWheels is a datatype property, with a max cardinality of 1 
> for the Vehicle class.
>
> When the two vehicles are linked via the SameAs property, the number 
> of wheels are also linked because of cardinality. However, sameAs 
> doesn’t allow datatype values (literals) to be linked. It’s even more 
> annoying in this case since the two values are in fact the same.
>
> This also occurs if I declare the numWheels property as a functional 
> property, so that’s no help.

This list doesn't allow attachments, so no one's got your ontology.
I'm not a Jena dev, so I can't necessarily help with the bug, but:
from the initial reading of the email, I'm not clear exactly what the bug was.  What was the expected behavior?  What is the actual behavior?  An inconsistency that wasn't detected?  A consistent ontology reported as inconsistency? ... ?

//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/


Re: Bug in SameAs

Posted by Joshua TAYLOR <jo...@gmail.com>.
On Tue, May 14, 2013 at 10:20 AM, Ed Swing <Ed...@sas.com> wrote:
> I discovered a significant bug when dealing with SameAs and functional
> properties. Here’s the Java code:
>
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.util.Iterator;
> import com.hp.hpl.jena.ontology.*;
> import com.hp.hpl.jena.rdf.model.ModelFactory;
> import com.hp.hpl.jena.reasoner.ValidityReport;
>
> public class SameAsTest {
>     public static void main(String[] args) throws IOException {
>         OntModel m =
> ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>         FileInputStream inStream = new
> FileInputStream("ontology/vehicle.owl");
>         m.read(inStream, null);
>         inStream.close();
>         String uriBase = m.getNsPrefixURI("");
>         OntClass vehCls = m.getOntClass(uriBase + "Vehicle");
>         Individual myCar = vehCls.createIndividual(uriBase + "/data/myCar");
>         DatatypeProperty wheels = m.getDatatypeProperty(uriBase +
> "numWheels");
>         // state that myCar has 4 wheels
>         myCar.addProperty(wheels, "4");
>         // do the same for another vehicle
>         Individual redCrv = vehCls.createIndividual(uriBase +
> "/data/redCrv");
>         redCrv.addProperty(wheels, "4");
>         // now add the fact that the redCrv and myCar are the same object
>         myCar.addSameAs(redCrv);
>         ValidityReport rept = m.validate();
>         for (Iterator<ValidityReport.Report> riter = rept.getReports();
> riter
>             .hasNext();) {
>             ValidityReport.Report rep = riter.next();
>             System.out.println("ValRep: " + rep.getDescription());
>         }
>     }
> }
>
> The relevant ontology is attached to this message. The crucial thing is that
> numWheels is a datatype property, with a max cardinality of 1 for the
> Vehicle class.
>
> When the two vehicles are linked via the SameAs property, the number of
> wheels are also linked because of cardinality. However, sameAs doesn’t allow
> datatype values (literals) to be linked. It’s even more annoying in this
> case since the two values are in fact the same.
>
> This also occurs if I declare the numWheels property as a functional
> property, so that’s no help.

This list doesn't allow attachments, so no one's got your ontology.
I'm not a Jena dev, so I can't necessarily help with the bug, but:
from the initial reading of the email, I'm not clear exactly what the
bug was.  What was the expected behavior?  What is the actual
behavior?  An inconsistency that wasn't detected?  A consistent
ontology reported as inconsistency? ... ?

//JT
-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/