results = results ['results'] ['bindings']烧瓶错误 [英] results = results['results']['bindings'] Flask error

查看:194
本文介绍了results = results ['results'] ['bindings']烧瓶错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过这个Sparql查询获得结果绑定。
通过这个Sparql入口点: http:// digitale .bncf.firenze.sbn.it / openrdf-workbench / repositories / NS_03_2014 / query

我有错误:TypeError:query()至少2个参数(1给出)

谢谢!!!

pre $ code > @ app.route('/ caricaArgomento /< type>',methods = ['GET'])
def getArgomento(type):
#sparql = SPARQLUpdateStore(http:// digitale。 bncf.firenze.sbn.it/openrdf- workbench / repositories / NS_03_2014 / query)
sparql = SPARQLUpdateStore(http://digitale.bncf.firenze.sbn.it/openrdf-workbench/repositories/NS_03_2014/查询)
sparql.setQuery(
PREFIX dc:< http://purl.org/dc/elements/1.1/>
PREFIX rdfs:< http: //www.w3.org/2000/01/rdf-schema#>
PREFIX nsogi:< http://prefix.cc/nsogi>
PREFIX rdf:< http:// www.w3.org/1999/02/22-rdf -syntax-NS#>
PREFIX skos:< http://www.w3.org/2004/02/skos/core#>
PREFIX dcterms:< http://purl.org/dc/terms/>
SELECT?risultato
WHERE {
?item a skos:Concept。
?item skos:prefLabel?risultato。
过滤正则表达式(?risultato,+ type +,i)
} ORDER BY?risultato


#FILTER正则表达式(str(?aConcept),http://thes.bncf.firenze.sbn.it/,i)。}

sparql.setReturnFormat(JSON)
结果()结果= json.dumps(结果)

返回结果$($结果)='sparql.query()。convert()
results = results ['results'] ['bindings'] b $ b

digitale.bncf.firenze.sbn.it
digitale.bncf.firenze.sbn.it

解决方案

查看相关的 documentation sparql.query()... 需要一个查询参数。

  sparql = SPARQLUpdateStore(http://digitale.bncf.firenze.sbn.it/openrdf- workbench / repositories / NS_03_2014 / query)

sparql.setReturnFormat(JSON)

query =
PREFIX dc:< http://purl.org/dc/elements/1.1/>
PREFIX rdfs:< http://www.w3.org/2000/01/rdf-schema#>
PREFIX nsogi:< http://prefix.cc/nsogi>
PREFIX rdf:< http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX skos:< http://www.w3.org/2004/02/skos/core#>
PREFIX dcterms:< http://purl.org/dc/terms/>
SELECT?risultato
WHERE {
?item a skos:Concept。
?item skos:prefLabel?risultato。
filter regex(?risultato,+ type +,i)
} ORDER BY?risultato


results = sparql .query(query).convert()

我不能确定 sparql.setQuery(...)是,但很明显这不是你想要的。

编辑:



查看源代码 setQuery(...)确实供内部使用(例如,编写子类的人员)不是用于普通的api用户,它提取查询表单并记录查询文本 query(...)在内部调用它


I try to obtain results bindings by this Sparql query. Through this Sparql entry point: http://digitale.bncf.firenze.sbn.it/openrdf-workbench/repositories/NS_03_2014/query

I have the error: "TypeError: query() takes at least 2 arguments (1 given)

Thank you!!!

@app.route('/caricaArgomento/<type>', methods=['GET'])
def getArgomento(type):
    #sparql = SPARQLUpdateStore("http://digitale.bncf.firenze.sbn.it/openrdf-      workbench/repositories/NS_03_2014/query")
    sparql=SPARQLUpdateStore("http://digitale.bncf.firenze.sbn.it/openrdf-workbench/repositories/NS_03_2014/query")
    sparql.setQuery("""
    PREFIX dc:<http://purl.org/dc/elements/1.1/>
    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX nsogi:<http://prefix.cc/nsogi>
    PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
    PREFIX dcterms:<http://purl.org/dc/terms/>
        SELECT ?risultato
        WHERE {
         ?item a skos:Concept .
         ?item skos:prefLabel ?risultato .
         filter regex(?risultato, """+type+""", "i")
        } ORDER BY  ?risultato
         """)

     #FILTER regex(str(?aConcept), "http://thes.bncf.firenze.sbn.it/", "i").}

    sparql.setReturnFormat(JSON)
    results = sparql.query().convert()
    results = results['results']['bindings']
    results = json.dumps(results)

return results

digitale.bncf.firenze.sbn.it digitale.bncf.firenze.sbn.it

解决方案

Looking at the relevant documentation sparql.query()... requires a query argument.

sparql=SPARQLUpdateStore("http://digitale.bncf.firenze.sbn.it/openrdf-workbench/repositories/NS_03_2014/query")

sparql.setReturnFormat(JSON)

query = """
    PREFIX dc:<http://purl.org/dc/elements/1.1/>
    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    PREFIX nsogi:<http://prefix.cc/nsogi>
    PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
    PREFIX dcterms:<http://purl.org/dc/terms/>
    SELECT ?risultato
    WHERE {
     ?item a skos:Concept .
     ?item skos:prefLabel ?risultato .
     filter regex(?risultato, """+type+""", "i")
    } ORDER BY  ?risultato
"""

results = sparql.query(query).convert()

I can't work out what the purpose of sparql.setQuery(...) is, but clearly it's not what you want.

Edit:

Having looked at the source setQuery(...) is really for internal use (people writing subclasses, for example), and not for regular api users. It pulls out the query form and records the query text. query(...) calls it internally.

这篇关于results = results ['results'] ['bindings']烧瓶错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