lotus-sparql-examples

A set of SPARQL examples that are used in LOTUS

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

wd_nps_with_taxon_image_details

rq turtle/ttl

NPs with corresponding taxon image and details.

Use at


PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
SELECT ?compoundLabel ?compound ?taxon ?taxonLabel ?reference ?referenceLabel ?smiles ?taxon_image ?kingdom ?kingdomLabel WHERE {
      VALUES ?compound {wd:Q2079986}
      ?compound wdt:P233 ?smiles_c .
      OPTIONAL { ?compound wdt:P2017 ?smiles_i . }
      BIND(COALESCE(?smiles_i, ?smiles_c) AS ?smiles)
      FILTER(BOUND(?smiles))
      ?compound p:P703 ?statement .
      ?statement ps:P703 ?taxon ;
                 prov:wasDerivedFrom ?refnode .
      ?refnode pr:P248 ?reference .
      ?taxon wdt:P18 ?taxon_image .
      ?taxon wdt:P171* ?kingdom .
      FILTER(
        ?kingdom IN (
          wd:Q729,   # Animalia
          wd:Q756,   # Plantae
          wd:Q764,   # Fungi
          wd:Q10876  # Bacteria (domain, not kingdom)
        )
      )
      ?kingdom rdfs:label ?kingdomLabel . FILTER (lang(?kingdomLabel) = "en")
      ?compound rdfs:label ?compoundLabel . FILTER (lang(?compoundLabel) = "en")
      ?taxon rdfs:label ?taxonLabel . FILTER (lang(?taxonLabel) = "en")
      SERVICE <https://query-scholarly.wikidata.org/sparql> {
        ?reference rdfs:label ?referenceLabel . FILTER (lang(?referenceLabel) = "en")
      }
    }
    LIMIT 10

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?compound"):::projected 
  v2("?compoundLabel"):::projected 
  v4("?kingdom"):::projected 
  v3("?kingdomLabel"):::projected 
  v12("?reference"):::projected 
  v14("?referenceLabel"):::projected 
  v11("?refnode")
  v9("?smiles"):::projected 
  v7("?smiles_c")
  v8("?smiles_i")
  v9("?statement")
  v10("?taxon"):::projected 
  v1("?taxonLabel"):::projected 
  v13("?taxon_image"):::projected 
  f0[["?taxonLabel = 'en'"]]
  f0 --> v1
  f1[["?compoundLabel = 'en'"]]
  f1 --> v2
  f2[["?kingdomLabel = 'en'"]]
  f2 --> v3
  list0c3(["wd:Q764"]):::iri 
  list0c2(["wd:Q756"]):::iri 
  list0c1(["wd:Q729"]):::iri 
  list0c4(["wd:Q10876"]):::iri 
  list0c1 --o f3
  list0c2 --o f3
  list0c3 --o f3
  list0c4 --o f3
  f3[[" in "]]
  f3 --> v4
  f4[["bound(?smiles)"]]
  f4 --> v9
  bind5[/VALUES ?compound/]
  bind5-->v6
  bind50(["wd:Q2079986"])
  bind50 --> bind5
  v6 --"p:direct/P233"-->  v7
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v6 -."p:direct/P2017".->  v8
  end
  bind6[/"?smiles_i?smiles_c"/]
  v8 --o bind6
  v7 --o bind6
  bind6 --as--o v9
  v6 --"p:P703"-->  v9
  v9 --"p:statement/P703"-->  v10
  v9 --"prov:wasDerivedFrom"-->  v11
  v11 --"p:reference/P248"-->  v12
  v10 --"p:direct/P18"-->  v13
  v10 --"p:direct/P171"-->  v4
  v4 --"rdfs:label"-->  v3
  v6 --"rdfs:label"-->  v2
  v10 --"rdfs:label"-->  v1
  subgraph s1["https://query-scholarly.wikidata.org/sparql"]
    style s1 stroke-width:4px;
    f7[["?referenceLabel = 'en'"]]
    f7 --> v14
    v12 --"rdfs:label"-->  v14
  end