0

I'm trying to make OWL inferences with Jena. As a start, my goal is merely to infer that if an educational institution is of type dbo:EducationalInstitution, then it is also dbo:institution

Here's the java code (adapted from the jena doc) :

package test;

import org.apache.jena.util.FileManager;
import org.apache.jena.util.PrintUtil;
import org.apache.jena.rdf.model.*;
import org.apache.jena.reasoner.Reasoner;
import org.apache.jena.reasoner.ReasonerRegistry;  

public class Test {
    public static void main(String[] args){
        Model schema = FileManager.get().loadModel("file:/home/mica/Downloads/sparql/ontology.ttl");
        Model data = FileManager.get().loadModel("file:/home/mica/Downloads/sparql/result.ttl");
        Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
        reasoner = reasoner.bindSchema(schema);
        InfModel infmodel = ModelFactory.createInfModel(reasoner, data);

        Resource nForce = infmodel.getResource("<0762762P>");
        System.out.println(nForce);
        System.out.println("nForce *:");
        printStatements(infmodel, nForce, null, null);
}
    public static void printStatements(Model m, Resource s, Property p, Resource o) {
        for (StmtIterator i = m.listStatements(s,p,o); i.hasNext(); ) {
            Statement stmt = i.nextStatement();
            System.out.println(" - " + PrintUtil.print(stmt));
        }
    }

}

An example of my data :

@prefix dbo:  <http://dbpedia.org/ontology/> .
@prefix ex:  <http://ex.org/a#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix dbf:  <http://fr.dbpedia.org/resource/> .
@prefix foaf:  <http://xmlns.com/foaf/0.1/> .

<0762762P>  rdf:type  dbo:Event ;
        dbo:status  "En cours" ;
        dbo:Place   _:b0 .

_:b0    dbf:Ville                   "Rouen" ;
    rdf:type dbo:EducationalInstitution ;
        foaf:name                   "Université du Havre" .

And the following ontology:

@prefix dbo:  <http://dbpedia.org/ontology/> .
@prefix ex:  <http://ex.org/a#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#'> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix dbf:  <http://fr.dbpedia.org/resource/> .
@prefix foaf:  <http://xmlns.com/foaf/0.1/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .

dbo:Event rdf:type owl:Class .
dbo:Place rdf:type owl:ObjectProperty ;
          rdfs:domain dbo:Event ;
          rdfs:range dbo:Event .
dbo:institution rdf:type owl:Class .
dbo:EducationalInstitution rdf:type owl:Class ;
                           rdfs:subClassOf dbo:institution .
dbo:Place rdf:type dbo:EducationalInstitution .

I'm not getting the expected results: nForce *:

micoco
  • 279
  • 1
  • 4
  • 16
  • Your schema is strange. 1. `dbo:Place` as a class in the DBpedia ontology. 2. In your ontology you declared it as object property, ok. But then you added this triple `dbo:Place rdf:type dbo:EducationalInstitution .` Which makes `dbo:Place` to an OWL individual as well. Why? – UninformedUser Nov 24 '17 at 12:57
  • Next, you're using relative URIs which is bad practice as those will be resolved to absolute URIs usually taking the document URI as namespace. You should start with absolute URIs and check if this already solves your problem. – UninformedUser Nov 24 '17 at 12:59
  • Last, what do you expect to be inferred in your example? – UninformedUser Nov 24 '17 at 13:01
  • I want to infer that if a "place" is of type "educational institution", then it is also an "institution". – micoco Nov 24 '17 at 17:35
  • You're mixing up things here. In your data nothing is of type `place`. So again ,what should be inferred here? The only thing that can be inferred is that `_:b0` is an `institution` – UninformedUser Nov 24 '17 at 18:03
  • And what is the meaning of `dbo:Place rdf:type dbo:EducationalInstitution .` ? – UninformedUser Nov 24 '17 at 18:05
  • Thanks for the help. The issue was fixed by dropping the prefix in the java code and replacing it by the authentic URI. – micoco Nov 24 '17 at 18:27
  • Yes, that's what I also mentioned in one of my previous comments. Use full URIs, not relative ones. Anyways, please read my answer below and rethink your current modeling – UninformedUser Nov 25 '17 at 09:57

1 Answers1

2

Your whole ontology is strange:

  1. You're reusing the DBpedia ontology in which dbo:Place is already defined as a class, but you're using it as an object property.
  2. Next, you declared the range of this object property to be an dbo:Event. Semantically, this also sound strange.
  3. You have a triple which assigns dbo:Place to be an instance of class dbo:EducationalInstitution. That means, in the end dbo:Place is a class, a property and an individual. This is really bad modelling.

Other conventions:

  • reusing ontologies is good, but you should not reuse the namespace but use your own namespace
  • naming convention:
    • for classes CamelCase style
    • for properties lowerCamelCase style

Why don't you use a more appropriate modelling like this:

@prefix dbo:  <http://dbpedia.org/ontology/> .
@prefix ex:  <http://ex.org/a#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#'> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .

dbo:Event rdf:type owl:Class .
ex:takesPlaceAt rdf:type owl:ObjectProperty ;
          rdfs:domain dbo:Event ;
          rdfs:range dbo:Place .
ex:Institution rdf:type owl:Class .
ex:EducationalInstitution rdf:type owl:Class ;
                           rdfs:subClassOf ex:Institution .
dbo:EducationalInstitution rdfs:subClassOf dbo:Place .

Regarding the data:

_:b0    dbf:Ville                   "Rouen" ;
    rdf:type ex:EducationalInstitution ;
        foaf:name                   "Université du Havre" .

DBpedia ontology has propertiesThat's for sure wrong.

  • dbf:Ville is not a property but an individual. Why do you use it as a property? The Dbpedia ontology has a property dbo:city. And the resource for Rouen exists already.

Maybe you could do it like this:

@prefix dbo:  <http://dbpedia.org/ontology/> .
@prefix ex:  <http://ex.org/a#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix dbr:  <http://dbpedia.org/resource/> .
@prefix foaf:  <http://xmlns.com/foaf/0.1/> .

<0762762P>  rdf:type  dbo:Event ;
        dbo:status  "En cours" ;
        dbo:Place   _:b0 .

_:b0    dbo:city                 http://dbpedia.org/resource/Rouen ;
    rdf:type ex:EducationalInstitution ;
        foaf:name                   "Université du Havre" .
UninformedUser
  • 8,397
  • 1
  • 14
  • 23