Search code examples
javajenadbpedia

How can I get category hierarchy from DBPedia?


I am using lookup service of DBpedia. My initial intend was using the class field in response of the lookup in order to do some kind of semantic search implementation. After some experience, I saw that class field returns empty for lots of the lookups. Then I thought that if I can use the category field for the same purpose.

Sample lookup; http://lookup.dbpedia.org/api/search.asmx/PrefixSearch?QueryClass=&MaxHits=1&QueryString=Antarctica

I found class hieararchy in dbpedia_2015-04.owl file and loaded it with Apache Jena. However, I couldn't find a way to load hierarchy of all categories.

I can lookup sub categories of a given category with following query in Virtuoso but I don't want to do remote calls in order to find parents/children of a category.

SELECT ?parent ?sub
WHERE {
  {
    ?sub skos:broader <http://dbpedia.org/resource/Category:Algebra>
  } UNION {
  <http://dbpedia.org/resource/Category:Algebra> rdfs:label ?parent
 }
}

Is there a file that contains hierarchy of categories? And how can I load it Jena or some other framework?


Solution

  • You can find a dump of categories here: http://dbpedia.org/Downloads2015-04#p25033-2

    A comprehensive guide on how to load a model into jena (depending on the syntax you will choose) can be found here. But let's assume you have chosen the turtle syntax, then the code in Jena will basically look like this:

    Model model = ModelFactory.createDefaultModel(); 
    model.read("data.ttl", "TURTLE") ;