On 06/09/18 15:55, DAVID MOLINA ESTRADA wrote:
Hi,

Why the class NodeFactoryExtra (In api jena 3.8.0, 
org.apache.jena.sparql.util.NodeFactoryExtra) converts a int/long into a 
XSDinteger, but XSDint into int. The problem that I have is with the first one. 
In anothers API Jena and Fuseki versions, a int was converted into XSDint, and 
now is a XSDinteger, so some sparql doesn't work.

public static Node intToNode(int integer) {
     return NodeFactory.createLiteral(Integer.toString(integer), 
XSDDatatype.XSDinteger) ;

I can only guess: but maybe because in XSD evaluation, xsd:integer is favoured. Any operation will promote a derived type to a integer before doing anything with it.

Elsewhere, for historical reasons, it might be an xsd:int/long/integer.

Personally, I think it is better to state which datatype you want when creating literals. The mapping java avlue <-> XSD mapping is inevitably imperfect.

}

public static int nodeToInt(Node node) {
     LiteralLabel lit = node.getLiteral() ;

     if ( !XSDDatatype.XSDint.isValidLiteral(lit) )
         return Integer.MIN_VALUE ;
     int i = ((Number)lit.getValue()).intValue() ;
     return i ;

A java int is a signed 32 bit value.

XSDint is being used to test the lexical form represents a value in the range of a java int. (Number#intVaklue is undefined for values out of range.)

       Node n = NodeFactoryExtra.intToNode(5);
       int i = NodeFactoryExtra.nodeToInt(n);
       System.out.println(n);
       System.out.println(i);
==>
"5"^^http://www.w3.org/2001/XMLSchema#integer
5

        Andy




}

Thanks for all
David Molina Estrada
  Software Architect


Evite imprimir este mensaje si no es estrictamente necesario | Eviti imprimir 
aquest missatge si no és estrictament necessari | Avoid printing this message 
if it is not absolutely necessary

Reply via email to