我有一个本体论女巫是在保护下创造出来的,它坚持:
我有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中加载我的本体之后如何才能获得特定类的个体?
答案 0 :(得分:0)
您的代码中存在一些错误:
file:
,另一个用于本体中用于唯一标识本体中构造的IRI。StructuralReasonerFactory
而是使用Hermit
。见Hermit。 JFact也不起作用。以下是使用隐士的工作代码:
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);
}