@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix ex: <https://sparql.rhea-db.org/.well-known/sparql-examples/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

ex:50_Number_of_reactions_that_have_parent_and_child_reactions a sh:SPARQLExecutable,
    sh:SPARQLSelectExecutable;
  rdfs:comment "Number of reactions that have parent and child reactions"@en;
  sh:select """PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rh:<http://rdf.rhea-db.org/>
SELECT ?reaction
  (count(distinct ?reactionChild) as ?reactionChildCount)
  (count(distinct ?reactionDescendant) as ?reactionDescendantCount)
  ?equation
WHERE {
  ?reaction rdfs:subClassOf rh:Reaction .
  ?reaction rh:status rh:Approved .
  ?reaction rh:equation ?equation .

  ?reactionChild rdfs:subClassOf rh:Reaction .
  ?reactionChild rh:status rh:Approved .

  ?reactionDescendant rdfs:subClassOf rh:Reaction .
  ?reactionDescendant rh:status rh:Approved .

  ?reaction ^rdfs:subClassOf ?reactionChild .
  ?reaction ^rdfs:subClassOf+ ?reactionDescendant .
}
GROUP BY ?reaction ?equation
ORDER BY DESC (count(?reactionChild))
""";
  schema:target <https://sparql.rhea-db.org/sparql> .
