0

I have a SPARQL Query that returns the Europe capitals and their population. The query looks like this:

 select ?s ?pop
 where {
    ?s <http://dbpedia.org/ontology/populationTotal> ?pop . 
    ?s a <http://dbpedia.org/ontology/place> 
 }

In this state, it returns the names of the cities in the following form: e.g. "<http://dbpedia.org/resource/London>" and what I want is to display only London in this case. So, is there a way I can tell SPARQL that I want only the final label?

I am querying against this endpoint: https://rdf.s4.ontotext.com/4730361296/demo01/repositories/test01

scotthenninger
  • 3,921
  • 1
  • 15
  • 24

1 Answers1

0

The advice here is similar to other questions - use SPARQL to inspect the data. So first try this query to see if there are any label properties defined:

select *
where {
  ?s <http://dbpedia.org/ontology/populationTotal> ?pop . 
  ?s a <http://dbpedia.org/ontology/place> .
  ?s ?p ?o .
}

In this case you'll find that no label properties have been defined for place class definitions. If desired you can take the local name - the text after the last slash (or hash) as the name. Try this query:

select *
where {
  ?s <http://dbpedia.org/ontology/populationTotal> ?pop . 
  ?s a <http://dbpedia.org/ontology/place> .
  BIND(REPLACE(xsd:string(?s), ".*[/#]", "") AS ?label)
}
scotthenninger
  • 3,921
  • 1
  • 15
  • 24