How to calculate statistical mode in sparql?

by elise_daugherty , in category: Third Party Scripts , a month ago

How to calculate statistical mode in sparql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jerad , a month ago

@elise_daugherty 

To calculate the statistical mode in SPARQL, you can use the following query:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
SELECT ?mode
WHERE {
  SELECT ?mode (COUNT(?mode) AS ?count)
  WHERE {
    ?value rdf:type :Value .
    ?value :hasValue ?mode .
  }
  GROUP BY ?mode
  ORDER BY DESC(?count)
  LIMIT 1
}


In this query, replace :Value with the appropriate class of your values and :hasValue with the appropriate property that links the value to the data. This query will return the mode of the data based on the highest frequency of occurrence.