Funciones para manipular colecciones RDF en SPARQL.
Me gustaría saber si hay algunas funciones para manipular colecciones RDF en SPARQL.
Un problema motivador es el siguiente.
Supongamos que usted tiene:
@prefix : <http://example.org#> .
:x1 :value 3 .
:x2 :value 5 .
:x3 :value 6 .
:x4 :value 8 .
:list :values (:x1 :x2 :x3 :x4) .
Y desea calcular la siguiente fórmula: ((Xn - Xn-1) + ... (X2 - X1)) / (N - 1)
¿Hay alguna forma general de calcularlo?
Hasta ahora, solo podía calcularlo para un conjunto fijo de valores. Por ejemplo, para 4 valores, puedo usar la siguiente consulta:
prefix : <http://example.org#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?r {
?list :values ?ls .
?ls rdf:first ?x1 .
?ls rdf:rest/rdf:first ?x2 .
?ls rdf:rest/rdf:rest/rdf:first ?x3 .
?ls rdf:rest/rdf:rest/rdf:rest/rdf:first ?x4 .
?x1 :value ?v1 .
?x2 :value ?v2 .
?x3 :value ?v3 .
?x4 :value ?v4 .
BIND ( ((?v4 - ?v3) + (?v3 - ?v2) + (?v2 - ?v1)) / 3 as ?r)
}
Lo que me gustaría es alguna forma de acceder al valor Nth y definir algún tipo de función recursiva para calcular esa expresión. Creo que no es posible, pero tal vez, alguien tiene una buena solución.