Search in sources :

Example 41 with DiffResult

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.

the class CasMergeTest method copyLinkToExistingButDiffLinkTest.

@Test
public void copyLinkToExistingButDiffLinkTest() throws Exception {
    JCas mergeCas = JCasFactory.createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    Type type = mergeCas.getTypeSystem().getType(CurationTestUtils.HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");
    AnnotationFS mergeFs = makeLinkHostMultiSPanFeatureFS(mergeCas, 0, 0, feature, "A", makeLinkFS(mergeCas, "slot1", 0, 0));
    FeatureStructure copyFS = makeLinkFS(mergeCas, "slot2", 0, 0);
    List<FeatureStructure> linkFs = new ArrayList<>();
    linkFs.add(copyFS);
    WebAnnoCasUtil.setLinkFeatureValue(mergeFs, type.getFeatureByBaseName("links"), linkFs);
    JCas jcasA = createJCas(CurationTestUtils.createMultiLinkWithRoleTestTypeSystem("f1"));
    makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A", makeLinkFS(jcasA, "slot1", 0, 0));
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(mergeCas.getCas()));
    casByUser.put("user2", asList(jcasA.getCas()));
    DiffResult diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    assertEquals(0, diff.getDifferingConfigurationSets().size());
    assertEquals(2, diff.getIncompleteConfigurationSets().size());
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) JCasFactory.createJCas(org.apache.uima.fit.factory.JCasFactory.createJCas) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) FSUtil.getFeature(org.apache.uima.fit.util.FSUtil.getFeature) Feature(org.apache.uima.cas.Feature) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 42 with DiffResult

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.

the class CasDiffTest method singleNoDifferencesTest.

@Test
public void singleNoDifferencesTest() throws Exception {
    Map<String, List<CAS>> casByUser = load("casdiff/singleSpanNoDifference/data.conll", "casdiff/singleSpanNoDifference/data.conll");
    List<? extends DiffAdapter> diffAdapters = asList(new SpanDiffAdapter(POS.class.getName(), "PosValue"));
    CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
    DiffResult result = diff.toResult();
    // result.print(System.out);
    assertEquals(1, result.size());
    assertEquals(0, result.getDifferingConfigurationSets().size());
    assertEquals(0, result.getIncompleteConfigurationSets().size());
// Todo: Agreement has moved to separate project - should create agreement test there
// CodingAgreementResult agreement = getCohenKappaAgreement(diff, entryTypes.get(0),
// "PosValue", casByUser);
// assertEquals(NaN, agreement.getAgreement(), 0.000001d);
// assertEquals(0, agreement.getIncompleteSetsByPosition().size());
}
Also used : SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Test(org.junit.Test)

Example 43 with DiffResult

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.

the class CasDiffTest method noDifferencesPosDependencyTest.

@Test
public void noDifferencesPosDependencyTest() throws Exception {
    Map<String, List<CAS>> casByUser = load("casdiff/noDifferences/data.conll", "casdiff/noDifferences/data.conll");
    List<? extends DiffAdapter> diffAdapters = asList(POS_DIFF_ADAPTER, DEPENDENCY_DIFF_ADAPTER);
    CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
    DiffResult result = diff.toResult();
    // result.print(System.out);
    assertEquals(52, result.size());
    assertEquals(26, result.size(POS.class.getName()));
    assertEquals(26, result.size(Dependency.class.getName()));
    assertEquals(0, result.getDifferingConfigurationSets().size());
    assertEquals(0, result.getIncompleteConfigurationSets().size());
// Todo: Agreement has moved to separate project - should create agreement test there
// CodingAgreementResult agreement = AgreementUtils.getCohenKappaAgreement(diff,
// entryTypes.get(0), "PosValue", casByUser);
// assertEquals(1.0d, agreement.getAgreement(), 0.000001d);
// assertEquals(0, agreement.getIncompleteSetsByPosition().size());
}
Also used : ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Test(org.junit.Test)

Example 44 with DiffResult

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.

the class SuggestionBuilder method buildCurationContainer.

