PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ex: <http://example.org/>

CONSTRUCT
{
  ?compound wdt:P31                     wd:Q113145171 ;
            ex:label                    ?compoundLabel ;
              wdt:P232                    ?ec_number    ;
              wdt:P231                    ?cas_number   ;
              wdt:P2240                   ?ld50         ;
              wdt:P366                    ?use_type     ;
              p:P2240                     ?ref            ;
              ex:hasCASnumberIRI          ?cas_number_iri .
    ?use_type ex:childof                   wd:Q131656   .
    ?ref      pq:P636                     wd:Q285166    ;
              ex:affects                  wd:Q184224       .
}
WHERE
{
    # Note: 'wdt:P2240' and 'ld50' is the toxicity level (median lethal
    # dose), not many data points have this info (only 9 results in total).
    ?compound wdt:P31                     wd:Q113145171 ;
              wdt:P232                    ?ec_number    ;
              wdt:P231                    ?cas_number   ;
              wdt:P2240                   ?ld50         ;
              wdt:P366                    ?use_type     ;
              p:P2240                     ?ref          .
    ?use_type wdt:P279*                   wd:Q131656    .
    ?ref      pq:P636                     wd:Q285166    ;
              (pq:P689|pq:P2352)/wdt:P279 wd:Q184224    .

    # Helps get the label in your language, if not, then default for all
    # languages, then en language
    SERVICE wikibase:label {
        bd:serviceParam wikibase:language '[AUTO_LANGUAGE],mul,en'.
    }
    BIND (
      IRI (CONCAT("https://identifiers.org/cas:", ?cas_number)) AS ?cas_number_iri
    )
}
