Search in sources :

Example 41 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState 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 42 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class CorrectionPage method setCurationSegmentBeginEnd.

private void setCurationSegmentBeginEnd(JCas aEditorCas) throws UIMAException, ClassNotFoundException, IOException {
    AnnotatorState state = getModelObject();
    curationSegment.setBegin(state.getWindowBeginOffset());
    curationSegment.setEnd(state.getWindowEndOffset());
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)

Example 43 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class CorrectionPage method actionFinishDocument.

private void actionFinishDocument(AjaxRequestTarget aTarget) {
    finishDocumentDialog.setConfirmAction((aCallbackTarget) -> {
        ensureRequiredFeatureValuesSet(aCallbackTarget, getEditorCas());
        AnnotatorState state = getModelObject();
        AnnotationDocument annotationDocument = documentService.getAnnotationDocument(state.getDocument(), state.getUser());
        documentService.transitionAnnotationDocumentState(annotationDocument, ANNOTATION_IN_PROGRESS_TO_ANNOTATION_FINISHED);
        aCallbackTarget.add(finishDocumentIcon);
        aCallbackTarget.add(finishDocumentLink);
        aCallbackTarget.add(detailEditor);
        aCallbackTarget.add(createOrGetResetDocumentLink());
    });
    finishDocumentDialog.show(aTarget);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)

Example 44 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class CorrectionPage method getEditorCas.

@Override
protected JCas getEditorCas() throws IOException {
    AnnotatorState state = getModelObject();
    if (state.getDocument() == null) {
        throw new IllegalStateException("Please open a document first!");
    }
    SourceDocument aDocument = getModelObject().getDocument();
    AnnotationDocument annotationDocument = documentService.getAnnotationDocument(aDocument, state.getUser());
    // If there is no CAS yet for the annotation document, create one.
    return documentService.readAnnotationCas(annotationDocument);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)

Example 45 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState 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)

Aggregations

AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)84 JCas (org.apache.uima.jcas.JCas)37 IOException (java.io.IOException)26 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)23 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)22 UIMAException (org.apache.uima.UIMAException)20 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)16 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)16 ArrayList (java.util.ArrayList)16 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)14 List (java.util.List)13 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)12 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)9 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)9 SuggestionBuilder (de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder)9 Map (java.util.Map)9 NoResultException (javax.persistence.NoResultException)9 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)9 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)8 Selection (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection)8