@Override public ChainAdapter createAdapter(AnnotationLayer aLayer) { ChainAdapter adapter = new ChainAdapter(featureSupportRegistry, eventPublisher, aLayer, schemaService.listAnnotationFeature(aLayer), layerBehaviorsRegistry.getLayerBehaviors(this, SpanLayerBehavior.class)); return adapter; }
@Override public ChainAdapter createAdapter(AnnotationLayer aLayer) { ChainAdapter adapter = new ChainAdapter(featureSupportRegistry, eventPublisher, aLayer, schemaService.listAnnotationFeature(aLayer), layerBehaviorsRegistry.getLayerBehaviors(this, SpanLayerBehavior.class)); return adapter; }
@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(featureSupportRegistry, null, corefLayer, asList(), behaviors); assertThatExceptionOfType(MultipleSentenceCoveredException.class) .isThrownBy(() -> sut.addSpan(document, username, jcas, 0, jcas.getDocumentText().length())) .withMessageContaining("covers multiple sentences"); }
@Test public void thatSpanStackingBehaviorOnCreateThrowsException() throws AnnotationException { TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class); builder.buildTokens(jcas, "This is a test ."); ChainAdapter sut = new ChainAdapter(featureSupportRegistry, null, corefLayer, asList(), behaviors); // First time should work sut.addSpan(document, username, jcas, 0, 1); // Second time not assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> sut.addSpan(document, username, jcas, 0, 1)) .withMessageContaining("stacking is not enabled"); }
@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(featureSupportRegistry, null, corefLayer, asList(), behaviors); // First time should work - we annotate the whole word "This" sut.addSpan(document, username, jcas, 0, 4); // Second time not - here we annotate "T" but it should be expanded to "This" assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> sut.addSpan(document, username, jcas, 0, 1)) .withMessageContaining("stacking is not enabled"); } }