Skip to content

SPARQL endpoint query #35

@zoometh

Description

@zoometh

✅ This Python code works with the DBpedia SPARQL endpoint and returns a JSON object

sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("""
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    SELECT ?label
    WHERE { <http://dbpedia.org/resource/Asturias> rdfs:label ?label }
""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
    print(result["label"]["value"])

🔴 But this code doesn't works with Nomisma:

sparql = SPARQLWrapper("http://nomisma.org/sparql/")
sparql.setQuery("""
PREFIX dcterms:  <http://purl.org/dc/terms/>
PREFIX skos:  <http://www.w3.org/2004/02/skos/core#>

SELECT ?concept ?label WHERE {
  ?concept dcterms:isPartOf <http://nomisma.org/id/celtic_numismatics> .
  OPTIONAL { ?concept skos:prefLabel ?label . FILTER (lang(?label) = "en") }
}
""")
print('\n\n*** JSON Example')
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
    print(result["label"]["value"])

With this error: it returns a bytes containing the SPARQL page HTML content: b'<!DOCTYPE html>\n<html lang="en">..

What would be the fix if I want to query the Nomisma SPARQL endpoint remotely?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions