Search in sources :

Example 31 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer 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 AnnotationLayer

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

the class MergeCas method addArcAnnotation.

public static void addArcAnnotation(TypeAdapter aAdapter, JCas aJcas, int aAddressOriginClicked, int aAddressTargetClicked, String aFSArcaddress, JCas aClickedJCas, AnnotationFS aClickedFS) throws AnnotationException {
    AnnotationFS originFsClicked = selectByAddr(aClickedJCas, aAddressOriginClicked);
    AnnotationFS targetFsClicked = selectByAddr(aClickedJCas, aAddressTargetClicked);
    // this is a slot arc
    if (aFSArcaddress.contains(".")) {
        addSlotArcAnnotation((SpanAdapter) aAdapter, aJcas, aFSArcaddress, aClickedJCas, aClickedFS);
    } else // normal relation annotation arc is clicked
    {
        AnnotationLayer layer = aAdapter.getLayer();
        addRelationArcAnnotation(aJcas, aClickedFS, layer.getAttachType() != null, layer.isAllowStacking(), originFsClicked, targetFsClicked);
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 33 with AnnotationLayer

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

the class SuggestionViewPanel method mergeArc.

private void mergeArc(IRequestParameters aRequest, UserAnnotationSegment aCurationUserSegment, JCas aJcas) throws AnnotationException, IOException, UIMAException, ClassNotFoundException {
    int addressOriginClicked = aRequest.getParameterValue(PARAM_ORIGIN_SPAN_ID).toInt();
    int addressTargetClicked = aRequest.getParameterValue(PARAM_TARGET_SPAN_ID).toInt();
    String arcType = removePrefix(aRequest.getParameterValue(PARAM_TYPE).toString());
    String fsArcaddress = aRequest.getParameterValue(PARAM_ARC_ID).toString();
    AnnotatorState bModel = aCurationUserSegment.getAnnotatorState();
    SourceDocument sourceDocument = bModel.getDocument();
    // for correction and automation, the lower panel is the clickedJcase, from the suggestions
    JCas clickedJCas;
    if (!aCurationUserSegment.getAnnotatorState().getMode().equals(Mode.CURATION)) {
        clickedJCas = correctionDocumentService.readCorrectionCas(sourceDocument);
    } else {
        User user = userRepository.get(aCurationUserSegment.getUsername());
        AnnotationDocument clickedAnnotationDocument = documentService.getAnnotationDocument(sourceDocument, user);
        clickedJCas = getJCas(bModel, clickedAnnotationDocument);
    }
    long layerId = TypeUtil.getLayerId(arcType);
    AnnotationLayer layer = annotationService.getLayer(layerId);
    TypeAdapter adapter = annotationService.getAdapter(layer);
    int address = Integer.parseInt(fsArcaddress.split("\\.")[0]);
    AnnotationFS clickedFS = selectByAddr(clickedJCas, address);
    if (isCorefType(clickedFS)) {
        throw new AnnotationException(" Coreference Annotation not supported in curation");
    }
    MergeCas.addArcAnnotation(adapter, aJcas, addressOriginClicked, addressTargetClicked, fsArcaddress, clickedJCas, clickedFS);
    writeEditorCas(bModel, aJcas);
    int sentenceNumber = getSentenceNumber(clickedJCas, clickedFS.getBegin());
    bModel.setFocusUnitIndex(sentenceNumber);
    // Update timestamp
    bModel.getDocument().setSentenceAccessed(sentenceNumber);
    if (bModel.getPreferences().isScrollPage()) {
        Sentence sentence = selectSentenceAt(aJcas, bModel.getFirstVisibleUnitBegin(), bModel.getFirstVisibleUnitEnd());
        sentence = findWindowStartCenteringOnSelection(aJcas, sentence, clickedFS.getBegin(), bModel.getProject(), bModel.getDocument(), bModel.getPreferences().getWindowSize());
        bModel.setFirstVisibleUnit(sentence);
    }
}
Also used : User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 34 with AnnotationLayer

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

the class SuggestionViewPanel method addSuggestionColor.

/**
 * For each {@link ConfigurationSet}, where there are some differences in users annotation and
 * the curation annotation.
 */
private void addSuggestionColor(Project aProject, Mode aMode, Map<String, JCas> aCasMap, Map<String, Map<VID, AnnotationState>> aSuggestionColors, Collection<ConfigurationSet> aCfgSet, boolean aI, boolean aAgree) {
    for (ConfigurationSet cs : aCfgSet) {
        boolean use = false;
        for (String u : cs.getCasGroupIds()) {
            Map<VID, AnnotationState> colors = aSuggestionColors.get(u);
            if (colors == null) {
                colors = new HashMap<>();
                aSuggestionColors.put(u, colors);
            }
            for (Configuration c : cs.getConfigurations(u)) {
                FeatureStructure fs = c.getFs(u, aCasMap);
                AnnotationLayer layer = annotationService.getLayer(fs.getType().getName(), aProject);
                TypeAdapter typeAdapter = annotationService.getAdapter(layer);
                VID vid;
                // link FS
                if (c.getPosition().getFeature() != null) {
                    int fi = 0;
                    for (AnnotationFeature f : typeAdapter.listFeatures()) {
                        if (f.getName().equals(c.getPosition().getFeature())) {
                            break;
                        }
                        fi++;
                    }
                    vid = new VID(WebAnnoCasUtil.getAddr(fs), fi, c.getAID(u).index);
                } else {
                    vid = new VID(WebAnnoCasUtil.getAddr(fs));
                }
                if (aAgree) {
                    colors.put(vid, AnnotationState.AGREE);
                    continue;
                }
                // automation and correction projects
                if (!aMode.equals(Mode.CURATION) && !aAgree) {
                    if (cs.getCasGroupIds().size() == 2) {
                        colors.put(vid, AnnotationState.DO_NOT_USE);
                    } else {
                        colors.put(vid, AnnotationState.DISAGREE);
                    }
                    continue;
                }
                // this set agree with the curation annotation
                if (c.getCasGroupIds().contains(CURATION_USER)) {
                    use = true;
                } else {
                    use = false;
                }
                // this curation view
                if (u.equals(CURATION_USER)) {
                    continue;
                }
                if (aAgree) {
                    colors.put(vid, AnnotationState.AGREE);
                } else if (use) {
                    colors.put(vid, AnnotationState.USE);
                } else if (aI) {
                    colors.put(vid, AnnotationState.DISAGREE);
                } else if (!cs.getCasGroupIds().contains(CURATION_USER)) {
                    colors.put(vid, AnnotationState.DISAGREE);
                } else {
                    colors.put(vid, AnnotationState.DO_NOT_USE);
                }
            }
        }
    }
}
Also used : Configuration(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.Configuration) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) FeatureStructure(org.apache.uima.cas.FeatureStructure) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationState(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.AnnotationState) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 35 with AnnotationLayer

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

the class SuggestionViewPanel method createSpan.

private void createSpan(String spanType, AnnotatorState aBModel, JCas aMergeJCas, AnnotationDocument aAnnotationDocument, int aAddress) throws IOException, UIMAException, ClassNotFoundException, AnnotationException {
    JCas clickedJCas = getJCas(aBModel, aAnnotationDocument);
    AnnotationFS fsClicked = selectByAddr(clickedJCas, aAddress);
    if (isCorefType(fsClicked)) {
        throw new AnnotationException("Coreference Annotation not supported in curation");
    }
    long layerId = TypeUtil.getLayerId(spanType);
    AnnotationLayer layer = annotationService.getLayer(layerId);
    MergeCas.addSpanAnnotation(aBModel, annotationService, layer, aMergeJCas, fsClicked, layer.isAllowStacking());
    writeEditorCas(aBModel, aMergeJCas);
    // update timestamp
    int sentenceNumber = getSentenceNumber(clickedJCas, fsClicked.getBegin());
    aBModel.setFocusUnitIndex(sentenceNumber);
    aBModel.getDocument().setSentenceAccessed(sentenceNumber);
    if (aBModel.getPreferences().isScrollPage()) {
        Sentence sentence = selectSentenceAt(aMergeJCas, aBModel.getFirstVisibleUnitBegin(), aBModel.getFirstVisibleUnitEnd());
        sentence = findWindowStartCenteringOnSelection(aMergeJCas, sentence, fsClicked.getBegin(), aBModel.getProject(), aBModel.getDocument(), aBModel.getPreferences().getWindowSize());
        aBModel.setFirstVisibleUnit(sentence);
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) JCas(org.apache.uima.jcas.JCas) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Aggregations

AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)67 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)35 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)22 ArrayList (java.util.ArrayList)14 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)13 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)12 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)11 LogMessage (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage)8 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)7 Type (org.apache.uima.cas.Type)7 JCas (org.apache.uima.jcas.JCas)6 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)5 FeatureStructure (org.apache.uima.cas.FeatureStructure)5 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)5 Test (org.junit.Test)5 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)4 HashMap (java.util.HashMap)4 TypeSystemDescriptionFactory.createTypeSystemDescription (org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription)4 SoftAssertions (org.assertj.core.api.SoftAssertions)4 Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)3