Re: how to get all of abraham lincoln's occupations

From: Simeon Warner <simeon.warner_at_nyob>
Date: Mon, 7 Apr 2025 08:39:06 -0500
To: CODE4LIB_at_LISTS.CLIR.ORG
Have you tried removing "LIMIT 1"? Of course, the data has to be there too.

Cheers,
Simeon


On Mon, Apr 7, 2025, 8:27 AM Eric Lease Morgan <
00000107b9c961ae-dmarc-request_at_lists.clir.org> wrote:

> How do I use SPARQL to query WikiData and get all of Abraham Lincoln's
> occupations?
>
> The WikiData QNumber for Abraham Lincoln is Q91, and therefore his
> WikiData page can be seen here:
>
>   https://www.wikidata.org/wiki/Q91
>
> The following SPARQL query returns a label, a description, a gender, and a
> single occupation for President Lincoln:
>
>   SELECT ?label ?description ?genderLabel ?occupationLabel
>   WHERE {
>     wd:Q91 rdfs:label         ?label       .
>     wd:Q91 schema:description ?description .
>     wd:Q91 wdt:P21            ?gender      .
>     wd:Q91 wdt:P106           ?occupation  .
>     FILTER ( langMatches( lang( ?label ),       "en" ) )
>     FILTER ( langMatches( lang( ?description ), "en" ) )
>     SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }
>   }
>   LIMIT 1
>
> But President Lincoln had many occupations. How do I change the query to
> return all of the occupations he had? In other words, when there is a
> one-to-many relationship between a subject and objects, how do I get all
> the objects? This is akin to getting all of the subjects for a given book.
>
> --
> Eric Morgan
> Navari Family Center for Digital Scholarship
> Hesburgh Libraries
> University of Notre Dame
>
Received on Mon Apr 07 2025 - 09:38:04 EDT