-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleandubs.groovy
60 lines (46 loc) · 1.11 KB
/
cleandubs.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
56
57
58
59
def file = new File("qrels-unclean.csv")
def keys = []
file.splitEachLine("\t"){line ->
keys.add(line[0] + line[2])
}
keys = keys.unique()
//println keys
def qrelsMap = [:]
def lastIdurl
int lastRel = 0
int counter = 1
file.splitEachLine("\t"){line ->
def idurl = line[0] + line[2]
int rel = new Integer(line[3])
if (idurl.equals(lastIdurl)){
counter++
lastRel += rel
}
else {
double tmp_val = lastRel.div(counter)
qrelsMap[lastIdurl] = Math.round(Double.parseDouble(tmp_val.toString()))
qrelsMap[idurl] = Math.round(Double.parseDouble(rel.toString()))
/**if(idurl.startsWith("4946")) {
println "tmp_val: $tmp_val"
println "lastIdurl: $lastIdurl"
println "lastRel $lastRel"
println "counter $counter"
println "${qrelsMap[idurl]}"
println "......"
}**/
lastRel = rel
counter = 1
}
lastIdurl = idurl
}
def out = new File("qrels-clean.csv")
out.delete()
def lastkey
file.splitEachLine("\t"){line ->
def key = line[0] + line[2]
if (key != lastkey && qrelsMap.containsKey(key)){
out << "${line[0]}\t0\t${line[2]}\t${qrelsMap[key]}\n"
}
lastkey = key
}
//println qrelsMap