query-cb0279d4b0b4e24b563405a7afc7bef3

rq turtle/ttl

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

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

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?alias_en"):::projected v14("?aliases_en") v4("?birth_date"):::projected v7("?child") v12("?childLabel"):::projected v16("?children") v5("?country") v11("?countryLabel"):::projected v3("?gender") v10("?genderLabel"):::projected v2("?human"):::projected v9("?humanLabel"):::projected v6("?label"):::projected v15("?labels") v8("?spouse") v13("?spouseLabel"):::projected v17("?spouses") c1(["en"]):::literal c5(["wd:Q82955"]):::iri c14(["bd:serviceParam"]):::iri c3(["wd:Q5"]):::iri bind0[/VALUES ?human/] bind0-->v2 bind00(["wd:Q22686"]) bind00 --> bind0 v2 --"wdt:P31"--> c3 v2 --"wdt:P106"--> c5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P21".-> v3 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P569".-> v4 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P27".-> v5 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v2 -."skos:altLabel".-> v1 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v2 -."rdfs:label".-> v6 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P40".-> v7 end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P26".-> v8 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c14 --"wikibase:language"--> c1 v2 --"rdfs:label"--> v9 v3 --"rdfs:label"--> v10 v5 --"rdfs:label"--> v11 v7 --"rdfs:label"--> v12 v8 --"rdfs:label"--> v13 end bind5[/"?alias_en"/] v1 --o bind5 bind5 --as--o v14 bind6[/"str(?label)"/] v6 --o bind6 bind6 --as--o v15 bind7[/"?childLabel"/] v12 --o bind7 bind7 --as--o v16 bind8[/"?spouseLabel"/] v13 --o bind8 bind8 --as--o v17