Search in sources :

Example 1 with AnnotationDocument

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

the class AnnotationPage method getEditorCas.

@Override
public 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 2 with AnnotationDocument

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

the class AnnotationPage method actionLoadDocument.

protected void actionLoadDocument(AjaxRequestTarget aTarget, int aFocus) {
    LOG.info("BEGIN LOAD_DOCUMENT_ACTION at focus " + aFocus);
    AnnotatorState state = getModelObject();
    state.setUser(userRepository.getCurrentUser());
    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 CAS
        JCas editorCas = documentService.readAnnotationCas(annotationDocument);
        // Update the annotation document CAS
        annotationService.upgradeCas(editorCas.getCas(), annotationDocument);
        // After creating an new CAS or upgrading the CAS, we need to save it
        documentService.writeAnnotationCas(editorCas.getCas().getJCas(), annotationDocument, false);
        // (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());
        // if project is changed, reset some project specific settings
        if (currentprojectId != state.getProject().getId()) {
            state.clearRememberedFeatures();
            currentprojectId = state.getProject().getId();
        }
        // Initialize the visible content
        state.moveToUnit(editorCas, aFocus);
        gotoPageTextField.setModelObject(getModelObject().getFirstVisibleUnitIndex());
        // Set the actual editor component. This has to happen *before* any AJAX refreshs are
        // scheduled and *after* the preferences have been loaded (because the current editor
        // type is set in the preferences.
        AnnotationEditorBase newAnnotationEditor = createAnnotationEditor();
        annotationEditor.replaceWith(newAnnotationEditor);
        annotationEditor = newAnnotationEditor;
        // Update document state
        if (SourceDocumentState.NEW.equals(state.getDocument().getState())) {
            documentService.transitionSourceDocumentState(state.getDocument(), NEW_TO_ANNOTATION_IN_PROGRESS);
        }
        // Reset the editor (we reload the page content below, so in order not to schedule
        // a double-update, we pass null here)
        detailEditor.reset(null);
        // Populate the layer dropdown box
        detailEditor.loadFeatureEditorModels(editorCas, null);
        if (aTarget != null) {
            // Update URL for current document
            updateUrlFragment(aTarget);
            WicketUtil.refreshPage(aTarget, getPage());
        }
        applicationEventPublisherHolder.get().publishEvent(new DocumentOpenedEvent(this, editorCas, getModelObject().getDocument(), getModelObject().getUser().getUsername()));
        LOG.debug("Configured BratAnnotatorModel for user [" + state.getUser().getUsername() + "] f:[" + state.getFirstVisibleUnitIndex() + "] l:[" + state.getLastVisibleUnitIndex() + "] s:[" + state.getFocusUnitIndex() + "]");
    } catch (Exception e) {
        handleException(aTarget, e);
    }
    LOG.info("END LOAD_DOCUMENT_ACTION");
}
Also used : AnnotationEditorBase(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorBase) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) DocumentOpenedEvent(de.tudarmstadt.ukp.clarin.webanno.api.annotation.event.DocumentOpenedEvent) NoResultException(javax.persistence.NoResultException) IOException(java.io.IOException)

Example 3 with AnnotationDocument

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

the class WebhookServiceTest method test.

@Test
public void test() {
    Webhook hook = new Webhook();
    hook.setUrl("http://localhost:" + port + "/test/subscribe");
    hook.setTopics(asList(PROJECT_STATE, ANNOTATION_STATE, DOCUMENT_STATE));
    hook.setEnabled(true);
    webhooksConfiguration.setGlobalHooks(asList(hook));
    Project project = new Project();
    project.setState(ProjectState.NEW);
    project.setId(1l);
    SourceDocument doc = new SourceDocument();
    doc.setProject(project);
    doc.setId(2l);
    doc.setState(SourceDocumentState.ANNOTATION_IN_PROGRESS);
    AnnotationDocument ann = new AnnotationDocument();
    ann.setProject(project);
    ann.setId(3l);
    ann.setDocument(doc);
    ann.setState(AnnotationDocumentState.FINISHED);
    applicationEventPublisher.publishEvent(new ProjectStateChangedEvent(this, project, ProjectState.CURATION_FINISHED));
    applicationEventPublisher.publishEvent(new DocumentStateChangedEvent(this, doc, SourceDocumentState.NEW));
    applicationEventPublisher.publishEvent(new AnnotationStateChangeEvent(this, ann, AnnotationDocumentState.IN_PROGRESS));
    assertEquals(1, testService.projectStateChangeMsgs.size());
    assertEquals(1, testService.docStateChangeMsgs.size());
    assertEquals(1, testService.annStateChangeMsgs.size());
}
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) ProjectStateChangedEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.ProjectStateChangedEvent) AnnotationStateChangeEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.AnnotationStateChangeEvent) DocumentStateChangedEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.DocumentStateChangedEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with AnnotationDocument

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

the class DocumentServiceImpl method numberOfExpectedAnnotationDocuments.

@Override
public int numberOfExpectedAnnotationDocuments(Project aProject) {
    // Get all annotators in the project
    List<String> users = getAllAnnotators(aProject);
    // parameter right of "in"
    if (users.isEmpty()) {
        return 0;
    }
    int ignored = 0;
    List<AnnotationDocument> annotationDocuments = entityManager.createQuery("FROM AnnotationDocument WHERE project = :project AND user in (:users)", AnnotationDocument.class).setParameter("project", aProject).setParameter("users", users).getResultList();
    for (AnnotationDocument annotationDocument : annotationDocuments) {
        if (annotationDocument.getState().equals(AnnotationDocumentState.IGNORE)) {
            ignored++;
        }
    }
    return listSourceDocuments(aProject).size() * users.size() - ignored;
}
Also used : AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)

Example 5 with AnnotationDocument

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

the class DocumentServiceImpl method writeAnnotationCas.

@Override
@Transactional
public void writeAnnotationCas(JCas aJcas, SourceDocument aDocument, User aUser, boolean aUpdateTimestamp) throws IOException {
    AnnotationDocument annotationDocument = getAnnotationDocument(aDocument, aUser);
    writeAnnotationCas(aJcas, annotationDocument, aUpdateTimestamp);
}
Also used : AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) Transactional(org.springframework.transaction.annotation.Transactional)

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