aboutsummaryrefslogtreecommitdiff
path: root/examples/gen.go
diff options
context:
space:
mode:
Diffstat (limited to 'examples/gen.go')
-rw-r--r--examples/gen.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/examples/gen.go b/examples/gen.go
new file mode 100644
index 0000000..e25a308
--- /dev/null
+++ b/examples/gen.go
@@ -0,0 +1,60 @@
+package main
+
+import (
+ "bufio"
+ "database/sql"
+ "flag"
+ "fmt"
+ "math/bits"
+ "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")
+var 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<<(bits.LeadingZeros(uint(i))-40), key, val)
+ i++
+ }
+}