@Override public void configure(Project aProject) throws IOException { TagSet corefTypeTagSet = JsonImportUtil.importTagSetFromJson(aProject, new ClassPathResource("/tagsets/de-coref-type-bart.json").getInputStream(), annotationSchemaService); TagSet corefRelTagSet = JsonImportUtil.importTagSetFromJson(aProject, new ClassPathResource("/tagsets/de-coref-rel-tuebadz.json").getInputStream(), annotationSchemaService); AnnotationLayer base = new AnnotationLayer( "de.tudarmstadt.ukp.dkpro.core.api.coref.type.Coreference", "Coreference", CHAIN_TYPE, aProject, true, AnchoringMode.TOKENS); base.setCrossSentence(true); base.setAllowStacking(true); annotationSchemaService.createLayer(base); annotationSchemaService.createFeature(new AnnotationFeature(aProject, base, "referenceType", "referenceType", CAS.TYPE_NAME_STRING, "Coreference type", corefTypeTagSet)); annotationSchemaService.createFeature( new AnnotationFeature(aProject, base, "referenceRelation", "referenceRelation", CAS.TYPE_NAME_STRING, "Coreference relation", corefRelTagSet)); } }
private AnnotationLayer createCorefLayer(Project aProject, TagSet aCorefTypeTags, TagSet aCorefRelTags) throws IOException { AnnotationLayer base = new AnnotationLayer( "de.tudarmstadt.ukp.dkpro.core.api.coref.type.Coreference", "Coreference", CHAIN_TYPE, aProject, true, AnchoringMode.TOKENS); base.setCrossSentence(true); base.setAllowStacking(true); annotationSchemaService.createLayer(base); annotationSchemaService.createFeature(new AnnotationFeature(aProject, base, "referenceType", "referenceType", CAS.TYPE_NAME_STRING, "Coreference type", aCorefTypeTags)); annotationSchemaService.createFeature( new AnnotationFeature(aProject, base, "referenceRelation", "referenceRelation", CAS.TYPE_NAME_STRING, "Coreference relation", aCorefRelTags)); return base; }
@Override public void configure(Project aProject) throws IOException { TagSet corefTypeTagSet = JsonImportUtil.importTagSetFromJson(aProject, new ClassPathResource("/tagsets/de-coref-type-bart.json").getInputStream(), annotationSchemaService); TagSet corefRelTagSet = JsonImportUtil.importTagSetFromJson(aProject, new ClassPathResource("/tagsets/de-coref-rel-tuebadz.json").getInputStream(), annotationSchemaService); AnnotationLayer base = new AnnotationLayer( "de.tudarmstadt.ukp.dkpro.core.api.coref.type.Coreference", "Coreference", CHAIN_TYPE, aProject, true, AnchoringMode.TOKENS); base.setCrossSentence(true); base.setAllowStacking(true); annotationSchemaService.createLayer(base); annotationSchemaService.createFeature(new AnnotationFeature(aProject, base, "referenceType", "referenceType", CAS.TYPE_NAME_STRING, "Coreference type", corefTypeTagSet)); annotationSchemaService.createFeature( new AnnotationFeature(aProject, base, "referenceRelation", "referenceRelation", CAS.TYPE_NAME_STRING, "Coreference relation", corefRelTagSet)); } }
private AnnotationLayer createCorefLayer(Project aProject, TagSet aCorefTypeTags, TagSet aCorefRelTags) throws IOException { AnnotationLayer base = new AnnotationLayer( "de.tudarmstadt.ukp.dkpro.core.api.coref.type.Coreference", "Coreference", CHAIN_TYPE, aProject, true, AnchoringMode.TOKENS); base.setCrossSentence(true); base.setAllowStacking(true); annotationSchemaService.createLayer(base); annotationSchemaService.createFeature(new AnnotationFeature(aProject, base, "referenceType", "referenceType", CAS.TYPE_NAME_STRING, "Coreference type", aCorefTypeTags)); annotationSchemaService.createFeature( new AnnotationFeature(aProject, base, "referenceRelation", "referenceRelation", CAS.TYPE_NAME_STRING, "Coreference relation", aCorefRelTags)); return base; }
@Test public void thatRelationCrossSentenceBehaviorOnValidateGeneratesErrors() 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 sut = new RelationAdapter(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); sut.add(document, username, source, target, jcas, 0, jcas.getDocumentText().length()); depLayer.setCrossSentence(false); assertThat(sut.validate(jcas)) .extracting(Pair::getLeft) .usingElementComparatorIgnoringFields("source", "message") .containsExactly(LogMessage.error(null, "")); }
@Test public void thatSpanCrossSentenceBehaviorOnValidateReturnsErrorMessage() throws AnnotationException { 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(featureSupportRegistry, null, neLayer, asList(), behaviors); // Add two annotations neLayer.setCrossSentence(true); sut.add(document, username, jcas, 0, jcas.getDocumentText().length()); //Validation fails neLayer.setCrossSentence(false); assertThat(sut.validate(jcas)) .extracting(Pair::getLeft) .usingElementComparatorIgnoringFields("source", "message") .containsExactly(LogMessage.error(null, "")); }
@Test public void thatRelationCrossSentenceBehaviorOnCreateThrowsException() throws Exception { depLayer.setCrossSentence(false); 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 sut = new RelationAdapter(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); assertThatExceptionOfType(MultipleSentenceCoveredException.class) .isThrownBy(() -> sut.add(document, username, source, target, jcas, 0, jcas.getDocumentText().length())) .withMessageContaining("multiple sentences"); }
POS target = posAnnotations.get(posAnnotations.size() - 1); depLayer.setCrossSentence(true); AnnotationFS dep = adapter.add(document, username, source, target, jcas, 0, jcas.getDocumentText().length()); depLayer.setCrossSentence(false); RelationRenderer sut = new RelationRenderer(adapter, featureSupportRegistry, asList(new RelationCrossSentenceBehavior()));
@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(featureSupportRegistry, null, neLayer, asList(), behaviors); assertThatExceptionOfType(MultipleSentenceCoveredException.class) .isThrownBy(() -> sut.add(document, username, jcas, 0, jcas.getDocumentText().length())) .withMessageContaining("covers multiple sentences"); }
@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 thatSpanCrossSentenceBehaviorOnRenderGeneratesErrors() { neLayer.setCrossSentence(false); jcas.setDocumentText(StringUtils.repeat("a", 20)); new Sentence(jcas, 0, 10).addToIndexes(); new Sentence(jcas, 10, 20).addToIndexes(); NamedEntity ne = new NamedEntity(jcas, 5, 15); ne.addToIndexes(); SpanAdapter adapter = new SpanAdapter(featureSupportRegistry, null, neLayer, asList(), asList(new SpanCrossSentenceBehavior())); SpanRenderer sut = new SpanRenderer(adapter, featureSupportRegistry, asList(new SpanCrossSentenceBehavior())); VDocument vdoc = new VDocument(); sut.render(jcas, asList(), vdoc, 0, jcas.getDocumentText().length()); assertThat(vdoc.comments()) .usingFieldByFieldElementComparator() .containsExactlyInAnyOrder(new VComment(ne, VCommentType.ERROR, "Crossing sentence bounardies is not permitted.")); }
@Override public void configure(Project aProject) throws IOException { AnnotationLayer factLayer = new AnnotationLayer(FactLinkingConstants.FACT_LAYER, "Fact", SPAN_TYPE, aProject, false, AnchoringMode.TOKENS); factLayer.setAllowStacking(true); factLayer.setCrossSentence(false); annotationSchemaService.createFeature( new AnnotationFeature(aProject, factLayer, "predicate", "1) Predicate", PropertyFeatureSupport.PREFIX, "Predicate of a fact", null)); AnnotationFeature subjectFeature = createLinkedFeature("subject", "2) Subject", "The subject of a fact.", FactLinkingConstants.SUBJECT_LINK, factLayer, aProject); annotationSchemaService.createFeature(subjectFeature); annotationSchemaService.createLayer(factLayer); AnnotationFeature objectFeature = createLinkedFeature("object", "3) Object", "The object of a fact.", FactLinkingConstants.OBJECT_LINK, factLayer, aProject); annotationSchemaService.createFeature(objectFeature); annotationSchemaService.createLayer(factLayer); AnnotationFeature qualifierFeature = createLinkedFeature("qualifiers", "4) Qualifiers", "The qualifier of a fact.", FactLinkingConstants.QUALIFIER_LINK, factLayer, aProject); annotationSchemaService.createFeature(qualifierFeature); annotationSchemaService.createLayer(factLayer); }
@Override public void configure(Project aProject) throws IOException { AnnotationLayer factLayer = new AnnotationLayer(FactLinkingConstants.FACT_LAYER, "Fact", SPAN_TYPE, aProject, false, AnchoringMode.TOKENS); factLayer.setAllowStacking(true); factLayer.setCrossSentence(false); annotationSchemaService.createFeature( new AnnotationFeature(aProject, factLayer, "predicate", "1) Predicate", PropertyFeatureSupport.PREFIX, "Predicate of a fact", null)); AnnotationFeature subjectFeature = createLinkedFeature("subject", "2) Subject", "The subject of a fact.", FactLinkingConstants.SUBJECT_LINK, factLayer, aProject); annotationSchemaService.createFeature(subjectFeature); annotationSchemaService.createLayer(factLayer); AnnotationFeature objectFeature = createLinkedFeature("object", "3) Object", "The object of a fact.", FactLinkingConstants.OBJECT_LINK, factLayer, aProject); annotationSchemaService.createFeature(objectFeature); annotationSchemaService.createLayer(factLayer); AnnotationFeature qualifierFeature = createLinkedFeature("qualifiers", "4) Qualifiers", "The qualifier of a fact.", FactLinkingConstants.QUALIFIER_LINK, factLayer, aProject); annotationSchemaService.createFeature(qualifierFeature); annotationSchemaService.createLayer(factLayer); }
@Deprecated public static void setLayer(AnnotationSchemaService aAnnotationService, AnnotationLayer aLayer, ExportedAnnotationLayer aExLayer, Project aProject, User aUser) throws IOException { aLayer.setAllowStacking(aExLayer.isAllowStacking()); aLayer.setBuiltIn(aExLayer.isBuiltIn()); aLayer.setReadonly(aExLayer.isReadonly()); aLayer.setCrossSentence(aExLayer.isCrossSentence()); aLayer.setDescription(aExLayer.getDescription()); aLayer.setEnabled(aExLayer.isEnabled()); if (aExLayer.getAnchoringMode() == null) { // This allows importing old projects which did not have the anchoring mode yet aLayer.setAnchoringMode(aExLayer.isLockToTokenOffset(), aExLayer.isMultipleTokens()); } else { aLayer.setAnchoringMode(aExLayer.getAnchoringMode()); } aLayer.setLinkedListBehavior(aExLayer.isLinkedListBehavior()); aLayer.setUiName(aExLayer.getUiName()); aLayer.setName(aExLayer.getName()); aLayer.setProject(aProject); aLayer.setType(aExLayer.getType()); aAnnotationService.createLayer(aLayer); }
public static void setLayer(AnnotationService aAnnotationService, AnnotationLayer aLayer, de.tudarmstadt.ukp.clarin.webanno.model.export.AnnotationLayer aExLayer, Project aProject, User aUser) throws IOException { aLayer.setAllowStacking(aExLayer.isAllowStacking()); aLayer.setBuiltIn(aExLayer.isBuiltIn()); aLayer.setCrossSentence(aExLayer.isCrossSentence()); aLayer.setDescription(aExLayer.getDescription()); aLayer.setEnabled(aExLayer.isEnabled()); aLayer.setLockToTokenOffset(aExLayer.isLockToTokenOffset()); aLayer.setMultipleTokens(aExLayer.isMultipleTokens()); aLayer.setLinkedListBehavior(aExLayer.isLinkedListBehavior()); aLayer.setUiName(aExLayer.getUiName()); aLayer.setName(aExLayer.getName()); aLayer.setProject(aProject); aLayer.setType(aExLayer.getType()); aAnnotationService.createLayer(aLayer, aUser); }
@Deprecated public static void setLayer(AnnotationSchemaService aAnnotationService, AnnotationLayer aLayer, ExportedAnnotationLayer aExLayer, Project aProject, User aUser) throws IOException { aLayer.setAllowStacking(aExLayer.isAllowStacking()); aLayer.setBuiltIn(aExLayer.isBuiltIn()); aLayer.setReadonly(aExLayer.isReadonly()); aLayer.setCrossSentence(aExLayer.isCrossSentence()); aLayer.setDescription(aExLayer.getDescription()); aLayer.setEnabled(aExLayer.isEnabled()); if (aExLayer.getAnchoringMode() == null) { // This allows importing old projects which did not have the anchoring mode yet aLayer.setAnchoringMode(aExLayer.isLockToTokenOffset(), aExLayer.isMultipleTokens()); } else { aLayer.setAnchoringMode(aExLayer.getAnchoringMode()); } aLayer.setValidationMode(aExLayer.getValidationMode() != null ? aExLayer.getValidationMode() : ValidationMode.NEVER); aLayer.setLinkedListBehavior(aExLayer.isLinkedListBehavior()); aLayer.setUiName(aExLayer.getUiName()); aLayer.setName(aExLayer.getName()); aLayer.setProject(aProject); aLayer.setType(aExLayer.getType()); aAnnotationService.createLayer(aLayer); }
public void importLayer(AnnotationLayer aLayer, ExportedAnnotationLayer aExLayer, Project aProject) throws IOException { aLayer.setAllowStacking(aExLayer.isAllowStacking()); aLayer.setBuiltIn(aExLayer.isBuiltIn()); aLayer.setReadonly(aExLayer.isReadonly()); aLayer.setCrossSentence(aExLayer.isCrossSentence()); aLayer.setDescription(aExLayer.getDescription()); aLayer.setEnabled(aExLayer.isEnabled()); if (aExLayer.getAnchoringMode() == null) { // This allows importing old projects which did not have the anchoring mode yet aLayer.setAnchoringMode(aExLayer.isLockToTokenOffset(), aExLayer.isMultipleTokens()); } else { aLayer.setAnchoringMode(aExLayer.getAnchoringMode()); } aLayer.setLinkedListBehavior(aExLayer.isLinkedListBehavior()); aLayer.setUiName(aExLayer.getUiName()); aLayer.setName(aExLayer.getName()); aLayer.setProject(aProject); aLayer.setType(aExLayer.getType()); annotationService.createLayer(aLayer); }
public void importLayer(AnnotationLayer aLayer, ExportedAnnotationLayer aExLayer, Project aProject) throws IOException { aLayer.setAllowStacking(aExLayer.isAllowStacking()); aLayer.setBuiltIn(aExLayer.isBuiltIn()); aLayer.setReadonly(aExLayer.isReadonly()); aLayer.setCrossSentence(aExLayer.isCrossSentence()); aLayer.setDescription(aExLayer.getDescription()); aLayer.setEnabled(aExLayer.isEnabled()); if (aExLayer.getAnchoringMode() == null) { // This allows importing old projects which did not have the anchoring mode yet aLayer.setAnchoringMode(aExLayer.isLockToTokenOffset(), aExLayer.isMultipleTokens()); } else { aLayer.setAnchoringMode(aExLayer.getAnchoringMode()); } aLayer.setValidationMode(aExLayer.getValidationMode() != null ? aExLayer.getValidationMode() : ValidationMode.NEVER); aLayer.setLinkedListBehavior(aExLayer.isLinkedListBehavior()); aLayer.setUiName(aExLayer.getUiName()); aLayer.setName(aExLayer.getName()); aLayer.setProject(aProject); aLayer.setType(aExLayer.getType()); annotationService.createLayer(aLayer); }
@Test public void testSpanWithSlotFeatures() throws Exception { TypeSystemDescription tsd = createTypeSystemDescription("tsd/spanWithSlotFeatures"); TypeSystemAnalysis analysis = TypeSystemAnalysis.of(tsd); AnnotationLayer slotSpanLayer = new AnnotationLayer(); slotSpanLayer.setName("webanno.custom.SlotSpan"); slotSpanLayer.setUiName("SlotSpan"); slotSpanLayer.setType(WebAnnoConst.SPAN_TYPE); slotSpanLayer.setAnchoringMode(AnchoringMode.CHARACTERS); slotSpanLayer.setAllowStacking(true); slotSpanLayer.setCrossSentence(true); AnnotationFeature freeSlot = new AnnotationFeature( "freeSlot", CAS.TYPE_NAME_ANNOTATION); AnnotationFeature boundSlot = new AnnotationFeature( "boundSlot", "webanno.custom.SlotSpan"); SoftAssertions softly = new SoftAssertions(); softly.assertThat(analysis.getLayers()) .containsExactly(slotSpanLayer) .usingFieldByFieldElementComparator(); softly.assertThat(analysis.getFeatures(slotSpanLayer.getName())) .containsExactlyInAnyOrder(freeSlot, boundSlot) .usingFieldByFieldElementComparator(); softly.assertAll(); }
@Test public void testChain() throws Exception { TypeSystemDescription tsd = createTypeSystemDescription( "tsd/chain"); TypeSystemAnalysis analysis = TypeSystemAnalysis.of(tsd); AnnotationLayer chainLayer = new AnnotationLayer(); chainLayer.setName("webanno.custom.Chain"); chainLayer.setUiName("Chain"); chainLayer.setType(WebAnnoConst.CHAIN_TYPE); chainLayer.setAnchoringMode(AnchoringMode.CHARACTERS); chainLayer.setAllowStacking(true); chainLayer.setCrossSentence(true); AnnotationFeature referenceRelationFeature = new AnnotationFeature( "referenceRelation", CAS.TYPE_NAME_STRING); AnnotationFeature referenceTypeFeature = new AnnotationFeature( "referenceType", CAS.TYPE_NAME_STRING); SoftAssertions softly = new SoftAssertions(); softly.assertThat(analysis.getLayers()) .containsExactlyInAnyOrder(chainLayer) .usingFieldByFieldElementComparator(); softly.assertThat(analysis.getFeatures(chainLayer.getName())) .containsExactlyInAnyOrder(referenceRelationFeature, referenceTypeFeature) .usingFieldByFieldElementComparator(); softly.assertAll(); }