我用prot建立了一个小本体é克é 其中包含4个类:类人及其子类(学生、讲师)和类模块及其子类(mathmodule和csmodule),我有两个对象属性:教学和学习。我仍然是owlapi的初学者,我想做的是加载这个本体并迭代不同的类(包括子类),以便创建和插入与对象属性相关的个体。我开始做这个只有一个班,但我不知道我怎么能为其余的类。
public class adding_individuals {
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
try {
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File("C:\\..\\university.owl"));
OWLDataFactory dataFactory = manager.getOWLDataFactory();
//:lecturer 3 is an instance of the class :Lecturer and CS101 is an instance of CSModule
OWLClass Lecturer = dataFactory.getOWLClass(":Lecturer");
OWLClass CSModule = dataFactory.getOWLClass(":CSModule");
OWLNamedIndividual lecturer3 = dataFactory.getOWLNamedIndividual(":lecturer3");
OWLNamedIndividual CS101 = dataFactory.getOWLNamedIndividual(":CS101");
// create a property "teaches"
OWLObjectProperty teaches = dataFactory.getOWLObjectProperty(":teaches");
// To specify that :lecturer3 is related to :CS101 via the :teaches property, we create an object property
// assertion and add it to the ontology
OWLObjectPropertyAssertionAxiom propertyAssertion = dataFactory.getOWLObjectPropertyAssertionAxiom(teaches, lecturer3, CS101);
manager.addAxiom(ontology, propertyAssertion);
// Dump the ontology
StreamDocumentTarget target = new StreamDocumentTarget(new ByteArrayOutputStream());
manager.saveOntology(ontology);
} catch (OWLOntologyCreationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OWLOntologyStorageException eo) {
// TODO Auto-generated catch block
eo.printStackTrace();
}
}
}
1条答案
按热度按时间gg0vcinb1#
要迭代所有类,请使用
ontology.classesInSignature()
(在API 5中,否则ontology.getClassesInSignature()
).但是,我假设您需要一些更精确的标准来选择要使用的类—对所有类的迭代将包括对所有类的迭代
Persons
以及Modules
. 我想你应该有更多的选择。