Search in sources :

Example 1 with QuadPart

use of nl.knaw.huygens.timbuctoo.rml.dto.QuadPart 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();
}
Also used : Triple(org.apache.jena.graph.Triple) AtomicLong(java.util.concurrent.atomic.AtomicLong) TripleImporter(nl.knaw.huygens.timbuctoo.rdf.TripleImporter) LoggingErrorHandler(nl.knaw.huygens.timbuctoo.rml.LoggingErrorHandler) RdfBlankNode(nl.knaw.huygens.timbuctoo.rml.dto.RdfBlankNode) Node(org.apache.jena.graph.Node) BaseDatatype(org.apache.jena.datatypes.BaseDatatype) QuadPart(nl.knaw.huygens.timbuctoo.rml.dto.QuadPart) RdfBlankNode(nl.knaw.huygens.timbuctoo.rml.dto.RdfBlankNode)

Example 2 with QuadPart

use of nl.knaw.huygens.timbuctoo.rml.dto.QuadPart in project timbuctoo by HuygensING.

the class RrTemplateTest method returnsEmptyIfOneValueIsMissing.

@Test
public void returnsEmptyIfOneValueIsMissing() throws Exception {
    TestRow row = new TestRow(ImmutableMap.of("foo", ""), ImmutableMap.of(), new ThrowingErrorHandler());
    RrTemplate rrTemplate = new RrTemplate("{foo} and {bar}", TermType.Literal, XSD_STRING);
    Optional<QuadPart> actual = rrTemplate.generateValue(row);
    assertThat(actual, is(Optional.empty()));
}
Also used : TestRow(nl.knaw.huygens.timbuctoo.rml.TestRow) ThrowingErrorHandler(nl.knaw.huygens.timbuctoo.rml.ThrowingErrorHandler) QuadPart(nl.knaw.huygens.timbuctoo.rml.dto.QuadPart) Test(org.junit.Test)

Example 3 with QuadPart

use of nl.knaw.huygens.timbuctoo.rml.dto.QuadPart in project timbuctoo by HuygensING.

the class RrTemplateTest method iriEncodesValueIfResultTypeIsIri.

@Test
public void iriEncodesValueIfResultTypeIsIri() throws Exception {
    TestRow row = new TestRow(ImmutableMap.of("foo", "some s\"tring with wéird characters"), ImmutableMap.of(), new ThrowingErrorHandler());
    RrTemplate rrTemplate = new RrTemplate("http://{foo}", TermType.IRI, null);
    Optional<QuadPart> actual = rrTemplate.generateValue(row);
    assertThat(actual, is(Optional.of(new RdfUri("http://some%20s%22tring%20with%20w%C3%A9ird%20characters"))));
}
Also used : RdfUri(nl.knaw.huygens.timbuctoo.rml.dto.RdfUri) TestRow(nl.knaw.huygens.timbuctoo.rml.TestRow) ThrowingErrorHandler(nl.knaw.huygens.timbuctoo.rml.ThrowingErrorHandler) QuadPart(nl.knaw.huygens.timbuctoo.rml.dto.QuadPart) Test(org.junit.Test)

Example 4 with QuadPart

use of nl.knaw.huygens.timbuctoo.rml.dto.QuadPart in project timbuctoo by HuygensING.

the class RrTemplateTest method replacesTemplatesWithEmptyStringIfValueIsEmpty.

@Test
public void replacesTemplatesWithEmptyStringIfValueIsEmpty() throws Exception {
    TestRow row = new TestRow(ImmutableMap.of("foo", ""), ImmutableMap.of(), new ThrowingErrorHandler());
    RrTemplate rrTemplate = new RrTemplate("start {foo} end", TermType.Literal, XSD_STRING);
    Optional<QuadPart> actual = rrTemplate.generateValue(row);
    assertThat(actual, is(Optional.of(new RdfValue("start  end", "http://www.w3.org/2001/XMLSchema#string"))));
}
Also used : TestRow(nl.knaw.huygens.timbuctoo.rml.TestRow) ThrowingErrorHandler(nl.knaw.huygens.timbuctoo.rml.ThrowingErrorHandler) RdfValue(nl.knaw.huygens.timbuctoo.rml.dto.RdfValue) QuadPart(nl.knaw.huygens.timbuctoo.rml.dto.QuadPart) Test(org.junit.Test)

Aggregations

QuadPart (nl.knaw.huygens.timbuctoo.rml.dto.QuadPart)4 TestRow (nl.knaw.huygens.timbuctoo.rml.TestRow)3 ThrowingErrorHandler (nl.knaw.huygens.timbuctoo.rml.ThrowingErrorHandler)3 Test (org.junit.Test)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 TripleImporter (nl.knaw.huygens.timbuctoo.rdf.TripleImporter)1 LoggingErrorHandler (nl.knaw.huygens.timbuctoo.rml.LoggingErrorHandler)1 RdfBlankNode (nl.knaw.huygens.timbuctoo.rml.dto.RdfBlankNode)1 RdfUri (nl.knaw.huygens.timbuctoo.rml.dto.RdfUri)1 RdfValue (nl.knaw.huygens.timbuctoo.rml.dto.RdfValue)1 BaseDatatype (org.apache.jena.datatypes.BaseDatatype)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1