use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter in project webanno by webanno.
the class KrippendorffAlphaAgreementMeasure method calculatePairAgreement.
@Override
public CodingAgreementResult calculatePairAgreement(Map<String, List<CAS>> aCasMap) {
AnnotationFeature feature = getFeature();
KrippendorffAlphaAgreementTraits 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(), traits.isExcludeIncomplete(), aCasMap);
IAgreementMeasure agreement = new KrippendorffAlphaAgreement(agreementResult.getStudy(), new NominalDistanceFunction());
if (agreementResult.getStudy().getItemCount() > 0) {
try {
agreementResult.setAgreement(agreement.calculateAgreement());
} catch (InsufficientDataException e) {
agreementResult.setAgreement(NaN);
}
} else {
agreementResult.setAgreement(NaN);
}
return agreementResult;
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter in project webanno by webanno.
the class CasDiffTest method noDataTest.
@Test
public void noDataTest() throws Exception {
List<DiffAdapter> diffAdapters = new ArrayList<>();
Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
// result.print(System.out);
assertEquals(0, result.size());
assertEquals(0, result.getDifferingConfigurationSets().size());
assertEquals(0, result.getIncompleteConfigurationSets().size());
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter in project webanno by webanno.
the class CasDiff method getDiffAdapters.
public static List<DiffAdapter> getDiffAdapters(AnnotationSchemaService schemaService, Iterable<AnnotationLayer> aLayers) {
List<DiffAdapter> adapters = new ArrayList<>();
nextLayer: for (AnnotationLayer layer : aLayers) {
if (!layer.isEnabled()) {
continue nextLayer;
}
Set<String> labelFeatures = new LinkedHashSet<>();
nextFeature: for (AnnotationFeature f : schemaService.listSupportedFeatures(layer)) {
if (!f.isEnabled()) {
continue nextFeature;
}
// Link features are treated separately from primitive label features
if (!NONE.equals(f.getLinkMode())) {
continue nextFeature;
}
labelFeatures.add(f.getName());
}
DiffAdapter_ImplBase adapter;
switch(layer.getType()) {
case SPAN_TYPE:
{
adapter = new SpanDiffAdapter(layer.getName(), labelFeatures);
break;
}
case RELATION_TYPE:
{
RelationAdapter typeAdpt = (RelationAdapter) schemaService.getAdapter(layer);
adapter = new RelationDiffAdapter(layer.getName(), typeAdpt.getSourceFeatureName(), typeAdpt.getTargetFeatureName(), labelFeatures);
break;
}
default:
LOG.debug("Curation for layer type [{}] not supported - ignoring", layer.getType());
continue nextLayer;
}
adapters.add(adapter);
nextFeature: for (AnnotationFeature f : schemaService.listSupportedFeatures(layer)) {
if (!f.isEnabled()) {
continue nextFeature;
}
switch(f.getLinkMode()) {
case NONE:
// Nothing to do here
break;
case SIMPLE:
adapter.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), null);
break;
case WITH_ROLE:
adapter.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), f.getLinkTypeTargetFeatureName());
break;
default:
throw new IllegalStateException("Unknown link mode [" + f.getLinkMode() + "]");
}
labelFeatures.add(f.getName());
}
}
return adapters;
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter in project webanno by webanno.
the class CasDiff method getAdapter.
private DiffAdapter getAdapter(String aType) {
DiffAdapter adapter = typeAdapters.get(aType);
if (adapter == null) {
LOG.warn("No diff adapter for type [" + aType + "] -- treating as without features");
adapter = new SpanDiffAdapter(aType, emptySet());
typeAdapters.put(aType, adapter);
}
return adapter;
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter 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;
}
Aggregations