sparql-examples

A set of SPARQL examples that are used in different TGX resources

View the Project on GitHub BiGCAT-UM/sparql-examples

001

rq turtle/ttl

List all compounds with a PubChem identifier and optionally list the ToxBank Wiki link and roles.

Use at

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#>
PREFIX rdfs: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?cmp ?cmpLabel ?pubchem ?toxbank
       (GROUP_CONCAT(DISTINCT ?roleLabel; separator=", ") AS ?roles)
WHERE {
  ?cmp wdt:P13 ?pubchem .
  OPTIONAL { ?cmp wdt:P4 ?toxbank }
  OPTIONAL { ?cmp wdt:P17 ?role . ?role rdfs:label ?roleLabel}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} GROUP BY ?cmp ?cmpLabel ?pubchem ?toxbank
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v1("?cmp"):::projected 
  v2("?pubchem"):::projected 
  v4("?role")
  v5("?roleLabel"):::projected 
  v6("?roles")
  v3("?toxbank"):::projected 
  c6(["bd:serviceParam"]):::iri 
  c8(["#91;AUTO_LANGUAGE#93;,en"]):::literal 
  v1 --"wdt:P13"-->  v2
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v1 -."wdt:P4".->  v3
  end
  subgraph optional1["(optional)"]
  style optional1 fill:#bbf,stroke-dasharray: 5 5;
    v1 -."wdt:P17".->  v4
    v4 --"rdfs:label"-->  v5
  end
  subgraph s1["http://wikiba.se/ontology#label"]
    style s1 stroke-width:4px;
    c6 --"wikibase:language"-->  c8
  end
  bind1[/"?roleLabel"/]
  v5 --o bind1
  bind1 --as--o v6