2

I'm using the DBPediaSpotLight library and trying to get uri for each word in dbpedia like:

Word: teach

the URI is: http//dbpedia.org/resource/Teacher

the Category: /business/job_title

and I want to get all sub-categories for the word "teach" (3) levels.. I'm try to look for query in sparql but I didn't find what I want.

Zong
  • 6,160
  • 5
  • 32
  • 46
AsoooNol
  • 33
  • 4

1 Answers1

3

http://dbpedia.org/resource/Teacher (abbreviated dbpedia:Teacher) isn't a category in DBpedia, so it doesn't really make sense to ask for subcategories of it. However, http://dbpedia.org/resource/Category:Teaching is a category, and does have sub-categories. DBpedia organizes categories using the skos:broader property. Each supercategory is skos:broader than its subcategories. To get its subcategories, up to three levels deep, you can use a query like this:

select distinct ?subcategory where {
  category:Teaching skos:broader?/skos:broader?/skos:broader ?subcategory
}

SPARQL results

A property path with a / means one property path followed by another. A question mark after a property path means 0 or 1 occurrence of the path. Thus the path

skos:broader?/skos:broader?/skos:broader

means (0 or 1 broader)/(0 or 1 broader)/broader, which means that you'll find links between Teaching and subcategories 1, 2, or 3 broader links away.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • I'm trying to do something similar to fetch all social event types. I found the category "Social_events" which has subcategories with actual social event types that I think they are what I need. I tried to do something similar with your example, but it displays weird data - `select distinct ?subcategory where { category:Social_events skos:broader?/skos:broader?/skos:broader ?subcategory }` – Ionut Negru Jan 27 '15 at 02:32
  • [Sparql query result](http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=select+distinct+%3Fsubcategory+where+%7B%0D%0A++category%3ASocial_events+skos%3Abroader%3F%2Fskos%3Abroader%3F%2Fskos%3Abroader+%3Fsubcategory%0D%0A%7D&format=text%2Fhtml&timeout=30000&debug=on) – Ionut Negru Jan 27 '15 at 02:33
  • I've tried to run the above query on "Teaching" on DBPedia SPARQL but I only get empty results. Anyone know if the query syntax has changed? – istewart Mar 10 '20 at 00:02
  • @istewart the query syntax hasn't changed, but Dbpedia has changed some of its default prefixes on that endpoint, so that might have an effect. – Joshua Taylor Mar 10 '20 at 10:54
  • 1
    @istewart eg, I see the error, "Virtuoso 37000 Error SP030: SPARQL compiler, line 4: Undefined namespace prefix at 'category' before 'skos:broader'". You'll perhaps need to add prefix definitions. – Joshua Taylor Mar 10 '20 at 10:55
  • Resolved: I did not define the "skos" prefix correctly. Thanks! – istewart Mar 10 '20 at 14:49