Search in sources :

Example 1 with DefaultAgreementTraits

use of de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits in project webanno by webanno.

the class PairwiseCodingAgreementTable method exportAllAgreements.

private IResourceStream exportAllAgreements() {
    return new AbstractResourceStream() {

        private static final long serialVersionUID = 1L;

        @Override
        public InputStream getInputStream() throws ResourceStreamNotFoundException {
            AnnotationFeature feature = getModelObject().getFeature();
            DefaultAgreementTraits traits = getModelObject().getTraits();
            Map<String, List<CAS>> casMap = casMapSupplier.get();
            List<DiffAdapter> adapters = CasDiff.getDiffAdapters(annotationService, asList(feature.getLayer()));
            CasDiff diff = doDiff(adapters, traits.getLinkCompareBehavior(), casMap);
            // AgreementResult agreementResult = AgreementUtils.makeStudy(diff,
            // feature.getLayer().getName(), feature.getName(),
            // pref.excludeIncomplete, casMap);
            // TODO: for the moment, we always include incomplete annotations during this
            // export.
            CodingAgreementResult agreementResult = makeCodingStudy(diff, feature.getLayer().getName(), feature.getName(), false, casMap);
            try {
                return AgreementUtils.generateCsvReport(agreementResult);
            } catch (Exception e) {
                // FIXME Is there some better error handling here?
                LOG.error("Unable to generate report", e);
                throw new ResourceStreamNotFoundException(e);
            }
        }

        @Override
        public void close() throws IOException {
        // Nothing to do
        }
    };
}
Also used : AbstractResourceStream(org.apache.wicket.util.resource.AbstractResourceStream) CasDiff(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff) DefaultAgreementTraits(de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) IOException(java.io.IOException) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 2 with DefaultAgreementTraits

use of de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits in project webanno by webanno.

the class AgreementPage method getCasMap.

public Map<String, List<CAS>> getCasMap() {
    if (agreementForm.featureList.getModelObject() == null) {
        return Collections.emptyMap();
    }
    Project project = agreementForm.featureList.getModelObject().getProject();
    DefaultAgreementTraits traits = (DefaultAgreementTraits) agreementForm.traitsContainer.get(MID_TRAITS).getDefaultModelObject();
    // Avoid reloading the CASes when switching features within the same project
    if (cachedCASes != null && project.equals(cachedProject) && cachedLimitToFinishedDocuments == traits.isLimitToFinishedDocuments()) {
        return cachedCASes;
    }
    List<User> users = projectService.listProjectUsersWithPermissions(project, ANNOTATOR);
    List<SourceDocument> sourceDocuments = documentService.listSourceDocuments(project);
    cachedCASes = new LinkedHashMap<>();
    for (User user : users) {
        List<CAS> cases = new ArrayList<>();
        // Bulk-fetch all source documents for which there is already an annotation document for
        // the user which is faster then checking for their existence individually
        List<SourceDocument> docsForUser = documentService.listAnnotationDocuments(project, user).stream().map(AnnotationDocument::getDocument).distinct().collect(Collectors.toList());
        nextDocument: for (SourceDocument document : sourceDocuments) {
            CAS cas = null;
            try {
                if (docsForUser.contains(document)) {
                    AnnotationDocument annotationDocument = documentService.getAnnotationDocument(document, user);
                    if (traits.isLimitToFinishedDocuments() && !annotationDocument.getState().equals(FINISHED)) {
                        // Add a skip marker (null) for the current CAS to the CAS list - this
                        // is necessary because we expect the CAS lists for all users to have
                        // the same size
                        cases.add(null);
                        continue nextDocument;
                    }
                }
                // Reads the user's annotation document or the initial source document -
                // depending on what is available
                cas = documentService.readAnnotationCas(document, user.getUsername(), AUTO_CAS_UPGRADE, SHARED_READ_ONLY_ACCESS);
            } catch (Exception e) {
                error("Unable to load data: " + ExceptionUtils.getRootCauseMessage(e));
                LOG.error("Unable to load data", e);
            }
            if (cas != null) {
                // Set the CAS name in the DocumentMetaData so that we can pick it
                // up in the Diff position for the purpose of debugging / transparency.
                FeatureStructure dmd = WebAnnoCasUtil.getDocumentMetadata(cas);
                FSUtil.setFeature(dmd, "documentId", document.getName());
                FSUtil.setFeature(dmd, "collectionId", document.getProject().getName());
            }
            // The next line can enter null values into the list if a user didn't work on this
            // source document yet.
            cases.add(cas);
        }
        cachedCASes.put(user.getUsername(), cases);
    }
    cachedProject = project;
    cachedLimitToFinishedDocuments = traits.isLimitToFinishedDocuments();
    return cachedCASes;
}
Also used : User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) NoResultException(javax.persistence.NoResultException) FeatureStructure(org.apache.uima.cas.FeatureStructure) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) CAS(org.apache.uima.cas.CAS) DefaultAgreementTraits(de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits)

