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());
}
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);
}
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);
}
}
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);
});
}
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());
}
Aggregations