use of nl.knaw.huygens.timbuctoo.rml.rdfshim.RdfResource in project timbuctoo by HuygensING.
the class RdfDataSourceFactory method apply.
public Optional<DataSource> apply(RdfResource rdfResource) {
for (RdfResource resource : rdfResource.out(NS_RML + "source")) {
Set<RdfResource> rawCollection = resource.out("http://timbuctoo.huygens.knaw.nl/mapping#rawCollectionUri");
Set<RdfResource> customFields = resource.out("http://timbuctoo.huygens.knaw.nl/mapping#customField");
Map<String, String> expressions = new HashMap<>();
for (RdfResource customField : customFields) {
Set<RdfResource> fieldNameResource = customField.out("http://timbuctoo.huygens.knaw.nl/mapping#name");
Set<RdfResource> fieldValueResource = customField.out("http://timbuctoo.huygens.knaw.nl/mapping#expression");
fieldNameResource.iterator().next().asLiteral().ifPresent(fieldName -> {
fieldValueResource.iterator().next().asLiteral().ifPresent(fieldValue -> {
expressions.put(fieldName.getValue(), fieldValue.getValue());
});
});
}
if (rawCollection.size() == 1) {
return rawCollection.iterator().next().asIri().map(collectionIri -> new RdfDataSource(rmlDataSourceStore, collectionIri, new JexlRowFactory(expressions, new HashMapBasedJoinHandler())));
}
}
return Optional.empty();
}
use of nl.knaw.huygens.timbuctoo.rml.rdfshim.RdfResource in project timbuctoo by HuygensING.
the class JenaBasedReader method fromRdf.
public RmlMappingDocument fromRdf(Model data, Function<RdfResource, Optional<DataSource>> dataSourceFactory) {
ResIterator tripleMaps = data.listSubjectsWithProperty(data.createProperty(NS_RR + "subjectMap"));
MappingDocumentBuilder resultBuilder = rmlMappingDocument();
try {
while (tripleMaps.hasNext()) {
Resource resource = tripleMaps.nextResource();
buildTripleMap(JenaResource.fromModel(data, resource), resultBuilder.withTripleMap(resource.getURI()));
}
} finally {
tripleMaps.close();
}
return resultBuilder.build(dataSourceFactory);
}
Aggregations