有没有一种方法可以参数化sparql过滤条件? [英] is there a way to parameterize a sparql filter condition?
本文介绍了有没有一种方法可以参数化sparql过滤条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试找出以浮点值作为输入来参数化过滤条件的最佳方法是什么.
I am trying to find out what is the best way to parameterize a filter condition with a float value taken as input.
count=25.67
FILTER(?price < count)
代替:
FILTER ( ?price < 25.67 )
"count"的值将作为输入.
The value of "count" will be taken as input.
我想知道在FILTER命令中包括对象计数的语法.
I would like to know the syntax for including the object count in the FILTER command.
谢谢.
推荐答案
下面是setQuery
与通过`.format()添加的参数一起使用的示例:
Here's an example of setQuery
use with a parameter added via `.format():
from SPARQLWrapper import SPARQLWrapper, JSON
def query_dbpedia(my_uri)
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
q = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label
WHERE {{
{} rdfs:label ?label .
}}
""".format(my_uri)
sparql.setQuery(q)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
results_to_return = []
for result in results["results"]["bindings"]:
results_to_return.append(result["label"]["value"])
return results_to_return
print(query_dbpedia("http://dbpedia.org/resource/Asturias"))
(改编自SPARQLWrapper文档,网址为 https://sparqlwrapper.readthedocs.io/en /latest/main.html )
(adapted from SPARQLWrapper documentation at https://sparqlwrapper.readthedocs.io/en/latest/main.html)
这篇关于有没有一种方法可以参数化sparql过滤条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文