[
https://issues.apache.org/jira/browse/JENA-1359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16049622#comment-16049622
]
Panagiotis Papadakos edited comment on JENA-1359 at 6/14/17 8:31 PM:
---------------------------------------------------------------------
Here is an example that showcases the problem with decimals. It prints Integer
and Decimal
{code:java}
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix example: <http://www.example.com/#> .
<http://www.example.com/#example> a rdfs:Class .
<http://www.example.com/#ShouldBeDecimal>
a rdf:Property ;
rdfs:domain <http://www.example.com/#instanceof> ;
rdfs:range xsd:decimal .
<http://www.example.com/#test1>
a example:instanceof ;
example:ShouldBeDecimal "12.0"^^xsd:decimal .
<http://www.example.com/#test2>
a example:instanceof ;
example:ShouldBeDecimal "12.1"^^xsd:decimal .
{code}
{code:java}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.jena.example;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.rdf.model.StmtIterator;
import org.apache.jena.riot.RDFDataMgr;
/**
*
* @author papadako
*/
public class Jena1359 {
public static void main(String[] args) {
Model model = RDFDataMgr.loadModel("jena1359.ttl");
StmtIterator iter = model.listStatements();
try {
while (iter.hasNext()) {
Statement stmt = iter.next();
Property prop = stmt.getPredicate();
System.out.println(prop.toString());
if
(prop.toString().equals("http://www.example.com/#ShouldBeDecimal")) {
Literal literal = stmt.getObject().asLiteral();
System.out.println(literal.getValue().getClass());
}
}
} finally {
if (iter != null) {
iter.close();
}
}
}
}
{code}
was (Author: papadako):
Here is an example that show case the problem with decimals. It prints Integer
and Decimal
{code:java}
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix example: <http://www.example.com/#> .
<http://www.example.com/#example> a rdfs:Class .
<http://www.example.com/#ShouldBeDecimal>
a rdf:Property ;
rdfs:domain <http://www.example.com/#instanceof> ;
rdfs:range xsd:decimal .
<http://www.example.com/#test1>
a example:instanceof ;
example:ShouldBeDecimal "12.0"^^xsd:decimal .
<http://www.example.com/#test2>
a example:instanceof ;
example:ShouldBeDecimal "12.1"^^xsd:decimal .
{code}
{code:java}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.jena.example;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.rdf.model.StmtIterator;
import org.apache.jena.riot.RDFDataMgr;
/**
*
* @author papadako
*/
public class Jena1359 {
public static void main(String[] args) {
Model model = RDFDataMgr.loadModel("jena1359.ttl");
StmtIterator iter = model.listStatements();
try {
while (iter.hasNext()) {
Statement stmt = iter.next();
Property prop = stmt.getPredicate();
System.out.println(prop.toString());
if
(prop.toString().equals("http://www.example.com/#ShouldBeDecimal")) {
Literal literal = stmt.getObject().asLiteral();
System.out.println(literal.getValue().getClass());
}
}
} finally {
if (iter != null) {
iter.close();
}
}
}
}
{code}
> Literal.getValue() does not respect the datatype
> -------------------------------------------------
>
> Key: JENA-1359
> URL: https://issues.apache.org/jira/browse/JENA-1359
> Project: Apache Jena
> Issue Type: Bug
> Reporter: Panagiotis Papadakos
>
> I was expecting that the getValue would return a Java object based on the
> datatype of typed literals. This is not the case, since jena will coerce a
> decimal literal with value 12.0 to an Integer with value 12.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)