Discussion:
Support for non-string plain literals?
Jindřich Mynarz
2016-06-25 09:54:15 UTC
Permalink
Hi,

can I use Jena to create non-string plain literals, such as integers?

ResourceFactory.createLiteral() (
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/ResourceFactory.html#createPlainLiteral-java.lang.String-)
is available only for strings.

- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
Jean-Marc Vanel
2016-06-25 10:32:02 UTC
Permalink
Jindrich you had to read further on the javadoc:


- createTypedLiteral

public static Literal
<https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Literal.html>
createTypedLiteral(String
<http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
string,
RDFDatatype
<https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/datatypes/RDFDatatype.html>
dType)

Answer a typed literal.
Parameters:string - the string which forms the value of the literaldType
- RDFDatatype of the type literalReturns:a Literal node with that string
as value


- createTypedLiteral

public static Literal
<https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Literal.html>
createTypedLiteral(Object
<http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true>
value)

Answer a typed literal.
Parameters:value - a java Object, the default RDFDatatype for that
object will be usedReturns:a Literal node with that value
Post by Jindřich Mynarz
Hi,
can I use Jena to create non-string plain literals, such as integers?
ResourceFactory.createLiteral() (
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/ResourceFactory.html#createPlainLiteral-java.lang.String-
)
is available only for strings.
- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
--
Jean-Marc Vanel
Déductions SARL - Consulting, services, training,
Rule-based programming, Semantic Web
http://deductions-software.com/
+33 (0)6 89 16 29 52
Twitter: @jmvanel , @jmvanel_fr ; chat: irc://irc.freenode.net#eulergui
Jindřich Mynarz
2016-06-25 10:34:30 UTC
Permalink
Hi Jean-Marc,

I'm aware of createTypedLiteral, but I don't want to generate typed
literal, but a plain one instead, as I have indicated in my question.

For example, 1000 instead of "1000"^^xsd:integer.

- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
Post by Jean-Marc Vanel
- createTypedLiteral
public static Literal
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Literal.html
createTypedLiteral(String
<
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true
string,
RDFDatatype
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/datatypes/RDFDatatype.html
dType)
Answer a typed literal.
Parameters:string - the string which forms the value of the literaldType
- RDFDatatype of the type literalReturns:a Literal node with that string
as value
- createTypedLiteral
public static Literal
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Literal.html
createTypedLiteral(Object
<
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true
value)
Answer a typed literal.
Parameters:value - a java Object, the default RDFDatatype for that
object will be usedReturns:a Literal node with that value
Post by Jindřich Mynarz
Hi,
can I use Jena to create non-string plain literals, such as integers?
ResourceFactory.createLiteral() (
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/ResourceFactory.html#createPlainLiteral-java.lang.String-
Post by Jindřich Mynarz
)
is available only for strings.
- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
--
Jean-Marc Vanel
Déductions SARL - Consulting, services, training,
Rule-based programming, Semantic Web
http://deductions-software.com/
+33 (0)6 89 16 29 52
Jean-Marc Vanel
2016-06-25 10:42:27 UTC
Permalink
Sorry, now it's clear.

AFAIK internally
1000
and
"1000"^^xsd:integer
are the same.
What you ask is a feature of the Turtle Writer.
You should look for settings of the Turtle Writer, if any.

If Jena does not do it,
look for another tool like rapper, Euler/EYE, etc.
Post by Jindřich Mynarz
Hi Jean-Marc,
I'm aware of createTypedLiteral, but I don't want to generate typed
literal, but a plain one instead, as I have indicated in my question.
For example, 1000 instead of "1000"^^xsd:integer.
- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
On Sat, Jun 25, 2016 at 12:32 PM, Jean-Marc Vanel <
Post by Jean-Marc Vanel
- createTypedLiteral
public static Literal
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Literal.html
Post by Jean-Marc Vanel
createTypedLiteral(String
<
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true
Post by Jean-Marc Vanel
string,
RDFDatatype
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/datatypes/RDFDatatype.html
Post by Jean-Marc Vanel
dType)
Answer a typed literal.
Parameters:string - the string which forms the value of the
literaldType
Post by Jean-Marc Vanel
- RDFDatatype of the type literalReturns:a Literal node with that
string
Post by Jean-Marc Vanel
as value
- createTypedLiteral
public static Literal
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Literal.html
Post by Jean-Marc Vanel
createTypedLiteral(Object
<
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true
Post by Jean-Marc Vanel
value)
Answer a typed literal.
Parameters:value - a java Object, the default RDFDatatype for that
object will be usedReturns:a Literal node with that value
Post by Jindřich Mynarz
Hi,
can I use Jena to create non-string plain literals, such as integers?
ResourceFactory.createLiteral() (
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/ResourceFactory.html#createPlainLiteral-java.lang.String-
Post by Jean-Marc Vanel
Post by Jindřich Mynarz
)
is available only for strings.
- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
--
Jean-Marc Vanel
Déductions SARL - Consulting, services, training,
Rule-based programming, Semantic Web
http://deductions-software.com/
+33 (0)6 89 16 29 52
--
Jean-Marc Vanel
Déductions SARL - Consulting, services, training,
Rule-based programming, Semantic Web
http://deductions-software.com/
+33 (0)6 89 16 29 52
Twitter: @jmvanel , @jmvanel_fr ; chat: irc://irc.freenode.net#eulergui
Andy Seaborne
2016-06-25 14:12:44 UTC
Permalink
Post by Jean-Marc Vanel
Sorry, now it's clear.
AFAIK internally
1000
and
"1000"^^xsd:integer
are the same.
What you ask is a feature of the Turtle Writer.
You should look for settings of the Turtle Writer, if any.
It does that. N-triples does not, nor does RDF/XML.
Post by Jean-Marc Vanel
If Jena does not do it,
look for another tool like rapper, Euler/EYE, etc.
Yes - it's a syntax feature of Turtle that xsd:integer can be written
that way. Same with xsd:decimal (if there is a dot)

xsd:int and other derived types can't - it would loose the detailed type
information.

Jindřich - do you have a detailed example?

Andy
Post by Jean-Marc Vanel
Post by Jindřich Mynarz
Hi Jean-Marc,
I'm aware of createTypedLiteral, but I don't want to generate typed
literal, but a plain one instead, as I have indicated in my question.
For example, 1000 instead of "1000"^^xsd:integer.
- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
On Sat, Jun 25, 2016 at 12:32 PM, Jean-Marc Vanel <
Post by Jean-Marc Vanel
- createTypedLiteral
public static Literal
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Literal.html
Post by Jean-Marc Vanel
createTypedLiteral(String
<
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true
Post by Jean-Marc Vanel
string,
RDFDatatype
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/datatypes/RDFDatatype.html
Post by Jean-Marc Vanel
dType)
Answer a typed literal.
Parameters:string - the string which forms the value of the
literaldType
Post by Jean-Marc Vanel
- RDFDatatype of the type literalReturns:a Literal node with that
string
Post by Jean-Marc Vanel
as value
- createTypedLiteral
public static Literal
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Literal.html
Post by Jean-Marc Vanel
createTypedLiteral(Object
<
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true
Post by Jean-Marc Vanel
value)
Answer a typed literal.
Parameters:value - a java Object, the default RDFDatatype for that
object will be usedReturns:a Literal node with that value
Post by Jindřich Mynarz
Hi,
can I use Jena to create non-string plain literals, such as integers?
ResourceFactory.createLiteral() (
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/ResourceFactory.html#createPlainLiteral-java.lang.String-
Post by Jean-Marc Vanel
Post by Jindřich Mynarz
)
is available only for strings.
- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
--
Jean-Marc Vanel
Déductions SARL - Consulting, services, training,
Rule-based programming, Semantic Web
http://deductions-software.com/
+33 (0)6 89 16 29 52
Jindřich Mynarz
2016-06-25 14:48:56 UTC
Permalink
The serialization context I'm interest in is
org.apache.jena.query.ParameterizedSparqlString (toString():
https://github.com/apache/jena/blob/master/jena-arq/src/main/java/org/apache/jena/query/ParameterizedSparqlString.java#L1291-L1377).
I probably should have clarified that before.

However, I just noticed that if the xsd:integer datatype is provided
explicitly, then it is serialized as a plain literal:

ResourceFactory.createTypedLiteral(1000) => "1000"^^<
http://www.w3.org/2001/XMLSchema#long>
ResourceFactory.createTypedLiteral(1000, XSDDatatype.XSDinteger) => 1000

This solves my issue. Thanks for your comments!

- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
Post by Andy Seaborne
Post by Jean-Marc Vanel
Sorry, now it's clear.
AFAIK internally
1000
and
"1000"^^xsd:integer
are the same.
What you ask is a feature of the Turtle Writer.
You should look for settings of the Turtle Writer, if any.
It does that. N-triples does not, nor does RDF/XML.
Post by Jean-Marc Vanel
If Jena does not do it,
look for another tool like rapper, Euler/EYE, etc.
Yes - it's a syntax feature of Turtle that xsd:integer can be written that
way. Same with xsd:decimal (if there is a dot)
xsd:int and other derived types can't - it would loose the detailed type
information.
Jindřich - do you have a detailed example?
Andy
Post by Jean-Marc Vanel
Hi Jean-Marc,
Post by Jindřich Mynarz
I'm aware of createTypedLiteral, but I don't want to generate typed
literal, but a plain one instead, as I have indicated in my question.
For example, 1000 instead of "1000"^^xsd:integer.
- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
On Sat, Jun 25, 2016 at 12:32 PM, Jean-Marc Vanel <
Post by Jean-Marc Vanel
- createTypedLiteral
public static Literal
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Literal.html
Post by Jean-Marc Vanel
Post by Jean-Marc Vanel
createTypedLiteral(String
<
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true
Post by Jean-Marc Vanel
Post by Jean-Marc Vanel
string,
RDFDatatype
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/datatypes/RDFDatatype.html
Post by Jean-Marc Vanel
Post by Jean-Marc Vanel
dType)
Answer a typed literal.
Parameters:string - the string which forms the value of the
literaldType
Post by Jean-Marc Vanel
- RDFDatatype of the type literalReturns:a Literal node with that
string
Post by Jean-Marc Vanel
as value
- createTypedLiteral
public static Literal
<
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Literal.html
Post by Jean-Marc Vanel
Post by Jean-Marc Vanel
createTypedLiteral(Object
<
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true
Post by Jean-Marc Vanel
Post by Jean-Marc Vanel
value)
Answer a typed literal.
Parameters:value - a java Object, the default RDFDatatype for that
object will be usedReturns:a Literal node with that value
Hi,
Post by Jean-Marc Vanel
can I use Jena to create non-string plain literals, such as integers?
ResourceFactory.createLiteral() (
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/ResourceFactory.html#createPlainLiteral-java.lang.String-
Post by Jean-Marc Vanel
)
Post by Jean-Marc Vanel
is available only for strings.
- Jindřich
--
Jindřich Mynarz
http://mynarz.net/#jindrich
--
Jean-Marc Vanel
Déductions SARL - Consulting, services, training,
Rule-based programming, Semantic Web
http://deductions-software.com/
+33 (0)6 89 16 29 52
Continue reading on narkive:
Loading...