1

Having the following query, I desire to show only "Jorge Glas"

prefix dbp: <http://dbpedia.org/property/> 
prefix dbpedia:<http://dbpedia.org/resource/>
prefix dbpedia-owl:<http://dbpedia.org/ontology/>
SELECT str(?leader) as ?label
WHERE {
dbpedia:Ecuador dbpedia-owl:leader ?leader
}

I desire to show only "Jorge Glas"

Abdulrahman Bres
  • 2,603
  • 1
  • 20
  • 39

1 Answers1

4

There are a couple of ways to approach this. One is to use SPARQL REPLACE to get the string you want:

REPLACE(?leader, "^.*/", "")

That gets you "Jorge_Glas", then you can do the same to replace the underscore with a space:

REPLACE(?x, "_", " ")

However, this is not how you should use DBPedia resources. Most DBPedia resources have an rdfs:label that will give you the desired name result in multiple languages. So a first step is to find out what DBPedia has on these resources through an exploratory query:

SELECT (str(?leader) as ?label) ?p ?o
WHERE {
   dbpedia:Ecuador dbpedia-owl:leader ?leader .
   ?leader ?p ?o
}

You'll find that the matches for ?leader have rdfs:label properties in multiple languages. To get the English label, use the following:

SELECT ?leaderName
WHERE {
   dbpedia:Ecuador dbpedia-owl:leader ?leader .
   ?leader rdfs:label ?leaderName .
   FILTER (lang(?leaderName) = "en")
}
scotthenninger
  • 3,921
  • 1
  • 15
  • 24
  • **replace** is useful, but in a case like this where the prefix send to always be the same, **strafter** Can suffice, as in the older, essentially the same, http://stackoverflow.com/questions/28479394/why-my-sparql-query-return-uri-of-a-class-instead-of-its-name?lq=1. – Joshua Taylor Mar 06 '16 at 23:52
  • strafter() would be more performant if the prefix is known for all results. if this isn't the case a regex solution can be use. – scotthenninger Mar 07 '16 at 15:08