Search in sources :

Example 1 with SuggestionBuilder

use of de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder 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 2 with SuggestionBuilder

use of de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder in project webanno by webanno.

the class AutomationPage method actionRefreshDocument.

@Override
protected void actionRefreshDocument(AjaxRequestTarget aTarget) {
    try {
        AnnotatorState state = getModelObject();
        SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
        curationContainer = builder.buildCurationContainer(state);
        setCurationSegmentBeginEnd(getEditorCas());
        curationContainer.setBratAnnotatorModel(state);
        update(aTarget);
        annotationEditor.requestRender(aTarget);
    } catch (Exception e) {
        handleException(aTarget, e);
    }
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SuggestionBuilder(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 3 with SuggestionBuilder

use of de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder in project webanno by webanno.

the class AutomationPage method actionCompletePreferencesChange.

private void actionCompletePreferencesChange(AjaxRequestTarget aTarget) {
    try {
        AnnotatorState state = getModelObject();
        JCas editorCas = getEditorCas();
        // The number of visible sentences may have changed - let the state recalculate
        // the visible sentences
        Sentence sentence = selectByAddr(editorCas, Sentence.class, state.getFirstVisibleUnitAddress());
        state.setFirstVisibleUnit(sentence);
        SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
        curationContainer = builder.buildCurationContainer(state);
        setCurationSegmentBeginEnd(editorCas);
        curationContainer.setBratAnnotatorModel(state);
        update(aTarget);
        aTarget.appendJavaScript("Wicket.Window.unloadConfirmation = false;window.location.reload()");
        // Re-render the whole page because the width of the sidebar may have changed
        aTarget.add(this);
    } catch (Exception e) {
        handleException(aTarget, e);
    }
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) SuggestionBuilder(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 4 with SuggestionBuilder

use of de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder in project webanno by webanno.

the class CorrectionPage method actionCompletePreferencesChange.

private void actionCompletePreferencesChange(AjaxRequestTarget aTarget) {
    try {
        AnnotatorState state = getModelObject();
        JCas editorCas = getEditorCas();
        // The number of visible sentences may have changed - let the state recalculate
        // the visible sentences
        Sentence sentence = selectByAddr(editorCas, Sentence.class, state.getFirstVisibleUnitAddress());
        state.setFirstVisibleUnit(sentence);
        SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
        curationContainer = builder.buildCurationContainer(state);
        setCurationSegmentBeginEnd(editorCas);
        curationContainer.setBratAnnotatorModel(state);
        update(aTarget);
        aTarget.appendJavaScript("Wicket.Window.unloadConfirmation = false;window.location.reload()");
        // Re-render the whole page because the width of the sidebar may have changed
        aTarget.add(this);
    } catch (Exception e) {
        handleException(aTarget, e);
    }
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) SuggestionBuilder(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 5 with SuggestionBuilder

use of de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder in project webanno by webanno.

the class AutomationPage method actionGotoPage.

private void actionGotoPage(AjaxRequestTarget aTarget, Form<?> aForm) throws Exception {
    AnnotatorState state = getModelObject();
    JCas editorCas = getEditorCas();
    List<Sentence> sentences = new ArrayList<>(select(editorCas, Sentence.class));
    int selectedSentence = gotoPageTextField.getModelObject();
    selectedSentence = Math.min(selectedSentence, sentences.size());
    gotoPageTextField.setModelObject(selectedSentence);
    state.setFirstVisibleUnit(sentences.get(selectedSentence - 1));
    state.setFocusUnitIndex(selectedSentence);
    SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
    curationContainer = builder.buildCurationContainer(state);
    setCurationSegmentBeginEnd(editorCas);
    curationContainer.setBratAnnotatorModel(state);
    update(aTarget);
    aTarget.add(gotoPageTextField);
    annotationEditor.requestRender(aTarget);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) SuggestionBuilder(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder)

Aggregations

AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)9 SuggestionBuilder (de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder)9 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)7 IOException (java.io.IOException)7 UIMAException (org.apache.uima.UIMAException)7 JCas (org.apache.uima.jcas.JCas)7 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)4 ArrayList (java.util.ArrayList)3 AnnotationDetailEditorPanel (de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 ProjectType (de.tudarmstadt.ukp.clarin.webanno.api.ProjectType)1 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)1 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)1 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)1 Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)1 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)1 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)1 Feature (org.apache.uima.cas.Feature)1 Type (org.apache.uima.cas.Type)1 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)1