W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > July to September 2010

Re: isNumeric

From: Axel Polleres <axel.polleres@deri.org>
Date: Sun, 19 Sep 2010 21:24:16 +0100
Cc: Axel Polleres <axel.polleres@deri.org>
Message-Id: <5590ADC1-4750-4355-BD49-442B1D91CAFD@deri.org>
To: SPARQL Working Group <public-rdf-dawg@w3.org>
Some 3 draft test cases for this...

Data:

@prefix ex: <http://example.org/> .
ex:lemonade1    ex:price 3 ;
                rdf:type ex:Softdrink.
ex:beer1        ex:price 3;
                rdf:type ex:Beer.
ex:wine1        ex:price 3.50 ;
                rdf:type ex:Wine.
ex:wine2        ex:price 4 .
                rdf:type ex:Wine.
ex:wine3        ex:price "n/a";
                rdf:type ex:Wine.



Queries:

sum-per-category-1:

PREFIX ex: <http://example.org/>
SELECT ?T (Sum(COLAESCE(xs:decimal(?Pr),0) AS ?P)
WHERE { ?Item rdf:type ?T; ex:price ?Pr }
GROUP BY ?T

sum-per-category-2:

PREFIX ex: <http://example.org/>
SELECT ?T (Sum(?Pr) AS ?P)
WHERE { ?Item rdf:type ?T; ex:price ?Pr
        FILTER( isNumeric(?Pr) ) }
GROUP BY ?T

sum-per-category-3:

PREFIX ex: <http://example.org/>
SELECT ?T (Sum(IF(isNumeric(?Pr),?Pr,0) AS ?P)
WHERE { ?Item rdf:type ?T; ex:price ?Pr
         ) }
GROUP BY ?T


best,
Axel


On 19 Sep 2010, at 21:13, Axel Polleres wrote:

> Hi all,
> 
> Don't we need something like a function isNumeric to test for a numeric argument?
> Seems to be handy, useful for instance for numeric aggregates, or no?
> 
> It seems COALESCE together with a cast would work as well, but
> something like
>  SUM(IF(isNumeric(?X), ?X, 0))
> looks better - at least to me - than:
>    SUM(COALESCE(xs:double(?X) , 0))
> 
> Opinions?
> 
> Axel
Received on Sunday, 19 September 2010 20:24:53 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:43 GMT