use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class TypeSystemAnalysis method analyzeType.
private void analyzeType(TypeSystem aTS, TypeSystemDescription aTSD, TypeDescription aTD) {
log.trace("Analyzing [{}]", aTD.getName());
Type type = aTS.getType(aTD.getName());
// Skip built-in UIMA types
if (aTD.getName().startsWith("uima.tcas.")) {
log.debug("[{}] is a built-in UIMA type. Skipping.", aTD.getName());
return;
}
// Skip document metadata types
if (aTS.subsumes(aTS.getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION), type)) {
log.debug("[{}] is a document-level annotation. Skipping.", type.getName());
return;
}
// Skip DKPro Core Token and Sentence which as handled specially by WebAnno
if ("de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence".equals(aTD.getName()) || "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token".equals(aTD.getName())) {
log.debug("[{}] is a DKPro Core segmentation type. Skipping.", aTD.getName());
return;
}
Optional<RelationDetails> relationDetails = analyzeRelationLayer(aTS, type);
Optional<ChainDetails> chainDetails = analyzeChainLayer(aTS, type);
boolean isChain = chainDetails.isPresent();
// Layers must be sub-types of Annotation (unless they are chains)
if (!isChain && !aTS.subsumes(aTS.getType(CAS.TYPE_NAME_ANNOTATION), type)) {
log.debug("[{}] is not an annotation type. Skipping.", aTD.getName());
return;
}
// because WebAnno presently does not support DKPro Core elevated types (e.g. NOUN).
if (isElevatedType(aTS, type)) {
log.debug("[{}] looks like an elevated type. Skipping.", aTD.getName());
return;
}
AnnotationLayer layer = new AnnotationLayer();
Optional<? extends LayerDetails> details;
if (isChain) {
details = chainDetails;
layer.setName(removeEnd(aTD.getName(), "Chain"));
layer.setUiName(removeEnd(type.getShortName(), "Chain"));
layer.setType(CHAIN_TYPE);
chainDetailMap.put(layer.getName(), chainDetails.get());
} else if (relationDetails.isPresent()) {
details = relationDetails;
layer.setName(aTD.getName());
layer.setUiName(type.getShortName());
layer.setType(RELATION_TYPE);
relationDetailMap.put(layer.getName(), relationDetails.get());
} else if (isSpanLayer(aTS, type)) {
details = Optional.empty();
layer.setName(aTD.getName());
layer.setUiName(type.getShortName());
layer.setType(SPAN_TYPE);
} else {
log.debug("Unable to determine layer type for [{}]", type.getName());
return;
}
log.debug("[{}] seems to be a {}", aTD.getName(), layer.getType());
layer.setDescription(trimToNull(aTD.getDescription()));
layer.setEnabled(true);
layer.setBuiltIn(false);
// We cannot determine good values for these without looking at actual annotations, thus
// we choose the most relaxed/permissive configuration here.
layer.setAllowStacking(true);
layer.setCrossSentence(true);
layer.setLockToTokenOffset(false);
layer.setMultipleTokens(false);
layer.setLinkedListBehavior(false);
layers.add(layer);
// any features for it - instead we record the features of the link type.
if (CHAIN_TYPE.equals(layer.getType())) {
TypeDescription linkTypeDescription = aTSD.getType(layer.getName() + "Link");
analyzeFeatures(layer, aTS, linkTypeDescription, details);
} else {
analyzeFeatures(layer, aTS, aTD, details);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class TypeSystemAnalysisTest method testSpanWithPrimitiveFeatures.
@Test
public void testSpanWithPrimitiveFeatures() throws Exception {
TypeSystemDescription tsd = createTypeSystemDescription("tsd/spanWithPrimitiveFeatures");
TypeSystemAnalysis analysis = TypeSystemAnalysis.of(tsd);
AnnotationLayer spanLayer = new AnnotationLayer();
spanLayer.setName("webanno.custom.Span");
spanLayer.setUiName("Span");
spanLayer.setType(WebAnnoConst.SPAN_TYPE);
spanLayer.setLockToTokenOffset(false);
spanLayer.setAllowStacking(true);
spanLayer.setCrossSentence(true);
AnnotationFeature stringFeature = new AnnotationFeature("stringFeature", CAS.TYPE_NAME_STRING);
AnnotationFeature intFeature = new AnnotationFeature("intFeature", CAS.TYPE_NAME_INTEGER);
AnnotationFeature booleanFeature = new AnnotationFeature("booleanFeature", CAS.TYPE_NAME_BOOLEAN);
AnnotationFeature floatFeature = new AnnotationFeature("floatFeature", CAS.TYPE_NAME_FLOAT);
SoftAssertions softly = new SoftAssertions();
softly.assertThat(analysis.getLayers()).containsExactly(spanLayer).usingFieldByFieldElementComparator();
softly.assertThat(analysis.getFeatures(spanLayer.getName())).containsExactlyInAnyOrder(stringFeature, intFeature, booleanFeature, floatFeature).usingFieldByFieldElementComparator();
softly.assertAll();
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class TypeSystemAnalysisTest method testSpanWithSlotFeatures.
@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.setLockToTokenOffset(false);
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();
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class TypeSystemAnalysisTest method testChain.
@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.setLockToTokenOffset(false);
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();
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class TypeSystemAnalysisTest method testRelationWithPrimitiveFeatures.
@Test
public void testRelationWithPrimitiveFeatures() throws Exception {
TypeSystemDescription tsd = createTypeSystemDescription("tsd/relationWithPrimitiveFeatures");
TypeSystemAnalysis analysis = TypeSystemAnalysis.of(tsd);
AnnotationLayer relationLayer = new AnnotationLayer();
relationLayer.setName("webanno.custom.Relation");
relationLayer.setUiName("Relation");
relationLayer.setType(WebAnnoConst.RELATION_TYPE);
relationLayer.setLockToTokenOffset(false);
relationLayer.setAllowStacking(true);
relationLayer.setCrossSentence(true);
AnnotationLayer relationTargetLayer = new AnnotationLayer();
relationTargetLayer.setName("webanno.custom.RelationTarget");
relationTargetLayer.setUiName("RelationTarget");
relationTargetLayer.setType(WebAnnoConst.SPAN_TYPE);
relationTargetLayer.setLockToTokenOffset(false);
relationTargetLayer.setAllowStacking(true);
relationTargetLayer.setCrossSentence(true);
AnnotationFeature stringFeature = new AnnotationFeature("stringFeature", CAS.TYPE_NAME_STRING);
AnnotationFeature intFeature = new AnnotationFeature("intFeature", CAS.TYPE_NAME_INTEGER);
AnnotationFeature booleanFeature = new AnnotationFeature("booleanFeature", CAS.TYPE_NAME_BOOLEAN);
AnnotationFeature floatFeature = new AnnotationFeature("floatFeature", CAS.TYPE_NAME_FLOAT);
SoftAssertions softly = new SoftAssertions();
softly.assertThat(analysis.getLayers()).containsExactlyInAnyOrder(relationLayer, relationTargetLayer).usingFieldByFieldElementComparator();
softly.assertThat(analysis.getFeatures(relationLayer.getName())).containsExactlyInAnyOrder(stringFeature, intFeature, booleanFeature, floatFeature).usingFieldByFieldElementComparator();
softly.assertAll();
}
Aggregations