Search in sources :

Example 21 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.

the class TypeSystemAnalysis method analyzeFeature.

private AnnotationFeature analyzeFeature(TypeSystem aTS, FeatureDescription aFD, Feature aFeat) {
    AnnotationFeature feat = new AnnotationFeature();
    feat.setType(aFeat.getRange().getName());
    feat.setName(aFeat.getShortName());
    feat.setUiName(aFeat.getShortName());
    feat.setDescription(trimToNull(aFD.getDescription()));
    feat.setEnabled(true);
    if (isSlotFeature(aTS, aFeat)) {
        feat.setType(aFeat.getRange().getComponentType().getFeatureByBaseName("target").getRange().getName());
        feat.setMode(MultiValueMode.ARRAY);
        feat.setLinkMode(LinkMode.WITH_ROLE);
        // Need to strip the "[]" marking the type as multi-valued off the type name
        feat.setLinkTypeName(removeEnd(aFeat.getRange().getName(), "[]"));
        // FIXME Instead of hard-coding the feature names here, try to auto-detect them by
        // looking for a String feature and a feature whose type is subsumed by Annotation
        feat.setLinkTypeRoleFeatureName("role");
        feat.setLinkTypeTargetFeatureName("target");
    }
    return feat;
}
Also used : AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 22 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature 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();
}
Also used : TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) TypeSystemDescriptionFactory.createTypeSystemDescription(org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription) SoftAssertions(org.assertj.core.api.SoftAssertions) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Test(org.junit.Test)

Example 23 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature 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();
}
Also used : TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) TypeSystemDescriptionFactory.createTypeSystemDescription(org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription) SoftAssertions(org.assertj.core.api.SoftAssertions) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Test(org.junit.Test)

Example 24 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature 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();
}
Also used : TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) TypeSystemDescriptionFactory.createTypeSystemDescription(org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription) SoftAssertions(org.assertj.core.api.SoftAssertions) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Test(org.junit.Test)

Example 25 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature 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();
}
Also used : TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) TypeSystemDescriptionFactory.createTypeSystemDescription(org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription) SoftAssertions(org.assertj.core.api.SoftAssertions) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Test(org.junit.Test)

Aggregations

AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)73 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)34 Feature (org.apache.uima.cas.Feature)20 ArrayList (java.util.ArrayList)16 Type (org.apache.uima.cas.Type)16 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)15 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)12 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)11 JCas (org.apache.uima.jcas.JCas)10 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)9 File (java.io.File)9 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)8 LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)6 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)6 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)6 List (java.util.List)6 FeatureStructure (org.apache.uima.cas.FeatureStructure)6 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)5 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)5 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)5