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
60
61
|
package main
import (
"bufio"
"database/sql"
"flag"
"fmt"
"os"
"strings"
_ "modernc.org/sqlite"
)
/*
https://en.wiktionary.org/wiki/Appendix:Mandarin_Frequency_lists/1-1000
https://lingua.mtsu.edu/chinese-computing/statistics/char/list.php?Which=MO
https://jslearnchinese.wordpress.com/2018/07/24/the-1000-most-used-characters-in-chinese/
*/
var (
verbose = flag.Bool("v", false, "debug output")
file = flag.String("f", "cards", "cards file")
)
func main() {
flag.Parse()
db, err := sql.Open("sqlite", *file)
if err != nil {
panic(err)
}
// Create table
_, err = db.Exec("CREATE TABLE IF NOT EXISTS cards (idx INTEGER PRIMARY KEY, weight INTEGER, key STRING, val STRING)")
if err != nil {
panic(err)
}
f, err := os.Open("list")
if err != nil {
panic(err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
i := 0
for scanner.Scan() {
line := strings.Split(scanner.Text(), "|")
key := line[2]
val := line[3] + " " + strings.Split(line[4], " {")[0]
if *verbose {
fmt.Println(key)
fmt.Println(val)
}
_, err = db.Exec("INSERT INTO cards VALUES(?, ?, ?, ?)", i, 1<<(30-i/50), key, val)
i++
}
}
|