0

I recently started working on sparql to generate query for getting the age of a specific person (say, Donald Trump)

The only thing I could understand is that it would be an instance of Person class. Can someone help me with what else needs to be done to get that specific information.

SELECT ?item WHERE {
  ?item wdt:P31 wd:Q5.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
  • just add another triple pattern with the predicate being the property specifying the age of a person. That's all. Go to any Wikidata persons page, there you can see the property URI used for age. And if you want it for a specific person, the subject of the triple pattern should be the URI denoting the subject: `SELECT ?age { ?age}` - done. Clearly, the age of a person might not be contained explicitely in the data, given that the data would have to be updated on each birtdate – UninformedUser Jan 29 '22 at 07:34
  • 1
    `SELECT * WHERE { wd:Q22686 wdt:P569 ?birth . BIND(now() as ?today) bind( year(?today) - year(?birth) - if(month(?today) < month(?birth) || (month(?today) = month(?birth) && day(?today)< day(?birth)), 1, 0) as ?age ) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }` – UninformedUser Jan 29 '22 at 08:36
  • Thanks for this. I actually need to query this from python. How do I know before hand what is the I'd of Donald Trump? – Nishant Saraswat Jan 30 '22 at 09:28
  • then you have to search for the ID resp. URI before - you can also do this with SPARQL but it should be clear that multiple person can have the same name, so the result might not be unique - just use the Wikidata entity search service directly in SPARQL – UninformedUser Jan 30 '22 at 09:31
  • Sorry I didn't get your point. I am a beginner in this and couldn't find anything like this in the documentation. Could you please help me with what exactly would be required to get the Q I'd of the item. maybe any links to documentation/examples that would be helpful? – Nishant Saraswat Jan 30 '22 at 17:42
  • just combine [this](https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced#Filter_labels_using_EntitySearch_from_mwapi_service_to_provide_Full_Text_Search) with the other query – UninformedUser Jan 30 '22 at 18:37
  • @UninformedUser Thank you so much, this was quite helpful. Sorry one last question, if I need the property id of say, age, how do I get that using sparql query? – Nishant Saraswat Jan 31 '22 at 03:34

0 Answers0