-
Notifications
You must be signed in to change notification settings - Fork 0
/
rank.wok
37 lines (33 loc) · 1.04 KB
/
rank.wok
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
#!/usr/bin/wok -f
/** rank.wok
*
* Usage:
* java -jar wok-0.1.0.jar -f rank.wok -v src=0 -v dst=1 -v grp=1 -v update=true -v@rawstr list=path_to_ranking_file input > output
*
* Option:
* -v src: The index number of the source column.
* -v dst: The index number of the destination column.
* -v grp: The unit size to group members. This value must be larger than zero.
* -v@rawstr list: Path to a ranking file. The first column is used as the ranking criteria.
* -v update: Whether or not update all cells of the column specified by `dst`.
*/
FS = '\t'
FQ = Quote.Min
OFS = '\t'
OFQ = Quote.All
val rank = In.from(list) { _
.zipWithIndex
.map { case (row, i) => row(0) -> i }
.toMap
}
In { _
.filter (_ isDefinedAt src)
.map (_.padTo(dst+1, ""))
.map { row =>
rank.get(row(src)) match {
case Some(v) if (update || row(dst).isEmpty) => row.updated(dst, s"${v / grp + 1}")
case _ => row
}
}
.foreach (row => println(row: _*))
}