Search in sources :

Example 46 with SourceDocument

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

the class TwoPairedKappaTest method testTwoUserDiffArcAnnotation.

@Test
public void testTwoUserDiffArcAnnotation() throws Exception {
    Map<User, List<SourceDocument>> userDocs = new HashMap<>();
    userDocs.put(user1, asList(document));
    userDocs.put(user2, asList(document));
    Map<User, JCas> userCases = new HashMap<>();
    userCases.put(user1, kappatestCas.getJCas());
    userCases.put(user2, kappaarcdiff.getJCas());
    Map<SourceDocument, Map<User, JCas>> documentJCases = new HashMap<>();
    documentJCases.put(document, userCases);
    // Check against new impl
    DiffResult diff = CasDiff2.doDiff(Dependency.class, new ArcDiffAdapter(Dependency.class, "Dependent", "Governor", "DependencyType"), LinkCompareBehavior.LINK_TARGET_AS_LABEL, convert(userCases));
    AgreementResult agreement = AgreementUtils.getCohenKappaAgreement(diff, Dependency.class.getName(), "DependencyType", convert(userCases));
    // Asserts
    System.out.printf("Agreement: %s%n", agreement.toString());
    diff.print(System.out);
    assertEquals(0.86153d, agreement.getAgreement(), 0.00001d);
    assertEquals(9, diff.size());
    assertEquals(1, diff.getDifferingConfigurationSets().size());
    assertEquals(0, diff.getIncompleteConfigurationSets().size());
}
Also used : AgreementResult(de.tudarmstadt.ukp.clarin.webanno.curation.agreement.AgreementUtils.AgreementResult) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) ArcDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ArcDiffAdapter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) Dependency(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 47 with SourceDocument

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

the class ProjectCasDoctorPanel method actionRepair.

private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
    casStorageService.disableCache();
    CasDoctor casDoctor = new CasDoctor();
    casDoctor.setApplicationContext(ApplicationContextProvider.getApplicationContext());
    casDoctor.setFatalChecks(false);
    casDoctor.setRepairClasses(formModel.repairs);
    Project project = getModelObject();
    formModel.messageSets = new ArrayList<>();
    for (SourceDocument sd : documentService.listSourceDocuments(project)) {
        {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
            JCas initialCas;
            if (documentService.existsInitialCas(sd)) {
                initialCas = documentService.readInitialCas(sd, false);
            } else {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "Created initial CAS for [" + sd.getName() + "]"));
                initialCas = documentService.createInitialCas(sd, false);
            }
            casDoctor.repair(project, initialCas.getCas(), messageSet.messages);
            CasPersistenceUtils.writeSerializedCas(initialCas, documentService.getCasFile(sd, INITIAL_CAS_PSEUDO_USER));
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
            if (documentService.existsAnnotationCas(ad)) {
                LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
                JCas userCas = documentService.readAnnotationCas(ad, false);
                casDoctor.repair(project, userCas.getCas(), messageSet.messages);
                CasPersistenceUtils.writeSerializedCas(userCas, documentService.getCasFile(ad.getDocument(), ad.getUser()));
                noticeIfThereAreNoMessages(messageSet);
                formModel.messageSets.add(messageSet);
            }
        }
    }
    aTarget.add(this);
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)

Example 48 with SourceDocument

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

the class ProjectCasDoctorPanel method actionCheck.

private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
    casStorageService.disableCache();
    CasDoctor casDoctor = new CasDoctor();
    casDoctor.setApplicationContext(ApplicationContextProvider.getApplicationContext());
    casDoctor.setFatalChecks(false);
    casDoctor.setCheckClasses(CasDoctor.scanChecks());
    Project project = getModelObject();
    formModel.messageSets = new ArrayList<>();
    for (SourceDocument sd : documentService.listSourceDocuments(project)) {
        {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
            JCas initialCas;
            try {
                if (documentService.existsInitialCas(sd)) {
                    initialCas = documentService.readInitialCas(sd, false);
                } else {
                    messageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "No initial CAS for [" + sd.getName() + "]"));
                    initialCas = documentService.createInitialCas(sd, false);
                }
                casDoctor.analyze(project, initialCas.getCas(), messageSet.messages);
            } catch (Exception e) {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error reading initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
                LOG.error("Error reading initial CAS for [" + sd.getName() + "]", e);
            }
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
            if (documentService.existsAnnotationCas(ad)) {
                LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
                JCas userCas = documentService.readAnnotationCas(ad, false);
                casDoctor.analyze(project, userCas.getCas(), messageSet.messages);
                noticeIfThereAreNoMessages(messageSet);
                formModel.messageSets.add(messageSet);
            }
        }
    }
    aTarget.add(this);
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 49 with SourceDocument

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

the class ImportDocumentsPanel method actionImport.

private void actionImport(AjaxRequestTarget aTarget, Form<Void> aForm) {
    aTarget.addChildren(getPage(), IFeedback.class);
    List<FileUpload> uploadedFiles = fileUpload.getFileUploads();
    Project project = projectModel.getObject();
    if (isEmpty(uploadedFiles)) {
        error("No document is selected to upload, please select a document first");
        return;
    }
    if (isNull(project.getId())) {
        error("Project not yet created, please save project details!");
        return;
    }
    for (FileUpload documentToUpload : uploadedFiles) {
        String fileName = documentToUpload.getClientFileName();
        if (documentService.existsSourceDocument(project, fileName)) {
            error("Document " + fileName + " already uploaded ! Delete " + "the document if you want to upload again");
            continue;
        }
        try {
            SourceDocument document = new SourceDocument();
            document.setName(fileName);
            document.setProject(project);
            document.setFormat(importExportService.getReadableFormatId(format.getObject()));
            try (InputStream is = documentToUpload.getInputStream()) {
                documentService.uploadSourceDocument(is, document);
            }
            info("File [" + fileName + "] has been imported successfully!");
        } catch (Exception e) {
            error("Error while uploading document " + fileName + ": " + ExceptionUtils.getRootCauseMessage(e));
            LOG.error(fileName + ": " + e.getMessage(), e);
        }
    }
    WicketUtil.refreshPage(aTarget, getPage());
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) InputStream(java.io.InputStream) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

Example 50 with SourceDocument

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

the class MonitoringPage method getFinishedDocumentsPerUser.

private Map<String, Integer> getFinishedDocumentsPerUser(Project aProject) {
    Map<String, Integer> annotatorsProgress = new HashMap<>();
    if (aProject != null) {
        for (User user : projectService.listProjectUsersWithPermissions(aProject, PermissionLevel.USER)) {
            for (SourceDocument document : documentService.listSourceDocuments(aProject)) {
                if (documentService.isAnnotationFinished(document, user)) {
                    if (annotatorsProgress.get(user.getUsername()) == null) {
                        annotatorsProgress.put(user.getUsername(), 1);
                    } else {
                        int previousValue = annotatorsProgress.get(user.getUsername());
                        annotatorsProgress.put(user.getUsername(), previousValue + 1);
                    }
                }
            }
            if (annotatorsProgress.get(user.getUsername()) == null) {
                annotatorsProgress.put(user.getUsername(), 0);
            }
        }
    }
    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)

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