You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Laura Morales <la...@mail.com> on 2021/07/16 07:35:01 UTC

Does Jena use duck typing?

When I insert new triples into a Jena/Fuseki store, are *all* the quoted literals treated as strings by default unless I specify the type explicitly (eg. xsd:dateTime)? Or does Jena use duck typing to determine the best type fit for storing the value?
What about numbers instead? Will Jena store 42 as an xsd:integer and 42.99 as xsd:double if I don't explicitly write the type?

How can I specify a set of constraints in Fuseki for all the properties of my model? For example "this property is a double, with range [1.0 .. 2.0]" (the same way that I can specify constraints on Postgres for example)?

Re: Does Jena use duck typing?

Posted by Martynas Jusevičius <ma...@atomgraph.com>.
In RDF 1.1 “Simple literals are syntactic sugar for abstract syntax literals
<https://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#dfn-literal> with
the datatype IRI
<https://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#dfn-datatype-iri>
http://www.w3.org/2001/XMLSchema#string”
https://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#section-Graph-Literal

On Fri, 16 Jul 2021 at 09.35, Laura Morales <la...@mail.com> wrote:

> When I insert new triples into a Jena/Fuseki store, are *all* the quoted
> literals treated as strings by default unless I specify the type explicitly
> (eg. xsd:dateTime)? Or does Jena use duck typing to determine the best type
> fit for storing the value?
> What about numbers instead? Will Jena store 42 as an xsd:integer and 42.99
> as xsd:double if I don't explicitly write the type?
>
> How can I specify a set of constraints in Fuseki for all the properties of
> my model? For example "this property is a double, with range [1.0 .. 2.0]"
> (the same way that I can specify constraints on Postgres for example)?
>

Re: Does Jena use duck typing?

Posted by Jean-Claude Moissinac <je...@telecom-paristech.fr>.
"25" is sometimes really a string so
"25"^^xsd:string
could be OK

If you have an weakly build dataset with sometimes the age expressed as a
string and sometimes as an integer, and you know that, you can try
something like
SELECT *
    WHERE
    {
        ?s :age ?age .
        FILTER (xsd:integer(?age) < 30)
    }

--
Jean-Claude Moissinac



<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Garanti
sans virus. www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Le dim. 25 juil. 2021 à 15:35, Andy Seaborne <an...@apache.org> a écrit :

>
>
> On 25/07/2021 14:08, Laura Morales wrote:
> > What I mean is... (with an example):
> > As far as I understand, these are valid triples that I can load into
> Fuseki/Jena at the same time in the same graph
> >
> >      :alice   :age "25"^^xsd:string;
> >      :bob     :age "20"^^xsd:integer;
> >
> > If then I execute this query:
> >
> >      SELECT *
> >      WHERE
> >      {
> >          ?s :age ?age .
> >          FILTER (?age < 30)
> >      }
> >
> > should Jena raise an error (because there is a :age property with a
> value that is not integer), or should it simply ignore :alice entirely
> because the type of the property (string) doesn't match the type that I'm
> querying for?
>
> "25"^^xsd:string < 30
>
> is a type error.
>
> Type errors in a FILTER makes the filter false. (It does not become an
> overall query error.)
>
>      Andy
>
> >
> >
> >
> >
> >> Sent: Monday, July 19, 2021 at 12:40 PM
> >> From: "Andy Seaborne" <an...@apache.org>
> >> To: users@jena.apache.org
> >> Subject: Re: Does Jena use duck typing?
> >>
> >> It store triples/quads.
> >> Think of it as a table of triples and table of quads
> >>
> >> Comparison is defined by XQuery/XPath Functions and Operators.
> >>
> >> But maybe I don't understand what's behind the question.
> >>
> >> On 19/07/2021 07:02, Laura Morales wrote:
> >>> How is Jena able to index and search/compare properties with different
> data types?
> >>> For example if I have this graph
> >>>
> >>>       :alice :foobar "2021-07-16"^^xsd:date;
> >>>       :alice :foobar "foobar"^^xsd:string;
> >>>       :alice :foobar "42"^^xsd:integer;
> >>
> >> You can't compare "2021-07-16"^^xsd:date with an xsd:string or an
> >> xsd:integer.
> >>
> >> They have different value spaces.
> >>
> >>       Andy
>

Re: Does Jena use duck typing?

