0

I am trying to obtain the wikidata entity_id containing a given literal, for example "crypto". I'm using:

SELECT ?item WHERE { 
  ?o rdfs:label ?ol 
  FILTER (lang(?ol) = 'en') 
  FILTER(contains(str(?ol),'crypto' ))
}

Of course, the wrong approach :-/ Any help, more than welcome. Thx in advance.

David G. Hdez
  • 125
  • 1
  • 8
  • why do you thin it's "wrong"? It does exactly what you want. Obviously, those kind of queries never scale given that it has to check all hundreds of millions of labels with an expensive string operation without having a fulltext index. – UninformedUser May 02 '20 at 10:19
  • here is a faster query returning 20 "best" matching entities: `SELECT ?item WHERE { SERVICE wikibase:mwapi { bd:serviceParam wikibase:endpoint "www.wikidata.org"; wikibase:api "EntitySearch"; mwapi:search "crypto"; mwapi:language "en". ?item wikibase:apiOutputItem mwapi:item. ?num wikibase:apiOrdinal true. } } ORDER BY ASC(?num) LIMIT 20` – UninformedUser May 02 '20 at 10:22
  • Really helpful. Thx 1.000.000 Now I know it was not SPARQL failure, but experience failure. – David G. Hdez May 02 '20 at 11:22
  • well, to be fair, my query is using some non-standard SPARQL feature from the Blazegraph triple store which is the backend of Wikidata. So you couldn't know this, and unfortunately, there is still no fulltext feature in the SPARQL standard (it's likely this will be integrated with SPARQL 1.2, but it will take a long time until we get the new version for sure). So yeah, your query was fine and indeed works for small datasets, but Wikidata is large. Good luck with your project – UninformedUser May 02 '20 at 11:29

0 Answers0