use of de.tudarmstadt.ukp.clarin.webanno.agreement.results.unitizing.UnitizingAgreementResult in project webanno by webanno.
the class KrippendorffAlphaUnitizingAgreementMeasure method calculatePairAgreement.
public UnitizingAgreementResult calculatePairAgreement(Map<String, List<CAS>> aCasMap) {
String typeName = getFeature().getLayer().getName();
// Calculate a character offset continuum over all CASses. We assume here that the documents
// all have the same size - since the users cannot change the document sizes, this should be
// an universally true assumption.
List<CAS> firstUserCasses = aCasMap.values().stream().findFirst().get();
int docCount = firstUserCasses.size();
int[] docSizes = new int[docCount];
Arrays.fill(docSizes, 0);
for (Entry<String, List<CAS>> set : aCasMap.entrySet()) {
int i = 0;
for (CAS cas : set.getValue()) {
if (cas != null) {
assert docSizes[i] == 0 || docSizes[i] == cas.getDocumentText().length();
docSizes[i] = cas.getDocumentText().length();
}
i++;
}
}
int continuumSize = Arrays.stream(docSizes).sum();
// Create a unitizing study for that continuum.
UnitizingAnnotationStudy study = new UnitizingAnnotationStudy(continuumSize);
// them to the unitizing study based on character offsets.
for (Entry<String, List<CAS>> set : aCasMap.entrySet()) {
int raterIdx = study.addRater(set.getKey());
int docOffset = 0;
int i = 0;
for (CAS cas : set.getValue()) {
// skip it.
if (cas != null) {
Type t = cas.getTypeSystem().getType(typeName);
Feature f = t.getFeatureByBaseName(getFeature().getName());
int currentDocOffset = docOffset;
cas.select(t).map(fs -> (AnnotationFS) fs).forEach(fs -> {
study.addUnit(currentDocOffset + fs.getBegin(), fs.getEnd() - fs.getBegin(), raterIdx, FSUtil.getFeature(fs, f, Object.class));
});
}
docOffset += docSizes[i];
i++;
}
}
UnitizingAgreementResult result = new UnitizingAgreementResult(typeName, getFeature().getName(), study, new ArrayList<>(aCasMap.keySet()), getTraits().isExcludeIncomplete());
IAgreementMeasure agreement = new KrippendorffAlphaUnitizingAgreement(study);
if (result.getStudy().getUnitCount() > 0) {
result.setAgreement(agreement.calculateAgreement());
} else {
result.setAgreement(Double.NaN);
}
return result;
}
use of de.tudarmstadt.ukp.clarin.webanno.agreement.results.unitizing.UnitizingAgreementResult in project webanno by webanno.
the class KrippendorffAlphaUnitizingAgreementMeasure method getAgreement.
@Override
public PairwiseAnnotationResult<UnitizingAgreementResult> getAgreement(Map<String, List<CAS>> aCasMap) {
PairwiseAnnotationResult<UnitizingAgreementResult> result = new PairwiseAnnotationResult<>(getFeature(), getTraits());
List<Entry<String, List<CAS>>> entryList = new ArrayList<>(aCasMap.entrySet());
for (int m = 0; m < entryList.size(); m++) {
for (int n = 0; n < entryList.size(); n++) {
// Triangle matrix mirrored
if (n < m) {
Map<String, List<CAS>> pairwiseCasMap = new LinkedHashMap<>();
pairwiseCasMap.put(entryList.get(m).getKey(), entryList.get(m).getValue());
pairwiseCasMap.put(entryList.get(n).getKey(), entryList.get(n).getValue());
UnitizingAgreementResult res = calculatePairAgreement(pairwiseCasMap);
result.add(entryList.get(m).getKey(), entryList.get(n).getKey(), res);
}
}
}
return result;
}
Aggregations