首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用OwlApi从带有标签的owl文件中提取子类

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

Stack Overflow用户
提问于 2014-09-02 16:26:25
回答 1查看 1.5K关注 0票数 0

我正在研究从owl文件中提取类和子类。我正在使用OwlApi并提供来自dlquery教程示例的一些指导。除了处理保留字符的实体外,它工作得很好。有人建议我使用label注释,而不是从IRIs中提取实体,特别是使用AnnotationValueShortFormProvider而不是SimpleShortFormProvider。下面是检索所有子类的代码。让我们以“美国”为例作为实体。

代码语言:javascript
复制
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();
}

我的解析器是这样设置的:

代码语言:javascript
复制
this.parser = new DLQueryParser(rootOntology, shortFormProvider);

其中shortFormProvider是AnnotationValueShortFormProvider的一个实例

我的问题是,如何在不解析字符串'United‘的情况下实例化classExpression,因为解析字符串将提取前缀/令牌’United‘?或者,我们是否可以使用另一个示例代码块从标签注释(而不是IRIs )中检索子类?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-03 17:38:27

如果您有一个像'United‘这样的标签,Java字符串应该是"'United’“。单引号用于多字文字值。

如果您有标签值,您也可以直接在本体中查找,而不必使用曼彻斯特语法解析器。在相同的文档页面中,您可以找到DL查询示例,其中也有关于如何处理这个问题的示例。

代码语言:javascript
复制
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/Documentation

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25628078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档