因此,我在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]
[这非常慢,加载大约需要5-10分钟才能搜索大约140种子注释类型,而仅使用注释需要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
的所有注释属性及其值,并且,可选地,如果该注释具有“子注释”,则还将检索该子注释。
“ XPath表达式,这是一种将搜索指定为XML结构的方法,也许可以完成工作。
参见:
https://docs.python.org/2/library/xml.etree.elementtree.html#xpath-support
如果您具有XML结构中的数据,则XPath可能可以遍历树(为您...)并检索感兴趣的节点。