results = results['results']['bindings

2019-09-03 15:51发布

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条回答
Fickle 薄情
2楼-- · 2019-09-03 16:32

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.

查看更多
登录 后发表回答