使用 RDFLIB 获取每个类的元素

发布于 2025-01-11 02:55:20 字数 1336 浏览 0 评论 0原文

我有一个 OWL RDF 数据文件,其中包含多个数据,例如以下示例:

<!-- http://purl.obolibrary.org/obo/OGMS_0000014 -->

    <owl:Class rdf:about="http://purl.obolibrary.org/obo/OGMS_0000014">
        <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/OGMS_0000123"/>
        <obo:IAO_0000115 xml:lang="en">A representation that is either the output of a clinical history taking or a physical examination or an image finding, or some combination thereof.</obo:IAO_0000115>
        <obo:IAO_0000117>Albert Goldfain</obo:IAO_0000117>
        <obo:IAO_0000119>http://ontology.buffalo.edu/medo/Disease_and_Diagnosis.pdf</obo:IAO_0000119>
        <obo:IAO_0000232>creation date: 2010-07-19T10:18:02Z</obo:IAO_0000232>
        <rdfs:label>clinical finding</rdfs:label>
    </owl:Class>

并且只需要提取 rdfs:label标签。

我成功地读取了 RDF 文件,如下所示:

from rdflib import Graph, URIRef
g = Graph()
g.parse("ogms_20210819.owl")

然后像往常一样循环遍历它:

# Loop through each triple in the graph (subj, pred, obj)
for subj, pred, obj in g:
    print(subj, pred, obj)

但我不明白如何从每个类所需的两个标签中仅获取文本。

非常感谢您的帮助。

I have an OWL RDF data file that contains several data such as the following example:

<!-- http://purl.obolibrary.org/obo/OGMS_0000014 -->

    <owl:Class rdf:about="http://purl.obolibrary.org/obo/OGMS_0000014">
        <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/OGMS_0000123"/>
        <obo:IAO_0000115 xml:lang="en">A representation that is either the output of a clinical history taking or a physical examination or an image finding, or some combination thereof.</obo:IAO_0000115>
        <obo:IAO_0000117>Albert Goldfain</obo:IAO_0000117>
        <obo:IAO_0000119>http://ontology.buffalo.edu/medo/Disease_and_Diagnosis.pdf</obo:IAO_0000119>
        <obo:IAO_0000232>creation date: 2010-07-19T10:18:02Z</obo:IAO_0000232>
        <rdfs:label>clinical finding</rdfs:label>
    </owl:Class>

and need to extract only the strings following the rdfs:label and the <obo:IAO_0000115 xml:lang="en"> tags for each class.

I am successfully reading the RDF file as follows:

from rdflib import Graph, URIRef
g = Graph()
g.parse("ogms_20210819.owl")

and then loop through it as usual:

# Loop through each triple in the graph (subj, pred, obj)
for subj, pred, obj in g:
    print(subj, pred, obj)

but I'm not understanding how to fetch only the text from the two tags I need for each class.

Thanks a lot for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文