Search in sources :

Example 21 with AnnotationDocument

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

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

the class DocumentServiceImpl method existFinishedDocument.

/**
 * Return true if there exist at least one annotation document FINISHED for annotation for this
 * {@link SourceDocument}
 *
 * @param aSourceDocument
 *            the source document.
 * @param aProject
 *            the project.
 * @return if a finished document exists.
 */
@Override
public boolean existFinishedDocument(SourceDocument aSourceDocument, Project aProject) {
    List<de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument> annotationDocuments = listAnnotationDocuments(aSourceDocument);
    boolean finishedAnnotationDocumentExist = false;
    for (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument annotationDocument : annotationDocuments) {
        if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
            finishedAnnotationDocumentExist = true;
            break;
        }
    }
    return finishedAnnotationDocumentExist;
}
Also used : AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)

Example 23 with AnnotationDocument

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

the class DocumentServiceImpl method resetAnnotationCas.

@Override
public void resetAnnotationCas(SourceDocument aDocument, User aUser) throws UIMAException, IOException {
    AnnotationDocument adoc = getAnnotationDocument(aDocument, aUser);
    JCas jcas = createOrReadInitialCas(aDocument);
    writeAnnotationCas(jcas, aDocument, aUser, false);
    applicationEventPublisher.publishEvent(new AfterDocumentResetEvent(this, adoc, jcas));
}
Also used : JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) AfterDocumentResetEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.AfterDocumentResetEvent)

Example 24 with AnnotationDocument

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

the class DocumentServiceImpl method readAnnotationCas.

@Override
@Transactional
@Deprecated
public JCas readAnnotationCas(SourceDocument aDocument, User aUser) throws IOException {
    // Check if there is an annotation document entry in the database. If there is none,
    // create one.
    AnnotationDocument annotationDocument = createOrGetAnnotationDocument(aDocument, aUser);
    // Change the state of the source document to in progress
    transitionSourceDocumentState(aDocument, NEW_TO_ANNOTATION_IN_PROGRESS);
    return readAnnotationCas(annotationDocument);
}
Also used : AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with AnnotationDocument

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

the class AnnotationPage method handleParameters.

private void handleParameters(AjaxRequestTarget aTarget, StringValue aProjectParameter, StringValue aDocumentParameter, StringValue aFocusParameter, boolean aLockIfPreset) {
    // Get current project from parameters
    Project project = null;
    try {
        project = getProjectFromParameters(aProjectParameter);
    } catch (NoResultException e) {
        error("Project [" + aProjectParameter + "] does not exist");
        return;
    }
    // Get current document from parameters
    SourceDocument document = null;
    if (project != null) {
        try {
            document = getDocumentFromParameters(project, aDocumentParameter);
        } catch (NoResultException e) {
            error("Document [" + aDocumentParameter + "] does not exist in project [" + project.getId() + "]");
        }
    }
    // Get current focus unit from parameters
    int focus = 0;
    if (aFocusParameter != null) {
        focus = aFocusParameter.toInt(0);
    }
    // there is also a document change.
    if (document != null && document.equals(getModelObject().getDocument()) && focus == getModelObject().getFocusUnitIndex()) {
        return;
    }
    // Check access to project
    if (project != null && !isAnnotator(project, projectService, getModelObject().getUser())) {
        error("You have no permission to access project [" + project.getId() + "]");
        return;
    }
    // Check if document is locked for the user
    if (project != null && document != null && documentService.existsAnnotationDocument(document, getModelObject().getUser())) {
        AnnotationDocument adoc = documentService.getAnnotationDocument(document, getModelObject().getUser());
        if (AnnotationDocumentState.IGNORE.equals(adoc.getState())) {
            error("Document [" + document.getId() + "] in project [" + project.getId() + "] is locked for user [" + getModelObject().getUser().getUsername() + "]");
            return;
        }
    }
    // i.e. not only in the case that it was a URL fragment parameter.
    if (project != null) {
        getModelObject().setProject(project);
        if (aLockIfPreset) {
            getModelObject().setProjectLocked(true);
        }
    }
    if (document != null) {
        // or a change of focus (or both)
        if (!document.equals(getModelObject().getDocument())) {
            getModelObject().setDocument(document, getListOfDocs());
            actionLoadDocument(aTarget, focus);
        } else {
            try {
                getModelObject().moveToUnit(getEditorCas(), focus);
                actionRefreshDocument(aTarget);
            } catch (Exception e) {
                aTarget.addChildren(getPage(), IFeedback.class);
                LOG.info("Error reading CAS " + e.getMessage());
                error("Error reading CAS " + e.getMessage());
            }
        }
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) NoResultException(javax.persistence.NoResultException) IFeedback(org.apache.wicket.feedback.IFeedback) NoResultException(javax.persistence.NoResultException) IOException(java.io.IOException)

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