SpanAdapter extends TypeAdapter_ImplBase { public AnnotationFS add(SourceDocument aDocument, String aUsername, CAS aCas, int aBegin, int aEnd) throws AnnotationException { return handle(new CreateSpanAnnotationRequest(aDocument, aUsername, aCas, aBegin, aEnd)); } SpanAdapter(LayerSupportRegistry aLayerSupportRegistry,
            FeatureSupportRegistry aFeatureSupportRegistry,
            ApplicationEventPublisher aEventPublisher, AnnotationLayer aLayer,
            Supplier<Collection<AnnotationFeature>> aFeatures, List<SpanLayerBehavior> aBehaviors); AnnotationFS add(SourceDocument aDocument, String aUsername, CAS aCas, int aBegin,
            int aEnd); AnnotationFS handle(CreateSpanAnnotationRequest aRequest); @Override void delete(SourceDocument aDocument, String aUsername, CAS aCas, VID aVid); @Override List<Pair<LogMessage, AnnotationFS>> validate(CAS aCas);  }
@Test public void thatSpanCrossSentenceBehaviorOnCreateThrowsException() { neLayer.setCrossSentence(false); TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class); builder.buildTokens(jcas, "This is a test .\nThis is sentence two ."); SpanAdapter sut = new SpanAdapter(layerSupportRegistry, featureSupportRegistry, null, neLayer, () -> asList(), behaviors); assertThatExceptionOfType(MultipleSentenceCoveredException.class) .isThrownBy(() -> sut.add(document, username, jcas.getCas(), 0, jcas.getDocumentText().length())) .withMessageContaining("covers multiple sentences"); }
@Test public void thatSpanOverlapBehaviorOnCreateWorks() throws AnnotationException { TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class); builder.buildTokens(jcas, "This is a test ."); SpanAdapter sut = new SpanAdapter(layerSupportRegistry, featureSupportRegistry, null, neLayer, () -> asList(), behaviors); neLayer.setOverlapMode(ANY_OVERLAP); sut.add(document, username, jcas.getCas(), 0, 1); neLayer.setOverlapMode(NO_OVERLAP); assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> sut.add(document, username, jcas.getCas(), 0, 1)) .withMessageContaining("no overlap or stacking"); neLayer.setOverlapMode(OVERLAP_ONLY); assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> sut.add(document, username, jcas.getCas(), 0, 1)) .withMessageContaining("stacking is not allowed"); neLayer.setOverlapMode(STACKING_ONLY); assertThatCode(() -> sut.add(document, username, jcas.getCas(), 0, 1)) .doesNotThrowAnyException(); neLayer.setOverlapMode(ANY_OVERLAP); assertThatCode(() -> sut.add(document, username, jcas.getCas(), 0, 1)) .doesNotThrowAnyException(); }
@Test public void thatSpanAnchoringAndOverlapBehaviorsWorkInConcert() throws AnnotationException { TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class); builder.buildTokens(jcas, "This is a test ."); SpanAdapter sut = new SpanAdapter(layerSupportRegistry, featureSupportRegistry, null, neLayer, () -> asList(), behaviors); neLayer.setOverlapMode(ANY_OVERLAP); sut.add(document, username, jcas.getCas(), 0, 4); neLayer.setOverlapMode(NO_OVERLAP); assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> sut.add(document, username, jcas.getCas(), 0, 1)) .withMessageContaining("no overlap or stacking"); neLayer.setOverlapMode(OVERLAP_ONLY); assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> sut.add(document, username, jcas.getCas(), 0, 1)) .withMessageContaining("stacking is not allowed"); neLayer.setOverlapMode(STACKING_ONLY); assertThatCode(() -> sut.add(document, username, jcas.getCas(), 0, 1)) .doesNotThrowAnyException(); neLayer.setOverlapMode(ANY_OVERLAP); assertThatCode(() -> sut.add(document, username, jcas.getCas(), 0, 1)) .doesNotThrowAnyException(); }