Example 3 with DefaultAgreementTraits

use of de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits in project webanno by webanno.

the class CohenKappaAgreementMeasure method calculatePairAgreement.

@Override
public CodingAgreementResult calculatePairAgreement(Map<String, List<CAS>> aCasMap) {
    AnnotationFeature feature = getFeature();
    DefaultAgreementTraits traits = getTraits();
    List<DiffAdapter> adapters = getDiffAdapters(annotationService, asList(feature.getLayer()));
    CasDiff diff = doDiff(adapters, traits.getLinkCompareBehavior(), aCasMap);
    CodingAgreementResult agreementResult = makeCodingStudy(diff, feature.getLayer().getName(), feature.getName(), true, aCasMap);
    IAgreementMeasure agreement = new CohenKappaAgreement(agreementResult.getStudy());
    if (agreementResult.getStudy().getItemCount() > 0) {
        agreementResult.setAgreement(agreement.calculateAgreement());
    } else {
        agreementResult.setAgreement(Double.NaN);
    }
    return agreementResult;
}
Also used : CodingAgreementResult(de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult) CohenKappaAgreement(org.dkpro.statistics.agreement.coding.CohenKappaAgreement) IAgreementMeasure(org.dkpro.statistics.agreement.IAgreementMeasure) CasDiff(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff) DefaultAgreementTraits(de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 4 with DefaultAgreementTraits

use of de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits in project webanno by webanno.

the class FleissKappaAgreementMeasure method calculatePairAgreement.

@Override
public CodingAgreementResult calculatePairAgreement(Map<String, List<CAS>> aCasMap) {
    AnnotationFeature feature = getFeature();
    DefaultAgreementTraits traits = getTraits();
    List<DiffAdapter> adapters = getDiffAdapters(annotationService, asList(feature.getLayer()));
    CasDiff diff = doDiff(adapters, traits.getLinkCompareBehavior(), aCasMap);
    CodingAgreementResult agreementResult = makeCodingStudy(diff, feature.getLayer().getName(), feature.getName(), true, aCasMap);
    IAgreementMeasure agreement = new FleissKappaAgreement(agreementResult.getStudy());
    if (agreementResult.getStudy().getItemCount() > 0) {
        agreementResult.setAgreement(agreement.calculateAgreement());
    } else {
        agreementResult.setAgreement(Double.NaN);
    }
    return agreementResult;
}
Also used : CodingAgreementResult(de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult) IAgreementMeasure(org.dkpro.statistics.agreement.IAgreementMeasure) FleissKappaAgreement(org.dkpro.statistics.agreement.coding.FleissKappaAgreement) CasDiff(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff) DefaultAgreementTraits(de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

DefaultAgreementTraits (de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits)4 CasDiff (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff)3 DiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter)3 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)3 CodingAgreementResult (de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult)2 ArrayList (java.util.ArrayList)2 IAgreementMeasure (org.dkpro.statistics.agreement.IAgreementMeasure)2 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)1 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)1 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)1 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)1 IOException (java.io.IOException)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 NoResultException (javax.persistence.NoResultException)1 CAS (org.apache.uima.cas.CAS)1 FeatureStructure (org.apache.uima.cas.FeatureStructure)1 AbstractResourceStream (org.apache.wicket.util.resource.AbstractResourceStream)1 ResourceStreamNotFoundException (org.apache.wicket.util.resource.ResourceStreamNotFoundException)1 CohenKappaAgreement (org.dkpro.statistics.agreement.coding.CohenKappaAgreement)1