Search code examples
dbpediaspotlight-dbpedia

How to extract DBPedia categories through DBPedia Spotlight?


I'm trying to extract the types and their respective levels from an entity named through DBPediaSpotlight. I already looked in forums, the documentation of the git hub and found nothing. I would like to know one way to do this extraction. Thank you!


Solution

  • Given that your desired root is <http://www.w3.org/2002/07/owl#Thing>, you're actually looking for the rdf:type tree (not Wikipedia Categories, as such).

    The typing of <http://dbpedia.org/resource/Semantic_Web> seems a bit odd, so I've used <http://dbpedia.org/resource/Cat> below. You'll note that the data does not always include a tree of the sort you wish.

    This will get explicit rdf:type statements --

    SELECT ?type
     WHERE
       { <http://dbpedia.org/resource/Cat> a ?type
       }
    

    -- and this will climb to the top of any rdf:type trees --

    SELECT ?type
     WHERE
       { <http://dbpedia.org/resource/Cat> a+ ?type
       }
    

    A query to build the full tree would be rather more complex, but is entirely possible.