Search code examples
pythonsparqldbpediaknowledge-graph

How to get all categories of an entity from DBpedia?


I am trying to build a dataset from DBpedia, but I am not super familiar with SPARQL. I think I need to do two things:

  1. Given an entity, I want to find all the dbc (categories) to which it belongs. E.g. in the page for Effiel Tower, you can see that there are 12 of them.

  2. In the opposite direction, given a dbc, e.g. Landmarks in France, I want to get all the subjects (instances) in the "is subject of" box.

I have looked through some other posts like post 1 and post 2, but was unable to apply them to my problems, especially the second problem. I would like some help with writing the SPARQL queries. Thank you!


Solution

    1. Categories of “Eiffel Tower”:
      SELECT * { dbr:Eiffel_Tower dct:subject ?category }
      
    2. Resources in category “Landmarks in France”:
      SELECT * { ?resource dct:subject dbc:Landmarks_in_France }
      

    The example on this page shows how to run SPARQL queries against DBpedia in Python.