Skip to content

Instantly share code, notes, and snippets.

@egonw
Created May 21, 2018 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egonw/7c932f6af6223129b5a6c5d524c51b8a to your computer and use it in GitHub Desktop.
Save egonw/7c932f6af6223129b5a6c5d524c51b8a to your computer and use it in GitHub Desktop.
Wikidata SPARQL to count the number of identifiers for substances.
SELECT ?IDpred ?IDpredLabel ?count WITH {
SELECT ?IDpred (COUNT(?id) AS ?count) WHERE {
?chemical ?IDdir ?id .
?IDpred wikibase:directClaim ?IDdir ;
wdt:P31 wd:Q19833835 .
FILTER (?IDpred != wd:P639)
FILTER (?IDpred != wd:P2926)
} GROUP BY ?IDpred
} AS %RESULTS {
INCLUDE %RESULTS
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY DESC(?count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment