Search in sources :

Example 61 with AnnotationFeature

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

the class MergeCas method addSlotArcAnnotation.

private static void addSlotArcAnnotation(SpanAdapter aAdapter, JCas aJcas, String aFSArcaddress, JCas aClickedJCas, AnnotationFS aClickedFS) throws AnnotationException {
    List<AnnotationFS> merges = MergeCas.getMergeFS(aClickedFS, aJcas).collect(Collectors.toList());
    AnnotationFS targetFs;
    if (merges.size() == 0) {
        throw new AnnotationException("The base annotation do not exist. Please add it first. ");
    }
    AnnotationFS mergeFs = merges.get(0);
    int fiIndex = Integer.parseInt(aFSArcaddress.split("\\.")[1]);
    int liIndex = Integer.parseInt(aFSArcaddress.split("\\.")[2]);
    AnnotationFeature slotFeature = null;
    LinkWithRoleModel linkRole = null;
    int fi = 0;
    f: for (AnnotationFeature feat : aAdapter.listFeatures()) {
        if (MultiValueMode.ARRAY.equals(feat.getMultiValueMode()) && LinkMode.WITH_ROLE.equals(feat.getLinkMode())) {
            List<LinkWithRoleModel> links = aAdapter.getFeatureValue(feat, aClickedFS);
            for (int li = 0; li < links.size(); li++) {
                LinkWithRoleModel link = links.get(li);
                if (fi == fiIndex && li == liIndex) {
                    slotFeature = feat;
                    List<AnnotationFS> targets = checkAndGetTargets(aJcas, aClickedJCas, selectByAddr(aClickedJCas, link.targetAddr));
                    targetFs = targets.get(0);
                    link.targetAddr = getAddr(targetFs);
                    linkRole = link;
                    break f;
                }
            }
        }
        fi++;
    }
    List<LinkWithRoleModel> links = aAdapter.getFeatureValue(slotFeature, mergeFs);
    // 
    LinkWithRoleModel duplicateLink = null;
    for (LinkWithRoleModel lr : links) {
        if (lr.targetAddr == linkRole.targetAddr) {
            duplicateLink = lr;
            break;
        }
    }
    links.add(linkRole);
    links.remove(duplicateLink);
    setFeature(mergeFs, slotFeature, links);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) LinkedList(java.util.LinkedList) List(java.util.List) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 62 with AnnotationFeature

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

the class MergeCas method copySpanAnnotation.

/**
 * Copy this same annotation from the user annotation to the mergeview
 */
