[英]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: 您的代码中有几个错误:
file:
, the other the IRI used in your ontology for uniquely identifying constructs in your ontology. file:
,该file:
前面带有file:
:,另一个用于本体中的IRI,用于唯一标识本体中的构造。 StructuralReasonerFactory
use say Hermit
. StructuralReasonerFactory
而是使用Hermit
。 See Hermit . 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.