You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Michael Brunnbauer <br...@netestate.de> on 2015/10/09 09:21:15 UTC

Casting with Fuseki (Was: How to specify power in select cause SPARQL)

Hello Maria,

I am not aware of a way to express power with SPARQL. For powers of 10, you
could use casting:

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select (xsd:double(concat("1e",str(?exp))) as ?result) where { VALUES ?exp { 3 } }

Which brings me to an interesting observation. Why is ?a not bound in the
Fuseki result of this query?

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select (xsd:integer(1e2) as ?a) where { }

The DBpedia SPARQL endpoint returns 100.

Regards,

Michael Brunnbauer

On Fri, Oct 09, 2015 at 12:19:00AM +0530, Maria Jackson wrote:
> Dear All,
> 
> select ?a?b?c?r where{ graph ?graph1{?a ?b <object1>} graph ?graph21{?a ?c
> <object2>} graph ?graph2{?a <time> ?r}} order by asc(?r+(1.1*10^(11)))
> limit 1
> 
> If I write the above expression to denote: ?r + (1.1 x (pow(10,11))) then
> will it be a correct expression in Jena. I am struggling to find how to
> express power in Jena?

-- 
++  Michael Brunnbauer
++  netEstate GmbH
++  Geisenhausener Straße 11a
++  81379 München
++  Tel +49 89 32 19 77 80
++  Fax +49 89 32 19 77 89 
++  E-Mail brunni@netestate.de
++  http://www.netestate.de/
++
++  Sitz: München, HRB Nr.142452 (Handelsregister B München)
++  USt-IdNr. DE221033342
++  Geschäftsführer: Michael Brunnbauer, Franz Brunnbauer
++  Prokurist: Dipl. Kfm. (Univ.) Markus Hendel

Re: Casting with Fuseki (Was: How to specify power in select cause SPARQL)

Posted by Andy Seaborne <an...@apache.org>.
On 09/10/15 19:24, Michael Brunnbauer wrote:
>
> Hello Andy,
>
> On Fri, Oct 09, 2015 at 06:25:47PM +0100, Andy Seaborne wrote:
>>> So Fuseki can only cast from xsd:double to xsd:integer if the lexical value
>>> conforms to xsd:integer?

Yes, currently - it maintains term relationships (loosely [*])

X = cast (Y)
=>
str(X) = str(Y)


[*] except in one case for booleans.

The code is in CastXSD_numeric : patches/PRs welcome :  it's quite old code.

>>
>>> And the lexical value is preserved by the Fuseki engine unless a computation is
>>> involved, which has to convert the lexical value to the value and back to the
>>> canonical representation, which never conforms to xsd:integer?

That may be due to supporting printing doubles in short form in SPARQL. 
  Doubles to have "E0".  I doubt the tie is necessary.


>>>
>>> And the decision which lexical values of xsd:double can be casted to
>>> xsd:integer is up to the implementer of SPARQL?

The casting rules come from XSD (and IIRC are a bit different between 
edition 1 and edition 2, at least in how they are expressed).  What 
isn't clear with hindsight is the relationship to RDF terms.  The 
canonical (XSD) form of double does not identify it as a double - XSD 
has a schema, RDF has datatypes.

c.f. java's Double.toString(100) --> 100.0 where the output is a Java 
double string.


>>
>> What a lot of questions.
>>
>> Is there something driving all this?
>
> Just curiosity.
>
> Regards,
>
> Michael Brunnbauer
>


Re: Casting with Fuseki (Was: How to specify power in select cause SPARQL)

Posted by Michael Brunnbauer <br...@netestate.de>.
Hello Andy,

On Fri, Oct 09, 2015 at 06:25:47PM +0100, Andy Seaborne wrote:
> >So Fuseki can only cast from xsd:double to xsd:integer if the lexical value
> >conforms to xsd:integer?
> 
> >And the lexical value is preserved by the Fuseki engine unless a computation is
> >involved, which has to convert the lexical value to the value and back to the
> >canonical representation, which never conforms to xsd:integer?
> >
> >And the decision which lexical values of xsd:double can be casted to
> >xsd:integer is up to the implementer of SPARQL?
> 
> What a lot of questions.
> 
> Is there something driving all this?

Just curiosity.

Regards,

Michael Brunnbauer

