Search in sources :

Example 26 with DiffResult

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

the class CasDiffTest method singleDifferencesTest.

@Test
public void singleDifferencesTest() throws Exception {
    Map<String, List<CAS>> casByUser = load("casdiff/singleSpanDifference/user1.conll", "casdiff/singleSpanDifference/user2.conll");
    List<SpanDiffAdapter> diffAdapters = asList(SpanDiffAdapter.POS_DIFF_ADAPTER);
    CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
    DiffResult result = diff.toResult();
    // result.print(System.out);
    assertEquals(1, result.size());
    assertEquals(1, 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(0.0d, 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 27 with DiffResult

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

the class CasMergeSuiteTest method runTest.

@Test
public void runTest() throws Exception {
    Map<String, List<CAS>> casByUser = new HashMap<>();
    List<File> inputFiles = asList(referenceFolder.listFiles((FilenameFilter) new RegexFileFilter("user.*\\.tsv")));
    for (File inputFile : inputFiles) {
        casByUser.put(inputFile.getName(), asList(loadWebAnnoTsv3(inputFile).getCas()));
    }
    JCas curatorCas = createText(casByUser.values().stream().flatMap(Collection::stream).findFirst().get().getDocumentText());
    DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    // result.print(System.out);
    sut.reMergeCas(result, document, null, curatorCas.getCas(), getSingleCasByUser(casByUser));
    writeAndAssertEquals(curatorCas);
}
Also used : FilenameFilter(java.io.FilenameFilter) HashMap(java.util.HashMap) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) JCas(org.apache.uima.jcas.JCas) Collection(java.util.Collection) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) File(java.io.File) Test(org.junit.Test)

Example 28 with DiffResult

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

the class SuggestionViewPanel method init.

/**
 * Initializes the user annotation segments later to be filled with content.
 */
public void init(AjaxRequestTarget aTarget, CurationContainer aCurationContainer, Map<String, Map<Integer, AnnotationSelection>> aAnnotationSelectionByUsernameAndAddress, SourceListView aCurationSegment) throws UIMAException, ClassNotFoundException, IOException {
    AnnotatorState state = aCurationContainer.getState();
    SourceDocument sourceDocument = state.getDocument();
    Map<String, CAS> casses = new HashMap<>();
    // This is the CAS that the user can actively edit
    CAS annotatorCas = getAnnotatorCas(state, aAnnotationSelectionByUsernameAndAddress, sourceDocument, casses);
    // We store the CAS that the user will edit as the "CURATION USER"
    casses.put(CURATION_USER, annotatorCas);
    List<DiffAdapter> adapters = getDiffAdapters(schemaService, state.getAnnotationLayers());
    Map<String, Map<VID, AnnotationState>> annoStates1 = new HashMap<>();
    Project project = state.getProject();
    Mode mode1 = state.getMode();
    DiffResult diff;
    if (mode1.equals(CURATION)) {
        diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, aCurationSegment.getCurationBegin(), aCurationSegment.getCurationEnd()).toResult();
    } else {
        diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, aCurationSegment.getBegin(), aCurationSegment.getEnd()).toResult();
    }
    Collection<ConfigurationSet> d = diff.getDifferingConfigurationSets().values();
    Collection<ConfigurationSet> i = diff.getIncompleteConfigurationSets().values();
    for (ConfigurationSet cfgSet : d) {
        if (i.contains(cfgSet)) {
            i.remove(cfgSet);
        }
    }
    addSuggestionColor(project, mode1, casses, annoStates1, d, false, false);
    addSuggestionColor(project, mode1, casses, annoStates1, i, true, false);
    List<ConfigurationSet> all = new ArrayList<>();
    all.addAll(diff.getConfigurationSets());
    all.removeAll(d);
    all.removeAll(i);
    addSuggestionColor(project, mode1, casses, annoStates1, all, false, true);
    // get differing feature structures
    Map<String, Map<VID, AnnotationState>> annoStates = annoStates1;
    List<String> usernamesSorted = new ArrayList<>(casses.keySet());
    Collections.sort(usernamesSorted);
    final Mode mode = state.getMode();
    boolean isAutomationMode = mode.equals(Mode.AUTOMATION);
    boolean isCorrectionMode = mode.equals(Mode.CORRECTION);
    boolean isCurationMode = mode.equals(Mode.CURATION);
    List<UserAnnotationSegment> segments = new ArrayList<>();
    for (String username : usernamesSorted) {
        if ((!username.equals(CURATION_USER) && isCurationMode) || (username.equals(CURATION_USER) && (isAutomationMode || isCorrectionMode))) {
            CAS cas = casses.get(username);
            // Set up coloring strategy
            ColoringStrategy curationColoringStrategy = makeColoringStrategy(annoStates.get(username));
            // Create curation view for the current user
            UserAnnotationSegment seg = new UserAnnotationSegment();
            seg.setUsername(username);
            seg.setAnnotatorState(state);
            seg.setCollectionData(getCollectionInformation(schemaService, aCurationContainer));
            seg.setDocumentResponse(render(cas, state, curationColoringStrategy));
            seg.setSelectionByUsernameAndAddress(aAnnotationSelectionByUsernameAndAddress);
            segments.add(seg);
        }
    }
    sentenceListView.setModelObject(segments);
    if (aTarget != null) {
        aTarget.add(this);
    }
}
Also used : HashMap(java.util.HashMap) Mode(de.tudarmstadt.ukp.clarin.webanno.model.Mode) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) ColoringStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.ConfigurationSet) CAS(org.apache.uima.cas.CAS) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Map(java.util.Map) HashMap(java.util.HashMap) UserAnnotationSegment(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)

