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

From: Eric Lease Morgan <00000107b9c961ae-dmarc-request_at_nyob>
Date: Mon, 7 Apr 2025 13:51:00 -0400
To: CODE4LIB_at_LISTS.CLIR.ORG
On Apr 7, 2025, at 9:39 AM, Simeon Warner <simeon.warner_at_gmail.com> wrote:

> Have you tried removing "LIMIT 1"? Of course, the data has to be there too.
> 
> --
> Simeon


Loosing LIMIT 1? Well, duh. That's a good idea, and over on the LD4Libraries Slack channel, the following SPARQL query was suggested, where DISTINCT was also employed:

  SELECT DISTINCT ?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-us"))
    FILTER (langMatches(lang(?description), "en-us"))
    SERVICE wikibase:label {bd:serviceParam wikibase:language 'en-us' .}
  } 

This returns seven records, one for each occupation.

But I'm never satisfied. What I'd like to see is a single record with all of the occupations concatonated together. GROUP_CONCAT begins to do this work, like this:

  SELECT (group_concat(?occupation) as ?occupations)
  WHERE {
    wd:Q91 wdt:P106 ?occupation . 
  }

But as soon as I augment the SELECT statement with additional values, I get syntax errors:

  SELECT ?label (group_concat(?occupation) as ?occupations)
  WHERE {
    wd:Q91 rdfs:label ?label .
    FILTER (langMatches(lang(?label), "en-us"))
    wd:Q91 wdt:P106 ?occupation . 
  }


What do y'all suggest?

--
Eric Morgan
University of Notre Dame
Received on Mon Apr 07 2025 - 13:49:59 EDT