我正在研究从owl文件中提取类和子类。我正在使用OwlApi并提供来自dlquery教程示例的一些指导。除了处理保留字符的实体外,它工作得很好。有人建议我使用label注释,而不是从IRIs中提取实体,特别是使用AnnotationValueShortFormProvider而不是SimpleShortFormProvider。下面是检索所有子类的代码。让我们以“美国”为例作为实体。
private Set<OWLClass> getSubClasses(String cls, boolean direct) {
if (cls.trim().length() == 0) {
return Collections.emptySet();
}
OWLClassExpression classExpression = this.parser.parseClassExpression(cls);
NodeSet<OWLClass> subClasses = this.reasoner.getSubClasses(classExpression, direct);
return subClasses.getFlattened();
}
我的解析器是这样设置的:
this.parser = new DLQueryParser(rootOntology, shortFormProvider);其中shortFormProvider是AnnotationValueShortFormProvider的一个实例
我的问题是,如何在不解析字符串'United‘的情况下实例化classExpression,因为解析字符串将提取前缀/令牌’United‘?或者,我们是否可以使用另一个示例代码块从标签注释(而不是IRIs )中检索子类?
发布于 2014-09-03 17:38:27
如果您有一个像'United‘这样的标签,Java字符串应该是"'United’“。单引号用于多字文字值。
如果您有标签值,您也可以直接在本体中查找,而不必使用曼彻斯特语法解析器。在相同的文档页面中,您可以找到DL查询示例,其中也有关于如何处理这个问题的示例。
for(OWLClass owlClass: o.getClassesInSignature()){
// Get the annotations on the class that use the label property
for (OWLAnnotation annotation : owlClass.getAnnotations(o, dataFactoryf.getRDFSLabel())) {
if (annotation.getValue() instanceof OWLLiteral) {
OWLLiteral val = (OWLLiteral) annotation.getValue();
if (val.getLiteral().equals(inputLabel)) {
// at this point, the owlClass variable is the OWLClass you were looking for
NodeSet<OWLClass> subClasses = this.reasoner.getSubClasses(owlClass, direct);
return subClasses.getFlattened();
}
}
}
}https://stackoverflow.com/questions/25628078
复制相似问题