query-25c736392043c46225f2ef5561f00733

rq turtle/ttl

TODO

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?item_label ?last_name_label (lang(?last_name_label) AS ?lang) ?last_name ?last_nameLabel
{
  ?item wdt:P5008 wd:Q51682734;
        rdfs:label ?item_label .
  FILTER( LANG( ?item_label ) = 'en' && REGEX( ?item_label, "^.+ " ) ) . # label in English and contains a space
  BIND( REPLACE( ?item_label, "^.+ ", "" ) as ?last_name_label ) . # replace anything before the last space to have surname label
  OPTIONAL { ?last_name_label ^rdfs:label ?last_name } . # the trick I describe below
  ?last_name_label ^rdfs:label ?last_name . # label is on an item (inverse to "an item has a label)
  ?last_name wdt:P31 wd:Q101352 . # is a surname
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } .
} 
ORDER BY ?last_name_label

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?item"):::projected v2("?item_label"):::projected v5("?lang") v4("?last_name"):::projected v4("?last_name_label"):::projected c4(["wd:Q51682734"]):::iri c7(["wd:Q101352"]):::iri c9(["bd:serviceParam"]):::iri c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["?item_label = 'en'regex(?item_label,'^.+ ')"]] f0 --> v2 v3 --"wdt:P5008"--> c4 v3 --"rdfs:label"--> v2 bind1[/"replace(?item_label,'^.+ ','')"/] v2 --o bind1 bind1 --as--o v4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."rdfs:label".-> v4 end v4 --"rdfs:label"--> v4 v4 --"wdt:P31"--> c7 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end bind2[/"?last_name_label"/] v4 --o bind2 bind2 --as--o v5