Search in sources :

Example 1 with RdfResource

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();
}
Also used : HashMap(java.util.HashMap) HashMapBasedJoinHandler(nl.knaw.huygens.timbuctoo.rml.datasource.joinhandlers.HashMapBasedJoinHandler) RdfResource(nl.knaw.huygens.timbuctoo.rml.rdfshim.RdfResource) JexlRowFactory(nl.knaw.huygens.timbuctoo.rml.datasource.jexl.JexlRowFactory)

Example 2 with RdfResource

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);
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) RdfResource(nl.knaw.huygens.timbuctoo.rml.rdfshim.RdfResource) Resource(org.apache.jena.rdf.model.Resource) MappingDocumentBuilder(nl.knaw.huygens.timbuctoo.rml.rmldata.builders.MappingDocumentBuilder)

Aggregations

RdfResource (nl.knaw.huygens.timbuctoo.rml.rdfshim.RdfResource)2 HashMap (java.util.HashMap)1 JexlRowFactory (nl.knaw.huygens.timbuctoo.rml.datasource.jexl.JexlRowFactory)1 HashMapBasedJoinHandler (nl.knaw.huygens.timbuctoo.rml.datasource.joinhandlers.HashMapBasedJoinHandler)1 MappingDocumentBuilder (nl.knaw.huygens.timbuctoo.rml.rmldata.builders.MappingDocumentBuilder)1 ResIterator (org.apache.jena.rdf.model.ResIterator)1 Resource (org.apache.jena.rdf.model.Resource)1