Search in sources :

Example 76 with AnnotatorState

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

the class CorrectionPage method actionLoadDocument.

@Override
protected void actionLoadDocument(AjaxRequestTarget aTarget) {
    LOG.info("BEGIN LOAD_DOCUMENT_ACTION");
    AnnotatorState state = getModelObject();
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    User user = userRepository.get(username);
    state.setUser(user);
    state.setProject(state.getProject());
    state.setDocument(state.getDocument(), getListOfDocs());
    try {
        // Check if there is an annotation document entry in the database. If there is none,
        // create one.
        AnnotationDocument annotationDocument = documentService.createOrGetAnnotationDocument(state.getDocument(), user);
        // Read the correction CAS - if it does not exist yet, from the initial CAS
        JCas correctionCas;
        if (correctionDocumentService.existsCorrectionCas(state.getDocument())) {
            correctionCas = correctionDocumentService.readCorrectionCas(state.getDocument());
        } else {
            correctionCas = documentService.createOrReadInitialCas(state.getDocument());
        }
        // Read the annotation CAS or create an annotation CAS from the initial CAS by stripping
        // annotations
        JCas editorCas;
        if (documentService.existsCas(state.getDocument(), user.getUsername())) {
            editorCas = documentService.readAnnotationCas(annotationDocument);
        } else {
            editorCas = documentService.createOrReadInitialCas(state.getDocument());
            editorCas = BratAnnotatorUtility.clearJcasAnnotations(editorCas, state.getDocument(), user, documentService);
        }
        // Update the CASes
        annotationService.upgradeCas(editorCas.getCas(), annotationDocument);
        correctionDocumentService.upgradeCorrectionCas(correctionCas.getCas(), state.getDocument());
        // After creating an new CAS or upgrading the CAS, we need to save it
        documentService.writeAnnotationCas(editorCas.getCas().getJCas(), annotationDocument.getDocument(), user, false);
        correctionDocumentService.writeCorrectionCas(correctionCas, state.getDocument());
        // (Re)initialize brat model after potential creating / upgrading CAS
        state.reset();
        // Load constraints
        state.setConstraints(constraintsService.loadConstraints(state.getProject()));
        // Load user preferences
        PreferencesUtil.loadPreferences(username, settingsService, projectService, annotationService, state, state.getMode());
        // Initialize the visible content
        state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(editorCas));
        // if project is changed, reset some project specific settings
        if (currentprojectId != state.getProject().getId()) {
            state.clearRememberedFeatures();
        }
        currentprojectId = state.getProject().getId();
        LOG.debug("Configured BratAnnotatorModel for user [" + state.getUser() + "] f:[" + state.getFirstVisibleUnitIndex() + "] l:[" + state.getLastVisibleUnitIndex() + "] s:[" + state.getFocusUnitIndex() + "]");
        gotoPageTextField.setModelObject(1);
        setCurationSegmentBeginEnd(editorCas);
        suggestionView.init(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
        update(aTarget);
        // Re-render the whole page because the font size
        if (aTarget != null) {
            aTarget.add(this);
        }
        // Update document state
        documentService.transitionSourceDocumentState(state.getDocument(), SourceDocumentStateTransition.NEW_TO_ANNOTATION_IN_PROGRESS);
        // Reset the editor
        detailEditor.reset(aTarget);
        // Populate the layer dropdown box
        detailEditor.loadFeatureEditorModels(editorCas, aTarget);
    } catch (Exception e) {
        handleException(aTarget, e);
    }
    LOG.info("END LOAD_DOCUMENT_ACTION");
}
Also used : User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 77 with AnnotatorState

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

the class CorrectionPage 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 78 with AnnotatorState

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

the class CorrectionPage method createDetailEditor.

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

        private static final long serialVersionUID = 2857345299480098279L;

        @Override
        protected void onChange(AjaxRequestTarget aTarget) {
            aTarget.addChildren(getPage(), IFeedback.class);
            aTarget.add(getOrCreatePositionInfoLabel());
            try {
                AnnotatorState state = getModelObject();
                JCas editorCas = getEditorCas();
                // JCas correctionCas = repository.readCorrectionCas(state.getDocument());
                annotationEditor.requestRender(aTarget);
                // info(bratAnnotatorModel.getMessage());
                SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
                curationContainer = builder.buildCurationContainer(state);
                setCurationSegmentBeginEnd(editorCas);
                curationContainer.setBratAnnotatorModel(state);
                update(aTarget);
            } catch (Exception e) {
                handleException(this, aTarget, e);
            }
        }

        @Override
        protected void onAutoForward(AjaxRequestTarget aTarget) {
            annotationEditor.requestRender(aTarget);
        }
    };
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) SuggestionBuilder(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder) 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)

Example 79 with AnnotatorState

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

the class CorrectionPage 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)

Example 80 with AnnotatorState

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

the class CorrectionPage method actionResetDocument.

/**
 * Reset the document by removing all annotations form the initial CAS and using the result as
 * the editor CAS.
 */
@Override
protected void actionResetDocument(AjaxRequestTarget aTarget) throws Exception {
    AnnotatorState state = getModelObject();
    JCas editorCas = documentService.createOrReadInitialCas(state.getDocument());
    editorCas = BratAnnotatorUtility.clearJcasAnnotations(editorCas, state.getDocument(), state.getUser(), documentService);
    documentService.writeAnnotationCas(editorCas, state.getDocument(), state.getUser(), false);
    actionLoadDocument(aTarget);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas)

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