You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Dimitris Spanos <di...@gmail.com> on 2012/08/11 20:05:13 UTC

[ARQ] ResultSetFormatter and typed literals

Hello all,

I have a ResultSetStream and I am using ResultSetFormatter to format
it. So far, I have used the asText() and toModel() methods to get it
as plain text or stored in a Model respectively. However, Bindings to
typed literals (with an xsd:integer datatype, to be precise) are
output as plain literals. Delving into the code a bit, I saw that
eventually, it is FmtUtils.stringForLiteral() which is responsible for
the formatting and apparently, it omits the datatype for xsd:integer,
xsd:decimal, xsd:double and xsd:boolean.
Is there any way to change this?
If I want to output the entire label of the literal (e.g.
10^^http://www.w3.org/2001/XMLSchema#integer) instead of just 10, do I
have to create from scratch a new utility class for the formatting of
my ResultSet?

Dimitris

Re: [ARQ] ResultSetFormatter and typed literals

Posted by Dimitris Spanos <di...@gmail.com>.
Thank you for your response Andy,

I was afraid that the datatype was not being stored at all in the
model, it did not occur to me that it was the Turtle output
implementation, now I can see it just fine with N-Triples (I guess I
will stick to it for now, although I still prefer Turtle :) ).
I might take your advice and override getVarValueForString and
FmtUtils.stringForLiteral (because I will need Turtle output somewhere
down the road), thanks for the code change, it makes things much
easier.

Dimitris

On Sun, Aug 12, 2012 at 10:28 PM, Andy Seaborne <an...@apache.org> wrote:
> On 11/08/12 19:05, Dimitris Spanos wrote:
>>
>> Hello all,
>>
>> I have a ResultSetStream and I am using ResultSetFormatter to format
>> it. So far, I have used the asText() and toModel() methods to get it
>> as plain text or stored in a Model respectively. However, Bindings to
>> typed literals (with an xsd:integer datatype, to be precise) are
>> output as plain literals. Delving into the code a bit, I saw that
>> eventually, it is FmtUtils.stringForLiteral() which is responsible for
>> the formatting and apparently, it omits the datatype for xsd:integer,
>> xsd:decimal, xsd:double and xsd:boolean.
>> Is there any way to change this?
>> If I want to output the entire label of the literal (e.g.
>> 10^^http://www.w3.org/2001/XMLSchema#integer) instead of just 10, do I
>> have to create from scratch a new utility class for the formatting of
>> my ResultSet?
>>
>> Dimitris
>>
>
> Hi there,
>
> The text form generated by asText() is supposed to be conveniently readable
> - it used Turtle formatting.  When asText() outputs
>
> 3
>
> not
>
> "3"^^xsd:integer
>
> it does not change the fact that the data in the results really is a types
> literal with lexical for "3" and datatype xsd:integer.
>
> toModel encodes the result ste in RDF - the RDF term will be
> "3"^^xsd:integer although if output in Turtle, it will appear as 3.  try
> N-Triples.
>
> The text formatter does not configuration options.  (Actually, the code is
> ancient - it could probably do with a clean!)
>
> If you want different text appearance, then simple take a copy of TextOutput
> (I have just made getVarValueAsString protected not private so if you use
> the build development from tonight, you can inherit the code).
>
>         Andy
>

Re: [ARQ] ResultSetFormatter and typed literals

Posted by Andy Seaborne <an...@apache.org>.
On 11/08/12 19:05, Dimitris Spanos wrote:
> Hello all,
>
> I have a ResultSetStream and I am using ResultSetFormatter to format
> it. So far, I have used the asText() and toModel() methods to get it
> as plain text or stored in a Model respectively. However, Bindings to
> typed literals (with an xsd:integer datatype, to be precise) are
> output as plain literals. Delving into the code a bit, I saw that
> eventually, it is FmtUtils.stringForLiteral() which is responsible for
> the formatting and apparently, it omits the datatype for xsd:integer,
> xsd:decimal, xsd:double and xsd:boolean.
> Is there any way to change this?
> If I want to output the entire label of the literal (e.g.
> 10^^http://www.w3.org/2001/XMLSchema#integer) instead of just 10, do I
> have to create from scratch a new utility class for the formatting of
> my ResultSet?
>
> Dimitris
>

Hi there,

The text form generated by asText() is supposed to be conveniently 
readable - it used Turtle formatting.  When asText() outputs

3

not

"3"^^xsd:integer

it does not change the fact that the data in the results really is a 
types literal with lexical for "3" and datatype xsd:integer.

toModel encodes the result ste in RDF - the RDF term will be 
"3"^^xsd:integer although if output in Turtle, it will appear as 3.  try 
N-Triples.

The text formatter does not configuration options.  (Actually, the code 
is ancient - it could probably do with a clean!)

If you want different text appearance, then simple take a copy of 
TextOutput (I have just made getVarValueAsString protected not private 
so if you use the build development from tonight, you can inherit the code).

	Andy