使用OWL API 3.4.9。
给定一个OWLClass
和本体,如何在该本体中获取该<rdfs:label>
的OWLClass
?
我希望以String
的类型获取标签。
最佳答案
受guide to the OWL-API的启发,以下代码应该可以正常工作(未经测试):
//Initialise
OWLOntologyManager m = create();
OWLOntology o = m.loadOntologyFromOntologyDocument(pizza_iri);
OWLDataFactory df = OWLManager.getOWLDataFactory();
//Get your class of interest
OWLClass cls = df.getOWLClass(IRI.create(pizza_iri + "#foo"));
// Get the annotations on the class that use the label property (rdfs:label)
for (OWLAnnotation annotation : cls.getAnnotations(o, df.getRDFSLabel())) {
if (annotation.getValue() instanceof OWLLiteral) {
OWLLiteral val = (OWLLiteral) annotation.getValue();
// look for portuguese labels - can be skipped
if (val.hasLang("pt")) {
//Get your String here
System.out.println(cls + " labelled " + val.getLiteral());
}
}
}
关于semantic-web - 使用OWL API,给定OWLClass,如何获取<rdfs :label> of it?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20780425/