static public ATermAppl makeLiteral(LiteralLabel jenaLiteral) { String lexicalValue = jenaLiteral.getLexicalForm(); String datatypeURI = jenaLiteral.getDatatypeURI(); ATermAppl literalValue = null; if( datatypeURI != null ) literalValue = ATermUtils.makeTypedLiteral( lexicalValue, datatypeURI ); else if( jenaLiteral.language() != null ) literalValue = ATermUtils.makePlainLiteral( lexicalValue, jenaLiteral.language() ); else literalValue = ATermUtils.makePlainLiteral( lexicalValue ); return literalValue; }
/** * Compares two instances of values of the given datatype. * This ignores lang tags and just uses the java.lang.Number * equality. */ @Override public boolean isEqual(LiteralLabel value1, LiteralLabel value2) { return value1.getDatatype() == value2.getDatatype() && Arrays.equals((byte[])value1.getValue(), (byte[])value2.getValue()); // && value1.getLexicalForm().equals(value2.getLexicalForm()); // bug tracking, not real code }
@Override public int getHashCode( LiteralLabel lit ) { // Can't use super.getHashCode as that does "value.hashCode" // Java arrays are not equal by value and their hash code of the sameValue array are different. if ( lit.isWellFormed() ) return getHashCode( (byte []) lit.getValue() ); else return lit.getLexicalForm().hashCode() ; } }
RDFDatatype dataType = ll.getDatatype(); if(dataType != null){ //add a value Object literalValue; try { literalValue = ll.getValue(); if(literalValue instanceof BaseDatatype.TypedValue){ source.add(field, literalValue.toString()); } else if(!ll.getLexicalForm().isEmpty()){ source.add(field, literalValue); ll.getLexicalForm(),ll.getDatatype()); literalValue = ll.getLexicalForm(); String lexicalForm = ll.getLexicalForm(); if(lexicalForm != null && !lexicalForm.isEmpty()){ String language = ll.language(); if(language!=null && language.length()<1){ language = null;
String lex = lit.getLexicalForm() ; RDFDatatype datatype = lit.getDatatype() ; return new NodeValueString(lit.getLexicalForm(), node) ; BigDecimal decimal = new BigDecimal(lit.getLexicalForm()) ; return new NodeValueDecimal(decimal, node) ; float f = ((Number)lit.getValue()).floatValue() ; return new NodeValueFloat(f, node) ; double d = ((Number)lit.getValue()).doubleValue() ; return new NodeValueDouble(d, node) ; XSDDateTime dateTime = (XSDDateTime)lit.getValue() ; return new NodeValueDT(lex, node) ; XSDDateTime dateTime = (XSDDateTime)lit.getValue() ; return new NodeValueDT(lex, node) ; XSDDateTime time = (XSDDateTime)lit.getValue() ; return new NodeValueDT(lex, node) ; XSDDateTime time = (XSDDateTime)lit.getValue() ; return new NodeValueDT(lex, node) ; XSDDateTime time = (XSDDateTime)lit.getValue() ; return new NodeValueDT(lex, node) ;
/** Answer true iff this literal is syntactically equal to <code>other</code>. Note: this is <i>not</i> <code>sameValueAs</code>. */ @Override public boolean equals(Object other) { if ( this == other ) return true ; if (other == null || !(other instanceof LiteralLabel)) { return false; } LiteralLabel otherLiteral = (LiteralLabel) other; boolean typeEqual = (dtype == null ? otherLiteral.getDatatype() == null : dtype.equals(otherLiteral.getDatatype())); boolean langEqual = (dtype == null ? lang.equals(otherLiteral.language()) : true); return typeEqual && langEqual && getLexicalForm().equals(otherLiteral.getLexicalForm()); }
@Override public final String getLiteralLexicalForm() { return getLiteral().getLexicalForm(); }
return new NodeValueString(lit.getLexicalForm(), node) ; long i = ((Number)lit.getValue()).longValue() ; return new NodeValueInteger(i, node) ; BigDecimal decimal = new BigDecimal(lit.getLexicalForm()) ; return new NodeValueDecimal(decimal, node) ; float f = ((Number)lit.getValue()).floatValue() ; return new NodeValueFloat(f, node) ; double d = ((Number)lit.getValue()).doubleValue() ; return new NodeValueDouble(d, node) ; XSDDateTime dateTime = (XSDDateTime)lit.getValue() ; return new NodeValueDateTime(dateTime, node) ; XSDDateTime dateTime = (XSDDateTime)lit.getValue() ; return new NodeValueDate(dateTime, node) ; XSDDateTime time = (XSDDateTime)lit.getValue() ; return new NodeValueTime(time, node) ; XSDDateTime time = (XSDDateTime)lit.getValue() ; return new NodeValueGYear(time, node) ; XSDDateTime time = (XSDDateTime)lit.getValue() ; return new NodeValueGYearMonth(time, node) ;
/** Answer true iff <i>this</i> and <i>other</i> have the same lexical form and [ignoring case] language code. [Note: both typed literals and plain literals have the empty string as language code.] */ private boolean sameByFormAndLanguage( LiteralLabel other ) { String lex1 = getLexicalForm() ; String lex2 = other.getLexicalForm() ; return lex1.equals( lex2 ) && lang.equalsIgnoreCase( other.language() ); }
/** Answer true iff <i>L</i> has type XSD string and we're treating plain literals and xsd string literals as "the same". */ private boolean looksLikePlainString( LiteralLabel L ) { return L.getDatatype().equals( XSDDatatype.XSDstring ) && JenaParameters.enablePlainLiteralSameAsString; }
/** * Test if the given typed value is in the right partition of the XSD type space. * If this test passes then if the typed value has a legal lexical form for * this type then it is a legal instance. */ public boolean isBaseTypeCompatible(LiteralLabel lit) { XSTypeDefinition base = getFoundingType(); RDFDatatype litDT = lit.getDatatype(); if (litDT instanceof XSDDatatype) { XSTypeDefinition litBase = ((XSDDatatype)litDT).getFoundingType(); return base.equals(litBase); } else if (litDT == null && lit.language().equals("")) { // Special RDF case, a plain literal is type compatible with and xsd:string-based type return base.equals(XSDstring.typeDeclaration); } else { return false; } }
/** * Helper function to compare language tag values */ public boolean langTagCompatible(LiteralLabel value1, LiteralLabel value2) { if (value1.language() == null) { return (value2.language() == null || value2.language().equals("")); } else { return value1.language().equalsIgnoreCase(value2.language()); } }
/** * Check if a literal value node is a legal value for the given datatype. * @param val the literal value node * @param dt the Node designating a datatype URI */ public static boolean isTypeOK(Node val, Node dt) { if (!dt.isURI()) return false; if (val.isBlank()) return true; if (val.isLiteral()) { LiteralLabel ll = val.getLiteral(); if (ll.getDatatype() != null && (! ll.isWellFormed())) return false; if (dt.equals(RDFS.Nodes.Literal)) { return true; } else { RDFDatatype dtype = TypeMapper.getInstance().getSafeTypeByName(dt.getURI()); return dtype.isValidLiteral(val.getLiteral()); } } return false; }
@Override public final String getLiteralDatatypeURI() { return getLiteral().getDatatypeURI(); }
if ( !node.getLiteral().isWellFormed() )
RDFDatatype dataType = ll.getDatatype(); if(dataType != null){ //add a value Object literalValue; try { literalValue = ll.getValue(); if(literalValue instanceof BaseDatatype.TypedValue){ source.add(field, literalValue.toString()); } else if(!ll.getLexicalForm().isEmpty()){ source.add(field, literalValue); ll.getLexicalForm(),ll.getDatatype()); literalValue = ll.getLexicalForm(); String lexicalForm = ll.getLexicalForm(); if(lexicalForm != null && !lexicalForm.isEmpty()){ String language = ll.language(); if(language!=null && language.length()<1){ language = null;
/** * Compares two instances of values of the given datatype. * This ignores lang tags and defers to the equality function * defined by the Xerces package - to be checked. */ @Override public boolean isEqual(LiteralLabel value1, LiteralLabel value2) { return typeDeclaration.isEqual(value1.getValue(), value2.getValue()); }
/** * Test whether the given LiteralLabel is a valid instance * of this datatype. This takes into accound typing information * as well as lexical form - for example an xsd:string is * never considered valid as an xsd:integer (even if it is * lexically legal like "1"). */ @Override public boolean isValidLiteral(LiteralLabel lit) { if (isBaseTypeCompatible(lit)) { String lex = lit.getLexicalForm(); if (JenaParameters.enableWhitespaceCheckingOfTypedLiterals) { if (lex.trim().equals(lex)) { return isValid(lit.getLexicalForm()); } else { return false; } } else { return isValid(lit.getLexicalForm()); } } else { return false; } }
/** * Test whether the given LiteralLabel is a valid instance * of this datatype. This takes into accound typing information * as well as lexical form - for example an xsd:string is * never considered valid as an xsd:integer (even if it is * lexically legal like "1"). */ @Override public boolean isValidLiteral(LiteralLabel lit) { // default is that only literals with the same type are valid return equals(lit.getDatatype()); }