results = results['results']['bindings'] Flask error

穿精又带淫゛_ 提交于 2020-01-07 08:07:19

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/26885347/results-resultsresultsbindings-flask-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!