简体   繁体   English

耶拿的OWL推论(Turtle格式)

[英]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: 您的整个本体很奇怪:

  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. 您正在重用已经dbo:Place定义为类的DBpedia本体,但是您将其用作对象属性。
  2. Next, you declared the range of this object property to be an dbo:Event . 接下来,您将该对象属性的范围声明为dbo:Event Semantically, this also sound strange. 从语义上来说,这听起来也很奇怪。
  3. You have a triple which assigns 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: 其他约定:

  • reusing ontologies is good, but you should not reuse the namespace but use your own namespace 重用本体是好的,但是您不应该重用命名空间,而应该使用自己的命名空间
  • naming convention: 命名约定:
    • for classes CamelCase style 用于班级CamelCase风格
    • 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. DBpedia本体具有属性那肯定是错误的。

  • dbf:Ville is not a property but an individual. dbf:Ville 不是财产而是个人。 Why do you use it as a property? 为什么将它用作属性? The Dbpedia ontology has a property dbo:city . Dbpedia本体具有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM