Search code examples
rdfsparqldbpedia

SPARQL query to get skos:broader property of a dbpedia category


I am using the endpoint http://dbpedia.org/sparql to query dbpedia for "skos:broader" property given a category. I've taken the categories from http://dbpedia.org/page/Andreessen_Horowitz to do the queries. I'm not sure what I did wrong in the following queries:

a. I got syntax error with this one. How do I escape ","?

prefix category: <http://dbpedia.org/resource/Category:>
select ?value where { 
  category:Companies_based_in_Menlo_Park,_California skos:broader ?value 
}

b. I got empty result with this one. But if I replaced the URI with "category:American_venture_capital_firms" then I got result back (with the proper prefix declaration).

select ?value where { 
  <http://dbpedia.org/page/Category:American_venture_capital_firms> skos:broader ?value 
}

Solution

  • Regarding point a, you can escape characters in a SPARQL 1.1 prefixed name by adding a backslash in front:

    category:Companies_based_in_Menlo_Park\,_California
    

    Unfortunately, however, that does not work on the DBPedia endpoint, because its SPARQL engine is not fully up to date with the SPARQL 1.1 standard. A workaround is to use the full IRI instead of the prefixed name, by 'expanding' the prefix:

    select ?value where { 
      <http://dbpedia.org/resource/Category:Companies_based_in_Menlo_Park,_California> skos:broader ?value 
    }
    

    Regarding point b: that query is not giving a result because you are using the wrong URI. You have '...dbpedia.org/page/Category:...' in your query, it should be '...dbpedia.org/resource/Category:...'.

    DBPedia URIs with /page/ in them are HTML info pages about a resource, whereas the URIs with /resource/ in them are the actual identifiers of the resource itself. The latter is what you should always be querying with SPARQL.