我正在尝试基于属性列表构建sparql查询,但是我收到一条错误消息,说明查询结果不好。问题是我不知道如何解决它。
这是功能:
def create_query(dbpedia_uri, props):
#props are something like this ('dbpedia-owl', 'birthdate')
filters = ''
for prop in QUERIES_DICT[ename]:
filters += ' OPTIONAL { ?x %s:%s ?%s. } \n' % (corresp_dict[prop[0]], prop[1], prop[1])
query = u"""
SELECT * WHERE {
. <%s>.
?x dbpedia-owl:abstract ?abstract.
%s
FILTER (LANG(?abstract) = 'en')
}
""" % (dbpedia_uri, filters)
return query
这是我得到的查询:
u"\n SELECT * WHERE { <http://dbpedia.org/resource/Tim_Cook>\n ?x dbpedia-owl:abstract ?abstract.\n OPTIONAL { ?x dbpedia-owl:birthDate ?birthDate. }\n OPTIONAL { ?x dbpedia-owl:birthPlace ?birthPlace. }\n OPTIONAL { ?x dbpprop:name ?name. }\n OPTIONAL { ?x dbpedia-owl:profession ?profession. }\n OPTIONAL { ?x dbpprop:residence ?residence. }\n OPTIONAL { ?x dbpprop:website ?website. }\n \n FILTER (LANG(?abstract) = 'en')\n }\n "
或打印:
SELECT * WHERE { <http://dbpedia.org/resource/Tim_Cook>
?x dbpedia-owl:abstract ?abstract.
OPTIONAL { ?x dbpedia-owl:birthDate ?birthDate. }
OPTIONAL { ?x dbpedia-owl:birthPlace ?birthPlace. }
OPTIONAL { ?x dbpprop:name ?name. }
OPTIONAL { ?x dbpedia-owl:profession ?profession. }
OPTIONAL { ?x dbpprop:residence ?residence. }
OPTIONAL { ?x dbpprop:website ?website. }
FILTER (LANG(?abstract) = 'en')
}
答案 0 :(得分:5)
您需要定义所有使用的前缀,例如dbpprop,dbpedia-owl