From: Mark D W. <mar...@ko...> - 2015-04-09 13:19:15
|
I have the following SPARQL query which Apache Fuseki evaluates just fine, but which dotNetRDF throws an exception in method ParseInternal in SparqlQueryParser if I try to parse it locally. This query, borrowing from someone's kind example<http://stackoverflow.com/questions/11040274/custom-functions-in-sparql-with-the-jena-api> on Stack Overflow, computes an average and standard deviation value using a Jena-specific built-in function. PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX sem: <http://ns.kodak.com/sem/1.0/> PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#> SELECT ( afn:sqrt( sum( (?fVal - ?ave) * (?fVal - ?ave) ) / (COUNT(?fv) - 1) ) as ?stddev ) (avg(?fVal) as ?a) FROM <urn:guid:mdw> WHERE { ?pic sem:MyPredicate ?fv . BIND (xsd:float(?fv ) AS ?fVal) { SELECT (AVG(?fVal2) AS ?ave) (COUNT(?fVal2) as ?cnt) WHERE { ?pic sem:MyPredicate ?fvi . BIND (xsd:float(?fvi ) AS ?fVal2) } } } The SPARQL 1.1 specification does say in Section 1.1 In aggregate queries and sub-queries, variables that appear in the query pattern, but are not in the GROUP BY clause, can only be projected or used in select expressions if they are aggregated. The SAMPLE aggregate may be used for this purpose. For details see the section on Projection Restrictions<http://www.w3.org/TR/sparql11-query/#aggregateRestrictions>. so it would appear that Fuseki is supporting something here that goes beyond the standard? (If so, it is a nice extension as otherwise I don't know how I'd compute a standard deviation.) I believe the exception is generated in the following line of code: //Check that either there are no Aggregates used or only Aggregates used if (SparqlSpecsHelper.IsSelectQuery(context.Query.QueryType) && (context.Query.IsAggregate && context.Query.GroupBy == null && context.Query.Variables.Any(v => v.IsResultVariable && !v.IsAggregate))) { throw new RdfParseException("The Select Query is invalid since it contains both Aggregates and Variables in the SELECT Clause but it does not contain a GROUP BY clause"); } Is there a way to get dotNetRDF to pass this query along to Fuseki? I am using SparqlConnector.Query. Thanks, -Mark |