{"id":13656652,"url":"https://github.com/nieldlr/hanzi","last_synced_at":"2025-04-23T22:31:18.170Z","repository":{"id":2750926,"uuid":"3747427","full_name":"nieldlr/hanzi","owner":"nieldlr","description":"HanziJS is a Chinese character and NLP module for Chinese language processing for Node.js","archived":false,"fork":false,"pushed_at":"2020-03-01T09:31:26.000Z","size":29996,"stargazers_count":374,"open_issues_count":15,"forks_count":56,"subscribers_count":30,"default_branch":"master","last_synced_at":"2024-10-02T08:13:18.327Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://hanzijs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nieldlr.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-17T12:18:05.000Z","updated_at":"2024-09-29T16:24:51.000Z","dependencies_parsed_at":"2022-09-08T05:50:38.858Z","dependency_job_id":null,"html_url":"https://github.com/nieldlr/hanzi","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nieldlr%2Fhanzi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nieldlr%2Fhanzi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nieldlr%2Fhanzi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nieldlr%2Fhanzi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nieldlr","download_url":"https://codeload.github.com/nieldlr/hanzi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223936134,"owners_count":17228099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:00:28.761Z","updated_at":"2024-11-10T09:31:40.053Z","avatar_url":"https://github.com/nieldlr.png","language":"JavaScript","funding_links":[],"categories":["Libraries/Packages","JavaScript"],"sub_categories":["Javascript"],"readme":"# HanziJS\n\n[![NPM version](https://img.shields.io/npm/v/hanzi.svg?style=flat-square)](https://npmjs.org/package/hanzi)\n[![Build Status](https://img.shields.io/travis/nieldlr/hanzi/master.svg?style=flat-square)](https://travis-ci.org/nieldlr/hanzi)\n[![Coverage Status](https://img.shields.io/codecov/c/github/nieldlr/hanzi/master.svg?style=flat-square)](https://codecov.io/gh/nieldlr/hanzi/branch/master)\n[![codecov](https://codecov.io/gh/nieldlr/Hanzi/branch/master/graph/badge.svg)](https://codecov.io/gh/nieldlr/hanzi)\n\nHanziJS is a Chinese character and NLP module for Chinese language processing for Node.js. It is primarily written to help provide a framework for Chinese language learners to explore Chinese.\n\nAt present features include:\n\n*   Character decomposition into components\n*   Dictionary definition lookup using CC-CEDICT\n*   Phonetic Regularity Computation\n*   Example Word Calculations\n\nFuture features planned:\n\n* Chinese sentence segmentation\n* Determine regularities and other variables between characters \u0026 their components.\n\nCurrently the data was generated by Gavin Grover\nhttp://groovy.codeplex.com/wikipage?title=cjk-decomp\n\n## Install\n\n```javascript\nnpm install hanzi\n```\n\n## How to use\n### Initiate HanziJS. Required.\n\n```javascript\n//Require\nvar hanzi = require(\"hanzi\");\n//Initiate\nhanzi.start();\n```\n\n### Functions\n\n#### hanzi.decompose(character, type of decomposition);\n\nA function that takes a Chinese character and returns an object with decomposition data. Type of decomposition is optional.\n\nType of decomposition levels:\n\n* 1 - \"Once\" (only decomposes character once),\n* 2 - \"Radical\" (decomposes character into its lowest radical components),\n* 3 - \"Graphical\" (decomposes into lowest forms, will be mostly strokes and small indivisable units)\n\n```javascript\nvar decomposition = hanzi.decompose('爱');\nconsole.log(decomposition);\n\n{ character: '爱',\n  components1: [ 'No glyph available', '友' ],\n  components2: [ '爫', '冖', '𠂇', '又' ],\n  components3: [ '爫', '冖', '𠂇', '㇇', '㇏' ] }\n\n//Example of forced level decomposition\n\nvar decomposition = hanzi.decompose('爱', 2);\nconsole.log(decomposition);\n\n{ character: '爱', components: [ '爫', '冖', '𠂇', '又' ] }\n```\n\n#### hanzi.decomposeMany(character string, type of decomposition);\n\nA function that takes a string of characters and returns one object for all characters.\n\n```javascript\nvar decomposition = hanzi.decomposeMany('爱橄黃');\nconsole.log(decomposition);\n\n{ '爱':\n   { character: '爱',\n     components1: [ 'No glyph available', '友' ],\n     components2: [ '爫', '冖', '𠂇', '又' ],\n     components3: [ '爫', '冖', '𠂇', '㇇', '㇏' ] },\n  '橄':\n   { character: '橄',\n     components1: [ '木', '敢' ],\n     components2: [ '木', 'No glyph available', '耳', '⺙' ],\n     components3: [ '一', '丨', '八', '匚', '二', '丨', '二', '丿', '一', '乂' ] },\n  '黃':\n   { character: '黃',\n     components1: [ '廿', 'No glyph available' ],\n     components2: [ '黃' ],\n     components3: [ '卄', '一', '一', '二', '丨', '凵', '八' ] } }\n```\n\n#### hanzi.ifComponentExists(character/component);\n\nCheck if a component/character exists in the data. Returns boolean value.\n\n```javascript\nconsole.log(hanzi.ifComponentExists('乂'));\n\ntrue\n\nconsole.log(hanzi.ifComponentExists('$'));\n\nfalse\n```\n\n#### hanzi.definitionLookup(character/word, script type);\n\nReturns a dictionary entry object. Script type is optional.\n\nScript type parameters:\n\n*   's' - Simplified\n*   't' - Traditional\n\n```javascript\nconsole.log(hanzi.definitionLookup('雪'));\n\n[ { traditional: '雪',\n    simplified: '雪',\n    pinyin: 'Xue3',\n    definition: 'surname Xue' },\n  { traditional: '雪',\n    simplified: '雪',\n    pinyin: 'xue3',\n    definition: 'snow/snowfall/CL:場|场[chang2]/to have the appearance of snow/to wipe away, off or out/to clean' } ]\n```\n\n#### hanzi.dictionarySearch(characters, search type);\n\nSearches the dictionary based on input. Search type changes what data it returns. Defaults to\n\nSearch type paramaters:\n\n*   'only' - this parameter returns only entries with the characters specfied. This is a means to find all compounds words with the characters specified.\n*   null - returns all occurences of the character.\n\n```javascript\nconsole.log(hanzi.dictionarySearch('雪'));\n\n[ [ { traditional: '下雪',\n      simplified: '下雪',\n      pinyin: 'xia4 xue3',\n      definition: 'to snow' } ],\n  [ { traditional: '似雪',\n      simplified: '似雪',\n      pinyin: 'si4 xue3',\n      definition: 'snowy' } ],\n  [ { traditional: '冰天雪地',\n      simplified: '冰天雪地',\n      pinyin: 'bing1 tian1 xue3 di4',\n      definition: 'a world of ice and snow' } ],\n  [ { traditional: '冰雪',\n      simplified: '冰雪',\n      pinyin: 'bing1 xue3',\n      definition: 'ice and snow' } ],\n  [ { traditional: '冰雪皇后',\n      simplified: '冰雪皇后',\n      pinyin: 'bing1 xue3 huang2 hou4',\n      definition: 'Dairy Queen (brand)' } ],\n  [ { traditional: '冰雪聰明',\n      simplified: '冰雪聪明',\n      pinyin: 'bing1 xue3 cong1 ming5',\n      definition: 'exceptionally intelligent (idiom)' } ],\n  [ { traditional: '各人自掃門前雪，莫管他家瓦上霜',\n      simplified: '各人自扫门前雪，莫管他家瓦上霜',\n      pinyin: 'ge4 ren2 zi4 sao3 men2 qian2 xue3 , mo4 guan3 ta1 jia1 wa3 shang4 shuang1',\n      definition: 'sweep the snow from your own door step, don\\'t worry about the frost on your neighbor\\'s roof (idiom)' } ],\n  [ { traditional: '哈巴雪山',\n      simplified: '哈巴雪山',\n      pinyin: 'Ha1 ba1 xue3 shan1',\n      definition: 'Mt Haba (Nakhi: golden flower), in Lijiang 麗江|丽江, northwest Yunnan' } ],\n  [ { traditional: '單板滑雪',\n      simplified: '单板滑雪',\n      pinyin: 'dan1 ban3 hua2 xue3',\n      definition: 'to snowboard' } ],\n  [ { traditional: '報仇雪恥',\n      simplified: '报仇雪耻',\n      pinyin: 'bao4 chou2 xue3 chi3',\n      definition: 'to take revenge and erase humiliation (idiom)' } ],\n\n[....] //Truncated for display purposes\n\nconsole.log(hanzi.dictionarySearch('心的小孩真', 'only'));\n\n[ [ { traditional: '孩',\n      simplified: '孩',\n      pinyin: 'hai2',\n      definition: 'child' } ],\n  [ { traditional: '小',\n      simplified: '小',\n      pinyin: 'xiao3',\n      definition: 'small/tiny/few/young' } ],\n  [ { traditional: '小孩',\n      simplified: '小孩',\n      pinyin: 'xiao3 hai2',\n      definition: 'child/CL:個|个[ge4]' } ],\n  [ { traditional: '小小',\n      simplified: '小小',\n      pinyin: 'xiao3 xiao3',\n      definition: 'very small/very few/very minor' } ],\n  [ { traditional: '小心',\n      simplified: '小心',\n      pinyin: 'xiao3 xin1',\n      definition: 'to be careful/to take care' } ],\n  [ { traditional: '小的',\n      simplified: '小的',\n      pinyin: 'xiao3 de5',\n      definition: 'I (when talking to a superior)' } ],\n  [ { traditional: '心',\n      simplified: '心',\n      pinyin: 'xin1',\n      definition: 'heart/mind/intention/centre/core/CL:顆|颗[ke1],個|个[ge4]' } ],\n  [ { traditional: '的',\n      simplified: '的',\n      pinyin: 'de5',\n      definition: 'of/~\\'s (possessive particle)/(used after an attribute)/(used to form a nominal expression)/(used at the end of a declarative sentence for emphasis)' },\n    { traditional: '的',\n      simplified: '的',\n      pinyin: 'di2',\n      definition: 'really and truly' },\n    { traditional: '的',\n      simplified: '的',\n      pinyin: 'di4',\n      definition: 'aim/clear' } ],\n  [ { traditional: '真',\n      simplified: '真',\n      pinyin: 'zhen1',\n      definition: 'really/truly/indeed/real/true/genuine' } ],\n  [ { traditional: '真心',\n      simplified: '真心',\n      pinyin: 'zhen1 xin1',\n      definition: 'sincere/heartfelt/CL:片[pian4]' } ],\n  [ { traditional: '真真',\n      simplified: '真真',\n      pinyin: 'zhen1 zhen1',\n      definition: 'really/in fact/genuinely/scrupulously' } ] ]\n\n```\n\n#### hanzi.getExamples(character);\n\nThis function does a dictionarySearch(), then compares that to the Leiden University corpus for vocabulary frequency, then sorts the dictionary entries into three categories in an array: [high frequency, medium frequency and low frequency].\n\nThe frequency categories are determined relative to the frequency distribution of the dictionarySearch data compared to the corpus.\n\n```javascript\nconsole.log(hanzi.getExamples('橄'));\n\n[ [ { traditional: '橄欖',\n      simplified: '橄榄',\n      pinyin: 'gan3 lan3',\n      definition: 'Chinese olive/olive' },\n    { traditional: '橄欖油',\n      simplified: '橄榄油',\n      pinyin: 'gan3 lan3 you2',\n      definition: 'olive oil' } ],\n  [ { traditional: '橄欖球',\n      simplified: '橄榄球',\n      pinyin: 'gan3 lan3 qiu2',\n      definition: 'football played with oval-shaped ball (rugby, American football, Australian rules etc)' } ],\n  [ { traditional: '橄欖枝',\n      simplified: '橄榄枝',\n      pinyin: 'gan3 lan3 zhi1',\n      definition: 'olive branch/symbol of peace' },\n    { traditional: '橄欖樹',\n      simplified: '橄榄树',\n      pinyin: 'gan3 lan3 shu4',\n      definition: 'olive tree' },\n    { traditional: '橄欖石',\n      simplified: '橄榄石',\n      pinyin: 'gan3 lan3 shi2',\n      definition: 'olivine (rock-forming mineral magnesium-iron silicate (Mg,Fe)2SiO4)/peridot' } ] ]\n```\n\n#### hanzi.segment(phrase); - NEW in v0.5.0\n\nReturns an array of characters that are segmented based on a longest match lookup.\n\n````javascript\nconsole.log(hanzi.segment(\"我們都是陌生人。\"));\n\n[ '我們', '都', '是', '陌生人', '。' ]\n````\n\n#### hanzi.getPinyin(character);\n\nReturns all possible pinyin data for a character.\n\n```javascript\nconsole.log(hanzi.getPinyin('的'));\n\n[ 'de5', 'di2', 'di4' ]\n```\n\n#### hanzi.getCharacterFrequency(character);\n\nReturns frequency data for a character based on the Junda corpus. The data is in simplified characters, but I made the function script agnostic. So both traditional and simplified will return the same data.\n\n```javascript\nconsole.log(hanzi.getCharacterFrequency('热'));\n\n{ number: '530',\n  character: '热',\n  count: '31190',\n  percentage: '76.4970999352',\n  pinyin: 're4',\n  meaning: 'heat/to heat up/fervent/hot (of weather)/warm up' }\n```\n\n#### hanzi.getCharacterInFrequencyListByPosition(position); - NEW in v0.7.0\n\nGets a character based on its position the frequency list. This only goes up to 9933 based on the Junda Frequency list.\n\n```javascript\nconsole.log(hanzi.getCharacterInFrequencyListByPosition(111));\n\n{ number: '111',\n  character: '机',\n  count: '339823',\n  percentage: '43.7756134862',\n  pinyin: 'ji1',\n  meaning: 'machine/opportunity/secret' }\n```\n\n#### hanzi.getCharactersWithComponent(component);\n\nReturns an array of characters with the given component. If a component has bound forms, such as 手 and 扌, they're considered the same and returns all the characters with the component.\n\nNB: This feature is new. Data might not be hundred percent correct and consistent.\n\n```javascript\nconsole.log(hanzi.getCharactersWithComponent('囗'));\n\n[ '国','因','西','回','口','四','团','图','围','困','固','园','圆','圈','囚','圃','囤','囿','囡','囫','圜','囵','囹','圄','囝','圉','圊','釦']\n```\n\n#### hanzi.determinePhoneticRegularity(decomposition_object/character);\n\nThis function takes a decomposition object created by hanzi.decompose() or a character, then returns an object that displays all possible combinations of phonetic regularity relationship of the character to all its components.\n\nPhonetic Regularity Scale:\n\n*   0 = No regularity\n*   1 = Exact Match (with tone)\n*   2 = Syllable Match (without tone)\n*   3 = Similar in Initial (alliterates)\n*   4 = Similar in Final (rhymes)\n\nThe object returned is organized by the possible pronunciations of the character. You may notice duplicate entries in the fields, but these are there based on the similarities between the decomposition levels. It is up to the developer to use this data or not.\n\n```javascript\nconsole.log(hanzi.determinePhoneticRegularity('洋'));\n\n{ yang2:\n   { character: '洋',\n     component: [ '氵', '羊', '羊', '氵', '羊', '羊' ],\n     phoneticpinyin: [ 'shui3', 'Yang2', 'yang2', 'shui3', 'Yang2', 'yang2' ],\n     regularity: [ 0, 1, 1, 0, 1, 1 ] } }\n```\n\n#### hanzi.getRadicalMeaning(radical);\n\nReturns a short, usually one-word, meaning of a radical.\n\n```javascript\nconsole.log(hanzi.getRadicalMeaning('氵'));\n\nwater\n```\n\n## Projects\n\nHanziJS is used in the following projects:\n\n* [HanziCraft](http://hanzicraft.com)\n\n## Contributors\n\n* [nieldlr (Author)](http://github.com/nieldlr)\n* [djuretic](http://github.com/djuretic)\n* [nikdvp](http://github.com/nikvdp)\n* [hermanschaaf](http://github.com/hermanschaaf)\n* [raylillywhite](http://github.com/raylillywhite)\n* [zurawiki](http://github.com/zurawiki)\n* [zedwill](http://github.com/zedwill)\n* [mkmoisen](http://github.com/mkmoisen)\n\n## License\n\nHanziJS uses data from various sources:\n\n* [CEDICT](http://cc-cedict.org/wiki/)\n* [Gavin Grover's Decomposition Data](http://cjkdecomp.codeplex.com/license)\n* [Leiden Word Frequency Data](http://lwc.daanvanesch.nl/legal.php)\n* [Jun Da Character Frequency Data](http://lingua.mtsu.edu/chinese-computing/copyright.html)\n\nOther data files are either generated by HanziJS or are not in use at present in the software.\n\nThe MIT License below thus applies to HanziJS as software, not as data. If you want to use HanziJS commercially please do, but please consider the copyright and license of the data. In short, DO NOT SELL THE DATA! For example, do not sell Leiden's Word Frequency list by making users purchase the list. This goes against the terms.\n\nThe MIT License (MIT)\n\nCopyright (c) 2012-2014 Jeremiah Daneil de la Rouviere\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnieldlr%2Fhanzi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnieldlr%2Fhanzi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnieldlr%2Fhanzi/lists"}