use of nl.knaw.huygens.timbuctoo.rml.dto.RdfBlankNode in project timbuctoo by HuygensING.
the class RmlExecutorService method execute.
public void execute(Consumer<String> statusUpdate) {
transactionEnforcer.execute(timbuctooActions -> {
timbuctooActions.setVrePublishState(vreName, Vre.PublishState.MAPPING_EXECUTION);
timbuctooActions.rdfCleanImportSession(vreName, session -> {
final TripleImporter importer = new TripleImporter(graphWrapper, vreName, session);
// first save the archetype mappings
AtomicLong tripleCount = new AtomicLong(0);
AtomicLong curtime = new AtomicLong(Clock.systemUTC().millis());
// create the links from the collection entities to the archetypes
model.listStatements(null, model.createProperty("http://www.w3.org/2000/01/rdf-schema#subClassOf"), (String) null).forEachRemaining(statement -> {
importer.importTriple(true, new Triple(statement.getSubject().asNode(), statement.getPredicate().asNode(), statement.getObject().asNode()));
reportTripleCount(tripleCount, curtime, statusUpdate);
});
// generate and import rdf
rmlMappingDocument.execute(new LoggingErrorHandler()).forEach((quad) -> {
reportTripleCount(tripleCount, curtime, statusUpdate);
Node object;
final QuadPart sourceObject = quad.getObject();
if (sourceObject.getLiteralLanguage().isPresent()) {
object = createLiteral(sourceObject.getContent(), sourceObject.getLiteralLanguage().get());
} else if (sourceObject.getLiteralType().isPresent()) {
object = createLiteral(sourceObject.getContent(), new BaseDatatype(sourceObject.getLiteralType().get()));
} else if (sourceObject instanceof RdfBlankNode) {
object = NodeFactory.createBlankNode(sourceObject.getContent());
} else {
object = NodeFactory.createURI(sourceObject.getContent());
}
importer.importTriple(true, new Triple(quad.getSubject() instanceof RdfBlankNode ? NodeFactory.createBlankNode(quad.getSubject().getContent()) : NodeFactory.createURI(quad.getSubject().getContent()), NodeFactory.createURI(quad.getPredicate().getContent()), object));
});
reportTripleCount(tripleCount, curtime, statusUpdate);
// Give the collections a proper name
graphWrapper.getGraph().traversal().V().hasLabel(Vre.DATABASE_LABEL).has(Vre.VRE_NAME_PROPERTY_NAME, vreName).out(HAS_COLLECTION_RELATION_NAME).forEachRemaining(v -> {
if (!v.property(COLLECTION_LABEL_PROPERTY_NAME).isPresent()) {
String typeName = v.value(ENTITY_TYPE_NAME_PROPERTY_NAME);
v.property(COLLECTION_LABEL_PROPERTY_NAME, typeName.substring(vreName.length()));
}
});
return commit();
});
return commit();
});
// FIXME naar importSession.close can be done when the Vres are retrieved via TimbuctooActions
vres.reload();
}
use of nl.knaw.huygens.timbuctoo.rml.dto.RdfBlankNode in project timbuctoo by HuygensING.
the class RrTemplate method generateValue.
@Override
public Optional<QuadPart> generateValue(Row input) {
Matcher regexMatcher = pattern.matcher(template);
StringBuffer resultString = new StringBuffer();
while (regexMatcher.find()) {
String value = input.getRawValue(regexMatcher.group(1));
if (value == null) {
return Optional.empty();
} else {
if (termType == TermType.IRI) {
try {
value = URLEncoder.encode(value, "UTF-8").replace("+", "%20");
} catch (UnsupportedEncodingException e) {
LOG.error("Java is being really stoopid and throws an unsupportedEncodingException for UTF-8.");
throw new RuntimeException(e);
}
}
regexMatcher.appendReplacement(resultString, value);
}
}
if (StringUtils.isBlank(resultString.toString())) {
return Optional.empty();
}
regexMatcher.appendTail(resultString);
switch(termType) {
case IRI:
return Optional.of(new RdfUri(resultString.toString()));
case BlankNode:
return Optional.of(new RdfBlankNode(resultString.toString()));
case Literal:
return Optional.of(new RdfValue(resultString.toString(), dataType));
default:
throw new UnsupportedOperationException("Not all items in the Enumerable where handled");
}
}
Aggregations