sparql-examples

SPARQL examples for the EMI

View the Project on GitHub earth-metabolome-initiative/sparql-examples

metrics_2

rq turtle/ttl

Unique Wikidata identifiers mapped to GloBI taxons.

Use at

PREFIX emi: <https://w3id.org/emi#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT (COUNT(DISTINCT ?wdx) AS ?totalDistinctTaxa) 
WHERE {
  ?intxn emi:hasSource ?source ;
         emi:hasTarget ?target ;
         emi:isClassifiedWith ?intxnType .
  ?intxnType rdfs:label ?intxnLabel .
  ?source emi:inTaxon ?wdx_Source ;
          rdfs:label ?sourceName .
  ?target emi:inTaxon ?wdx_Target ;
          rdfs:label ?targetName .
  # merge sources and targets into a single ?wdx variable
  {
    ?source emi:inTaxon ?wdx
  }
  UNION {
    ?target emi:inTaxon ?wdx
  }
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v1("?intxn")
  v5("?intxnLabel")
  v4("?intxnType")
  v2("?source")
  v7("?sourceName")
  v3("?target")
  v9("?targetName")
  v11("?totalDistinctTaxa")
  v10("?wdx"):::projected 
  v6("?wdx_Source")
  v8("?wdx_Target")
  v1 --"emi:hasSource"-->  v2
  v1 --"emi:hasTarget"-->  v3
  v1 --"emi:isClassifiedWith"-->  v4
  v4 --"rdfs:label"-->  v5
  v2 --"emi:inTaxon"-->  v6
  v2 --"rdfs:label"-->  v7
  v3 --"emi:inTaxon"-->  v8
  v3 --"rdfs:label"-->  v9
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    v3 --"emi:inTaxon"-->  v10
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v2 --"emi:inTaxon"-->  v10
  end
  union0r <== or ==> union0l
  end
  bind1[/"count(?wdx)"/]
  v10 --o bind1
  bind1 --as--o v11