Search in sources :

Example 31 with Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class AutomationPage method createDetailEditor.

private AnnotationDetailEditorPanel createDetailEditor() {
    return new AnnotationDetailEditorPanel("annotationDetailEditorPanel", getModel()) {

        private static final long serialVersionUID = 2857345299480098279L;

        @Override
        protected void onChange(AjaxRequestTarget aTarget) {
            AnnotatorState state = getModelObject();
            aTarget.addChildren(getPage(), IFeedback.class);
            try {
                annotationEditor.requestRender(aTarget);
            } catch (Exception e) {
                handleException(this, aTarget, e);
                return;
            }
            try {
                SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
                curationContainer = builder.buildCurationContainer(state);
                setCurationSegmentBeginEnd(getEditorCas());
                curationContainer.setBratAnnotatorModel(state);
                suggestionView.updatePanel(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
                update(aTarget);
            } catch (Exception e) {
                handleException(this, aTarget, e);
            }
        }

        @Override
        public void onAnnotate(AjaxRequestTarget aTarget) {
            AnnotatorState state = getModelObject();
            if (state.isForwardAnnotation()) {
                return;
            }
            AnnotationLayer layer = state.getSelectedAnnotationLayer();
            int address = state.getSelection().getAnnotation().getId();
            try {
                JCas jCas = getEditorCas();
                AnnotationFS fs = selectByAddr(jCas, address);
                for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
                    Type type = CasUtil.getType(fs.getCAS(), layer.getName());
                    Feature feat = type.getFeatureByBaseName(f.getName());
                    if (!automationService.existsMiraTemplate(f)) {
                        continue;
                    }
                    if (!automationService.getMiraTemplate(f).isAnnotateAndRepeat()) {
                        continue;
                    }
                    TagSet tagSet = f.getTagset();
                    boolean isRepeatable = false;
                    // repeat only if the value is in the tagset
                    for (Tag tag : annotationService.listTags(tagSet)) {
                        if (fs.getFeatureValueAsString(feat) == null) {
                            // this is new annotation without values
                            break;
                        }
                        if (fs.getFeatureValueAsString(feat).equals(tag.getName())) {
                            isRepeatable = true;
                            break;
                        }
                    }
                    if (automationService.getMiraTemplate(f) != null && isRepeatable) {
                        if (layer.getType().endsWith(WebAnnoConst.RELATION_TYPE)) {
                            AutomationUtil.repeateRelationAnnotation(state, documentService, correctionDocumentService, annotationService, fs, f, fs.getFeatureValueAsString(feat));
                            update(aTarget);
                            break;
                        } else if (layer.getType().endsWith(WebAnnoConst.SPAN_TYPE)) {
                            AutomationUtil.repeateSpanAnnotation(state, documentService, correctionDocumentService, annotationService, fs.getBegin(), fs.getEnd(), f, fs.getFeatureValueAsString(feat));
                            update(aTarget);
                            break;
                        }
                    }
                }
            } catch (Exception e) {
                handleException(this, aTarget, e);
            }
        }

        @Override
        protected void onAutoForward(AjaxRequestTarget aTarget) {
            annotationEditor.requestRender(aTarget);
        }

        @Override
        public void onDelete(AjaxRequestTarget aTarget, AnnotationFS aFS) {
            AnnotatorState state = getModelObject();
            AnnotationLayer layer = state.getSelectedAnnotationLayer();
            for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
                if (!automationService.existsMiraTemplate(f)) {
                    continue;
                }
                if (!automationService.getMiraTemplate(f).isAnnotateAndRepeat()) {
                    continue;
                }
                try {
                    Type type = CasUtil.getType(aFS.getCAS(), layer.getName());
                    Feature feat = type.getFeatureByBaseName(f.getName());
                    if (layer.getType().endsWith(WebAnnoConst.RELATION_TYPE)) {
                        AutomationUtil.deleteRelationAnnotation(state, documentService, correctionDocumentService, annotationService, aFS, f, aFS.getFeatureValueAsString(feat));
                    } else {
                        AutomationUtil.deleteSpanAnnotation(state, documentService, correctionDocumentService, annotationService, aFS.getBegin(), aFS.getEnd(), f, aFS.getFeatureValueAsString(feat));
                    }
                    update(aTarget);
                } catch (Exception e) {
                    handleException(this, aTarget, e);
                }
            }
        }
    };
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) AnnotationDetailEditorPanel(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) ProjectType(de.tudarmstadt.ukp.clarin.webanno.api.ProjectType) KeyType(wicket.contrib.input.events.key.KeyType) EventType(wicket.contrib.input.events.EventType) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) SuggestionBuilder(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 32 with Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class MergeCas method addRelationArcAnnotation.

static void addRelationArcAnnotation(JCas aJcas, AnnotationFS aClickedFS, boolean aIsAttachType, boolean aIsAllowStacking, AnnotationFS originFsClicked, AnnotationFS targetFsClicked) throws AnnotationException {
    List<AnnotationFS> merges = MergeCas.getMergeFS(aClickedFS, aJcas).collect(Collectors.toList());
    List<AnnotationFS> origins = MergeCas.getMergeFS(originFsClicked, aJcas).collect(Collectors.toList());
    List<AnnotationFS> targets = MergeCas.getMergeFS(targetFsClicked, aJcas).collect(Collectors.toList());
    // check if target/source exists in the mergeview
    if (origins.size() == 0 || targets.size() == 0) {
        throw new AnnotationException("Both the source and target annotation" + " should exist on the mergeview. Please first copy/create them");
    }
    AnnotationFS originFs = origins.get(0);
    AnnotationFS targetFs = targets.get(0);
    if (origins.size() > 1) {
        throw new AnnotationException("Stacked sources exist in mergeview. Cannot copy this relation.");
    }
    if (targets.size() > 1) {
        throw new AnnotationException("Stacked targets exist in mergeview. Cannot copy this relation.");
    }
    if (merges.size() > 0) {
        throw new AnnotationException("The annotation already exists on the mergeview. " + "Add this manually to have stacked annotations");
    }
    // TODO: DKPro Core Dependency layer -> It should be done differently
    if (aIsAttachType) {
        Type type = aClickedFS.getType();
        Feature sourceFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
        originFsClicked = (AnnotationFS) aClickedFS.getFeatureValue(sourceFeature);
        Feature targetFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
        targetFsClicked = (AnnotationFS) aClickedFS.getFeatureValue(targetFeature);
        origins = MergeCas.getMergeFS(originFsClicked, aJcas).collect(Collectors.toList());
        targets = MergeCas.getMergeFS(targetFsClicked, aJcas).collect(Collectors.toList());
        originFs = origins.get(0);
        targetFs = targets.get(0);
    }
    List<AnnotationFS> existingAnnos = MergeCas.getRelAnnosOnPosition(aClickedFS, originFs, targetFs, aJcas);
    if (existingAnnos.size() == 0 || aIsAllowStacking) {
        MergeCas.copyRelationAnnotation(aClickedFS, originFs, targetFs, aJcas);
    } else {
        MergeCas.modifyRelationAnnotation(aClickedFS, existingAnnos.get(0), aJcas);
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) 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)

Example 33 with Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class MergeCas method modifySpanAnnotation.

/**
 * Modify existing non-stackable annotations from one of the users annotation
 */
private static void modifySpanAnnotation(AnnotationFS aOldFs, AnnotationFS aNewFs, JCas aJCas) {
    Feature[] features = getAllFeatures(aOldFs);
    for (Feature f : features) {
        if (isLinkOrBasicFeatures(aOldFs, f)) {
            continue;
        }
        setFeatureValue(aNewFs, f, getFeatureValue(aOldFs, f));
    }
    aJCas.addFsToIndexes(aNewFs);
}
Also used : 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)

