This repository has been archived by the owner on Dec 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagreement.groovy
executable file
·55 lines (39 loc) · 1.8 KB
/
agreement.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env groovy
@Grab('org.apache.commons:commons-csv:1.4')
import org.apache.commons.csv.CSVParser
import static org.apache.commons.csv.CSVFormat.TDF
@Grab('org.dkpro.statistics:dkpro-statistics-agreement:2.1.0')
import org.dkpro.statistics.agreement.coding.*
import org.dkpro.statistics.agreement.distance.NominalDistanceFunction
import java.nio.file.Paths
if (args.length != 1) {
System.err.println('Usage: agreement.groovy file.tsv')
System.exit(1)
}
items = new HashMap<String, Map<String, Boolean>>()
workers = new HashMap<String, Integer>()
Paths.get(args[0]).withReader { reader ->
CSVParser csv = new CSVParser(reader, TDF.withHeader())
for (record in csv.iterator()) {
if (record.get('GOLDEN:sense_id')) continue
if (!record.get('ASSIGNMENT:status').equalsIgnoreCase('APPROVED')) continue
taskID = record.get('INPUT:id')
if (!items.containsKey(taskID)) items[taskID] = new HashMap<String, Boolean>()
workerID = record.get('ASSIGNMENT:worker_id')
items[taskID][workerID] = Integer.valueOf(record.get('OUTPUT:sense_id'))
if (!workers.containsKey(workerID)) workers[workerID] = workers.size()
}
}
study = new CodingAnnotationStudy(workers.size())
items.each { taskID, answers ->
study.addItemAsArray(answers.inject(new Integer[workers.size()]) { array, workerID, answer ->
array[workers.get(workerID)] = answer
array
})
}
percent = new PercentageAgreement(study)
printf('PercentageAgreement: %f\n', percent.calculateAgreement())
alphaNominal = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction())
printf('KrippendorffAlphaAgreement: %f\n', alphaNominal.calculateAgreement())
randolphKappa = new RandolphKappaAgreement(study)
printf('RandolphKappaAgreement: %f\n', randolphKappa.calculateAgreement())