purohit / go-cc-cedict

Parser for the CC-CEDICT Chinese dictionary.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-cc-cedict

Build Status GoDoc

A parser for the wonderful Chinese <-> English CC-CEDICT project that returns structured entries including definitions, Pinyin, Simplified and Traditional variants, references and abbreviations.

The dictionary as written was not meant for machine consumption, but I'm doing my damndest to parse it for applications.

Usage

You can either use a convenience function to load up the whole dictionary given the raw data file or parse individual lines, as you please.

import (
    "fmt"
    "os"

    cedict "github.com/purohit/go-cc-cedict"
)

f, _ := os.Open("/home/data/cedict_1_0_ts_utf-8_mdbg.txt")
defer f.Close()
dict, _ := cedict.ParseDictionary(f)
for _, entry := range dict.Entries {
    fmt.Println(e)
    break
}

// Or, parse a line yourself:

entry, _ := cedict.ParseEntry("企投 企投 [qi4 tou2] /to have fun (Taiwanese, POJ pr. [chhit-thô])/")
fmt.Println(e.Simplified, e.Pinyin, e.EnglishDefinitions)

Contributing

I'd appreciate contributions that help make Entrys even more specific -- there are a lot of exceptions in the definitions since they're somewhat free-form. For example, adding a specific "Abbreviations" field to the struct where all abbreviations are parsed out instead of remaining in Definitions.

Please add your own tests and make sure the current ones pass! I'm okay with reasonable backwards-incompatibility (I expect this library to be low-usage) via modifications to Entry.

License

The license for this parsing software itself is MIT, however the actual dictionary data is licensed under a CC license (see the main project page for more info).

About

Parser for the CC-CEDICT Chinese dictionary.

License:MIT License


Languages

Language:Go 100.0%