Search in sources :

Example 1 with NO_OVERLAP

use of de.tudarmstadt.ukp.clarin.webanno.model.OverlapMode.NO_OVERLAP in project webanno by webanno.

the class RelationRendererTest method thatRelationOverlapBehaviorOnRenderGeneratesErrors.

@Test
public void thatRelationOverlapBehaviorOnRenderGeneratesErrors() throws Exception {
    TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class);
    builder.buildTokens(jcas, "This is a test .\nThis is sentence two .");
    for (Token t : select(jcas, Token.class)) {
        POS pos = new POS(jcas, t.getBegin(), t.getEnd());
        t.setPos(pos);
        pos.addToIndexes();
    }
    RelationAdapter adapter = new RelationAdapter(layerSupportRegistry, featureSupportRegistry, null, depLayer, FEAT_REL_TARGET, FEAT_REL_SOURCE, () -> asList(dependencyLayerGovernor, dependencyLayerDependent), behaviors);
    List<POS> posAnnotations = new ArrayList<>(select(jcas, POS.class));
    POS source = posAnnotations.get(0);
    POS target = posAnnotations.get(1);
    RelationRenderer sut = new RelationRenderer(adapter, layerSupportRegistry, featureSupportRegistry, asList(new RelationOverlapBehavior()));
    // Create two annotations stacked annotations
    depLayer.setOverlapMode(ANY_OVERLAP);
    AnnotationFS dep1 = adapter.add(document, username, source, target, jcas.getCas());
    AnnotationFS dep2 = adapter.add(document, username, source, target, jcas.getCas());
    {
        depLayer.setOverlapMode(ANY_OVERLAP);
        VDocument vdoc = new VDocument();
        sut.render(jcas.getCas(), asList(), vdoc, 0, jcas.getDocumentText().length());
        assertThat(vdoc.comments()).filteredOn(c -> !YIELD.equals(c.getCommentType())).isEmpty();
    }
    {
        depLayer.setOverlapMode(STACKING_ONLY);
        VDocument vdoc = new VDocument();
        sut.render(jcas.getCas(), asList(), vdoc, 0, jcas.getDocumentText().length());
        assertThat(vdoc.comments()).filteredOn(c -> !YIELD.equals(c.getCommentType())).isEmpty();
    }
    {
        depLayer.setOverlapMode(OVERLAP_ONLY);
        VDocument vdoc = new VDocument();
        sut.render(jcas.getCas(), asList(), vdoc, 0, jcas.getDocumentText().length());
        assertThat(vdoc.comments()).filteredOn(c -> !YIELD.equals(c.getCommentType())).usingFieldByFieldElementComparator().contains(new VComment(dep1, ERROR, "Stacking is not permitted."), new VComment(dep2, ERROR, "Stacking is not permitted."));
    }
    {
        depLayer.setOverlapMode(NO_OVERLAP);
        VDocument vdoc = new VDocument();
        sut.render(jcas.getCas(), asList(), vdoc, 0, jcas.getDocumentText().length());
        assertThat(vdoc.comments()).filteredOn(c -> !YIELD.equals(c.getCommentType())).usingFieldByFieldElementComparator().contains(new VComment(dep1, ERROR, "Stacking is not permitted."), new VComment(dep2, ERROR, "Stacking is not permitted."));
    }
    // Remove the stacked annotation and introduce one that is purely overlapping
    adapter.delete(document, username, jcas.getCas(), new VID(dep2));
    depLayer.setOverlapMode(ANY_OVERLAP);
    AnnotationFS dep3 = adapter.add(document, username, source, posAnnotations.get(2), jcas.getCas());
    {
        depLayer.setOverlapMode(NO_OVERLAP);
        VDocument vdoc = new VDocument();
        sut.render(jcas.getCas(), asList(), vdoc, 0, jcas.getDocumentText().length());
        assertThat(vdoc.comments()).filteredOn(c -> !YIELD.equals(c.getCommentType())).usingFieldByFieldElementComparator().contains(new VComment(dep1, ERROR, "Overlap is not permitted."), new VComment(dep3, ERROR, "Overlap is not permitted."));
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) FEAT_REL_SOURCE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_SOURCE) FEAT_REL_TARGET(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_TARGET) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RelationLayerBehavior(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationLayerBehavior) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) PROJECT_TYPE_ANNOTATION(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_ANNOTATION) TokenBuilder(org.apache.uima.fit.testing.factory.TokenBuilder) OVERLAP_ONLY(de.tudarmstadt.ukp.clarin.webanno.model.OverlapMode.OVERLAP_ONLY) RelationOverlapBehavior(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationOverlapBehavior) ArrayList(java.util.ArrayList) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Dependency(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency) Arrays.asList(java.util.Arrays.asList) LayerSupportRegistryImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistryImpl) JCasFactory(org.apache.uima.fit.factory.JCasFactory) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) LayerSupportRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistry) SINGLE_TOKEN(de.tudarmstadt.ukp.clarin.webanno.model.AnchoringMode.SINGLE_TOKEN) ANY_OVERLAP(de.tudarmstadt.ukp.clarin.webanno.model.OverlapMode.ANY_OVERLAP) Before(org.junit.Before) JCas(org.apache.uima.jcas.JCas) RelationCrossSentenceBehavior(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationCrossSentenceBehavior) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) NO_OVERLAP(de.tudarmstadt.ukp.clarin.webanno.model.OverlapMode.NO_OVERLAP) RelationAttachmentBehavior(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAttachmentBehavior) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) ERROR(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType.ERROR) YIELD(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType.YIELD) Test(org.junit.Test) RELATION_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE) SPAN_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE) RelationAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAdapter) STACKING_ONLY(de.tudarmstadt.ukp.clarin.webanno.model.OverlapMode.STACKING_ONLY) List(java.util.List) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) JCasUtil.select(org.apache.uima.fit.util.JCasUtil.select) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) FeatureSupportRegistryImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistryImpl) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) FeatureSupportRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry) TokenBuilder(org.apache.uima.fit.testing.factory.TokenBuilder) RelationAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAdapter) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) ArrayList(java.util.ArrayList) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) RelationOverlapBehavior(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationOverlapBehavior) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) Test(org.junit.Test)

Aggregations

FEAT_REL_SOURCE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_SOURCE)1 FEAT_REL_TARGET (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_TARGET)1 PROJECT_TYPE_ANNOTATION (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_ANNOTATION)1 RELATION_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE)1 SPAN_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE)1 RelationAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAdapter)1 RelationAttachmentBehavior (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAttachmentBehavior)1 RelationCrossSentenceBehavior (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationCrossSentenceBehavior)1 RelationLayerBehavior (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationLayerBehavior)1 RelationOverlapBehavior (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationOverlapBehavior)1 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)1 FeatureSupportRegistryImpl (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistryImpl)1 LayerSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistry)1 LayerSupportRegistryImpl (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistryImpl)1 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)1 VComment (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment)1 ERROR (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType.ERROR)1 YIELD (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType.YIELD)1 VDocument (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument)1 SINGLE_TOKEN (de.tudarmstadt.ukp.clarin.webanno.model.AnchoringMode.SINGLE_TOKEN)1