use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalPlacementException in project webanno by webanno.
the class RelationOverlapBehavior method onCreate.
@Override
public CreateRelationAnnotationRequest onCreate(RelationAdapter aAdapter, CreateRelationAnnotationRequest aRequest) throws AnnotationException {
final AnnotationLayer layer = aAdapter.getLayer();
final CAS cas = aRequest.getCas();
final Type type = getType(cas, layer.getName());
final Feature targetFeature = type.getFeatureByBaseName(aAdapter.getTargetFeatureName());
final Feature sourceFeature = type.getFeatureByBaseName(aAdapter.getSourceFeatureName());
switch(layer.getOverlapMode()) {
case ANY_OVERLAP:
return aRequest;
case NO_OVERLAP:
{
boolean hasAnyOverlapping = select(cas, type).stream().filter(rel -> overlapping(aRequest, rel, sourceFeature, targetFeature)).findAny().isPresent();
if (hasAnyOverlapping) {
throw new IllegalPlacementException("Cannot create another annotation of layer [" + layer.getUiName() + "] at this location - no overlap or stacking is allowed for this layer.");
}
break;
}
case OVERLAP_ONLY:
{
boolean hasStacking = select(cas, type).stream().filter(rel -> stacking(aRequest, rel, sourceFeature, targetFeature)).findAny().isPresent();
if (hasStacking) {
throw new IllegalPlacementException("Cannot create another annotation of layer [" + layer.getUiName() + "] at this location - stacking is not allowed for this layer.");
}
break;
}
case STACKING_ONLY:
{
boolean hasOverlapping = select(cas, type).stream().filter(rel -> overlapping(aRequest, rel, sourceFeature, targetFeature) && !stacking(aRequest, rel, sourceFeature, targetFeature)).findAny().isPresent();
if (hasOverlapping) {
throw new IllegalPlacementException("Cannot create another annotation of layer [" + layer.getUiName() + "] at this location - only stacking is allowed for this layer.");
}
break;
}
}
return aRequest;
}
Aggregations