use of com.hp.hpl.jena.datatypes.xsd.XSDDateTime in project stanbol by apache.
the class AbstractTdbBackend method timeValue.
@Override
public Date timeValue(Node node) {
if (node.isLiteral()) {
Object value = node.getLiteral().getValue();
try {
if (value instanceof XSDDateTime) {
Calendar cal = ((XSDDateTime) value).asCalendar();
//we need only the time
cal.set(1900, 0, 1);
return cal.getTime();
}
} catch (RuntimeException e) {
/*ignore*/
}
return super.timeValue(node);
} else {
throw new IllegalArgumentException("parsed node is not an Literal");
}
}
use of com.hp.hpl.jena.datatypes.xsd.XSDDateTime in project stanbol by apache.
the class RdfIndexingSource method processValue.
/**
* Processes a {@link Node} and adds the according value to the parsed
* Representation.
* @param value The node to convert to an value for the Representation
* @param source the representation (MUST NOT be <code>null</code>
* @param field the field (MUST NOT be <code>null</code>)
*/
private void processValue(Node value, Representation source, String field) {
if (value == null) {
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) {
//Entityhub uses the time
source.add(field, ((XSDDateTime) literalValue).asCalendar().getTime());
} 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
}
// "" is parsed if there is no language
} else if (value.isBlank()) {
if (bnodePrefix != null) {
//STANBOL-765: convert Bnodes to URIs
StringBuilder sb = new StringBuilder(bnodePrefix);
sb.append(value.getBlankNodeId().getLabelString());
source.addReference(field, sb.toString());
} else {
logIgnoredBnode(log, source, field, value);
}
} else {
log.warn("ignoreing value {} for field {} and RDFTerm {} because it is of an unsupported type!", new Object[] { value, field, source.getId() });
}
//end different value node type
}
Aggregations