如何在 Jena 中使用 Transitive Reasoner?

How to use Transitive Reasoner with Jena?

我想使用 Jena 设置一个 TransitiveReasoner,以根据模式和数据集创建一个新的推理模型。它适用于 RDFS 推理器,但不适用于 TransitiveReasoner。

这是我对推理的第一次体验;我查看了 Jena Inference Support 和其他教程,但无法解决我的问题。

这是我在 java 中的测试代码:

import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.vocabulary.*;

public class TestInference 
{

    public static void myTest() throws IOException
    {
      String NS = "testInference:";
      OntModel schema = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
      OntClass m = schema.createClass(NS + "Mention");
      OntClass pm = schema.createClass(NS + "PersonMention");
      pm.addProperty(RDFS.subClassOf, m);

      Model data = ModelFactory.createDefaultModel();
      Resource r = data.createResource(NS+"alberto");
      r.addProperty(RDF.type, pm);

      Reasoner rdfsReasoner = ReasonerRegistry.getRDFSSimpleReasoner();
      Reasoner transReasoner = ReasonerRegistry.getTransitiveReasoner();

      System.out.println("\n===== RDSF =====");
      InfModel rdfsInf = ModelFactory.createInfModel(rdfsReasoner, schema, data);
      rdfsInf.write(System.out, "TURTLE");

      System.out.println("\n===== Trans =====");
      InfModel transInf = ModelFactory.createInfModel(transReasoner, schema, data);
      transInf.write(System.out, "TURTLE");
}

public static void main(String[] args) throws IOException
{
    myTest();
}

尝试更改 OntModelSpec 没有帮助。

我做错了什么?

在此先感谢您的帮助。

TransitiveReasoner只处理了RDFSsubClassOf和RDFSsubPropertyOf的传递性。它没有提供rdf:type.

的步骤
A subClassOf B . B subClassOf C => A subClassOf C

但不是这部分:

x type T . T subClassOf S => x type S

https://jena.apache.org/documentation/inference/#transitive