猫头鹰推理:如何在加载本体后获得个人类

时间:2017-12-05 15:51:25

标签: java owl type-inference reasoner

我有一个本体论女巫是在保护下创造出来的,它坚持:

我有2个班(青少年和成人)。

我有个人John带有dataProperty hasAge。

为了保护我根据他的年龄得到约翰的班级。 (所以我的本体很好)

现在我已经在java中加载了我的本体,并且我试图让所有成人中的所有人(像约翰一样保护)。所以我做了

        //manager
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

        //IRI
        String x = "file:/D:/Studies/tpOwl.owl";
        IRI ontologyIRI = IRI.create(x);

        //ontology
        OWLOntology ont = manager.createOntology(ontologyIRI);

        //factory
        OWLDataFactory factory = manager.getOWLDataFactory();


        OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
        OWLReasoner reasoner = reasonerFactory.createReasoner(ont);

        OWLClass adult = factory.getOWLClass(IRI.create(ontologyIRI + "#Adult"));
        NodeSet<OWLNamedIndividual> instancess = reasoner.getInstances(adult, true);
        for (Node<OWLNamedIndividual> i : instancess)
        {
         System.out.println(""+i);
        }

但我一无所获。

那么在java中加载我的本体之后如何才能获得特定类的个体?

1 个答案:

答案 0 :(得分:0)

您的代码中存在一些错误:

  1. 您需要2个IRI:一个用于加载本体,前面加file:,另一个用于本体中用于唯一标识本体中构造的IRI。
  2. 您必须加载您的本体,而不是创建它。
  3. 你必须使用不同的推理器。因此,不要使用StructuralReasonerFactory而是使用Hermit。见Hermit。 JFact也不起作用。
  4. 以下是使用隐士的工作代码:

            OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    
            //IRI
            Path path = Paths.get(".").toAbsolutePath().normalize();
            IRI loadDocumentIRI = IRI.create("file:/D:/Studies/tpOwl.owl");
    
            IRI ontologyIRI = IRI.create("http://www.semanticweb.org/akkou/ontologies/2017/10/tp-ontology");
    
    
            //ontology
            OWLOntology ont = manager.loadOntologyFromOntologyDocument(loadDocumentIRI);
    
            //factory
            OWLDataFactory factory = manager.getOWLDataFactory();
    
    
            OWLReasonerFactory reasonerFactory = new ReasonerFactory();
            OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
    
    
            OWLClass adult = factory.getOWLClass(IRI.create(ontologyIRI + "#Adult"));
            NodeSet<OWLNamedIndividual> instancess = reasoner.getInstances(adult, true);
            for (Node<OWLNamedIndividual> i : instancess)  {
             System.out.println(""+i);
            }