To answer this historical question, I want to query DBpedia for all members of the United States House of Representatives.

Unfortunately, the following DBpedia query does not reach sub-categories and I get only 4 results:

select distinct ?member where {

How to get all representatives, including those in sub-categories?

asked 12 Jun '12, 02:35

Nicolas%20Raoul's gravatar image

Nicolas Raoul
accept rate: 0%

edited 12 Jun '12, 02:36

Categories are related by the skos:broader property. Until DBpedia supports SPARQL 1.1 property paths, to expand one level of sub-categories try something like:

prefix db: <>
prefix dc: <>
prefix skos: <>

prefix category: <>

select distinct ?member where {

        ?member dc:subject category:Members_of_the_United_States_House_of_Representatives .
    } union {
        ?member dc:subject [skos:broader category:Members_of_the_United_States_House_of_Representatives] .

    ?member a db:Person .
permanent link

answered 12 Jun '12, 03:12

AB's gravatar image

accept rate: 35%

edited 12 Jun '12, 03:17

Generally speaking, what you need is a way to traverse chains of skos:broader relations. SPARQL 1.1 offers the notion of property paths for this, like so:

select distinct ?member where {
  <> ?cat .
  ?cat skos:broader* <>

Unfortunately, the DBPedia endpoint does not yet support this SPARQL 1.1 construction, so this particular solution won't help you immediately. However, the DBPedia endpoint does offer the option of using additional inference rules when evaluating a SPARQL query. In this case, what you want is to have SKOS transitivity rules enabled. You can do this by adapting your query as follows:

DEFINE input:inference "skos-trans"
select distinct ?member where {
  <> ?cat .
  ?cat skos:broaderTransitive <>
permanent link

answered 12 Jun '12, 03:20

Jeen%20Broekstra's gravatar image

Jeen Broekstra ♦
accept rate: 37%

edited 12 Jun '12, 03:25

I'm not sure the skos-trans rule works. For example, the following returns 7, even though the category higherarchy extends deeper:

DEFINE input:inference "skos-trans"
select count(distinct ?cat) where {
  ?cat skos:broaderTransitive <  /Category:Members_of_the_United_States_Congress>
(05 Jan '13, 18:05) Chris Mungall Chris%20Mungall's gravatar image

To use transitivity in SPARQL on a Virtuoso endpoint (who is use by Dbpedia) you can use an OPTION. Like this :

?categorie skos:broader ?broader 
OPTION(TRANSITIVE, T_DISTINCT, t_in(?categorie), t_out(?broader), t_max(2), t_step('path_id') as ?path, t_step(?categorie) as ?route, t_step('step_no') AS ?jump, T_DIRECTION 2 )

You can use the very helpfull option t_max, who is the number of jump of your recursivity.

P.S : If you have a solution to make a real RDF hierarchy of categories with a CONSTRUCT query, I'm really interested by that :)

permanent link

answered 12 Jun '12, 09:31

Heeko's gravatar image

accept rate: 0%

edited 12 Jun '12, 10:50

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]( "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: 12 Jun '12, 02:35

question was seen: 3,548 times

last updated: 05 Jan '13, 18:05