query-cb0279d4b0b4e24b563405a7afc7bef3
https://www.wikidata.org/wiki/Q22686i need to add for example for trump as 1 row1. alternative name= Trump, John Barron, Donald John Trump, DJT, Donald J Trump, Donald J. Trump, POTUS 45, President Donald J. Trump, President Donald John Trump, President Donald Trump, President Trump, The Donald, Mr Trump, John Trump, President Donald J Trump 2.his name is other languages like arabic, hebrew, etc. (add it as you think is right, maybe like {germany:'yyy','french':'xxx'}) preferred 1 row as 1 row3. children as 1 row4.spouses the most important thing for me is 1 (alternative name), i can live without the other additions. i itend to use python and paginate through results (set limit to 1000 or something). if you think i should use 2 or more queries instead of 1, please suggest how (i am considering it). This query is the simplest, but will take long time to run because there are thousands of results with all labels, aliases, children and spouses joined together before grouping by the human. I think it would be faster to add each of these in separate subqueries with their own grouping. I will leave that as an exercise. :)
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?human ?humanLabel ?genderLabel ?countryLabel ?birth_date
(GROUP_CONCAT(DISTINCT ?alias_en; separator=", ") AS ?aliases_en)
(GROUP_CONCAT(DISTINCT STR(?label); separator=", ") AS ?labels)
(GROUP_CONCAT(DISTINCT ?childLabel; separator=", ") AS ?children)
(GROUP_CONCAT(DISTINCT ?spouseLabel; separator=", ") AS ?spouses)
WHERE
{
VALUES ?human { wd:Q22686 }
?human wdt:P31 wd:Q5;
wdt:P106 wd:Q82955.
OPTIONAL { ?human wdt:P21 ?gender. }
OPTIONAL { ?human wdt:P569 ?birth_date. }
OPTIONAL { ?human wdt:P27 ?country. }
OPTIONAL
{
?human skos:altLabel ?alias_en .
FILTER (LANG(?alias_en) = "en")
}
OPTIONAL { ?human rdfs:label ?label . }
OPTIONAL { ?human wdt:P40 ?child . }
OPTIONAL { ?human wdt:P26 ?spouse . }
SERVICE wikibase:label
{
bd:serviceParam wikibase:language "en" .
?human rdfs:label ?humanLabel .
?gender rdfs:label ?genderLabel .
?country rdfs:label ?countryLabel .
?child rdfs:label ?childLabel .
?spouse rdfs:label ?spouseLabel .
}
}
GROUP BY ?human ?humanLabel ?genderLabel ?countryLabel ?birth_date
limit 100