Search in sources :

Example 26 with AnnotationDocument

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

the class AnnotationPage 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);
        // manually update state change!! No idea why it is not updated in the DB
        // without calling createAnnotationDocument(...)
        documentService.createAnnotationDocument(annotationDocument);
        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 27 with AnnotationDocument

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

the class AutomationPage 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 28 with AnnotationDocument

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

the class AutomationPage method actionLoadDocument.

@Override
protected void actionLoadDocument(AjaxRequestTarget aTarget) {
    LOG.info("BEGIN LOAD_DOCUMENT_ACTION");
    AnnotatorState state = getModelObject();
    state.setUser(userRepository.getCurrentUser());
    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(), state.getUser());
        // 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(), state.getUser().getUsername())) {
            editorCas = documentService.readAnnotationCas(annotationDocument);
        } else {
            editorCas = documentService.createOrReadInitialCas(state.getDocument());
        // In automation mode, we do not remove the existing annotations from the documents
        // annotationCas = BratAnnotatorUtility.clearJcasAnnotations(annotationCas,
        // state.getDocument(), user, repository);
        }
        // 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(), state.getUser(), 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(state.getUser().getUsername(), 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
        if (state.getDocument().getState().equals(SourceDocumentState.NEW)) {
            documentService.transitionSourceDocumentState(state.getDocument(), 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 : 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 29 with AnnotationDocument

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

the class AutomationPage 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 30 with AnnotationDocument

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

the class AutomationUtil method deleteSpanAnnotation.

public static void deleteSpanAnnotation(AnnotatorState aBModel, DocumentService aDocumentService, CorrectionDocumentService aCorrectionDocumentService, AnnotationSchemaService aAnnotationService, int aStart, int aEnd, AnnotationFeature aFeature, String aValue) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
    AnnotationDocument annoDoc = aDocumentService.getAnnotationDocument(aBModel.getDocument(), aBModel.getUser());
    JCas annoCas = aDocumentService.readAnnotationCas(annoDoc);
    // get selected text, concatenations of tokens
    String selectedText = WebAnnoCasUtil.getSelectedText(annoCas, aStart, aEnd);
    for (SourceDocument d : aDocumentService.listSourceDocuments(aBModel.getProject())) {
        loadDocument(d, aAnnotationService, aDocumentService, aCorrectionDocumentService, aBModel.getUser());
        JCas jCas = aCorrectionDocumentService.readCorrectionCas(d);
        AutomationTypeAdapter adapter = (AutomationTypeAdapter) aAnnotationService.getAdapter(aFeature.getLayer());
        for (Sentence sentence : select(jCas, Sentence.class)) {
            String sentenceText = sentence.getCoveredText().toLowerCase();
            for (int i = -1; (i = sentenceText.indexOf(selectedText.toLowerCase(), i)) != -1; i = i + selectedText.length()) {
                if (selectCovered(jCas, Token.class, sentence.getBegin() + i, sentence.getBegin() + i + selectedText.length()).size() > 0) {
                    adapter.delete(aBModel, jCas, aFeature, sentence.getBegin() + i, sentence.getBegin() + i + selectedText.length() - 1, aValue);
                }
            }
        }
        aCorrectionDocumentService.writeCorrectionCas(jCas, d);
    }
}
Also used : SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) AutomationTypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.AutomationTypeAdapter)

Aggregations

AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)41 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)22 JCas (org.apache.uima.jcas.JCas)19 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)14 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)11 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)11 IOException (java.io.IOException)10 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)6 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)6 ArrayList (java.util.ArrayList)6 NoResultException (javax.persistence.NoResultException)6 UIMAException (org.apache.uima.UIMAException)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 File (java.io.File)4 Transactional (org.springframework.transaction.annotation.Transactional)4 AutomationTypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.AutomationTypeAdapter)3 RProject (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject)3 ApiOperation (io.swagger.annotations.ApiOperation)3 HashMap (java.util.HashMap)3 DataRetrievalFailureException (org.springframework.dao.DataRetrievalFailureException)3