Search in sources :

Example 1 with RelationCrossSentenceBehavior

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationCrossSentenceBehavior in project webanno by webanno.

the class RelationRendererTest method thatRelationCrossSentenceBehaviorOnRenderGeneratesErrors.

@Test
public void thatRelationCrossSentenceBehaviorOnRenderGeneratesErrors() 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(posAnnotations.size() - 1);
    depLayer.setCrossSentence(true);
    AnnotationFS dep = adapter.add(document, username, source, target, jcas.getCas());
    depLayer.setCrossSentence(false);
    RelationRenderer sut = new RelationRenderer(adapter, layerSupportRegistry, featureSupportRegistry, asList(new RelationCrossSentenceBehavior()));
    VDocument vdoc = new VDocument();
    sut.render(jcas.getCas(), asList(), vdoc, 0, jcas.getDocumentText().length());
    assertThat(vdoc.comments()).usingFieldByFieldElementComparator().contains(new VComment(dep, ERROR, "Crossing sentence boundaries is not permitted."));
}
Also used : TokenBuilder(org.apache.uima.fit.testing.factory.TokenBuilder) RelationAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAdapter) RelationCrossSentenceBehavior(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationCrossSentenceBehavior) 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) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) Test(org.junit.Test)

Example 2 with RelationCrossSentenceBehavior

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationCrossSentenceBehavior in project webanno by webanno.

the class RelationRendererTest method setup.

@Before
public void setup() throws Exception {
    if (jcas == null) {
        jcas = JCasFactory.createJCas();
    } else {
        jcas.reset();
    }
    username = "user";
    project = new Project();
    project.setId(1l);
    project.setMode(PROJECT_TYPE_ANNOTATION);
    document = new SourceDocument();
    document.setId(1l);
    document.setProject(project);
    // Set up annotation schema with POS and Dependency
    AnnotationLayer tokenLayer = new AnnotationLayer(Token.class.getName(), "Token", SPAN_TYPE, project, true, SINGLE_TOKEN, NO_OVERLAP);
    tokenLayer.setId(1l);
    AnnotationFeature tokenLayerPos = new AnnotationFeature(1l, tokenLayer, "pos", POS.class.getName());
    AnnotationLayer posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, project, true, SINGLE_TOKEN, NO_OVERLAP);
    posLayer.setId(2l);
    depLayer = new AnnotationLayer(Dependency.class.getName(), "Dependency", RELATION_TYPE, project, true, SINGLE_TOKEN, OVERLAP_ONLY);
    depLayer.setId(3l);
    depLayer.setAttachType(tokenLayer);
    depLayer.setAttachFeature(tokenLayerPos);
    dependencyLayerGovernor = new AnnotationFeature(2l, depLayer, "Governor", Token.class.getName());
    dependencyLayerDependent = new AnnotationFeature(3l, depLayer, "Dependent", Token.class.getName());
    featureSupportRegistry = new FeatureSupportRegistryImpl(asList());
    layerSupportRegistry = new LayerSupportRegistryImpl(asList());
    behaviors = asList(new RelationAttachmentBehavior(), new RelationOverlapBehavior(), new RelationCrossSentenceBehavior());
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) RelationCrossSentenceBehavior(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationCrossSentenceBehavior) FeatureSupportRegistryImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistryImpl) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) RelationOverlapBehavior(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationOverlapBehavior) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) LayerSupportRegistryImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistryImpl) RelationAttachmentBehavior(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAttachmentBehavior) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Before(org.junit.Before)

Aggregations

RelationCrossSentenceBehavior (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationCrossSentenceBehavior)2 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)2 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)2 RelationAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAdapter)1 RelationAttachmentBehavior (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAttachmentBehavior)1 RelationOverlapBehavior (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationOverlapBehavior)1 FeatureSupportRegistryImpl (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistryImpl)1 LayerSupportRegistryImpl (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistryImpl)1 VComment (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment)1 VDocument (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument)1 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)1 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)1 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)1 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)1 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)1 ArrayList (java.util.ArrayList)1 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)1 TokenBuilder (org.apache.uima.fit.testing.factory.TokenBuilder)1 Before (org.junit.Before)1 Test (org.junit.Test)1