SPARQL-未知的名称空间前缀错误 [英] SPARQL - Unknown namespace prefix error
问题描述
我有一个导入了rdflib的python文件,并实现了一些SPARQL查询
I have a python file with imported rdflib and some SPARQL query implemented
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,我收到一条错误消息:
res1 has no trouble to print out but for res2 I get an error saying:
Exception: Unknown namespace prefix : weather
显然,这是由于根据我所用的编辑器pycharm,第15行出现错误.
Apparently this is due to an error on line 15 according to pycharm, the editor I am using to implement this.
我遗漏了什么导致此错误?
在SPARQL查询中仅调用weather:region
还有其他功能吗?
如果可以,该如何解决此问题?
What am I missing that is causing this error?
Is there more to just calling weather:region
in my SPARQL query?
If so how to do fix this problem?
推荐答案
如错误消息所示,未定义名称空间weather:
-因此在SPARQL中,您需要使用PREFIX来定义天气,例如:
As the error message suggests, the namespace weather:
is not defined - so in the SPARQL you either need a PREFIX to define weather, like:
PREFIX weather: <weatheruri>
PREFIX weather: <weatheruri>
或者您应该放置明确的天气URI而不是weather:
Or you should put the explicit weather URI instead of the weather:
天气名称空间URI(或称为IRI?)将在rdf文档的XML名称空间中-它以/或#结尾,因此,如果URI为http://weather.com/
,则前缀定义为PREFIX weather: <http://weather.com/>
The weather namespace URI (or is it called an IRI?) will be in the XML namespaces in the rdf document - it will end with / or # so if the URI is http://weather.com/
the prefix definition is PREFIX weather: <http://weather.com/>
这篇关于SPARQL-未知的名称空间前缀错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!