Posted by Andy Seaborne <an...@apache.org>.

On 25/07/2021 14:08, Laura Morales wrote:
> What I mean is... (with an example):
> As far as I understand, these are valid triples that I can load into Fuseki/Jena at the same time in the same graph
> 
>      :alice   :age "25"^^xsd:string;
>      :bob     :age "20"^^xsd:integer;
> 
> If then I execute this query:
> 
>      SELECT *
>      WHERE
>      {
>          ?s :age ?age .
>          FILTER (?age < 30)
>      }
> 
> should Jena raise an error (because there is a :age property with a value that is not integer), or should it simply ignore :alice entirely because the type of the property (string) doesn't match the type that I'm querying for?

"25"^^xsd:string < 30

is a type error.

Type errors in a FILTER makes the filter false. (It does not become an 
overall query error.)

     Andy

> 
> 
> 
> 
>> Sent: Monday, July 19, 2021 at 12:40 PM
>> From: "Andy Seaborne" <an...@apache.org>
>> To: users@jena.apache.org
>> Subject: Re: Does Jena use duck typing?
>>
>> It store triples/quads.
>> Think of it as a table of triples and table of quads
>>
>> Comparison is defined by XQuery/XPath Functions and Operators.
>>
>> But maybe I don't understand what's behind the question.
>>
>> On 19/07/2021 07:02, Laura Morales wrote:
>>> How is Jena able to index and search/compare properties with different data types?
>>> For example if I have this graph
>>>
>>>       :alice :foobar "2021-07-16"^^xsd:date;
>>>       :alice :foobar "foobar"^^xsd:string;
>>>       :alice :foobar "42"^^xsd:integer;
>>
>> You can't compare "2021-07-16"^^xsd:date with an xsd:string or an
>> xsd:integer.
>>
>> They have different value spaces.
>>
>>       Andy

Re: Does Jena use duck typing?

Posted by Laura Morales <la...@mail.com>.
What I mean is... (with an example):
As far as I understand, these are valid triples that I can load into Fuseki/Jena at the same time in the same graph

    :alice   :age "25"^^xsd:string;
    :bob     :age "20"^^xsd:integer;

If then I execute this query:

    SELECT *
    WHERE
    {
        ?s :age ?age .
        FILTER (?age < 30)
    }

should Jena raise an error (because there is a :age property with a value that is not integer), or should it simply ignore :alice entirely because the type of the property (string) doesn't match the type that I'm querying for?




> Sent: Monday, July 19, 2021 at 12:40 PM
> From: "Andy Seaborne" <an...@apache.org>
> To: users@jena.apache.org
> Subject: Re: Does Jena use duck typing?
>
> It store triples/quads.
> Think of it as a table of triples and table of quads
>
> Comparison is defined by XQuery/XPath Functions and Operators.
>
> But maybe I don't understand what's behind the question.
>
> On 19/07/2021 07:02, Laura Morales wrote:
> > How is Jena able to index and search/compare properties with different data types?
> > For example if I have this graph
> >
> >      :alice :foobar "2021-07-16"^^xsd:date;
> >      :alice :foobar "foobar"^^xsd:string;
> >      :alice :foobar "42"^^xsd:integer;
>
> You can't compare "2021-07-16"^^xsd:date with an xsd:string or an
> xsd:integer.
>
> They have different value spaces.
>
>      Andy

Re: Does Jena use duck typing?

Posted by Andy Seaborne <an...@apache.org>.
It store triples/quads.
Think of it as a table of triples and table of quads

Comparison is defined by XQuery/XPath Functions and Operators.

But maybe I don't understand what's behind the question.

On 19/07/2021 07:02, Laura Morales wrote:
> How is Jena able to index and search/compare properties with different data types?
> For example if I have this graph
> 
>      :alice :foobar "2021-07-16"^^xsd:date;
>      :alice :foobar "foobar"^^xsd:string;
>      :alice :foobar "42"^^xsd:integer;

You can't compare "2021-07-16"^^xsd:date with an xsd:string or an 
xsd:integer.

They have different value spaces.

     Andy

