1

I have an ontology (called CODO) about patients of the Covid pandemic. One of our classes is a Cluster and each patient codo:isMemberOf one and only one Cluster. I want to compute the percentage of patients in each Cluster using SPARQL. Also, we have the inverse property as well codo:hasMember linking a Cluster to a Patient if that is easier to compute.

  • 1
    Try something like this: `SELECT ?cluster (?x/?n AS ?proportion) WHERE{ {SELECT ?cluster (COUNT(?patient) AS ?x) WHERE{ ?patient codo:isMemberOf ?cluster} GROUP BY ?cluster} {SELECT (COUNT(?patient) AS ?n) WHERE{ ?patient codo:isMemberOf ?cluster}} }` – Valerio Cocchi Sep 16 '20 at 23:36
  • The first subquery will compute how many patients of a specific cluster. The second will compute how many patients are members of *any* cluster. Then the outer query will divide the two numbers and tell you the proportion for each cluster. – Valerio Cocchi Sep 16 '20 at 23:38
  • 1
    you'll have to cast one of the count values to a double, otherwise the result will always be 0: `SELECT ?cluster (xsd:double(?x)/?n AS ?proportion) ` – UninformedUser Sep 16 '20 at 23:43
  • 1
    @Valerio_Cocchi Thanks. I'm new to this site. I want to accept one answer and mark the others as helpful but I don't see how to do that. The help says there should be a "greyed out" check box next to the answer that I can click to accept the answer but all I see is a greyed out flag to the left of each answer which to flag it as inappropriate. – Michael DeBellis Sep 18 '20 at 16:39
  • @MichaelDeBellis: Welcome to the site! The reason you cannot accept an answer is that there are no answers on this question, only comments. – Konrad Höffner Sep 21 '20 at 09:14
  • @KonradHöffner Thanks very much for the explanation. – Michael DeBellis Sep 22 '20 at 18:29
  • I wish people would stop posting their answers as comments. It’s false modesty that makes it impossible, among other things, to rely on the answer counts in search results. – Matthias Winkelmann Oct 15 '20 at 00:39

0 Answers0