
query.aggregate.rq Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of corese-gui Show documentation
Show all versions of corese-gui Show documentation
Corese is a Semantic Web Factory (triple store and SPARQL endpoint)
implementing RDF, RDFS, SPARQL 1.1 Query and Update, Shacl. STTL. LDScript.
The newest version!
#
# Custom aggregates
# Olivier Corby, 2015, Wimmics Inria I3S UNS CNRS
#
prefix ag:
select
(aggregate(?v, ag:avg) as ?a)
(aggregate(?v, ag:median) as ?m)
(aggregate(?v, ag:sort_concat) as ?c)
(aggregate(?v, ag:sigma) as ?s)
where {
?x rdf:value ?v
}
#
# Median
#
function ag:median(?list){
let (?l = xt:sort(?list)){
xt:get(?l, xsd:integer((xt:size(?l) - 1) / 2))
}
}
#
# Standard deviation
#
function ag:sigma(?list){
let (?m = ag:avg(?list),
?dev = reduce (rq:plus, maplist(ag:sqdiff, ?list, ?m)) / xt:size(?list))
{ power(?dev, 0.5) }
}
function ag:avg(?list){
reduce (rq:plus, ?list) / xt:size(?list)
}
function ag:sqdiff(?x, ?m){
rq:power(?x - ?m, 2)
}
#
# group_concat that would sort its argument list
#
function ag:sort_concat(?list){
reduce(ag:concat, xt:sort(?list))
}
function ag:concat(?x, ?y){
concat(?x, "; ", ?y)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy