Issue #2812: Reflect explicitly XSD-typed Literals in JSON-LD serialization by lu-pl · Pull Request #2889 · RDFLib/rdflib (original) (raw)
@lu-pl I thought in an RDFLib Literal there is no way to distinguish between a provided datatype and an inferred datatype.
How does this know whether to emit a datatype for only user-provided datatypes?
Thanks for the reply!
Is there such a thing as an inferred explicit datatype in rdflib.Literal
?
A datatype is either explicitly assigned, in which case rdflib.Literal.datatype
holds the datatype URI, or not, in which case rdflib.Literal.datatype
is None
.
from rdflib import Liteal, XSD
literal_implicit_type = Literal("value") literal_explicit_type = Literal("value", datatype=XSD.string)
print(literal_implicit_type.datatype) print(literal_explicit_type.datatype)
The only type inference defined in the standard are simple literals, so if something is not explicitly typed, it is interpreted as syntactic sugar for xsd:string
.
Please note that concrete syntaxes MAY support simple literals consisting of only a lexical form without any datatype IRI, language tag, or base direction. Simple literals are syntactic sugar for abstract syntax literals with the datatype IRI http://www.w3.org/2001/XMLSchema#string (which is commonly abbreviated as xsd:string). (3.3 Literals)
(E.g. Turtle provides a type-infery shorthand syntax for numbers and bools, see 2.5.2)
The problem I am trying to address is that the JSON-LD serializer does not retain datatypes defined in an rdflib.Graph
instance (regardless of how that graph got populated).