log.warn("Encountered NULL value for field {} and entity {}",
field,source.getId());
} else if(value.isURI()){ //add a reference
source.addReference(field, value.getURI());
} else if(value.isLiteral()){ //add a value or a text depending on the dataType
LiteralLabel ll = value.getLiteral();
// log.debug("LL: lexical {} | value {} | dataType {} | language {}",
// new Object[]{ll.getLexicalForm(),ll.getValue(),ll.getDatatype(),ll.language()});
//if the dataType == null , than we can expect a plain literal
RDFDatatype dataType = ll.getDatatype();
if(dataType != null){ //add a value
Object literalValue;
try {
literalValue = ll.getValue();
if(literalValue instanceof BaseDatatype.TypedValue){
//used for unknown data types
// -> in such cases just use the lexical type
String lexicalValue = ((BaseDatatype.TypedValue)literalValue).lexicalValue;
if(lexicalValue != null && !lexicalValue.isEmpty()){
source.add(field,lexicalValue);
}
} else if(literalValue instanceof XSDDateTime) {
source.add(field, ((XSDDateTime)literalValue).asCalendar().getTime()); //Entityhub uses the time
} else if(literalValue instanceof XSDDuration) {
String duration = literalValue.toString();
if(duration != null && !duration.isEmpty()) {
source.add(field, literalValue.toString());
}
} else if(!ll.getLexicalForm().isEmpty()){
source.add(field, literalValue);
} //else ignore literals that are empty
} catch (DatatypeFormatException e) {
log.warn(" Unable to convert {} to {} -> use lecicalForm",
ll.getLexicalForm(),ll.getDatatype());
literalValue = ll.getLexicalForm();
}
} else { //add a text
String lexicalForm = ll.getLexicalForm();
if(lexicalForm != null && !lexicalForm.isEmpty()){
String language = ll.language();
if(language!=null && language.length()<1){
language = null;
}
source.addNaturalText(field, lexicalForm, language);
} //else ignore empty literals