Example 34 with Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class MergeCas method copyRelationAnnotation.

private static void copyRelationAnnotation(AnnotationFS aOldFs, AnnotationFS asourceFS, AnnotationFS aTargetFs, JCas aJCas) {
    Feature[] features = getAllFeatures(aOldFs);
    Type type = aOldFs.getType();
    Feature sourceFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
    Feature targetFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
    AnnotationFS newFs = aJCas.getCas().createAnnotation(type, aOldFs.getBegin(), aOldFs.getEnd());
    for (Feature f : features) {
        if (isLinkOrBasicFeatures(aOldFs, f)) {
            continue;
        }
        if (f.equals(sourceFeat)) {
            newFs.setFeatureValue(f, asourceFS);
        } else if (f.equals(targetFeat)) {
            newFs.setFeatureValue(f, aTargetFs);
        } else {
            setFeatureValue(newFs, f, getFeatureValue(aOldFs, f));
        }
    }
    aJCas.addFsToIndexes(newFs);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) 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)

Example 35 with Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class CopyAnnotationTest method copySpanWithSlotNoStackingTest.

@Test
public void copySpanWithSlotNoStackingTest() throws Exception {
    slotLayer.setAllowStacking(false);
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
    Type type = jcasA.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");
    AnnotationFS clickedFs = DiffUtils.makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A", DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
    JCas mergeCAs = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
    DiffUtils.makeLinkHostMultiSPanFeatureFS(mergeCAs, 0, 0, feature, "C", DiffUtils.makeLinkFS(mergeCAs, "slot1", 0, 0));
    MergeCas.addSpanAnnotation(new AnnotatorStateImpl(Mode.CURATION), annotationSchemaService, slotLayer, mergeCAs, clickedFs, false);
    assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) AnnotatorStateImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl) JCas(org.apache.uima.jcas.JCas) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Test(org.junit.Test)

Aggregations

Feature (org.apache.uima.cas.Feature)84 Type (org.apache.uima.cas.Type)62 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)50 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)48 ArrayList (java.util.ArrayList)23 FeatureStructure (org.apache.uima.cas.FeatureStructure)18 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)18 JCas (org.apache.uima.jcas.JCas)18 List (java.util.List)15 Test (org.junit.Test)14 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)13 WebAnnoCasUtil.setFeature (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature)12 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)12 CAS (org.apache.uima.cas.CAS)10 HashSet (java.util.HashSet)8 LinkedHashMap (java.util.LinkedHashMap)8 Map (java.util.Map)8 HashMap (java.util.HashMap)7 TypeSystem (org.apache.uima.cas.TypeSystem)7 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)6