Search in sources :

Example 31 with SourceDocument

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

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

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

Example 34 with SourceDocument

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

the class DocumentServiceImpl method listAnnotatableDocuments.

@Override
public Map<SourceDocument, AnnotationDocument> listAnnotatableDocuments(Project aProject, User aUser) {
    // First get the source documents
    List<SourceDocument> sourceDocuments = entityManager.createQuery("FROM SourceDocument " + "WHERE project = (:project)", SourceDocument.class).setParameter("project", aProject).getResultList();
    // Next we get all the annotation document records. We can use these to filter out
    // documents which are IGNOREed for given users.
    List<AnnotationDocument> annotationDocuments = entityManager.createQuery("FROM AnnotationDocument " + "WHERE user = (:username) AND project = (:project)", AnnotationDocument.class).setParameter("username", aUser.getUsername()).setParameter("project", aProject).getResultList();
    // First we add all the source documents
    Map<SourceDocument, AnnotationDocument> map = new TreeMap<>(SourceDocument.NAME_COMPARATOR);
    for (SourceDocument doc : sourceDocuments) {
        map.put(doc, null);
    }
    // documents
    for (AnnotationDocument adoc : annotationDocuments) {
        switch(adoc.getState()) {
            case IGNORE:
                map.remove(adoc.getDocument());
                break;
            default:
                map.put(adoc.getDocument(), adoc);
                break;
        }
    }
    return map;
}
Also used : SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) TreeMap(java.util.TreeMap)

Example 35 with SourceDocument

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

the class DocumentServiceImpl method listSourceDocuments.

@Override
@Transactional(noRollbackFor = NoResultException.class)
public List<SourceDocument> listSourceDocuments(Project aProject) {
    List<SourceDocument> sourceDocuments = entityManager.createQuery("FROM SourceDocument where project =:project ORDER BY name ASC", SourceDocument.class).setParameter("project", aProject).getResultList();
    List<SourceDocument> tabSepDocuments = new ArrayList<>();
    for (SourceDocument sourceDocument : sourceDocuments) {
        if (sourceDocument.getFormat().equals(WebAnnoConst.TAB_SEP)) {
            tabSepDocuments.add(sourceDocument);
        }
    }
    sourceDocuments.removeAll(tabSepDocuments);
    return sourceDocuments;
}
Also used : SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)59 JCas (org.apache.uima.jcas.JCas)24 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)22 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)22 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)19 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 File (java.io.File)13 RProject (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 ApiOperation (io.swagger.annotations.ApiOperation)9 IOException (java.io.IOException)9 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)8 Map (java.util.Map)8 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)7 LinkedHashMap (java.util.LinkedHashMap)7 List (java.util.List)7 DiffResult (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult)6 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)6 NoResultException (javax.persistence.NoResultException)6