sparql-examples

A set of SPARQL examples

View the Project on GitHub Adafede/sparql-examples

wd_maintenance_orphan_chemicals

rq turtle/ttl

Maintenance. Add subclasses to orphan chemical entities.

Use at


PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX hint: <http://www.bigdata.com/queryHints#>
#title: Maintenance. Add subclasses to orphan chemical entities.
SELECT DISTINCT (REPLACE(STR(?item), ".*Q", "Q") AS ?qid) ?P279 WHERE {
  VALUES ?chemicals {
    wd:Q113145171
    wd:Q59199015
  }
  ?item wdt:P31 ?chemicals. hint:Prior hint:rangeSafe true.
  OPTIONAL {
    ?item p:P279 ?sub.
  }
  FILTER(!(BOUND(?sub)))
  BIND("Q11173" AS ?P279)
}
# LIMIT 500000

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?P279"):::projected 
  v2("?chemicals")
  v3("?item"):::projected 
  v5("?qid")
  v1("?sub")
  c2([http://www.bigdata.com/queryHints#Prior]):::iri 
  c4(["true^^xsd:boolean"]):::literal 
  f0[["not bound(?sub)"]]
  f0 --> v1
  bind1[/VALUES ?chemicals/]
  bind1-->v2
  bind10(["wd:Q113145171"])
  bind10 --> bind1
  bind11(["wd:Q59199015"])
  bind11 --> bind1
  v3 --"p:direct/P31"-->  v2
  c2 --http://www.bigdata.com/queryHints#rangeSafe-->  c4
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v3 -."p:P279".->  v1
  end
  bind2[/"'Q11173'"/]
  bind2 --as--o v4
  bind3[/"replace(str(?item),'.*Q','Q')"/]
  v3 --o bind3
  bind3 --as--o v5