With rdflib's Graph.query, is there a way to pass in a list of values to use in a SPARQL query? I'm aware of the initBindings
argument for binding single values to variables, but I'm looking to pass in the equivalent of a VALUES block.
Conceptually, something like this:
from rdflib import Graph, URIRef
g = Graph()
query = """
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?org ?label ?altLabel
WHERE {
SERVICE <https://query.wikidata.org/sparql> {
?org rdfs:label ?label filter (lang(?label) = "en") .
OPTIONAL {
?org skos:altLabel ?altLabel filter (lang(?altLabel) = "en") .
}
VALUES (?org) { ?values }
}
}
"""
values = (
(URIRef("http://www.wikidata.org/entity/Q533617"),),
(URIRef("http://www.wikidata.org/entity/Q706184"),),
)
# Something like initBindings, but for list of values?
res = g.query(query, values=values)