繁体   English   中英

使用OwlApi从带有标签的owl文件中提取子类

[英]Using OwlApi to extract subclasses from owl file with labels

我正在寻找从猫头鹰文件中提取类和子类。 我在dlquery教程示例的一些指导下使用OwlApi。 除处理带有保留字符的实体外,它效果很好。 建议我使用标签注释,而不是从IRI中提取实体,特别是使用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 States'的情况下实例化classExpression,因为解析字符串将提取前缀/令牌'United'? 还是有另一个示例代码块可用于通过使用标签注释而不是IRI来检索子类?

如果您有类似“美国”的标签,则Java字符串应看起来像“美国”。 单引号用于多字文字值。

如果您具有标签值,则也可以直接在本体中查找,而不必使用曼彻斯特语法解析器。 在同一文档页面中,您可以找到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://github.com/owlcs/owlapi/wiki/文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM