Hello guys,

I'm working with LinkedMovieDataBase <http://data.linkedmdb.org/> + Apache
Jena and would like to know the sum of the runtime of the films. However I
have had many problems with queries using aggregates functions.

It is known that literal has its standard type as a string, then it is
necessary to cast to decimal. Thus it was formulated the following SPARQL
query:

PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema>
SELECT (SUM(?runtime^^xsd:decimal) as ?sum_runtime)
WHERE {?filmUri movie:runtime ?runtime}

Returning the following error:

Exception in thread "main" com.hp.hpl.jena.query.QueryParseException:
Encountered " "^^" "^^ "" at line 1, column 126.
Was expecting one of:
    "not" ...
    "in" ...
    <INTEGER_POSITIVE> ...
    <DECIMAL_POSITIVE> ...
    <DOUBLE_POSITIVE> ...
    <INTEGER_NEGATIVE> ...
    <DECIMAL_NEGATIVE> ...
    <DOUBLE_NEGATIVE> ...
    ")" ...
    "=" ...
    "!=" ...
    ">" ...
    "<" ...
    "<=" ...
    ">=" ...
    "||" ...
    "&&" ...
    "+" ...
    "-" ...
    "*" ...
    "/" ...

I've done several adaptations to this query and i didn't get the expected
result. One approach used was to modify the cast into the following form:

...
SELECT (SUM(xsd:decimal(?runtime)) as ?sum_runtime)
...

But the return is null, which I do not understand. If you try cast to
integer (xsd:integer) or floating point (xsd:float) returns the same error.

Using COUNT as aggregation function the result is correct, but the count is
not necessary to make the conversion, so it works. With the MIN and MAX
functions the result also goes wrong.

The proof that the query is semantically correct is that if removing the
sum function of the query returns the expected result.

Can someone help me?

Thanks in advance
Daniel Leite

Reply via email to