Open TobiasNx opened 10 months ago
The default key uses two underscores (__default
) and it has to be defined on the map, not the lookup()
call.
put_map("typeMap",
"dog": "mammal",
"parrot": "bird",
"shark": "fish",
__default: "other"
)
okay, then this behaviour is different to catmandu:
lookup("title","dict.csv", default:test) # lookup 'marc' in dict.csv and replace the value or set it to 'test'
and the documentation is incorrect: https://github.com/metafacture/metafacture-fix#lookup
The name difference is a Metamorph relict, the behaviour should be adapted IMO (would be a behaviour change, though).
diff --git metafix/src/main/java/org/metafacture/metafix/FixMethod.java metafix/src/main/java/org/metafacture/metafix/FixMethod.java
index 0b185ca..56de7e9 100644
--- metafix/src/main/java/org/metafacture/metafix/FixMethod.java
+++ metafix/src/main/java/org/metafacture/metafix/FixMethod.java
@@ -516,7 +516,7 @@ public enum FixMethod implements FixFunction { // checkstyle-disable-line ClassD
map = metafix.getMap(mapName);
}
- final String defaultValue = map.get(Maps.DEFAULT_MAP_KEY); // TODO: Catmandu uses 'default'
+ final String defaultValue = options.getOrDefault(Maps.DEFAULT_MAP_KEY, map.get(Maps.DEFAULT_MAP_KEY)); // TODO: Catmandu uses 'default'
final boolean delete = getBoolean(options, "delete");
final boolean printUnknown = getBoolean(options, "print_unknown");
We decided at the Metafacture Meeting to still support the old MORPH way but without promoting it. By this we comply with Catmandus way without creating the confiusing in the documentation that there is an additional "old" way of providing default values.
See example here:
https://metafacture.org/playground/?flux=inputFile%0A%7C+open-file%0A%7C+as-records%0A%7C+decode-yaml%0A%7C+fix%28transformationFile%29%0A%7C+encode-yaml%0A%7C+print%0A%3B%0A&transformation=put_map%28%22typeMap%22%2C%0A++%22dog%22%3A+%22mammal%22%2C%0A++%22parrot%22%3A+%22bird%22%2C%0A++%22shark%22%3A+%22fish%22%0A%29%0A%0Acopy_field%28%22animal%22%2C%22type%22%29%0A%0Alookup%28%22type%22%2C%22typeMap%22%2C+_default%3A%22other%22%29%0A&data=---%0Aanimal%3A+dog%0A%0A---%0Aanimal%3A+parrot%0A%0A%0A---%0Aanimal%3A+shark%0A%0A---%0Aanimal%3A+crab