A set of SPARQL examples that are used in different TGX resources
List all collections and the number of compounds in that collection.
PREFIX wd: <https://compoundcloud.wikibase.cloud/entity/>
PREFIX wdt: <https://compoundcloud.wikibase.cloud/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?collectionLabel (COUNT(DISTINCT ?compound) AS ?count) WHERE {
VALUES ?collectionType { wd:Q52 wd:Q54 wd:Q55 }
?collection wdt:P1 ?collectionType .
?compound wdt:P21 ?collection .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} GROUP BY ?collectionLabel
ORDER BY DESC(?count)
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?collection")
v2("?collectionType")
v4("?compound"):::projected
v5("?count")
c4(["bd:serviceParam"]):::iri
c6(["#91;AUTO_LANGUAGE#93;,en"]):::literal
bind0[/VALUES ?collectionType/]
bind0-->v2
bind00(["wd:Q52"])
bind00 --> bind0
bind01(["wd:Q54"])
bind01 --> bind0
bind02(["wd:Q55"])
bind02 --> bind0
v3 --"wdt:P1"--> v2
v4 --"wdt:P21"--> v3
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c4 --"wikibase:language"--> c6
end
bind2[/"count(?compound)"/]
v4 --o bind2
bind2 --as--o v5