xml - 有没有办法从 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>
非常感谢大家!
解决方案
从您的问题中,我了解到“子注释”级别只有一个深度。如果是这种情况,您可以按如下方式执行 SPARQL 查询:
SELECT ?annProp ?annValue ?subAnn ?subValue
WHERE {
?annProp a owl:AnnotationProperty .
<the:concept> ?annProp ?annValue .
OPTIONAL { ?annValue ?subAnn ?subValue . }
}
这将检索给定概念的所有注释属性及其值the:concept
,并且可选地,如果该注释具有“子注释”,它还检索该子注释。
推荐阅读
- postgresql - EF Core 实体配置未在 OnModelCreating 中应用
- r - 在 R 中使用 ANOVA 分析错误数量
- github - 在 circleci 中提取发行说明的任何方式
- webmethods - SAG Web 方法 - Soap Web 服务 - URL 别名
- python - 鉴于列可能具有多个值,将数据框列转换为 int dtype
- java - 自定义列表视图上的空对象引用错误
- azure-blob-storage - 使用逻辑应用创建并附加到 Blob 存储
- r - 使用 emmeans 的 2-way 和 3-way 交互的置信区间
- tsql - 在递归成员中使用函数的递归 CTE
- oracle - 以 oracle 11g 或 12c 形式直接打印