public CurationContainer buildCurationContainer(AnnotatorState aState) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
    CurationContainer curationContainer = new CurationContainer();
    // initialize Variables
    SourceDocument sourceDocument = aState.getDocument();
    Map<Integer, Integer> segmentBeginEnd = new HashMap<>();
    Map<Integer, Integer> segmentNumber = new HashMap<>();
    Map<String, Map<Integer, Integer>> segmentAdress = new HashMap<>();
    // get annotation documents
    List<AnnotationDocument> finishedAnnotationDocuments = new ArrayList<>();
    for (AnnotationDocument annotationDocument : documentService.listAnnotationDocuments(aState.getDocument())) {
        if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
            finishedAnnotationDocuments.add(annotationDocument);
        }
    }
    Map<String, CAS> casses = new HashMap<>();
    AnnotationDocument randomAnnotationDocument = null;
    CAS mergeCas;
    // get the correction/automation CAS for the logged in user
    if (aState.getMode().equals(AUTOMATION) || aState.getMode().equals(CORRECTION)) {
        casses = listCasesforCorrection(randomAnnotationDocument, sourceDocument, aState.getMode());
        mergeCas = getMergeCas(aState, sourceDocument, casses, randomAnnotationDocument, false, false, false);
        String username = casses.keySet().iterator().next();
        updateSegment(aState, segmentBeginEnd, segmentNumber, segmentAdress, casses.get(username), username, aState.getWindowBeginOffset(), aState.getWindowEndOffset());
    } else {
        casses = listCassesforCuration(finishedAnnotationDocuments, aState.getMode());
        mergeCas = getMergeCas(aState, sourceDocument, casses, randomAnnotationDocument, false, false, false);
        updateSegment(aState, segmentBeginEnd, segmentNumber, segmentAdress, mergeCas, CURATION_USER, getFirstSentence(mergeCas).getBegin(), mergeCas.getDocumentText().length());
    }
    segmentAdress.put(CURATION_USER, new HashMap<>());
    Type sentenceType = getType(mergeCas, Sentence.class);
    for (AnnotationFS s : selectCovered(mergeCas, sentenceType, diffRangeBegin, diffRangeEnd)) {
        segmentAdress.get(CURATION_USER).put(s.getBegin(), getAddr(s));
    }
    List<DiffAdapter> adapters = getDiffAdapters(schemaService, aState.getAnnotationLayers());
    long diffStart = System.currentTimeMillis();
    log.debug("Calculating differences...");
    int count = 0;
    for (Integer begin : segmentBeginEnd.keySet()) {
        Integer end = segmentBeginEnd.get(begin);
        count++;
        if (count % 100 == 0) {
            log.debug("Processing differences: {} of {} sentences...", count, segmentBeginEnd.size());
        }
        DiffResult diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, begin, end).toResult();
        SourceListView curationSegment = new SourceListView();
        curationSegment.setBegin(begin);
        curationSegment.setEnd(end);
        curationSegment.setSentenceNumber(segmentNumber.get(begin));
        if (diff.hasDifferences() || !diff.getIncompleteConfigurationSets().isEmpty()) {
            // Is this confSet a diff due to stacked annotations (with same configuration)?
            boolean stackedDiff = false;
            stackedDiffSet: for (ConfigurationSet d : diff.getDifferingConfigurationSets().values()) {
                for (Configuration c : d.getConfigurations()) {
                    if (c.getCasGroupIds().size() != d.getCasGroupIds().size()) {
                        stackedDiff = true;
                        break stackedDiffSet;
                    }
                }
            }
            if (stackedDiff) {
                curationSegment.setSentenceState(DISAGREE);
            } else if (!diff.getIncompleteConfigurationSets().isEmpty()) {
                curationSegment.setSentenceState(DISAGREE);
            } else {
                curationSegment.setSentenceState(AGREE);
            }
        } else {
            curationSegment.setSentenceState(AGREE);
        }
        for (String username : segmentAdress.keySet()) {
            curationSegment.getSentenceAddress().put(username, segmentAdress.get(username).get(begin));
        }
        curationContainer.getCurationViewByBegin().put(begin, curationSegment);
    }
    log.debug("Difference calculation completed in {}ms", (System.currentTimeMillis() - diffStart));
    return curationContainer;
}
Also used : Configuration(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.ConfigurationSet) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) CAS(org.apache.uima.cas.CAS) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DiffResult (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult)44 Test (org.junit.Test)39 Arrays.asList (java.util.Arrays.asList)34 List (java.util.List)34 ArrayList (java.util.ArrayList)31 LinkedHashMap (java.util.LinkedHashMap)25 CAS (org.apache.uima.cas.CAS)16 JCas (org.apache.uima.jcas.JCas)16 JCasFactory.createJCas (org.apache.uima.fit.factory.JCasFactory.createJCas)15 SpanDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter)14 CodingAgreementResult (de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult)11 HashMap (java.util.HashMap)11 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)9 Map (java.util.Map)9 Collection (java.util.Collection)8 Type (org.apache.uima.cas.Type)8 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)7 CasDiff (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff)5 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)5 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)5