> 
> 
> 
> 
>> Sent: Friday, July 16, 2021 at 10:06 AM
>> From: "Andy Seaborne" <an...@apache.org>
>> To: users@jena.apache.org
>> Subject: Re: Does Jena use duck typing?
>>
>> Literals are always datatyped in RDF. No guessing.
>>
>>
>>
>> There syntax conveniences:
>>
>> "abc" is the same as writing "abc"^^xsd:string.
>>
>> The specs say to prefer writing output without ^^xsd:string.
>>
>> In Turtle and related syntaxes:
>>
>> 42 is an xsd:integer == "42"^^xsd:integer
>>
>> 42.99 is an xsd:decimal
>>
>> 42e0 is an xsd;double.
>>
>> "2021-07-16" is string.
>> "2021-07-16"^^xsd;date is a date.
>>
>> and language strings "abc"@en have datatype rdf:langString.
>>
>> On 16/07/2021 08:35, Laura Morales wrote:
>>> When I insert new triples into a Jena/Fuseki store, are *all* the quoted literals treated as strings by default unless I specify the type explicitly (eg. xsd:dateTime)? Or does Jena use duck typing to determine the best type fit for storing the value?
>>> What about numbers instead? Will Jena store 42 as an xsd:integer and 42.99 as xsd:double if I don't explicitly write the type?
>>>
>>> How can I specify a set of constraints in Fuseki for all the properties of my model? For example "this property is a double, with range [1.0 .. 2.0]" (the same way that I can specify constraints on Postgres for example)?
>>
>> Using ontology/schema/shapes.
>>
>>       Andy
>>

Re: Does Jena use duck typing?

Posted by Laura Morales <la...@mail.com>.
How is Jena able to index and search/compare properties with different data types?
For example if I have this graph

    :alice :foobar "2021-07-16"^^xsd:date;
    :alice :foobar "foobar"^^xsd:string;
    :alice :foobar "42"^^xsd:integer;




> Sent: Friday, July 16, 2021 at 10:06 AM
> From: "Andy Seaborne" <an...@apache.org>
> To: users@jena.apache.org
> Subject: Re: Does Jena use duck typing?
>
> Literals are always datatyped in RDF. No guessing.
>
>
>
> There syntax conveniences:
>
> "abc" is the same as writing "abc"^^xsd:string.
>
> The specs say to prefer writing output without ^^xsd:string.
>
> In Turtle and related syntaxes:
>
> 42 is an xsd:integer == "42"^^xsd:integer
>
> 42.99 is an xsd:decimal
>
> 42e0 is an xsd;double.
>
> "2021-07-16" is string.
> "2021-07-16"^^xsd;date is a date.
>
> and language strings "abc"@en have datatype rdf:langString.
>
> On 16/07/2021 08:35, Laura Morales wrote:
> > When I insert new triples into a Jena/Fuseki store, are *all* the quoted literals treated as strings by default unless I specify the type explicitly (eg. xsd:dateTime)? Or does Jena use duck typing to determine the best type fit for storing the value?
> > What about numbers instead? Will Jena store 42 as an xsd:integer and 42.99 as xsd:double if I don't explicitly write the type?
> >
> > How can I specify a set of constraints in Fuseki for all the properties of my model? For example "this property is a double, with range [1.0 .. 2.0]" (the same way that I can specify constraints on Postgres for example)?
>
> Using ontology/schema/shapes.
>
>      Andy
>

Re: Does Jena use duck typing?

Posted by Andy Seaborne <an...@apache.org>.
Literals are always datatyped in RDF. No guessing.



There syntax conveniences:

"abc" is the same as writing "abc"^^xsd:string.

The specs say to prefer writing output without ^^xsd:string.

In Turtle and related syntaxes:

42 is an xsd:integer == "42"^^xsd:integer

42.99 is an xsd:decimal

42e0 is an xsd;double.

"2021-07-16" is string.
"2021-07-16"^^xsd;date is a date.

and language strings "abc"@en have datatype rdf:langString.

On 16/07/2021 08:35, Laura Morales wrote:
> When I insert new triples into a Jena/Fuseki store, are *all* the quoted literals treated as strings by default unless I specify the type explicitly (eg. xsd:dateTime)? Or does Jena use duck typing to determine the best type fit for storing the value?
> What about numbers instead? Will Jena store 42 as an xsd:integer and 42.99 as xsd:double if I don't explicitly write the type?
> 
> How can I specify a set of constraints in Fuseki for all the properties of my model? For example "this property is a double, with range [1.0 .. 2.0]" (the same way that I can specify constraints on Postgres for example)?

Using ontology/schema/shapes.

     Andy