Example 29 with DiffResult

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

the class SuggestionViewPanel method updatePanel.

/**
 * @param aTarget
 *            the AJAX target.
 * @param aCurationContainer
 *            the container.
 * @param aAnnotationSelectionByUsernameAndAddress
 *            selections by user.
 * @param aCurationSegment
 *            the segment.
 * @throws UIMAException
 *             hum?
 * @throws ClassNotFoundException
 *             hum?
 * @throws IOException
 *             hum?
 * @throws AnnotationException
 *             hum?
 */
private void updatePanel(AjaxRequestTarget aTarget, CurationContainer aCurationContainer, Map<String, Map<Integer, AnnotationSelection>> aAnnotationSelectionByUsernameAndAddress, SourceListView aCurationSegment) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
    LOG.trace("call update");
    AnnotatorState state = aCurationContainer.getState();
    if (state.getDocument() == null) {
        return;
    }
    SourceDocument sourceDocument = state.getDocument();
    Map<String, CAS> casses = new HashMap<>();
    // This is the CAS that the user can actively edit
    CAS annotatorCas = getAnnotatorCas(state, aAnnotationSelectionByUsernameAndAddress, sourceDocument, casses);
    // We store the CAS that the user will edit as the "CURATION USER"
    casses.put(CURATION_USER, annotatorCas);
    List<DiffAdapter> adapters = getDiffAdapters(schemaService, state.getAnnotationLayers());
    Map<String, Map<VID, AnnotationState>> annoStates = new HashMap<>();
    Project project = state.getProject();
    Mode mode = state.getMode();
    DiffResult diff;
    if (mode.equals(CURATION)) {
        diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, aCurationSegment.getCurationBegin(), aCurationSegment.getCurationEnd()).toResult();
    } else {
        diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, aCurationSegment.getBegin(), aCurationSegment.getEnd()).toResult();
    }
    Collection<ConfigurationSet> d = diff.getDifferingConfigurationSets().values();
    Collection<ConfigurationSet> i = diff.getIncompleteConfigurationSets().values();
    for (ConfigurationSet cfgSet : d) {
        if (i.contains(cfgSet)) {
            i.remove(cfgSet);
        }
    }
    addSuggestionColor(project, mode, casses, annoStates, d, false, false);
    addSuggestionColor(project, mode, casses, annoStates, i, true, false);
    List<ConfigurationSet> all = new ArrayList<>();
    all.addAll(diff.getConfigurationSets());
    all.removeAll(d);
    all.removeAll(i);
    addSuggestionColor(project, mode, casses, annoStates, all, false, true);
    // get differing feature structures
    sentenceListView.visitChildren(BratSuggestionVisualizer.class, (v, visit) -> {
        BratSuggestionVisualizer vis = (BratSuggestionVisualizer) v;
        UserAnnotationSegment seg = vis.getModelObject();
        CAS cas = casses.get(seg.getUsername());
        if (cas == null) {
            // This may happen if a user has not yet finished document
            return;
        }
        // Set up coloring strategy
        ColoringStrategy curationColoringStrategy = makeColoringStrategy(annoStates.get(seg.getUsername()));
        // Create curation view for the current user
        try {
            seg.setCollectionData(getCollectionInformation(schemaService, aCurationContainer));
            seg.setDocumentResponse(render(cas, state, curationColoringStrategy));
            seg.setAnnotatorState(state);
            seg.setSelectionByUsernameAndAddress(aAnnotationSelectionByUsernameAndAddress);
        } catch (IOException e) {
            error("Unable to render: " + e.getMessage());
            LOG.error("Unable to render", e);
        }
        if (isBlank(vis.getDocumentData())) {
            return;
        }
        vis.render(aTarget);
    });
}
Also used : BratSuggestionVisualizer(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.BratSuggestionVisualizer) HashMap(java.util.HashMap) Mode(de.tudarmstadt.ukp.clarin.webanno.model.Mode) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) ColoringStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) IOException(java.io.IOException) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.ConfigurationSet) CAS(org.apache.uima.cas.CAS) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Map(java.util.Map) HashMap(java.util.HashMap) UserAnnotationSegment(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)

Example 30 with DiffResult

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

the class CohenKappaAgreementMeasureTest method twoEmptyCasTest.

@Test
public void twoEmptyCasTest() throws Exception {
    PairwiseAnnotationResult<CodingAgreementResult> agreement = twoEmptyCasTest(sut);
    CodingAgreementResult result = agreement.getStudy("user1", "user2");
    DiffResult diff = result.getDiff();
    assertEquals(0, diff.size());
    assertEquals(0, diff.getDifferingConfigurationSets().size());
    assertEquals(0, diff.getIncompleteConfigurationSets().size());
    assertEquals(NaN, result.getAgreement(), 0.000001d);
    assertEquals(0, result.getIncompleteSetsByPosition().size());
}
Also used : CodingAgreementResult(de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Test(org.junit.Test)

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