0

I am trying to learn sparql by thinking of problems to solve, with a view to one day writing a wikidata bot, whilst I use SQL every day, I find sparql confusing.

What I thought I would do is try to list everyone of a first name, that does not have the P735 "given name" attribute, I have got it to list 10 humans called Neil but cannot find how to only show those without the attribute (or to not show duplicates)

SELECT DISTINCT ?item ?itemLabel
WHERE { 
  ?item rdfs:label ?itemLabel.
  ?item wdt:P31 wd:Q5 .  
  FILTER(STRSTARTS(?itemLabel, "Neil "@en)).
} limit 10
back_ache
  • 382
  • 1
  • 13
  • absence of information is done via `FILTER NOT EXISTS`. For example, `FILTER NOT EXISTS {?item wdt:P735 ?gn}` in your case. – UninformedUser Feb 07 '21 at 16:57
  • Duplicates occur because of labels in multiple languages. You can add `FILTER (lang(?itemLabel) = "en")` – UninformedUser Feb 07 '21 at 16:57
  • note, your filter `strstarts` is expensive as it needs a full scan, there is not fulltext index by default A performance optimized Wikidata specific query: `SELECT DISTINCT ?item ?itemLabel WHERE { SERVICE wikibase:mwapi { bd:serviceParam wikibase:endpoint "www.wikidata.org"; wikibase:api "EntitySearch"; mwapi:search "Neil"; mwapi:language "en". ?item wikibase:apiOutputItem mwapi:item. }?item wdt:P31 wd:Q5 . FILTER NOT EXISTS {?item wdt:P735 ?gn} SERVICE wikibase:label {bd:serviceParam wikibase:language "en".} } limit 10` – UninformedUser Feb 07 '21 at 17:03
  • without the filter you can see 38 entities with `Neil` in their label. Only one of them has no given name property. – UninformedUser Feb 07 '21 at 17:05

0 Answers0