Class MappingEditor
- java.lang.Object
-
- org.incenp.obofoundry.sssom.transform.MappingEditor
-
- All Implemented Interfaces:
ISimpleSlotVisitor<Mapping,Void>,IMappingTransformer<Mapping>
public class MappingEditor extends Object implements IMappingTransformer<Mapping>, ISimpleSlotVisitor<Mapping,Void>
A mapping transformer that applies arbitrary changes to a 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
Constructors Constructor Description MappingEditor()Creates a new instance with the default SSSOM prefix manager.MappingEditor(PrefixManager prefixManager)Creates a new instance with the specified prefix manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDelayedAssign(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.voidaddReplacement(String slotName, String pattern, String replacement)Adds a replacement operation to be applied by this transformer.voidaddSimpleAssign(String slotName, String value)Adds a change to be applied by this transformer.Mappingtransform(Mapping mapping)Transform a mapping into something else.Voidvisit(Slot<Mapping> slot, Mapping object, Object value)Visits a SSSOM slot.
-
-
-
Constructor Detail
-
MappingEditor
public MappingEditor()
Creates a new instance with the default SSSOM prefix manager.
-
MappingEditor
public MappingEditor(PrefixManager prefixManager)
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 Detail
-
transform
public Mapping transform(Mapping mapping)
Description copied from interface:IMappingTransformerTransform a mapping into something else.- Specified by:
transformin interfaceIMappingTransformer<Mapping>- Parameters:
mapping- The mapping to transform.- Returns:
- The object generated from the mapping.
-
visit
public Void visit(Slot<Mapping> slot, Mapping object, Object value)
Description copied from interface:ISimpleSlotVisitorVisits a SSSOM slot.- Specified by:
visitin 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
public void addSimpleAssign(String slotName, String value)
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 benullor an empty string to remove an existing value. For multi-value slots, the values must be separated by a|character.- Throws:
IllegalArgumentException- IfslotNameis not a valid slot name, or if the value is invalid.
-
addDelayedAssign
public void 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.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- IfslotNameis not a valid slot name.
-
addReplacement
public void addReplacement(String slotName, String pattern, String replacement)
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- IfslotNameis 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).
-
-