package main
import (
"compress/gzip"
"fmt"
"os"
"github.com/themoeway/jmdict-go"
)
func main() {
f, err := os.Open("./JMdict_e.gz")
if err != nil {
fmt.Println(err.Error())
return
}
defer f.Close()
gzReader, err := gzip.NewReader(f)
if err != nil {
fmt.Println(err.Error())
return
}
jdict, _, err := jmdict.LoadJmdict(gzReader)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("there are %d entries in the dictionary.\n", len(jdict.Entries))
kanji := "-"
if len(jdict.Entries[0].Kanji) > 0 {
kanji = jdict.Entries[0].Kanji[0].Expression
}
fmt.Printf("first entry: %s [%s] : %s\n", kanji,
jdict.Entries[0].Readings[0].Reading,
jdict.Entries[0].Sense[0].Glossary[0].Content)
kanji = "-"
last := len(jdict.Entries) - 1
if len(jdict.Entries[last].Kanji) > 0 {
kanji = jdict.Entries[last].Kanji[0].Expression
}
fmt.Printf("last entry: %s [%s] : %s\n", kanji,
jdict.Entries[last].Readings[0].Reading,
jdict.Entries[last].Sense[0].Glossary[0].Content)
}