ECDICT English-to-Chinese Dictionary Database

repository·master·Indexed 27 days ago

https://github.com/skywind3000/ecdict

A comprehensive English-to-Chinese dictionary database featuring hundreds of thousands of words with metadata including exam syllabus tags (CET4, IELTS), corpus frequency rankings, and morphological transformations. It supports CSV, SQLite, and MySQL formats and provides a Python interface via stardict.py for querying, batch processing, and lemma lookups using LemmaDB.

Tokens
1.8K
Snippets
3
Records
9
Agent score
43%

What's inside ECDICT

  1. Use the Simplified English-Chinese Enhanced Edition

    master

    The ECDICT data is used to generate the Simplified English-Chinese Enhanced Edition dictionary. This version is highly optimized for local use and can be loaded into various dictionary applications, including:

    • GoldenDict
    • Eudic (欧陆词典)
    • MDict
    • StarDict
    • BlueDict
    • EDWin
    • Kindle (via Kindle format support)

    This version provides a massive collection of localized vocabulary that works offline, avoiding the latency and ads associated with online dictionaries.

  2. Choose a dictionary format for usage

    master

    ECDICT supports three formats: CSV, SQLite, and MySQL.

    • CSV: The format used on GitHub. It is text-based and ideal for Pull Requests (PRs) and viewing diffs, but slow for local use due to large file sizes.
    • SQLite: The recommended format for local use (e.g., generating Anki cards or personal study tools). It provides fast, near-instant lookups. stardict.py provides a complete interface for SQLite.
    • MySQL: Supported for larger-scale deployments.

    Workflow Tip for Contributors: If you want to make revisions, create a small .csv file for your changes. Use it alongside your large local SQLite .db file by checking the small .csv first, then falling back to the SQLite database. Once your changes are stable, merge them into the main SQLite database or submit them via a CSV-based PR.

  3. Perform Lemma (Stem) Lookups with LemmaDB

    master
    To find the root form (lemma) of a word (e.g., converting 'gave' to 'give'), use the LemmaDB class in stardict.py. This class uses a pre-generated lemma.en.txt derived from the BNC corpus to provide highly accurate lemma lookups, which is more reliable than standard algorithmic approaches.
  4. Use the stardict.py Programming Interface

    master

    The stardict.py script provides a Python interface (compatible with Python 2/3) to interact with the dictionary data via three main classes:

    • DictCsv: For reading/writing the ecdict.csv format.
    • StarDict: For reading/writing SQLite dictionary files.
    • DictMySQL: For reading/writing MySQL dictionary files.

    All three classes implement a unified set of methods for querying and managing data.

  5. Perform fuzzy matching using the `sw` field

    master

    ECDICT includes a hidden field called sw (strip-word). This field is a normalized version of the word where all non-alphanumeric characters are removed and the string is converted to lowercase.

    Normalization Logic:

    def stripword(word):
        return (''.join([ n for n in word if n.isalnum() ])).lower()

    How to use it: When using the match method in stardict.py, pass True as the third parameter to enable fuzzy matching via the sw field.

    • Strict Match (sw parameter is False): Matches the exact string. Searching long-time will only match words starting with long-time (e.g., long-time base).
    • Fuzzy Match (sw parameter is True): Matches based on the normalized sw value. Searching long-time will match any word where the sw field starts with longtime (e.g., longtime, long time, long-time base).

    This is useful for finding different morphological forms of a word (e.g., transitioning from a hyphenated phrase to a single word) that might not be explicitly indexed in other dictionaries.

    # Example of the internal stripword logic used for fuzzy matching
    def stripword(word):
        return (''.join([ n for n in word if n.isalnum() ])).lower()
  6. Query and Manage Dictionary Data with stardict.py

    master

    The following methods are available on the DictCsv, StarDict, and DictMySQL classes:

    • query(id_or_word): Query a word by its integer ID or string. Returns a Python dictionary.
    • match(word, n): Find the n most similar words to the input.
    • query_batch(words): Perform batch queries.
    • count(): Returns the total number of entries in the database.
    • register(data): Register a new word.
    • update(id, **kwargs): Update existing word data (except id and word).
    • remove(id_or_word): Delete a word.
    • commit(): Commit changes to the database.
  7. Understand the ECDICT Data Format

    master

    ECDICT uses a CSV file encoded in UTF-8 to store dictionary entries. Each row represents a word with various metadata including phonetics, definitions, translations, and corpus frequency rankings.

    Note on Excel: Do not open the CSV directly in Excel as it may cause encoding errors. Instead, use the 'Data -> From Text' feature in Excel, select 'Comma' as the delimiter, and specify 'UTF-8' encoding.

    | 字段        | 解释                                                       |
    | ----------- | ---------------------------------------------------------- |
    | word        | 单词名称                                                   |
    | phonetic    | 音标,以英语英标为主                                       |
    | definition  | 单词释义(英文),每行一个释义                             |
    | translation | 单词释义(中文),每行一个释义                             |
    | pos         | 词语位置,用 "/" 分割不同位置                              |
    | collins     | 柯林斯星级                                                 |
    | oxford      | 是否是牛津三千核心词汇                                     |
    | tag         | 字符串标签:zk/中考,gk/高考,cet4/四级 等等标签,空格分割 |
    | bnc         | 英国国家语料库词频顺序                                     |
    | frq         | 当代语料库词频顺序                                         |
    | exchange    | 时态复数等变换,使用 "/" 分割不同项目,见后面表格          |
    | detail      | json 扩展信息,字典形式保存例句(待添加)                  |
    | audio       | 读音音频 url (待添加)                                    |
  8. Interpret Part-of-Speech (POS) Frequency

    master

    The pos field indicates the part-of-speech distribution for a word based on corpus frequency. Multiple parts of speech are separated by /.

    Example: fuse: pos = n:46/v:54 means the word 'fuse' appears as a noun (n) 46% of the time and as a verb (v) 54% of the time.

  9. Parse Word Inflections using the exchange field

    master

    The exchange field provides morphological transformations (inflections) for words. The format uses type:word pairs separated by /.

    Common type codes include:

    • p: Past tense (did)
    • d: Past participle (done)
    • i: Present participle (doing)
    • 3: Third-person singular (does)
    • r: Adjective comparative (-er)
    • t: Adjective superlative (-est)
    • s: Noun plural
    • 0: Lemma (the root form)
    • 1: Lemma's transformation (e.g., s for the plural of apples is apple)
    d:perceived/p:perceived/3:perceives/i:perceiving