2

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.

svick
  • 236,525
  • 50
  • 385
  • 514
Frown
  • 259
  • 1
  • 12

1 Answers1

5

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 
}

enter image description here 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.

Artemis
  • 3,271
  • 2
  • 20
  • 33
  • "However, each endpoint has some specific restrictions. Thus, Virtuoso doesn't simply like \ in the query." It's not that endpoints have specific restrictions; Virtuoso simply allows lots of things that **aren't** legal, and doesn't accept everything that **is** legal. (But aside from that, good answer. :)). – Joshua Taylor Jun 01 '15 at 16:36
  • Thanks, I rephrased it, as per your suggestion. – Artemis Jun 01 '15 at 17:01
  • @Artemis@Taylor Thx u both ! – Frown Jun 01 '15 at 18:44
  • @Artemis@Taylor When I query names with **umlaut** or **hyphen** such as “Georg_III._(Anhalt-Plötzkau)” or "Friedrich_von_Sachsen_(1504–1539)" like this: 'endpoint="http://live.dbpedia.org/sparql" query= "SELECT COUNT (*){ ?p ?o }" ' there still exists errors. Do you know why? – Frown Jun 01 '15 at 19:42
  • But that resource (Georg_III) doesn't exist. I checked by `SELECT distinct ?s{ ?s ?p ?o filter(contains(str(?s), "Anhalt")) }` and it doesn't show up. So I am assuming either it is present in a regional dbpedia, or your link is wrong. If you click on the resource it must open up, which it doesn't. This suggest you have an incorrect uri. – Artemis Jun 01 '15 at 20:09
  • @Artemis Sorry ;) it should be like this: ' '' endpoint="http://de.dbpedia.org/sparql" query= "SELECT COUNT (*){ ?p ?o }" ' – Frown Jun 01 '15 at 20:16
  • So if you write `SELECT COUNT (*){ ?p ?o}` it gives you the answer. You are missing the WHOLE uri. – Artemis Jun 01 '15 at 20:24