use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter in project webanno by webanno.
the class SuggestionBuilder method createCurationCas.
/**
* For the first time a curation page is opened, create a MergeCas that contains only agreeing
* annotations Using the CAS of the curator user.
*
* @param aState
* the annotator state
* @param aRandomAnnotationDocument
* an annotation document.
* @param aCasses
* the CASes
* @param aAnnotationLayers
* the layers.
* @return the CAS.
* @throws IOException
* if an I/O error occurs.
*/
private CAS createCurationCas(AnnotatorState aState, AnnotationDocument aRandomAnnotationDocument, Map<String, CAS> aCasses, List<AnnotationLayer> aAnnotationLayers, boolean aMergeIncompleteAnnotations) throws IOException, UIMAException, AnnotationException {
Validate.notNull(aState, "State must be specified");
Validate.notNull(aRandomAnnotationDocument, "Annotation document must be specified");
// We need a modifiable copy of some annotation document which we can use to initialize
// the curation CAS. This is an exceptional case where BYPASS is the correct choice
CAS mergeCas = documentService.readAnnotationCas(aRandomAnnotationDocument, UNMANAGED_ACCESS);
List<DiffAdapter> adapters = getDiffAdapters(schemaService, aState.getAnnotationLayers());
DiffResult diff;
try (StopWatch watch = new StopWatch(log, "CasDiff")) {
diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, aCasses, 0, mergeCas.getDocumentText().length()).toResult();
}
try (StopWatch watch = new StopWatch(log, "CasMerge")) {
CasMerge casMerge = new CasMerge(schemaService);
casMerge.setMergeIncompleteAnnotations(aMergeIncompleteAnnotations);
casMerge.reMergeCas(diff, aState.getDocument(), aState.getUser().getUsername(), mergeCas, aCasses);
}
curationDocumentService.writeCurationCas(mergeCas, aRandomAnnotationDocument.getDocument(), false);
return mergeCas;
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter 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.api.DiffAdapter 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.api.DiffAdapter 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;
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter 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;
}
Aggregations