Skip to content

Commit bfca78a

Browse files
committed
generate indonesian pos, support go mod, and sort before picking results
1 parent 75c2f84 commit bfca78a

File tree

6 files changed

+114260
-45
lines changed

6 files changed

+114260
-45
lines changed

gen.go

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// +build ignore
2+
3+
// This program generates indonesian_pos.go
4+
// It can be invoked by running go generate
5+
6+
package main
7+
8+
import (
9+
"encoding/json"
10+
"io/ioutil"
11+
"os"
12+
"text/template"
13+
)
14+
15+
const FileTemplate = `// This file is generated by go generate, please do not change manually.
16+
17+
package tek
18+
19+
var {{ .VariableName }} = []*Vocab{
20+
{{ range .Data }}{
21+
Id: {{ .Id }},
22+
Word: "{{ .Word }}",
23+
Type: "{{ .Type }}",
24+
},{{ end }}
25+
}
26+
`
27+
28+
type TemplateFiller struct {
29+
VariableName string
30+
Data []*Vocab
31+
}
32+
33+
type Vocab struct {
34+
Id int `json:"id"`
35+
Word string `json:"word"`
36+
Type string `json:"type"`
37+
}
38+
39+
func main() {
40+
pos := []*Vocab{}
41+
fb, err := ioutil.ReadFile("./pos_id.json")
42+
if err != nil {
43+
panic(err)
44+
}
45+
err = json.Unmarshal(fb, &pos)
46+
if err != nil {
47+
panic(err)
48+
}
49+
50+
tmpl, err := template.New("indonesian_pos.go").Parse(FileTemplate)
51+
if err != nil {
52+
panic(err)
53+
}
54+
55+
targetFile, err := os.Create("./indonesian_pos.go")
56+
if err != nil {
57+
panic(err)
58+
}
59+
defer targetFile.Close()
60+
61+
templateFiller := &TemplateFiller{
62+
VariableName: "indonesianPos",
63+
Data: pos,
64+
}
65+
66+
err = tmpl.Execute(targetFile, templateFiller)
67+
if err != nil {
68+
panic(err)
69+
}
70+
}

go.mod

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/JesusIslam/tek
2+
3+
go 1.12
4+
5+
require (
6+
github.com/onsi/ginkgo v1.8.0
7+
github.com/onsi/gomega v1.5.0
8+
)

go.sum

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
2+
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
3+
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
4+
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
5+
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
6+
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
7+
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
8+
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
9+
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
10+
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
11+
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
12+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
13+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
14+
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
15+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
16+
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 commit comments

Comments
 (0)