Search in sources :

Example 1 with SourceDocument

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

the class AnnotationPage method getDocumentFromParameters.

private SourceDocument getDocumentFromParameters(Project aProject, StringValue documentParam) {
    SourceDocument document = null;
    if (documentParam != null && !documentParam.isEmpty()) {
        long documentId = documentParam.toLong();
        document = documentService.getSourceDocument(aProject.getId(), documentId);
    }
    return document;
}
Also used : SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)

Example 2 with SourceDocument

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

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

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

the class ImportUtil method createCurationDocumentContent.

/**
 * Copy curation documents from the exported project
 * @param zip the ZIP file.
 * @param aProject the project.
 * @param aRepository the repository service.
 * @throws IOException if an I/O error occurs.
 */
@SuppressWarnings("rawtypes")
public static void createCurationDocumentContent(ZipFile zip, Project aProject, DocumentService aRepository) throws IOException {
    for (Enumeration zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements(); ) {
        ZipEntry entry = (ZipEntry) zipEnumerate.nextElement();
        // Strip leading "/" that we had in ZIP files prior to 2.0.8 (bug #985)
        String entryName = normalizeEntryName(entry);
        if (entryName.startsWith(CURATION_AS_SERIALISED_CAS)) {
            String fileName = entryName.replace(CURATION_AS_SERIALISED_CAS, "");
            // the user annotated the document is file name minus extension
            // (anno1.ser)
            String username = FilenameUtils.getBaseName(fileName).replace(".ser", "");
            // name of the annotation document
            fileName = fileName.replace(FilenameUtils.getName(fileName), "").replace("/", "");
            if (fileName.trim().isEmpty()) {
                continue;
            }
            de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument sourceDocument = aRepository.getSourceDocument(aProject, fileName);
            File annotationFilePath = aRepository.getCasFile(sourceDocument, username);
            FileUtils.copyInputStreamToFile(zip.getInputStream(entry), annotationFilePath);
            LOG.info("Imported curation document content for user [" + username + "] for source document [" + sourceDocument.getId() + "] in project [" + aProject.getName() + "] with id [" + aProject.getId() + "]");
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ZipEntry(java.util.zip.ZipEntry) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 5 with SourceDocument

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

the class ImportUtil method createSourceDocumentContent.

/**
 * copy source document files from the exported source documents
 * @param zip the ZIP file.
 * @param aProject the project.
 * @param aRepository the repository service.
 * @throws IOException if an I/O error occurs.
 */
@SuppressWarnings("rawtypes")
public static void createSourceDocumentContent(ZipFile zip, Project aProject, DocumentService aRepository) throws IOException {
    for (Enumeration zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements(); ) {
        ZipEntry entry = (ZipEntry) zipEnumerate.nextElement();
        // Strip leading "/" that we had in ZIP files prior to 2.0.8 (bug #985)
        String entryName = normalizeEntryName(entry);
        if (entryName.startsWith(SOURCE)) {
            String fileName = FilenameUtils.getName(entryName);
            if (fileName.trim().isEmpty()) {
                continue;
            }
            de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument sourceDocument = aRepository.getSourceDocument(aProject, fileName);
            File sourceFilePath = aRepository.getSourceDocumentFile(sourceDocument);
            FileUtils.copyInputStreamToFile(zip.getInputStream(entry), sourceFilePath);
            LOG.info("Imported content for source document [" + sourceDocument.getId() + "] in project [" + aProject.getName() + "] with id [" + aProject.getId() + "]");
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ZipEntry(java.util.zip.ZipEntry) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ZipFile(java.util.zip.ZipFile) File(java.io.File)

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