[英]OWL Inferences With Jena (Turtle format)
I'm trying to make OWL inferences with Jena. 我正在尝试与耶拿进行OWL推断。 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
首先,我的目标只是推断如果一个教育机构是
dbo:EducationalInstitution
类型,那么它也是dbo:institution
Here's the java code (adapted from the jena doc) : 这是Java代码(改编自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 *:
我没有得到预期的结果:
nForce *:
Your whole ontology is strange: 您的整个本体很奇怪:
dbo:Place
is already defined as a class, but you're using it as an object property. dbo:Place
定义为类的DBpedia本体,但是您将其用作对象属性。 dbo:Event
. dbo:Event
。 Semantically, this also sound strange. dbo:Place
to be an instance of class dbo:EducationalInstitution
. dbo:Place
分配为dbo:EducationalInstitution
类的实例的三元组。 That means, in the end dbo:Place
is a class, a property and an individual. dbo:Place
最终是一个类,一个属性和一个个体。 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. DBpedia本体具有属性那肯定是错误的。
dbf:Ville
is not a property but an individual. dbf:Ville
不是财产而是个人。 Why do you use it as a property? dbo:city
. 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" .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.