【发布时间】:2018-11-09 15:03:56
【问题描述】:
我有一个导入了 rdflib 并实现了一些 SPARQL 查询的 python 文件
from rdflib import Graph
import html5lib
if __name__ == '__main__':
g = Graph()
g.parse('http://localhost:8085/weather-2.html', format='rdfa')
res1 = g.parse('http://localhost:8085/weather-2.html', format='rdfa')
print(res1.serialize(format='pretty-xml').decode("utf-8"))
print()
res2 = g.query("""SELECT ?obj
WHERE { <http://localhost:8085/weather-2.html> weather:region ?obj . }
""")
for row in res2:
print(row)
res1 打印出来没有问题,但是对于 res2,我收到一条错误消息:
Exception: Unknown namespace prefix : weather
根据我用来实现此功能的编辑器 pycharm,这显然是由于第 15 行出现错误。
我错过了什么导致此错误?
在我的 SPARQL 查询中调用 weather:region 是否还有更多内容?
如果是这样如何解决这个问题?
【问题讨论】:
标签: python pycharm sparql rdflib rdfa