I found another way of checking if a dbpedia resource exists for a given string. The first part of the below query will check if a resource exists in dbpedia for the string "Bob Marly". The second part will check if the string "Bob Marly" redirects page to any other page. You need to capitalize the first letter of each string to get correct results.
I think this way is better since you'll know if a resource exists even if you make minor spelling mistakes and you also don't have to replace the spaces with underscores (not that it's that big a deal).
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?s WHERE {
{
?s rdfs:label "Bob Marly"@en ;
a owl:Thing .
}
UNION
{
?altName rdfs:label "Bob Marly"@en ;
dbo:wikiPageRedirects ?s .
}
}
Reference: http://www.snee.com/bobdc.blog/2011/05/using-sparql-to-find-the-right.html
There is one more way to achieve the above:
SELECT ?subject ?label
WHERE {
?subject rdfs:label ?label
FILTER (langMatches(lang(?label), "EN")) .
FILTER ( ?label = "Two"@en )
} LIMIT 100
DESCRIBE dbr:Game_of_Thrones
. More canonical way isASK { VALUES (?r) {(dbr:Game_of_Thrones)} {?r ?p ?o} UNION {?s ?r ?o} UNION {?s ?p ?r} }
. DBpedia understands even this:ASK { VALUES (?r) {(dbr:Game_of_Thrones)} {?r [] []} UNION {[] ?r []} UNION {[] [] ?r} }
– Quadrangular