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 {
  ?member
  <http://purl.org/dc/terms/subject>
  <http://dbpedia.org/resource/Category:Members_of_the_United_States_House_of_Representatives>
  .
}

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

asked 12 Jun '12, 02:35

Nicolas%20Raoul's gravatar image

Nicolas Raoul
11516
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: <http://dbpedia.org/ontology/>
prefix dc: <http://purl.org/dc/terms/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>

prefix category: <http://dbpedia.org/resource/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

AB
1.6k310
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 {
  ?member
  <http://purl.org/dc/terms/subject> ?cat .
  ?cat skos:broader* <http://dbpedia.org/resource/Category:Members_of_the_United_States_House_of_Representatives>
}

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 {
  ?member
  <http://purl.org/dc/terms/subject> ?cat .
  ?cat skos:broaderTransitive <http://dbpedia.org/resource/Category:Members_of_the_United_States_House_of_Representatives>
}
permanent link

answered 12 Jun '12, 03:20

Jeen%20Broekstra's gravatar image

Jeen Broekstra ♦
11.6k412
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 <http://dbpedia.org/resource  /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

Heeko
313
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

By RSS:

Answers

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:

×1,296
×275

question asked: 12 Jun '12, 02:35

question was seen: 2,480 times

last updated: 05 Jan '13, 18:05