RDF查询为字符串
我是RDF和SPARQL的新手。最近,我试图从Turtle File中查询数据,并希望将其放入列表中。但是我得到的是一堆'rdflib.term.literal'。如何将其转换为可以附加到列表的字符串?
query =f"""
SELECT (STR(?goal) AS ?label)
WHERE {{
{sub} {predi} {obj} .
}}"""
g.query(query)
try:
return g.query(query).goal
except:
result = []
for item in g.query(query):
result.append(item.label)
print(type(item.label))
return result
这是我制作的代码,但不起作用。
] 1
I am new to RDF and SPARQL. Recently I tried to query the data from turtle file, and want to put it in a list. But what I've got are bunch of 'rdflib.term.Literal'. How can I convert it to string that can be append into list?
query =f"""
SELECT (STR(?goal) AS ?label)
WHERE {{
{sub} {predi} {obj} .
}}"""
g.query(query)
try:
return g.query(query).goal
except:
result = []
for item in g.query(query):
result.append(item.label)
print(type(item.label))
return result
Here is the code I made but it does not work.
]1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论