From f7d959e0ab55498150031489cb2286531a9b6075 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Fri, 2 Sep 2022 12:41:20 +0200 Subject: [PATCH] Expose CC-CEDICT bytes as a Go module --- README.md | 24 +++++++++++++++++++++++- cedict.go | 16 ++++++++++++++++ cedict_test.go | 9 +++++++++ go.mod | 3 +++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 cedict.go create mode 100644 cedict_test.go create mode 100644 go.mod diff --git a/README.md b/README.md index af8a301..3edf608 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,29 @@ characters. MDBG Chinese-English dictionary -The original dictionary is available as a plain text file. +The original dictionary is available as a plain text file. In addition to that, +this repository is a Go module, which allows for easy consumption of the +dictionary bytes from a Go program. + +```go +package main + +import ( + "os" + + "github.com/rhcarvalho/cedict" +) + +func main() { + os.Stdout.Write(append(cedict.Bytes[:200], []byte("...\n")...)) +} +``` + + # License diff --git a/cedict.go b/cedict.go new file mode 100644 index 0000000..ec91541 --- /dev/null +++ b/cedict.go @@ -0,0 +1,16 @@ +// Package cedict provides an embedded copy of the [CC-CEDICT] Chinese to +// English word dictionary. +// +// [CC-CEDICT]: https://www.mdbg.net/chinese/dictionary?page=cc-cedict +package cedict + +import _ "embed" + +// Bytes are the raw bytes of the dictionary. +// +// The format is described on the [CC-CEDICT Wiki]. +// +// [CC-CEDICT Wiki]: https://cc-cedict.org/wiki/format:syntax +// +//go:embed cedict_1_0_ts_utf-8_mdbg.txt +var Bytes []byte diff --git a/cedict_test.go b/cedict_test.go new file mode 100644 index 0000000..6d91bb9 --- /dev/null +++ b/cedict_test.go @@ -0,0 +1,9 @@ +package cedict + +import "testing" + +func TestBytes(t *testing.T) { + if len(Bytes) < 1000 { + t.Error("too few bytes") + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ebcfc8f --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/rhcarvalho/cedict + +go 1.19