12

I am trying to output a table using query.wikidata.org and SPARQL, with the name, birthdate, and brief description of notable, living Americans (i.e. those with wikidata entries) who will turn 100 years old between January and June 2016.

I've cobbled together some code which seems to be working, but I can't figure out how to output the description of the people.

For example, one of the people the code grabs is Beverly Cleary, whose wikidata description is "American writer of children's books." I would like to print that in the table.

Any help is much appreciated; code below. Thanks so much.

--

prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
SELECT ?Name ?Birthday WHERE {
  ?item wdt:P569 ?Birthday .
  FILTER ( ?Birthday >= "1916-01-01T00:00:00Z"^^xsd:dateTime && ?Birthday <= "1916-06-01T00:00:00Z"^^xsd:dateTime )
  ?item wdt:P27 wd:Q30 .
  OPTIONAL { ?item wdt:P570 ?dummy0 }
  FILTER(!bound(?dummy0))
  OPTIONAL {?item rdfs:label ?Name filter (lang(?Name) = "en") .} 
}
ORDER BY ASC(?time0)

3 Answers 3

5

I am far from expert in this, but your question motivated me to learn a little, and I have a solution, below.

In short, there is a "label service" which can be added to the WHERE clause. By simply adding it, you get access to the label, altLabel, and description of items in the query. There seems to be more nuance, but I'd be fooling if I tried to explain it...

prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT ?Name ?itemDescription ?Birthday WHERE {
  ?item wdt:P569 ?Birthday .
  FILTER ( ?Birthday >= "1916-01-01T00:00:00Z"^^xsd:dateTime && ?Birthday <= "1916-06-01T00:00:00Z"^^xsd:dateTime )
  ?item wdt:P27 wd:Q30 .
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
  OPTIONAL { ?item wdt:P570 ?dummy0 }
  FILTER(!bound(?dummy0))
  OPTIONAL {?item rdfs:label ?Name filter (lang(?Name) = "en") .} 
}
ORDER BY ASC(?time0)
1
  • I know I'm far behind, but I just wanted to say thank you! This is exactly what I needed. May 16, 2016 at 20:39
4
  1. Include SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } inside your WHERE clause
  2. Append the magic string Label and Description to the variable names of your SELECT

For instance, if your item variable is ?item then SELECT ?itemLabel ?itemDescription will show the label and description of that Wikidata item.

Full example (live demo) that shows this info of all embassies:

SELECT ?itemLabel ?itemDescription
WHERE
{
    ?item wdt:P31 wd:Q3917681 .
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
0

Another way to list the description of items can be done by using schema:description. Further information can be found in this page at the official documentation.

Here's a minimal working example: List of all continents with their description.

SELECT
  ?item
  ?description
{
  ?item wdt:P31 wd:Q5107;
        schema:description ?description.
  FILTER(LANG(?description) = "en")
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.