Values.literal factory method with int argument should return xsd:integer datatype #3195
abrokenjester
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When calling
ValueFactory.createLiteral(42)
orValues.literal(42)
the returned literal object hasxsd:int
as its datatype. While technically correct, this can easily catch people out: in both SPARQL 1.1 (see https://www.w3.org/TR/sparql11-query/#QSynLiterals) and Turtle syntax (see https://www.w3.org/TR/turtle/#abbrev) the assigned datatype when using shorthand syntax for integer values isxsd:integer
rather thanxsd:int
.This means that when first loading the following Turtle data:
and then using Java for example to retrieve all statements with that value:
We get an empty result, because
literal(42)
will not match with the turtle literal (wrong datatype). Workarounds areor
The difference between the two datatypes is that
xsd:integer
represents an unbounded integer (technically it's a restriction onxsd:decimal
allowing no fraction in the lexical space), whereasxsd:int
represents a 32-bit two-complement signed integer value. We originally chose to represent Javaint
primitives (and instances ofjava.lang.Integer
) withxsd:int
precisely because it corresponds 1:1 with the intended datatype, and usexsd:Integer
only to represent ajava.math.BigInteger
.I propose instead of using the datatype that technically aligns closest with the Java primitive, we use the datatype that from an API usability perspective makes the most sense. I'm suspecting that in 99 out of 100 cases people want to use
xsd:integer
to align with Turtle and SPARQL.Beta Was this translation helpful? Give feedback.
All reactions