I have a question about a SPARQL query that I'm trying to build from a tutorial. I want to generate triples that return a list of band members and the bands that they are in using a DBPedia endpoint.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?bandname where {
?person foaf:name ?name .
?band dbo:bandMember ?person .
?band dbo:genre dbpedia:Punk_rock .
?band dbp:name ?bandname .
}
I'm also using a [SPARQL query validator][2] to try to figure out my problem and it seems I'm using an incorrect prefix for "dbp:name ?bandname"I just want the triples returned in JSON if possible.
Once I can get this to run, I'd like to add another prefix, from GeoNames, to see the places associated with the bands, if possible (but that part is in the future). Any insights would be greatly appreciated!
There are some issues with your query.
PREFIX dbp: <http://dbpedia.org/property/>
Here is the query I used to retrieve a list of bands associated with their members :
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?members ?bandName where {
?band dbo:genre dbr:Punk_rock .
?band dbp:currentMembers ?members.
?band foaf:name ?bandName
FILTER(langMatches(lang(?bandName), "en"))
}
The filter part allows us to avoid duplicates in case the literals are also defined in other languages.
But if you still want to use the dbo:bandMember property, this query also does the job :
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?personName ?bandName where {
?band dbo:bandMember ?person .
?person foaf:name ?personName .
?band dbo:genre dbr:Punk_rock .
?band foaf:name ?bandName
FILTER(langMatches(lang(?bandName), "en"))
FILTER(langMatches(lang(?personName), "en"))
}
Hope that helps !