使用前缀显示rdflib图中的实体

2024-05-16 15:11:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用rdflib将RDF图加载到Python scrpit中 我想用已定义的前缀打印主题列表 我没有找到任何方法来应用前缀。 我的代码

import rdflib
filepath = "... my file path ..."
gs = rdflib.Graph()
gs.bind('qs', "http://qs.org/")
gs.bind('foaf',"http://xmlns.com/foaf/0.1/")
gs.parse(filepath,format="nt")
mdstr = ""
for subject in gs.subjects():
    mdstr += str(subject) +"\n"
print(mdstr)

例如,我知道 http://qs.org/s12095 代替 质量标准:s12095


Tags: orggshttp主题定义bindrdfrdflib