我有一个本体巫婆在protege中创建,insid it:
我有2堂课(青少年和成人)。
我有一个带有dataproperty usage的约翰。
在Protege中,我按照他的年龄获得约翰的班级。(所以我的本体效果很好)
现在,我已经在Java加载了本体论,并试图让所有班级成年人(例如John In Protege)中的所有人。所以我做了
//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加载我的本体后,我该如何获得特定班级的个人?
您的代码中有几个错误:
- 您需要2个IRIS:一个用于加载您的本体论,该本体与
file:
一起使用,另一个用于您本体中使用的IRI,用于唯一识别本体学中的构造。 - 您必须 load 您的本体论,而不是创建它。
- 您必须使用其他原因。因此,而不是使用
StructuralReasonerFactory
使用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);
}