use of com.hp.hpl.jena.graph.impl.LiteralLabel 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
}
use of com.hp.hpl.jena.graph.impl.LiteralLabel in project stanbol by apache.
the class StartsWithAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
Node arg1Node = null;
Node arg2Node = null;
org.apache.stanbol.rules.manager.atoms.EndsWithAtom tmp = (org.apache.stanbol.rules.manager.atoms.EndsWithAtom) ruleAtom;
ExpressionAtom argument = tmp.getArgument();
ExpressionAtom term = tmp.getTerm();
ClauseEntry clauseEntry1 = adapter.adaptTo(argument, Rule.class);
ClauseEntry clauseEntry2 = adapter.adaptTo(term, Rule.class);
List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
if (clauseEntry1 instanceof HigherOrderClauseEntry) {
arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
} else if (clauseEntry1 instanceof NodeClauseEntry) {
arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
if (clauseEntry2 instanceof HigherOrderClauseEntry) {
arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
} else if (clauseEntry2 instanceof NodeClauseEntry) {
Node tmpNode = ((NodeClauseEntry) clauseEntry2).getNode();
LiteralLabel literalLabel = tmpNode.getLiteral();
String lexicalForm = literalLabel.getLexicalForm();
StringBuilder sb = new StringBuilder();
sb.append("^");
sb.append(lexicalForm);
String regex = sb.toString();
arg2Node = Node_RuleVariable.createLiteral(regex);
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
java.util.List<Node> nodes = new ArrayList<Node>();
nodes.add(arg1Node);
nodes.add(arg2Node);
return (T) new Functor("regex", nodes, new BuiltinRegistry());
}
use of com.hp.hpl.jena.graph.impl.LiteralLabel in project stanbol by apache.
the class EndsWithAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
Node arg1Node = null;
Node arg2Node = null;
org.apache.stanbol.rules.manager.atoms.EndsWithAtom tmp = (org.apache.stanbol.rules.manager.atoms.EndsWithAtom) ruleAtom;
ExpressionAtom argument = tmp.getArgument();
ExpressionAtom term = tmp.getTerm();
ClauseEntry clauseEntry1 = adapter.adaptTo(argument, Rule.class);
ClauseEntry clauseEntry2 = adapter.adaptTo(term, Rule.class);
List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
if (clauseEntry1 instanceof HigherOrderClauseEntry) {
arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
} else if (clauseEntry1 instanceof NodeClauseEntry) {
arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
if (clauseEntry2 instanceof HigherOrderClauseEntry) {
arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
} else if (clauseEntry2 instanceof NodeClauseEntry) {
Node tmpNode = ((NodeClauseEntry) clauseEntry2).getNode();
LiteralLabel literalLabel = tmpNode.getLiteral();
String lexicalForm = literalLabel.getLexicalForm();
StringBuilder sb = new StringBuilder();
sb.append(lexicalForm);
sb.append("$");
String regex = sb.toString();
arg2Node = Node_RuleVariable.createLiteral(regex);
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
java.util.List<Node> nodes = new ArrayList<Node>();
nodes.add(arg1Node);
nodes.add(arg2Node);
return (T) new Functor("regex", nodes, BuiltinRegistry.theRegistry);
}
Aggregations