query-209d4bda1667e2879185df165474e9ed

rq turtle/ttl

Propertiesinstance of (P31)drug or therapy used for treatment (P2176)stated in (P248)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?disease ?diseaseLabel ?drug ?drugLabel ?hasRef ?stated_inLabel WHERE {
  ?disease wdt:P31 wd:Q12136 ;  # find items that are in instance of disease
        p:P2176 ?id .  # get "drug used for treatment" statements
  ?id ?b ?drug .  # get the object used in these statements
  FILTER(regex(str(?b), "http://www.wikidata.org/prop/statement" ))
  # FILTER NOT EXISTS { ?id prov:wasDerivedFrom ?provenance }  # filter out statements with no references
  # ?id prov:wasDerivedFrom ?provenance  # only keep statements with a references
  BIND(EXISTS {?id prov:wasDerivedFrom ?provenance } as ?hasRef) # tag statements with whether or not a ref exists
  OPTIONAL {?id prov:wasDerivedFrom ?prov .
            ?prov pr:P248 ?stated_in }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?b") v2("?disease"):::projected v4("?drug"):::projected v5("?hasRef"):::projected v3("?id") v6("?prov") v7("?stated_in") c8(["bd:serviceParam"]):::iri c10(["en"]):::literal c3(["wd:Q12136"]):::iri f0[["regex(str(?b),'http://www.wikidata.org/prop/statement')"]] f0 --> v1 v2 --"p:direct/P31"--> c3 v2 --"p:P2176"--> v3 v3 -->v1--> v4 v3 --"prov:wasDerivedFrom"--> null bind1[/" "/] subgraph bind1e0["Exists Clause"] e0v1 --"prov:wasDerivedFrom"--> e0v2 e0v1("?id"):::projected e0v2("?provenance"):::projected end bind1--EXISTS--> bind1e0 v3 --o bind1 c5 --o bind1 null --o bind1 bind1 --as--o v5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."prov:wasDerivedFrom".-> v6 v6 --"p:reference/P248"--> v7 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end