Coder Social home page Coder Social logo

chin-dict-lib's Introduction

Project Description

Python library for manipulating WikiCommons Character Info and CEDICT.

Main features

  • Decompose Chinese characters into sub-components with tree-like structure
  • Character data such as radical, stroke number and traditional/simplified form
  • Word lookup for meaning and pronunciation

Installation

chin-dict is available on PyPI at https://pypi.org/project/chin-dict/

pip install chin-dict

Command line tools

To make sure chin-dict is working properly, try looking up a word using the command line

chindict 钱
---------------------------------------------
Character: 钱
Pinyin: ['Qian2', 'qian2']
Meaning: ['surname Qian', 'coin', 'money', 'CL:筆|笔[bi3]', 'unit of weight, one tenth of a tael 兩|两[liang3]']

To see the tree structure, use -t flag

chindict 钱 -t
---------------------------------------------
钱
├── 戋
│   ├── 一
│   └── 戈
│       ├── 丿
│       └── 弋
└── 钅

To lookup as a word instead of a character, use -w flag

chindict 钱 -w
-----------------------------
Simplified: 钱
Traditional: 錢
Pinyin: Qian2
Meaning: ['surname Qian']

Simplified: 钱
Traditional: 錢
Pinyin: qian2
Meaning: ['coin', 'money', 'CL:筆|笔[bi3]', 'unit of weight, one tenth of a tael 兩|两[liang3]']

To see the character's radical, use -r flag

chindict 钱 -r
---------------------------------------------
金

To see meanings of character's or characters' components, use -cm

chindict -cm 你好
-----------------------------
你 meaning(s):
['you (informal, as opposed to courteous 您[nin2])']

好 meaning(s):
['good', 'well', 'proper', 'good to', 'easy to', 'very', 'so', '(suffix indicating completion or readiness)', '(of two people) close', 'on intimate terms', '(after a personal pronoun) hello', 'to be fond of', 'to have a tendency to', 'to be prone to']

To see meanings of character's or characters' radicals, use -cr

chindict -cr 你好
-----------------------------
你 radical:
Radical(人)

好 radical:
Radical(女)

Python demo

from chin_dict.chindict import ChinDict

cd = ChinDict()

char_result = cd.lookup_char("泪")

print()
print("泪 components:")
print()

for component in char_result.components:
	print(component.character + ":", component.meaning)

# 氵: ['"water" radical in Chinese characters (Kangxi radical 85), occurring in 没, 法, 流 etc', 'see also 三點水|三点水[san1 dian3 shui3]']
# 目: ['eye', 'item', 'section', 'list', 'catalogue', 'table of contents', 'order (taxonomy)', 'goal', 'name', 'title']

print()

word_result = cd.lookup_word("发")

print("Translations for 发:")
print()
for word in word_result:
	print(word)

# Simplified: 发
# Traditional: 發
# Pinyin: fa1
# Meaning: ['to send out', "to show (one's feeling)", 'to issue', 'to develop', 'to make a bundle of money', 'classifier for gunshots (rounds)']

# Simplified: 发
# Traditional: 髮
# Pinyin: fa4
# Meaning: ['hair', 'Taiwan pr. [fa3]']

chin-dict-lib's People

Contributors

georgeharvey3 avatar andrewcurriebroughton avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.