ChainAdapter extends TypeAdapter_ImplBase { public AnnotationFS addSpan(SourceDocument aDocument, String aUsername, CAS aCas, int aBegin, int aEnd) throws AnnotationException { return handle(new CreateSpanAnnotationRequest(aDocument, aUsername, aCas, aBegin, aEnd)); } ChainAdapter(LayerSupportRegistry aLayerSupportRegistry,
            FeatureSupportRegistry aFeatureSupportRegistry,
            ApplicationEventPublisher aEventPublisher, AnnotationLayer aLayer,
            Supplier<Collection<AnnotationFeature>> aFeatures, List<SpanLayerBehavior> aBehaviors); AnnotationFS addSpan(SourceDocument aDocument, String aUsername, CAS aCas, int aBegin,
            int aEnd); AnnotationFS handle(CreateSpanAnnotationRequest aRequest); int addArc(SourceDocument aDocument, String aUsername, CAS aCas,
            AnnotationFS aOriginFs, AnnotationFS aTargetFs); @Override void delete(SourceDocument aDocument, String aUsername, CAS aCas, VID aVid); @Override String getAnnotationTypeName(); String getChainTypeName(); boolean isLinkedListBehavior(); String getLinkNextFeatureName(); String getChainFirstFeatureName(); @Override void initialize(AnnotationSchemaService aSchemaService); @Override List<Pair<LogMessage, AnnotationFS>> validate(CAS aCas); static final String CHAIN; static final String LINK; static final String FEAT_FIRST; static final String FEAT_NEXT; }
@Test public void thatSpanCrossSentenceBehaviorOnCreateThrowsException() { corefLayer.setCrossSentence(false); TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class); builder.buildTokens(jcas, "This is a test .\nThis is sentence two ."); ChainAdapter sut = new ChainAdapter(layerSupportRegistry, featureSupportRegistry, null, corefLayer, () -> asList(), behaviors); assertThatExceptionOfType(MultipleSentenceCoveredException.class) .isThrownBy(() -> sut.addSpan(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 ."); ChainAdapter sut = new ChainAdapter(layerSupportRegistry, featureSupportRegistry, null, corefLayer, () -> asList(), behaviors); corefLayer.setOverlapMode(ANY_OVERLAP); sut.addSpan(document, username, jcas.getCas(), 0, 1); corefLayer.setOverlapMode(NO_OVERLAP); assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> sut.addSpan(document, username, jcas.getCas(), 0, 1)) .withMessageContaining("no overlap or stacking"); corefLayer.setOverlapMode(OVERLAP_ONLY); assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> sut.addSpan(document, username, jcas.getCas(), 0, 1)) .withMessageContaining("stacking is not allowed"); corefLayer.setOverlapMode(STACKING_ONLY); assertThatCode(() -> sut.addSpan(document, username, jcas.getCas(), 0, 1)) .doesNotThrowAnyException(); corefLayer.setOverlapMode(ANY_OVERLAP); assertThatCode(() -> sut.addSpan(document, username, jcas.getCas(), 0, 1)) .doesNotThrowAnyException(); }
@Test public void thatSpanAnchoringAndStackingBehaviorsWorkInConcert() throws AnnotationException { TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class); builder.buildTokens(jcas, "This is a test ."); ChainAdapter sut = new ChainAdapter(layerSupportRegistry, featureSupportRegistry, null, corefLayer, () -> asList(), behaviors); corefLayer.setOverlapMode(ANY_OVERLAP); sut.addSpan(document, username, jcas.getCas(), 0, 4); corefLayer.setOverlapMode(NO_OVERLAP); assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> sut.addSpan(document, username, jcas.getCas(), 0, 1)) .withMessageContaining("no overlap or stacking"); corefLayer.setOverlapMode(OVERLAP_ONLY); assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> sut.addSpan(document, username, jcas.getCas(), 0, 1)) .withMessageContaining("stacking is not allowed"); corefLayer.setOverlapMode(STACKING_ONLY); assertThatCode(() -> sut.addSpan(document, username, jcas.getCas(), 0, 1)) .doesNotThrowAnyException(); corefLayer.setOverlapMode(ANY_OVERLAP); assertThatCode(() -> sut.addSpan(document, username, jcas.getCas(), 0, 1)) .doesNotThrowAnyException(); }