Ok, I just learned to use SPARQL to query data from dbpedia.org, and I use dbpedia http://dbpedia.org/snorql/ to run my queries. I am trying to get a list of MusicalArtists based on finding the same string over three fields, for example:
SELECT ?subject ?artistRdfsLabel ?artistFoafName ?artistDbpedia2Name WHERE { ?subject rdf:type <http://dbpedia.org/ontology/MusicalArtist> . OPTIONAL { ?subject rdfs:label ?artistRdfsLabel . } OPTIONAL { ?subject foaf:name ?artistFoafName . } OPTIONAL { ?subject dbpedia2:name ?artistDbpedia2Name . } FILTER ( str(?artistRdfsLabel) = "Stevie Nicks" || str(?artistFoafName) = "Stevie Nicks" || str(?artistDbpedia2Name) = "Stevie Nicks" ) } LIMIT 10
This works because "Stevie Nicks" has all three fields (rdfs: label, foaf: name, dbpedia2: name). But when I try to request another MusicalArtist that does not have all three (e.g. Depeche Mode), I get no results.
I tried various things like BIND (COALESCE (? Field, ..., ...) AS? ArtistName) to filter? artistName, and I also tried UNION, but nothing works. Can anyone point out the error of my SPARQL methods? :)
Thanks! Jason
source share