use of de.tudarmstadt.ukp.clarin.webanno.model.OverlapMode.STACKING_ONLY 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."));
}
}
Aggregations