Skip to content

Commit b11a77e

Browse files
committed
Set default value if not defined (metafacture-core#415)
1 parent 1d34730 commit b11a77e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

metafix/src/main/java/org/metafacture/metafix/FixMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ public void apply(final Metafix metafix, final Record record, final List<String>
535535
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
536536
final Map<String, String> map = getMap(metafix, record, params, options, KIND_OF_RDFMAP);
537537
record.transform(params.get(0), oldValue -> {
538-
final String newValue = map.get(oldValue);
538+
final String newValue = map.getOrDefault(oldValue, defaultValue);
539539
return newValue != null ? newValue : getBoolean(options, "delete") ? null : oldValue;
540540
});
541541
}

metafix/src/test/java/org/metafacture/metafix/MetafixLookupTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ public void shouldPrintUnknownToFileWithoutAppend() throws IOException {
959959
}
960960

961961
@Test
962-
public void shouldLookupInExternalRdfUseDefaultValueIfNotFound() {
962+
public void shouldLookupInExternalRdfUseDefinedDefaultValueIfNotFound() {
963963
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
964964
"lookup_rdf('created', '" + RDF_MAP + "', target: 'created', __default: '0000-01-01')"
965965
),
@@ -976,6 +976,24 @@ public void shouldLookupInExternalRdfUseDefaultValueIfNotFound() {
976976
);
977977
}
978978

979+
@Test
980+
public void shouldLookupInExternalRdfUseDefaultValueIfNotFound() {
981+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
982+
"lookup_rdf('created', '" + RDF_MAP + "', target: 'created')"
983+
),
984+
i -> {
985+
i.startRecord("1");
986+
i.literal("created", "https://w3id.org/kim/hochschulfaechersystematik/n4");
987+
i.endRecord();
988+
},
989+
o -> {
990+
o.get().startRecord("1");
991+
o.get().literal("created", "__default");
992+
o.get().endRecord();
993+
}
994+
);
995+
}
996+
979997
@Test
980998
public void shouldLookupInExternalRdfMapGetObjectOfSubjectWithTargetedPredicate() {
981999
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(

0 commit comments

Comments
 (0)