Class SlotPropagator
- java.lang.Object
-
- org.incenp.obofoundry.sssom.slots.SlotPropagator
-
public class SlotPropagator extends Object
A helper class to implement the propagation of slots from the mapping set level to the level of individual mappings and the other way round.Some of the SSSOM metadata slots exist both on the MappingSet class and on the Mapping class. Among them, some represent a different metadata depending on whether they are on the mapping set or on a mapping. For example, the
creator_idslot on a mapping set represents the creators of the entire set, while that same slot on an individual mapping represents the creator of that particular mapping (which may be different from the creators of the set).But there are also metadata slots that are actually intended to represent a common value for all mappings in the set, rather than a value for the set itself. For example, the
mapping_toolslot, when used on a set, indicates the mapping tool used by all mappings in the set. A mapping set that has amapping_toolvalue should be considered as a mapping set in which all mappings have that same value in theirmapping_toolslots.To implement this behaviour, this class defines two operations on a mapping set:
- propagation, in which the value of any “propagatable” slot on the mapping set is explicitly assigned to the corresponding slot in all the mappings of that set;
- condensation, which does the opposite: if all the mappings in a set have the same value for a given ”propagatable” slot, that value is assigned to the corresponding slot on the mapping set.
-
-
Constructor Summary
Constructors Constructor Description SlotPropagator()Creates a new instance using the default propagation policy (always replace).SlotPropagator(PropagationPolicy policy)Creates a new instance with the specified propagation policy.SlotPropagator(PropagationPolicy policy, Version maxVersion)Creates a new instance with the specified propagation policy and highest version.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>condense(MappingSet mappingSet, boolean preserve)Condenses a mapping set, i.e. move slot values from the level of individual mappings up to the mapping set level wherever possible.Set<String>propagate(MappingSet mappingSet)Propagates the values of slots from the mapping set level to the individual mappings.Set<String>propagate(MappingSet mappingSet, boolean preserve)Propagates the values of slots the mapping set level to the individual mappings.voidsetMaxVersion(Version maxVersion)Sets the highest version of the SSSOM specification to use for deciding which slots should be affected by propagation or condensation operations.voidsetStrategy(PropagationPolicy policy)Sets the propagation policy to use.
-
-
-
Constructor Detail
-
SlotPropagator
public SlotPropagator()
Creates a new instance using the default propagation policy (always replace).
-
SlotPropagator
public SlotPropagator(PropagationPolicy policy)
Creates a new instance with the specified propagation policy.- Parameters:
policy- The default propagation policy to use.
-
SlotPropagator
public SlotPropagator(PropagationPolicy policy, Version maxVersion)
Creates a new instance with the specified propagation policy and highest version.- Parameters:
policy- The default propagation policy to use.maxVersion- The default highest version of the SSSOM specification that sets should remain compliant with after propagation or condensation.
-
-
Method Detail
-
setStrategy
public void setStrategy(PropagationPolicy policy)
Sets the propagation policy to use. The new policy will be used in all subsequent calls topropagate(MappingSet)andcondense(MappingSet, boolean).- Parameters:
policy- The new policy to use.
-
setMaxVersion
public void setMaxVersion(Version maxVersion)
Sets the highest version of the SSSOM specification to use for deciding which slots should be affected by propagation or condensation operations.This property allows to deal with the fact that some slots have existed since version 1.0 but have only been added to the MappingSet class (and made propagatable) in version 1.1. If we want to produce a SSSOM 1.0 compliant set, such a slot must not condensed.
- Parameters:
maxVersion- The target SSSOM version.
-
propagate
public Set<String> propagate(MappingSet mappingSet)
Propagates the values of slots from the mapping set level to the individual mappings.- Parameters:
mappingSet- The mapping set whose slot values should be propagated.- Returns:
- A set containing the names of slots that were effectively propagated.
-
propagate
public Set<String> propagate(MappingSet mappingSet, boolean preserve)
Propagates the values of slots the mapping set level to the individual mappings.- Parameters:
mappingSet- The mapping set whose slot values should be propagated.preserve- Iftrue, set-level values will not be removed after propagation.- Returns:
- A set containing the names of slots that were effectively propagated.
-
condense
public Set<String> condense(MappingSet mappingSet, boolean preserve)
Condenses a mapping set, i.e. move slot values from the level of individual mappings up to the mapping set level wherever possible.Note that for this operation, the
PropagationPolicy.ReplaceIfUnsetandPropagationPolicy.NeverReplacepolicies are equivalent. They both lead to a slot not being condensed if the set already has a value for that slot.- Parameters:
mappingSet- The mapping set to condense.preserve- Iftrue, mapping-level values will only be copied to the set, and not removed from the mappings.- Returns:
- A set containing the names of slots whose values were effectively moved (or copied) to the set level.
-
-