Esempio n. 1
0
 @Override
 public OWLLiteral getOWLLiteral(String lexicalValue, OWLDatatype datatype) {
   OWLLiteral literal;
   if (datatype.isRDFPlainLiteral()) {
     int sep = lexicalValue.lastIndexOf('@');
     if (sep != -1) {
       String lex = lexicalValue.substring(0, sep);
       String lang = lexicalValue.substring(sep + 1);
       literal = getBasicLiteral(lex, lang, getRDFPlainLiteral());
     } else {
       literal = getBasicLiteral(lexicalValue, datatype);
     }
   } else {
     // check the four special cases
     try {
       if (datatype.isBoolean()) {
         literal = getOWLLiteral(isBooleanTrueValue(lexicalValue.trim()));
       } else if (datatype.isFloat()) {
         if (lexicalValue.trim().equals("-0.0")) {
           // according to some W3C test, this needs to be
           // different from 0.0; Java floats disagree
           if (negativeFloatZero == null) {
             negativeFloatZero = getBasicLiteral("-0.0", XSD_FLOAT);
           }
           literal = negativeFloatZero;
         } else {
           try {
             float f = Float.parseFloat(lexicalValue);
             literal = getOWLLiteral(f);
           } catch (NumberFormatException e) {
             literal = getBasicLiteral(lexicalValue, datatype);
           }
         }
       } else if (datatype.isDouble()) {
         literal = getOWLLiteral(Double.parseDouble(lexicalValue));
       } else if (datatype.isInteger()) {
         // again, some W3C tests require padding zeroes to make
         // literals different
         if (lexicalValue.trim().charAt(0) == '0') {
           literal = getBasicLiteral(lexicalValue, getIntegerOWLDatatype());
         } else {
           try {
             // this is fine for values that can be parsed as
             // ints - not all values are
             literal = getOWLLiteral(Integer.parseInt(lexicalValue));
           } catch (NumberFormatException ex) {
             // try as a big decimal
             literal = getBasicLiteral(lexicalValue, datatype);
           }
         }
       } else {
         literal = getBasicLiteral(lexicalValue, datatype);
       }
     } catch (NumberFormatException e) {
       // some literal is malformed, i.e., wrong format
       literal = getBasicLiteral(lexicalValue, datatype);
     }
   }
   return literal;
 }
 @Override
 public OWLLiteral getOWLLiteral(String lexicalValue, OWLDatatype datatype) {
   OWLLiteral literal = super.getOWLLiteral(lexicalValue, datatype);
   // no caches for booleans, they are singleton in owldatafactory
   if (datatype.isBoolean()) {
     return literal;
   }
   if (literal instanceof OWLLiteralImplFloat) {
     return floatCache.cache(((OWLLiteralImplFloat) literal).parseFloat(), literal);
   }
   if (literal instanceof OWLLiteralImplDouble) {
     return doubleCache.cache(((OWLLiteralImplDouble) literal).parseDouble(), literal);
   }
   if (literal instanceof OWLLiteralImplInteger) {
     return intCache.cache(((OWLLiteralImplInteger) literal).parseInteger(), literal);
   }
   if (datatype.isString()) {
     return stringCache.cache(literal.getLiteral(), literal);
   }
   return litCache.cache(literal);
 }