2

I have an ontology (dgo.owl) and a simple program (SparqlQuery.java) to query the same ontology. On running the query I do not get any results. After debugging for a long time I thought it would be good to put it in the community.

The query script is as:

OntModel ontmodque = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
        InputStream in=FileManager.get().open("ontologies/dgo.owl");
        if (ontmodque.isEmpty())
        {
        ontmodque.read(in,"RDF/XML");
        }
        String qr= "PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>\n" +
                   "PREFIX dgo: <http://www.iiitd.edu.in/~haroonr/ontologies/DGO#>\n" +
                 "SELECT \n"+
                   "?property  \n"+ 
                    "WHERE\n"+
                    "{ \n"+
                    "dgo:DiningRoom ssn:hasProperty ?property .\n " +
                    "}";

        Query qy = QueryFactory.create(qr);
        QueryExecution qe = QueryExecutionFactory.create(qy,ontmodque);
        ResultSet rs= qe.execSelect();
        ResultSetFormatter.out(System.out, rs, qy) ;
        ontmodque.close();
        qe.close();

Output obtained is:


enter image description here

I know that hasProperty object relationship is present in said ontology. Also, possible properties for the DiningRoom should return Illuminance, Temperature, Co2Content,AbsoluteHumidity.

Haroon Lone
  • 2,837
  • 5
  • 29
  • 65

1 Answers1

5

I think you are forgetting how properties are defined in OWL. You have defined:

Class: DiningRoom subClassOf: hasProperty some AbsoluteHumidity

Thus, you need to write a more complicated query:

PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>
PREFIX dgo: <http://www.iiitd.edu.in/~haroonr/ontologies/DGO#>
SELECT distinct *
 WHERE  { 
     dgo:DiningRoom  rdfs:subClassOf ?property .
     ?property owl:someValuesFrom ?y.
}
Artemis
  • 3,271
  • 2
  • 20
  • 33
  • Thanks for pointing out. I am new to this Sparql world. I think I have to work more on owl:restrictions. I find it hard to understand. – Haroon Lone Jun 02 '15 at 10:58
  • A relatively good starting point is some tutorials such as [this] (http://www.cs.vu.nl/~guus/public/owl-restrictions/), After that I think just read a simple tutorial to description logic. – Artemis Jun 02 '15 at 11:05