簡體   English   中英

有沒有辦法從 OWL (RDF/XML) 文件中快速訪問所有注釋和子注釋?

[英]Is there a way to quickly access all annotations and sub-annotations from an OWL (RDF/XML) file?

因此,我在 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所有注釋屬性及其值,並且可選地,如果該注釋具有“子注釋”,它還檢索該子注釋。

所以我忽略了明顯的...我將owlready2從 0.18 更新到 0.22,現在它快如閃電了。

“XPath 表達式”是一種在 XML 結構中指定搜索的方法,可能能夠完成工作。

看:

如何在 Python 中使用 Xpath?

https://docs.python.org/2/library/xml.etree.elementtree.html#xpath-support

如果您有 XML 結構中的數據,XPath 可能會遍歷樹(為您...)並檢索感興趣的節點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM