apache / jena

Apache Jena
https://jena.apache.org/
Apache License 2.0
1.11k stars 650 forks source link

How to set rdf:parseType="Literal" ? #2654

Closed vuras closed 2 months ago

vuras commented 2 months ago

Version

5.1.0

Question

Hi,

As this method was deprecated and is removed in version 5.1.0: @Deprecated public Literal createLiteral(String v, boolean wellFormed);

How should I add a rdf:parseType="Literal" to any Property?

arne-bdt commented 2 months ago

Hi, The org.apache.jena.graph.NodeFactory still offers plenty of ways to create literals. Which kind of literal do you want to create?

Arne

afs commented 2 months ago

rdf:parseType="Literal" is the RDF/XML form syntax.

It may not get written out using rdf:parseType="Literal" because that only happens if the value is valid for the rdf:XMLLiteral value space. Otherwise, it will be written with rdf:datatype and a string with escaped XML characters.

Jena 5.1.0 supports the RDF 1.1 definition of the value space. While simpler than the RDF 1.0 definition of exclusive canonicalization, it still quite complicated.

https://www.w3.org/TR/rdf11-concepts/#section-XMLLiteral

Either way of writing is the same RDF term.

NodeFactory:

    NodeFactory.createLiteralDT(String, RDF.dtXMLLiteral)`.

RDF.dtXMLLiteralis an RDFDatatype.

and for Model:

    Literal createTypedLiteral(String lex, RDF.dtXMLLiteral);
vuras commented 2 months ago

Hi everyone,

Thank you for the answers.

I managed to find the solution myself before reading your answers.

Looks similar to what afs proposed:

Literal createTypedLiteral(String lex, XMLLiteralType.theXMLLiteralType);

afs commented 2 months ago

@vuras - Glad to hear you found it.

RDF.dtXMLLiteral and XMLLiteralType.theXMLLiteralType are the same constant. RDF.dtXMLLiteral is slightly better to use.

XMLLiteralType.theXMLLiteralType isn't a good name because nothing else is "the...". It really ought to be be migrated to more normal name.