简体   繁体   English

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

[英]Owl inference : How to get the class of Individuals after loading ontology

I have an ontology witch is created in protege, insid it : 我有一个本体创建女巫,它是insert:

I have 2 classes ( teenager and adult ). 我有2节课(青少年和成人)。

I have the individual John with a dataProperty hasAge. 我有一个John,他有一个dataProperty hasAge。

In protege i get the class of john according to his age. 为了保护我,我根据约翰的年龄得到了他的班级。 ( so my ontology work well) (所以我的本体工作正常)

Now i have loaded my ontology in java and i try to get all the individuals that are in the class adult ( Like John in protege ). 现在,我将自己的本体加载到Java中,并尝试使所有成人类的人(例如protege中的John)。 so i did 所以我做了

        //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);
        }

but i got nothing. 但是我什么都没有。

So how can i get the individuals of a specific class after loading my ontology in java ? 那么在用Java加载本体后如何获取特定类的个体?

There are a couple of errors in your code: 您的代码中有几个错误:

  1. You need 2 IRIs: One for loading your ontology which is prepended with file: , the other the IRI used in your ontology for uniquely identifying constructs in your ontology. 您需要2个IRI:一个用于加载本体的file: ,该file:前面带有file: :,另一个用于本体中的IRI,用于唯一标识本体中的构造。
  2. You have to load your ontology, not create it. 您必须加载您的本体,而不是创建它。
  3. You have to use a different reasoner. 您必须使用其他推理器。 So instead of using StructuralReasonerFactory use say Hermit . 因此,代替使用StructuralReasonerFactory而是使用Hermit See Hermit . 隐士 JFact also does not work. JFact也不起作用。

Here are the working code using Hermit: 以下是使用隐士的工作代码:

        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);
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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