Class MappingEditor
- All Implemented Interfaces:
ISimpleSlotVisitor<Mapping,
,Void> IMappingTransformer<Mapping>
There are three ways to specify a change to apply. The simplest one is to use
addSimpleAssign(String, String)
, when the value to assign is static
and therefore fully known at the time the function is called:
// Set a mapping justification editor.addSimpleAssign("mapping_justification", "semapv:ManualMappingCuration");
If the value to assign is to be generated from the mapping the change must be
applied to, then use addDelayedAssign(String, IMappingTransformer)
.
For example, to set the object label to a value derived from the subject
label:
editor.addDelayedAssign("object_label", (mapping) -> String.format("same as %s", mapping -> getSubjectLabel()));
Lastly, use addReplacement(String, String, String)
to change the
value of a slot by searching and replacing a pattern within the original
value:
editor.addReplacement("subject_id", "https://meshb.nlm.nih.gov/record/ui[?]ui=", "http://id.nlm.nih.gov/mesh/");
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with the default SSSOM prefix manager.MappingEditor
(PrefixManager prefixManager) Creates a new instance with the specified prefix manager. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDelayedAssign
(String slotName, IMappingTransformer<String> value) Adds a change to be applied by transformer, when the new value to assign will only be known at the time the change is applied because it may depend on the mapping the change is applied to.void
addReplacement
(String slotName, String pattern, String replacement) Adds a replacement operation to be applied by this transformer.void
addSimpleAssign
(String slotName, String value) Adds a change to be applied by this transformer.Transform a mapping into something else.Visits a SSSOM slot.
-
Constructor Details
-
MappingEditor
public MappingEditor()Creates a new instance with the default SSSOM prefix manager. -
MappingEditor
Creates a new instance with the specified prefix manager. The prefix manager is used to expand short identifiers in arguments toaddSimpleAssign(String, String)
.- Parameters:
prefixManager
- The prefix manager to use.
-
-
Method Details
-
transform
Description copied from interface:IMappingTransformer
Transform a mapping into something else.- Specified by:
transform
in interfaceIMappingTransformer<Mapping>
- Parameters:
mapping
- The mapping to transform.- Returns:
- The object generated from the mapping.
-
visit
Description copied from interface:ISimpleSlotVisitor
Visits a SSSOM slot.- Specified by:
visit
in interfaceISimpleSlotVisitor<Mapping,
Void> - Parameters:
slot
- The slot that is being visited.object
- The object to which the slot is attached.value
- The value of the slot.- Returns:
- Whatever value the visitor wishes to return once the slot has been visited.
-
addSimpleAssign
Adds a change to be applied by this transformer. This is a simple change where the value to assign is already fully known when the method is called: the value does not depend on the mapping the change is applied to.- Parameters:
slotName
- The name of the mapping slot to change.value
- The new value of the slot. May benull
or an empty string to remove an existing value. For multi-value slots, the values must be separated by a|
character.- Throws:
IllegalArgumentException
- IfslotName
is not a valid slot name, or if the value is invalid.
-
addDelayedAssign
Adds a change to be applied by transformer, when the new value to assign will only be known at the time the change is applied because it may depend on the mapping the change is applied to.Of note, because the new value is not known at the time the change is registered, we cannot perform any check on the value. We only check whether the given slot name is a valid one.
- Parameters:
slotName
- The name of the mapping slot to change.value
- The transformer that will derive the new value to assign from a mapping.- Throws:
IllegalArgumentException
- IfslotName
is not a valid slot name.
-
addReplacement
Adds a replacement operation to be applied by this transformer. The new value of the edited slot is computed by finding all occurrences of the specified pattern in the original slot value, and replacing them with the specified replacement value.- Parameters:
slotName
- The name of the mapping slot to change.pattern
- The pattern to replace in the slot's original value.replacement
- The value the pattern should be replaced by.- Throws:
IllegalArgumentException
- IfslotName
is not a valid slot name, if the pattern is not a valid regular expression, or if the slot type is unsupported (only string and list-of-strings slots are supported for now).
-