Hi. I am trying to write a SPARQL query to retrieve all the categories that have people in them. I am getting the categories with people but the count is wrong. Can you please help me figure out why.

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
SELECT count(?person) as ?pcount  ?concept  where {
     {?s skos:broader ?concept}
     {?s skos:Concept ?concept.}
     ?person skos:subject ?concept .
     ?person rdf:type dbpedia-owl:Person

I also tried to use ?person foaf:name ?name ?person dbo:birthDate ?birth

but that didn't help much. Please let me know what do i need to add to make sure its a person.

Thanks in advance!

asked 03 Oct '11, 19:54

yanz's gravatar image

accept rate: 0%

edited 03 Oct '11, 21:33


skos:subject -> dct:subject.

skos:Concept is not defined in SKOS and never used as a predicate in DBpedia... not sure what you're getting at there.

cf. http://dbpedia.org/page/Tim_Berners-Lee

(10 Oct '11, 07:58) Signified ♦ Signified's gravatar image

Thanks for the response. What i am trying to get a list of categories that include people in them. I have a query that will extract people names from a category for example http://dbpedia.org/resource/Category:Native_American_sportspeople. Instead of looking for categories manually i would like to get these type of categories in the list which include people that i can extract with the other query. I hope this makes it clearer.

Thanks again!

(11 Oct '11, 22:59) yanz yanz's gravatar image

For membership of "direct" categories, you just need this in the WHERE clause:

... WHERE { ?person dct:subject ?concept ; dbpedia-owl:Person . }

If you wanted to do the closure of categories (i.e., also include categories which are higher up in the hierarchy of those directly containing people), using SPARQL 1.1 property paths you could add

... WHERE { ... ?concept skos:broader+ ?bconcept . }

...however, I'd recommend against that since the DBpedia category hierarchy is quite messy, where skos:broader forms large/numerous cycles. If possible, stick to direct categories.

(12 Oct '11, 09:27) Signified ♦ Signified's gravatar image

...also, I think now I see the confusion. If running this query over DBpedia, any value for dct:subject can be assumed to be a category. There's no need to add additional checks. If you wanted to be doubly sure, use:

... WHERE { ... ?concept rdf:type skos:Concept . ... }

or a REGEX FILTER checking that the URI starts with http://dbpedia.org/resource/Category: should be a faster, but more hacky option.

(12 Oct '11, 09:31) Signified ♦ Signified's gravatar image

Yanz; This is really difficult to say without knowing what is in your data. Currently the query looks for all members of the dbpedia-owl:Person class that have a skos:subject property that is a skos:Concept. Membership in skos:Concept is entailed in the skos:broader relationship, so it's unclear whether the UNION is needed. If you have SPARQL 1.1, the UNION pattern you have can be expressed in a property path:

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
SELECT count(?person) as ?pcount  ?concept 
{  ?s skos:broader | skos:Concept ?concept.
   ?person skos:subject ?concept .
   ?person rdf:type dbpedia-owl:Person

But in the end no one could tell why your ?person count is incorrect without some knowledge of he data and how the count may fail (too many, too few, what is the difference between those that should and should not be in the count, etc.).

permanent link

answered 06 Oct '11, 12:06

scotthenninger's gravatar image

scotthenninger ♦
accept rate: 17%

Thank you very much for your answer. I think as long as i can get the categories with people in it I can use it for my purpose.

(06 Oct '11, 21:13) yanz yanz's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 03 Oct '11, 19:54

question was seen: 1,881 times

last updated: 12 Oct '11, 09:31