Reputation: 299
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 *:
Upvotes: 0
Views: 469
Reputation: 8465
Your whole ontology is strange:
dbo:Place
is already defined as a class, but you're using it as an object property.dbo:Event
. Semantically, this also sound strange.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:
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" .
Upvotes: 2