-
Notifications
You must be signed in to change notification settings - Fork 0
/
eb-html.wok
33 lines (27 loc) · 1.22 KB
/
eb-html.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
#!/usr/bin/wok -f
/** eb-html.wok
*
* Usage:
* java -jar wok-0.1.0.jar -f eb-html.wok -v src=0 -v dst=1 -v update=true -v@rawstr dic=path_to_epwing_dir -v@rawstr ebmap=path_to_ebmap_file input > output
*
* Option:
* -v src: The index number of the source column.
* -v dst: The index number of the destination column.
* -v@rawstr dic: Path to a directory containing Epwing's CATALOGS file.
* -v@rawstr ebmap: Path to a EBWin3/4 map file corresponding to the EPWING dictionary specified by `dic`.
* -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 eb = "ebquery-0.3.1.jar"
if (eb nonExistent)
eb write Resource.fromURL("https://bitbucket.org/rubyu/ebquery/downloads/ebquery-0.3.1.jar").bytes
def query(s: String) = Seq("java", "-Dfile.encoding=UTF-8", "-jar", eb, "-d", dic, "-f", "html", "-m", "en,tx,sb,sp,em,dc,kw,ls,ec", "--ebmap", ebmap, s).!>.string
In { _
.filter (_ isDefinedAt src)
.map (_.padTo(dst+1, ""))
.map (row => if (update || row(dst).isEmpty) row.updated(dst, query(row(src))) else row)
.foreach (row => println(row: _*))
}