A way to achieve this could be to fetch all labels and aliases for all chemical compounds in one query and store them locally in your web application. This certainly is only feasible if the number of compounds does not get to big in Wikdiata. Currently, the query takes ~ 6 sec.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?cmpnd ?label WHERE {
    {?cmpnd wdt:P279 wd:Q11173 .} UNION
      {?cmpnd wdt:P31 wd:Q11173 .}
    ?cmpnd rdfs:label ?label .
}

Best,
Sebastian
(sebotic)
 
Hi all! I'm building a web application where users can search for
protein/compound/etc. names and view their 3D structure using WebGL. I'm
currently using the PubChem (chemical compounds database) API to provide
some autocomplete data, but I found that Wikidata also has many chemical
compound names with PubChem indices! The most important reason to try to
autocomplete compound names via Wikidata is to allow users to search in
different languages. PubChem generally only provides English names.
However, I could not find a suitable API for this. I tried building a
SPARQL query but that quickly became very slow. I could not find an option
to limit full-text searches to a specific subclass in the search API
provided by:
https://www.wikidata.org/w/api.php?action=help&modules=wbsearchentities.
Do you have any ideas? The only option I see for now is iterating each
response entity and looking up their subclass of/instance of property.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.wikimedia.org/pipermail/wikidata/attachments/20160425/756c5f20/attachment.html>