use of nl.knaw.huygens.timbuctoo.rml.ThrowingErrorHandler 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()));
}
use of nl.knaw.huygens.timbuctoo.rml.ThrowingErrorHandler in project timbuctoo by HuygensING.
the class BdbRmlDataSourceStoreTest method itWorks.
@Test
public void itWorks() throws Exception {
BdbNonPersistentEnvironmentCreator dbCreator = new BdbNonPersistentEnvironmentCreator();
DataSetMetaData dataSetMetadata = new BasicDataSetMetaData("userid", "datasetid", "http://timbuctoo.huygens.knaw.nl/v5/userid/datasetid", "http://example.org/prefix/", false, false);
final RmlDataSourceStore rmlDataSourceStore = new BdbRmlDataSourceStore(dbCreator.getDatabase("userid", "datasetid", "rmlSource", true, TupleBinding.getPrimitiveBinding(String.class), TupleBinding.getPrimitiveBinding(String.class), new StringStringIsCleanHandler()), new ImportStatus(new LogList()));
RdfSerializer rdfSerializer = new RmlDataSourceRdfSerializer(rmlDataSourceStore);
RawUploadRdfSaver rawUploadRdfSaver = new RawUploadRdfSaver(dataSetMetadata, "fileName", APPLICATION_OCTET_STREAM_TYPE, rdfSerializer, "origFileName", Clock.systemUTC());
final String inputCol1 = rawUploadRdfSaver.addCollection("collection1");
ImportPropertyDescriptions importPropertyDescriptions = new ImportPropertyDescriptions();
importPropertyDescriptions.getOrCreate(1).setPropertyName("propName1");
importPropertyDescriptions.getOrCreate(2).setPropertyName("propName2");
rawUploadRdfSaver.addPropertyDescriptions(inputCol1, importPropertyDescriptions);
rawUploadRdfSaver.addEntity(inputCol1, ImmutableMap.of("propName1", "value1", "propName2", "val2"));
rawUploadRdfSaver.addEntity(inputCol1, ImmutableMap.of("propName1", "entVal1", "propName2", "entVal2"));
final String inputCol2 = rawUploadRdfSaver.addCollection("collection2");
ImportPropertyDescriptions importPropertyDescriptions1 = new ImportPropertyDescriptions();
importPropertyDescriptions1.getOrCreate(1).setPropertyName("prop3");
importPropertyDescriptions1.getOrCreate(2).setPropertyName("prop4");
rawUploadRdfSaver.addPropertyDescriptions(inputCol2, importPropertyDescriptions1);
rawUploadRdfSaver.addEntity(inputCol2, ImmutableMap.of("prop3", "value1", "prop4", "val2"));
rawUploadRdfSaver.addEntity(inputCol2, ImmutableMap.of("prop3", "entVal1", "prop4", "entVal2"));
rdfSerializer.close();
RdfDataSource rdfDataSource = new RdfDataSource(rmlDataSourceStore, inputCol1, new JexlRowFactory(ImmutableMap.of(), new HashMapBasedJoinHandler()));
RdfDataSource rdfDataSource2 = new RdfDataSource(rmlDataSourceStore, inputCol2, new JexlRowFactory(ImmutableMap.of(), new HashMapBasedJoinHandler()));
final List<String> collection1;
final List<String> collection2;
try (Stream<Row> stream = rdfDataSource.getRows(new ThrowingErrorHandler())) {
collection1 = stream.map(x -> x.getRawValue("propName1") + ":" + x.getRawValue("propName2")).collect(toList());
}
try (Stream<Row> stream = rdfDataSource2.getRows(new ThrowingErrorHandler())) {
collection2 = stream.map(x -> x.getRawValue("prop3") + ":" + x.getRawValue("prop4")).collect(toList());
}
assertThat(collection1, contains("value1:val2", "entVal1:entVal2"));
assertThat(collection2, contains("value1:val2", "entVal1:entVal2"));
dbCreator.close();
}
use of nl.knaw.huygens.timbuctoo.rml.ThrowingErrorHandler 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"))));
}
use of nl.knaw.huygens.timbuctoo.rml.ThrowingErrorHandler 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"))));
}
Aggregations