首页 > 解决方案 > 有没有办法从 OWL (RDF/XML) 文件中快速访问所有注释和子注释?

问题描述

所以我有一个我在 Protege 中构建的本体,它有注释和子注释。我的意思是,一个概念可能有定义,而该定义可能有注释。

所以你可能有类似(s,p,o)的东西:

'http://purl.fakeiri.org/ONTO/1111' --> 'label' --> 'Term'

'Term' --> 'comment' --> 'Comment about term.'

我正在尝试使用 Flask 应用程序使本体易于探索(我正在使用 Python 来解析本体文件),但我似乎无法快速获取所有注释和子注释。

我开始使用该owlready2包,但它要求您自定义每个单独的注释属性(您不能只获取所有这些属性的列表,因此如果您添加一个属性,例如random_identifier您必须返回代码并添加entity.random_identifier或它不会被接走)。这工作正常,速度非常快,但子注释需要加载 IRI,然后搜索它:

random_prop = IRIS['http://schema.org/fillerName']
sub_annotation = x[entity, random_prop, annotation_label]

这非常慢,加载搜索大约 140 种子注释类型需要 5-10 分钟,而仅注释大约需要 3-5 秒。

从那里我决定报废owlready2并尝试rdflib。但是,看起来子注释只是作为 BNode 附加的,我无法弄清楚如何通过它们的“父”注释访问它们,或者是否有可能。

TL;DR:有人知道如何访问一个条目并在 XML/RDF 本体文件中快速收集其所有注释和子注释吗?

编辑1:

正如所建议的,这里是本体的一个片段:

    <!-- http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C42610 -->

    <owl:Class rdf:about="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C42610">
        <rdfs:subClassOf rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C42698"/>
        <obo:IAO_0000115 xml:lang="en">A shortened form of a word or phrase.</obo:IAO_0000115>
        <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">https://en.wikipedia.org/wiki/Abbreviation</oboInOwl:hasDbXref>
        <rdfs:label xml:lang="en">abbreviation</rdfs:label>
        <schema:alternateName xml:lang="en">abbreviations</schema:alternateName>
        <Property:P1036 rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">411</Property:P1036>
    </owl:Class>
    <owl:Axiom>
        <owl:annotatedSource rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C42610"/>
        <owl:annotatedProperty rdf:resource="https://www.wikidata.org/wiki/Property:P1036"/>
        <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">411</owl:annotatedTarget>
        <schema:bookEdition rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">20</schema:bookEdition>
    </owl:Axiom>

非常感谢大家!

标签: xmlpython-3.6rdfontologyrdflib

解决方案


从您的问题中,我了解到“子注释”级别只有一个深度。如果是这种情况,您可以按如下方式执行 SPARQL 查询:

SELECT ?annProp ?annValue ?subAnn ?subValue
WHERE { 
   ?annProp a owl:AnnotationProperty .
   <the:concept> ?annProp ?annValue . 
   OPTIONAL { ?annValue ?subAnn ?subValue . }
}

这将检索给定概念的所有注释属性及其值the:concept,并且可选地,如果该注释具有“子注释”,它还检索该子注释。


推荐阅读