sparql-examples

A set of SPARQL examples that are used in different SIB resources

View the Project on GitHub sib-swiss/sparql-examples

47_Select_all_children_reactions_and_give_the_number_of_parent_reactions

rq turtle/ttl

Select all children reactions and give the number of parent reactions.

Use at

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rh:<http://rdf.rhea-db.org/>

SELECT 
  (count(?reactionChild) as ?isARelationCount) 
  (count(distinct ?reactionChild) as ?uniqueReactionChildCount) 
  (count(distinct ?reactionParent) as ?uniqueReactionParentCount) 
WHERE {
  ?reactionChild rdfs:subClassOf rh:Reaction .
  ?reactionChild rh:status rh:Approved .
  ?reactionParent rdfs:subClassOf rh:Reaction .
  ?reactionParent rh:status rh:Approved .
  ?reactionChild rdfs:subClassOf ?reactionParent .
}

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v3("?isARelationCount")
  v1("?reactionChild"):::projected 
  v2("?reactionParent"):::projected 
  v4("?uniqueReactionChildCount")
  v5("?uniqueReactionParentCount")
  c4(["rh:Approved"]):::iri 
  c2(["rh:Reaction"]):::iri 
  v1 --"rdfs:subClassOf"-->  c2
  v1 --"rh:status"-->  c4
  v2 --"rdfs:subClassOf"-->  c2
  v2 --"rh:status"-->  c4
  v1 --"rdfs:subClassOf"-->  v2
  bind3[/"count(?reactionChild)"/]
  v1 --o bind3
  bind3 --as--o v3
  bind4[/"count(?reactionChild)"/]
  v1 --o bind4
  bind4 --as--o v4
  bind5[/"count(?reactionParent)"/]
  v2 --o bind5
  bind5 --as--o v5