I am currently querying DBPedia for a list of person names by using the SPARQL package in R. When I retrieve a list of names by SPARQL, there appears a problem that some names in the form of URI, which contains punctuation marks (such as "," or "(") can't be recognized by SPARQL query, e.g.:
endpoint="http://de.dbpedia.org/sparql"
query= "SELECT COUNT (*){
dbpedia-de:Johannes_Aurifaber_(Vimariensis) ?p ?o
}"
qd=SPARQL(endpoint,query)
It turns out to be an error: XML content does not seem to be XML: 'Virtuoso 37000 Error SP030: SPARQL compiler, line 3: syntax error at 'Vimariensis' before ')'. But if I change the query to this:
endpoint="http://de.dbpedia.org/sparql"
query= "SELECT COUNT (*){
<http://de.dbpedia.org/resource/Johannes_Aurifaber_(Vimariensis)> ?p ?o
}"
qd=SPARQL(endpoint,query)
Everything turns out well. But is there any way to modify the first query, as it is more convenient to do query for a list of person names.
You should be able to put \
before special characters, and it is a valid SPARQL query. This is a valid SPARQL query:
SELECT (count(*) as ?count)
where {
dbpedia-de:Johannes_Aurifaber_\(Vimariensis\) ?p ?o
}
However, each endpoint has some specific restrictions. Thus, (as per Joshua's comment) Virtuoso simply allows lots of things that aren't legal, and doesn't accept everything that is legal.