Search in sources :

Example 16 with AnnotationDocument

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

the class AutomationUtil method loadDocument.

/**
 * Repeat annotation will repeat annotations of same pattern to all documents on the project
 * load CAS from document in case no initial CORRECTION_CAS is not created before
 */
public static void loadDocument(SourceDocument aDocument, AnnotationSchemaService annotationService, DocumentService aDocumentService, CorrectionDocumentService aCorrectionDocumentService, User logedInUser) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
    JCas jCas = null;
    if (!aCorrectionDocumentService.existsCorrectionCas(aDocument)) {
        try {
            AnnotationDocument logedInUserAnnotationDocument = aDocumentService.getAnnotationDocument(aDocument, logedInUser);
            jCas = aDocumentService.readAnnotationCas(logedInUserAnnotationDocument);
            annotationService.upgradeCas(jCas.getCas(), logedInUserAnnotationDocument);
            aCorrectionDocumentService.writeCorrectionCas(jCas, aDocument);
        } catch (DataRetrievalFailureException | NoResultException e) {
            jCas = aDocumentService.readAnnotationCas(aDocumentService.createOrGetAnnotationDocument(aDocument, logedInUser));
            // upgrade this cas
            annotationService.upgradeCas(jCas.getCas(), aDocumentService.createOrGetAnnotationDocument(aDocument, logedInUser));
            aCorrectionDocumentService.writeCorrectionCas(jCas, aDocument);
        }
    } else {
        jCas = aCorrectionDocumentService.readCorrectionCas(aDocument);
        // upgrade this automation cas
        aCorrectionDocumentService.upgradeCorrectionCas(jCas.getCas(), aDocument);
    }
}
Also used : JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException) NoResultException(javax.persistence.NoResultException)

Example 17 with AnnotationDocument

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

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

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

the class AgreementPage method getJCases.

/**
 * Get the finished CASes used to compute agreement.
 */
private Map<String, List<JCas>> getJCases() {
    // Avoid reloading the CASes when switching features.
    if (cachedCASes != null) {
        return cachedCASes;
    }
    Project project = projectSelectionForm.getModelObject().project;
    List<User> users = projectService.listProjectUsersWithPermissions(project, PermissionLevel.USER);
    List<SourceDocument> sourceDocuments = documentService.listSourceDocuments(project);
    cachedCASes = new LinkedHashMap<>();
    for (User user : users) {
        List<JCas> cases = new ArrayList<>();
        for (SourceDocument document : sourceDocuments) {
            JCas jCas = null;
            // Load the CAS if there is a finished one.
            if (documentService.existsAnnotationDocument(document, user)) {
                AnnotationDocument annotationDocument = documentService.getAnnotationDocument(document, user);
                if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
                    try {
                        jCas = documentService.readAnnotationCas(annotationDocument);
                        annotationService.upgradeCas(jCas.getCas(), annotationDocument);
                        // REC: I think there is no need to write the CASes here. We would not
                        // want to interfere with currently active annotator users
                        // Set the CAS name in the DocumentMetaData so that we can pick it
                        // up in the Diff position for the purpose of debugging / transparency.
                        DocumentMetaData documentMetadata = DocumentMetaData.get(jCas);
                        documentMetadata.setDocumentId(annotationDocument.getDocument().getName());
                        documentMetadata.setCollectionId(annotationDocument.getProject().getName());
                    } catch (Exception e) {
                        LOG.error("Unable to load data", e);
                        error("Unable to load data: " + ExceptionUtils.getRootCauseMessage(e));
                    }
                }
            }
            // The next line can enter null values into the list if a user didn't work on this
            // source document yet.
            cases.add(jCas);
        }
        cachedCASes.put(user.getUsername(), cases);
    }
    return cachedCASes;
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) DocumentMetaData(de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) IOException(java.io.IOException)

Example 20 with AnnotationDocument

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

the class MonitoringPage method getPercentageOfFinishedDocumentsPerUser.

private Map<String, Integer> getPercentageOfFinishedDocumentsPerUser(Project aProject) {
    Map<String, Integer> annotatorsProgress = new HashMap<>();
    if (aProject != null) {
        for (User user : projectService.listProjectUsersWithPermissions(aProject, PermissionLevel.USER)) {
            int finished = 0;
            int ignored = 0;
            int totalDocs = 0;
            List<SourceDocument> documents = documentService.listSourceDocuments(aProject);
            for (SourceDocument document : documents) {
                totalDocs++;
                if (documentService.isAnnotationFinished(document, user)) {
                    finished++;
                } else if (documentService.existsAnnotationDocument(document, user)) {
                    AnnotationDocument annotationDocument = documentService.getAnnotationDocument(document, user);
                    if (annotationDocument.getState().equals(AnnotationDocumentState.IGNORE)) {
                        ignored++;
                    }
                }
            }
            annotatorsProgress.put(user.getUsername(), (int) Math.round((double) (finished * 100) / (totalDocs - ignored)));
        }
    }
    return annotatorsProgress;
}
Also used : User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)

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