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

From: Stuart A. Yeates <syeates_at_nyob>
Date: Tue, 8 Apr 2025 07:28:26 +1200
To: CODE4LIB_at_LISTS.CLIR.ORG
I have some queries at
https://www.wikidata.org/wiki/User:Stuartyeates/InterestingPeopleQuery
which show how to query for people and handle things like multiple dates of
birth or LCCNs.

The core idea is to concat the LCCNs into a single field using:

(GROUP_CONCAT(DISTINCT ?lccnurl; SEPARATOR = ";") AS ?LCCN_urls)

and then GROUP BY.


cheers

stuart

--
...let us be heard from red core to black sky


On Tue, 8 Apr 2025 at 01:32, 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 - 15:27:26 EDT