I'm running this query. It works fine on DBpedia (http://dbpedia.org/sparql), but it doesn't work in my Java code:
PREFIX res: <http://dbpedia.org/resource/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT ?book
WHERE {
?book a dbpedia-owl:Book .
?book dbpprop:author ?author .
?author dbpprop:name ?name
FILTER regex(?name, "Agatha Christie", "i")
}
Infact, as stated by the query validator (http://www.sparql.org/query-validator.html):
Line 7, column 9: Unresolved prefixed name: dbpprop:author
Why does it work in DBpedia then? Does DBpedia automatically add missing prefixes? Where may I found the prefix to make it work inside my Java code?
The DBpedia endpoint by defaults knows about many of the most common prefixes for the most common vocabularies. As pointed out by KBorja in the comment above these can be looked up here: http://dbpedia.org/sparql?nsdecl . So you want to add this to your prefixes:
PREFIX dbpprop: <http://dbpedia.org/property/>
Aside from that there also is an informal "prefix registry" that you can use to get a good guess if you encounter a prefix that you don't know the URI for: http://prefix.cc or http://prefix.cc/popular/all