-- 
++  Michael Brunnbauer
++  netEstate GmbH
++  Geisenhausener Straße 11a
++  81379 München
++  Tel +49 89 32 19 77 80
++  Fax +49 89 32 19 77 89 
++  E-Mail brunni@netestate.de
++  http://www.netestate.de/
++
++  Sitz: München, HRB Nr.142452 (Handelsregister B München)
++  USt-IdNr. DE221033342
++  Geschäftsführer: Michael Brunnbauer, Franz Brunnbauer
++  Prokurist: Dipl. Kfm. (Univ.) Markus Hendel

Re: Casting with Fuseki (Was: How to specify power in select cause SPARQL)

Posted by Andy Seaborne <an...@apache.org>.
On 09/10/15 18:06, Michael Brunnbauer wrote:
>
> Hello Andy,
>
> On Fri, Oct 09, 2015 at 03:42:16PM +0100, Andy Seaborne wrote:
>> "1e2"^^xsd:double is not "100"^^xsd:double.  Same value, different term.
>> xsd:integer("100"^^xsd:double) works.
>
> So Fuseki can only cast from xsd:double to xsd:integer if the lexical value
> conforms to xsd:integer?

> And the lexical value is preserved by the Fuseki engine unless a computation is
> involved, which has to convert the lexical value to the value and back to the
> canonical representation, which never conforms to xsd:integer?
>
> And the decision which lexical values of xsd:double can be casted to
> xsd:integer is up to the implementer of SPARQL?

What a lot of questions.

Is there something driving all this?


>
> Regards,
>
> Michael Brunnbauer
>


Re: Casting with Fuseki (Was: How to specify power in select cause SPARQL)

Posted by Michael Brunnbauer <br...@netestate.de>.
Hello Andy,

On Fri, Oct 09, 2015 at 03:42:16PM +0100, Andy Seaborne wrote:
> "1e2"^^xsd:double is not "100"^^xsd:double.  Same value, different term.
> xsd:integer("100"^^xsd:double) works.

So Fuseki can only cast from xsd:double to xsd:integer if the lexical value 
conforms to xsd:integer?

And the lexical value is preserved by the Fuseki engine unless a computation is
involved, which has to convert the lexical value to the value and back to the
canonical representation, which never conforms to xsd:integer?

And the decision which lexical values of xsd:double can be casted to
xsd:integer is up to the implementer of SPARQL?

Regards,

Michael Brunnbauer

-- 
++  Michael Brunnbauer
++  netEstate GmbH
++  Geisenhausener Straße 11a
++  81379 München
++  Tel +49 89 32 19 77 80
++  Fax +49 89 32 19 77 89 
++  E-Mail brunni@netestate.de
++  http://www.netestate.de/
++
++  Sitz: München, HRB Nr.142452 (Handelsregister B München)
++  USt-IdNr. DE221033342
++  Geschäftsführer: Michael Brunnbauer, Franz Brunnbauer
++  Prokurist: Dipl. Kfm. (Univ.) Markus Hendel

Re: Casting with Fuseki (Was: How to specify power in select cause SPARQL)

Posted by Andy Seaborne <an...@apache.org>.
On 09/10/15 08:21, Michael Brunnbauer wrote:
>
> Hello Maria,
>
> I am not aware of a way to express power with SPARQL. For powers of 10, you
> could use casting:
>
> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
> select (xsd:double(concat("1e",str(?exp))) as ?result) where { VALUES ?exp { 3 } }
>
> Which brings me to an interesting observation. Why is ?a not bound in the
> Fuseki result of this query?
>
> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
> select (xsd:integer(1e2) as ?a) where { }
>
> The DBpedia SPARQL endpoint returns 100.

"1e2"^^xsd:double is not "100"^^xsd:double.  Same value, different term.

"1e2"^^xsd:integer isn't a valid integer.

xsd:integer("100"^^xsd:double) works.

(errors can extension points)

	Andy

>
> Regards,
>
> Michael Brunnbauer
>
> On Fri, Oct 09, 2015 at 12:19:00AM +0530, Maria Jackson wrote:
>> Dear All,
>>
>> select ?a?b?c?r where{ graph ?graph1{?a ?b <object1>} graph ?graph21{?a ?c
>> <object2>} graph ?graph2{?a <time> ?r}} order by asc(?r+(1.1*10^(11)))
>> limit 1
>>
>> If I write the above expression to denote: ?r + (1.1 x (pow(10,11))) then
>> will it be a correct expression in Jena. I am struggling to find how to
>> express power in Jena?
>