private static void copySpanAnnotation(AnnotatorState aState, AnnotationSchemaService aAnnotationService, AnnotationLayer aAnnotationLayer, AnnotationFS aOldFs, JCas aJCas) throws AnnotationException {
    SpanAdapter adapter = (SpanAdapter) aAnnotationService.getAdapter(aAnnotationLayer);
    // Create the annotation - this also takes care of attaching to an annotation if necessary
    int id = adapter.add(aState, aJCas, aOldFs.getBegin(), aOldFs.getEnd());
    List<AnnotationFeature> features = aAnnotationService.listAnnotationFeature(adapter.getLayer());
    // Copy the features
    for (AnnotationFeature feature : features) {
        Type oldType = adapter.getAnnotationType(aOldFs.getCAS());
        Feature oldFeature = oldType.getFeatureByBaseName(feature.getName());
        if (isLinkOrBasicFeatures(aOldFs, oldFeature)) {
            continue;
        }
        Object value = adapter.getFeatureValue(feature, aOldFs);
        adapter.setFeatureValue(aState, aJCas, id, feature, value);
    }
}
Also used : Type(org.apache.uima.cas.Type) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) Feature(org.apache.uima.cas.Feature) WebAnnoCasUtil.setFeature(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 63 with AnnotationFeature

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

the class CopyAnnotationTest method setup.

@Before
public void setup() {
    project = new Project();
    tokenLayer = new AnnotationLayer(Token.class.getName(), "Token", SPAN_TYPE, null, true);
    tokenPosFeature = new AnnotationFeature();
    tokenPosFeature.setName("pos");
    tokenPosFeature.setEnabled(true);
    tokenPosFeature.setType(POS.class.getName());
    tokenPosFeature.setUiName("pos");
    tokenPosFeature.setLayer(tokenLayer);
    tokenPosFeature.setProject(project);
    tokenPosFeature.setVisible(true);
    posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, project, true);
    posLayer.setAttachType(tokenLayer);
    posLayer.setAttachFeature(tokenPosFeature);
    posFeature = new AnnotationFeature();
    posFeature.setName("PosValue");
    posFeature.setEnabled(true);
    posFeature.setType(CAS.TYPE_NAME_STRING);
    posFeature.setUiName("PosValue");
    posFeature.setLayer(posLayer);
    posFeature.setProject(project);
    posFeature.setVisible(true);
    slotLayer = new AnnotationLayer(DiffUtils.HOST_TYPE, DiffUtils.HOST_TYPE, SPAN_TYPE, project, false);
    slotFeature = new AnnotationFeature();
    slotFeature.setName("links");
    slotFeature.setEnabled(true);
    slotFeature.setType(Token.class.getName());
    slotFeature.setLinkMode(LinkMode.WITH_ROLE);
    slotFeature.setUiName("f1");
    slotFeature.setLayer(slotLayer);
    slotFeature.setProject(project);
    slotFeature.setVisible(true);
    stringFeature = new AnnotationFeature();
    stringFeature.setName("f1");
    stringFeature.setEnabled(true);
    stringFeature.setType(CAS.TYPE_NAME_STRING);
    stringFeature.setUiName("f1");
    stringFeature.setLayer(slotLayer);
    stringFeature.setProject(project);
    stringFeature.setVisible(true);
    annotationSchemaService = new MockUp<AnnotationSchemaService>() {

        @Mock
        List<AnnotationFeature> listAnnotationFeature(AnnotationLayer type) {
            if (type.getName().equals(POS.class.getName())) {
                return asList(posFeature);
            }
            if (type.getName().equals(DiffUtils.HOST_TYPE)) {
                return asList(slotFeature, stringFeature);
            }
            throw new IllegalStateException("Unknown layer type: " + type.getName());
        }

        @Mock
        TypeAdapter getAdapter(AnnotationLayer aLayer) {
            return AnnotationSchemaServiceImpl.getAdapter(annotationSchemaService, featureSupportRegistry, null, aLayer);
        }
    }.getMockInstance();
    featureSupportRegistry = new FeatureSupportRegistryImpl(asList(new PrimitiveUimaFeatureSupport(), new SlotFeatureSupport()));
    featureSupportRegistry.init();
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) SlotFeatureSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.SlotFeatureSupport) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) FeatureSupportRegistryImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistryImpl) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) MockUp(mockit.MockUp) PrimitiveUimaFeatureSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.PrimitiveUimaFeatureSupport) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Before(org.junit.Before)

Example 64 with AnnotationFeature

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

the class ProjectLayersPanel method onModelChanged.

@Override
protected void onModelChanged() {
    super.onModelChanged();
    layerSelectionForm.getModelObject().layerSelection = null;
    featureSelectionForm.getModelObject().feature = null;
    layerDetailForm.setModelObject(new AnnotationLayer());
    layerDetailForm.setVisible(false);
    featureSelectionForm.setVisible(false);
    featureDetailForm.setModelObject(new AnnotationFeature());
    featureDetailForm.setVisible(false);
}
Also used : AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 65 with AnnotationFeature

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

the class CasDiff2 method getAdapters.

public static List<DiffAdapter> getAdapters(AnnotationSchemaService annotationService, Project project) {
    List<DiffAdapter> adapters = new ArrayList<>();
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(project)) {
        Set<String> labelFeatures = new LinkedHashSet<>();
        for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
            if (!f.isEnabled()) {
                continue;
            }
            // Link features are treated separately from primitive label features
            if (!LinkMode.NONE.equals(f.getLinkMode())) {
                continue;
            }
            labelFeatures.add(f.getName());
        }
        DiffAdapter_ImplBase adpt;
        switch(layer.getType()) {
            case SPAN_TYPE:
                {
                    adpt = new SpanDiffAdapter(layer.getName(), labelFeatures);
                    break;
                }
            case RELATION_TYPE:
                {
                    ArcAdapter typeAdpt = (ArcAdapter) annotationService.getAdapter(layer);
                    adpt = new ArcDiffAdapter(layer.getName(), typeAdpt.getSourceFeatureName(), typeAdpt.getTargetFeatureName(), labelFeatures);
                    break;
                }
            case CHAIN_TYPE:
                // FIXME Currently, these are ignored.
                continue;
            default:
                throw new IllegalStateException("Unknown layer type [" + layer.getType() + "]");
        }
        adapters.add(adpt);
        for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
            if (!f.isEnabled()) {
                continue;
            }
            switch(f.getLinkMode()) {
                case NONE:
                    // Nothing to do here
                    break;
                case SIMPLE:
                    adpt.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), null);
                    break;
                case WITH_ROLE:
                    adpt.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), f.getLinkTypeTargetFeatureName());
                    break;
                default:
                    throw new IllegalStateException("Unknown link mode [" + f.getLinkMode() + "]");
            }
            labelFeatures.add(f.getName());
        }
    }
    return adapters;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

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