使用 RDFLIB 获取每个类的元素
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论