Search in sources :

Example 6 with IllegalPlacementException

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;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) CAS(org.apache.uima.cas.CAS) Feature(org.apache.uima.cas.Feature) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) ArrayList(java.util.ArrayList) Type(org.apache.uima.cas.Type) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) WebAnnoCasUtil.isSame(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.isSame) FeatureStructure(org.apache.uima.cas.FeatureStructure) Collections.emptyList(java.util.Collections.emptyList) WebAnnoConst(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) CasUtil.select(org.apache.uima.fit.util.CasUtil.select) Collection(java.util.Collection) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) ERROR(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType.ERROR) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) OverlapMode(de.tudarmstadt.ukp.clarin.webanno.model.OverlapMode) AnnotationComparator(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.AnnotationComparator) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) IllegalPlacementException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalPlacementException) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) CAS(org.apache.uima.cas.CAS) IllegalPlacementException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalPlacementException) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Feature(org.apache.uima.cas.Feature)

Aggregations

IllegalPlacementException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalPlacementException)6 Type (org.apache.uima.cas.Type)4 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)4 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)3 Feature (org.apache.uima.cas.Feature)3 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)3 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)2 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CAS (org.apache.uima.cas.CAS)2 FeatureStructure (org.apache.uima.cas.FeatureStructure)2 WebAnnoConst (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst)1 SpanAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter)1 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)1 LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)1 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)1 VArc (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc)1 VComment (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment)1