lotus-sparql-examples

A set of SPARQL examples that are used in LOTUS

View the Project on GitHub lotusnprod/lotus-sparql-examples

wd_maintenance_nps_retracted_remove

rq turtle/ttl

Maintenance. Remove compound-taxon statements with multiple references (one being retracted).

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 ps: <http://www.wikidata.org/prop/statement/>
#title: Remove compound-taxon statements with multiple references (one being retracted)
SELECT DISTINCT 
  (CONCAT(
    "-STATEMENT | ",
    STRAFTER(STR(?compound), "http://www.wikidata.org/entity/"),
    "$",
    STRAFTER(STR(?statement), CONCAT(STRAFTER(STR(?compound), "http://www.wikidata.org/entity/"), "-"))
  ) AS ?quickstatement)
WHERE {
    ?compound p:P703 ?statement.
    ?statement ps:P703 ?taxon;
               prov:wasDerivedFrom [
                 pr:P248 ?reference
               ].
    ?compound wdt:P235 ?compound_inchikey.
    ?taxon wdt:P225 ?taxon_name.
    ?reference wdt:P31 wd:Q45182324.
    
    # Only statements with multiple references
    ?statement prov:wasDerivedFrom ?refNode1, ?refNode2.
    FILTER(?refNode1 != ?refNode2)
}

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v3("?compound"):::projected 
  v7("?compound_inchikey")
  v9("?quickstatement")
  v1("?refNode1")
  v2("?refNode2")
  v6("?reference")
  v4("?statement"):::projected 
  v5("?taxon")
  v8("?taxon_name")
  a1((" "))
  c8(["wd:Q45182324"]):::iri 
  f0[["?refNode1 != ?refNode2"]]
  f0 --> v1
  f0 --> v2
  v3 --"p:P703"-->  v4
  v4 --"p:statement/P703"-->  v5
  a1 --"p:reference/P248"-->  v6
  v4 --"prov:wasDerivedFrom"-->  a1
  v3 --"p:direct/P235"-->  v7
  v5 --"p:direct/P225"-->  v8
  v6 --"p:direct/P31"-->  c8
  v4 --"prov:wasDerivedFrom"-->  v1
  v4 --"prov:wasDerivedFrom"-->  v2
  bind1[/"concat('-STATEMENT | ',substring-after(str(?compound),'http://www.wikidata.org/entity/'),'$',substring-after(str(?statement),concat(substring-after(str(?compound),'http://www.wikidata.org/entity/'),'-')))"/]
  v3 --o bind1
  v4 --o bind1
  bind1 --as--o v9