You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by prerak pradhan <pr...@yahoo.com> on 2012/04/10 20:41:21 UTC

Converting from XMLSchema datatype to Java int

Hey there everyone, I am working on a project that involves fetching data from dbpedia. using its SPARQL endpoint  and I was wondering whether there is any method jena provides to convert the the object returned and stored in an RDFNode from a dbpedia query i.e a XMLSchema#double into a java int so that I can perform operations on it and modify the data for my use. I tried casting the RDFNode into a string and than onto an int but that doesn't work and throws a numberFormat exception. Anyone with any solution to this problem.

Regards
Prerak

Re: Converting from XMLSchema datatype to Java int

Posted by Chris Dollin <ch...@epimorphics.com>.
Prerak said:

> Hey there everyone, I am working on a project that involves fetching data 
> from dbpedia. using its SPARQL endpoint  and I was wondering whether
> there is any method jena provides to convert the the object returned 
> and stored in an RDFNode from a dbpedia query i.e a XMLSchema#double
> into a java int so that I can perform operations on it and modify the data
> for my use.

If the data is a double, why do you want to force it into a Java int? Can
you not deal with it as a double?

[Doubles have more range and more precision than ints.]

Chris

-- 
"You're down as expendable. You don't get a weapon."    /Dark Lord of Derkholm/

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)

Re: Converting from XMLSchema datatype to Java int

Posted by Dave Reynolds <da...@gmail.com>.
On 10/04/12 19:58, Robert Vesse wrote:
> See
> http://incubator.apache.org/jena/documentation/javadoc/jena/com/hp/hpl/jena/rdf/model/Literal.html
>
> Once you have a Literal - which you can get by calling asLiteral() -
> there are a bunch of get methods which will return the value as an
> appropriate java type e.g. getInt()

In particular Literal#getValue() will return the java object mapped to 
that literal type (a String for plain literals).

Dave

>
> Hope this helps
>
> Rob
>
>
> Rob Vesse -- YarcData.com <http://YarcData.com> -- A Division of Cray Inc
> Software Engineer, Bay Area
> m: 925.960.3941 | o: 925.264.4729 | @: rvesse@yarcdata.com
> <ma...@yarcdata.com> | Skype: rvesse
> 6210 Stoneridge Mall Rd | Suite 120 | Pleasanton CA, 94588
>
>
> On Apr 10, 2012, at 11:41 AM, prerak pradhan wrote:
>
>> Hey there everyone, I am working on a project that involves fetching
>> data from dbpedia. using its SPARQL endpoint and I was wondering
>> whether there is any method jena provides to convert the the object
>> returned and stored in an RDFNode from a dbpedia query i.e a
>> XMLSchema#double into a java int so that I can perform operations on
>> it and modify the data for my use. I tried casting the RDFNode into a
>> string and than onto an int but that doesn't work and throws a
>> numberFormat exception. Anyone with any solution to this problem.
>>
>> Regards
>> Prerak
>


Re: Converting from XMLSchema datatype to Java int

Posted by Robert Vesse <rv...@yarcdata.com>.
See http://incubator.apache.org/jena/documentation/javadoc/jena/com/hp/hpl/jena/rdf/model/Literal.html

Once you have a Literal - which you can get by calling asLiteral() - there are a bunch of get methods which will return the value as an appropriate java type e.g. getInt()

Hope this helps

Rob


Rob Vesse -- YarcData.com<http://YarcData.com> -- A Division of Cray Inc
Software Engineer, Bay Area
m: 925.960.3941  |  o: 925.264.4729 | @: rvesse@yarcdata.com<ma...@yarcdata.com>  |  Skype: rvesse
6210 Stoneridge Mall Rd  |  Suite 120  | Pleasanton CA, 94588

[cid:BC8A5E0A-0B0A-43B5-87B5-93039573F2CD@americas.cray.com]

On Apr 10, 2012, at 11:41 AM, prerak pradhan wrote:

Hey there everyone, I am working on a project that involves fetching data from dbpedia. using its SPARQL endpoint  and I was wondering whether there is any method jena provides to convert the the object returned and stored in an RDFNode from a dbpedia query i.e a XMLSchema#double into a java int so that I can perform operations on it and modify the data for my use. I tried casting the RDFNode into a string and than onto an int but that doesn't work and throws a numberFormat exception. Anyone with any solution to this problem.

Regards
Prerak