query-3c1fbac9e19e30883616023a6994bc04

rq turtle/ttl

Surname lookupCan anyone suggest any speed-ups for this query, that tries to find family name items to match people's last names. At the moment it can cope with only about 30 at a time without timing out:

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
WHERE {
   {
  SELECT ?item ?item_label ?last_name_label WHERE {
    ?item wdt:P5008 wd:Q51682734 .
    ?item rdfs:label ?item_label . FILTER(lang(?item_label) = 'en') .
    bind( replace( ?item_label, ".* ", "" ) as ?last_name_label )
  } LIMIT 30
}.
  OPTIONAL {
    ?last_name wdt:P31 wd:Q101352 .
    ?last_name rdfs:label ?last_name_label .
  }

  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 c3(["wd:Q51682734"]):::iri c6(["wd:Q101352"]):::iri c8(["bd:serviceParam"]):::iri c10(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["?item_label = 'en'"]] f0 --> v2 v3 --"wdt:P5008"--> c3 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 -."wdt:P31".-> c6 v4 --"rdfs:label"--> v4 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end bind2[/"?last_name_label"/] v4 --o bind2 bind2 --as--o v5