{"id":20039535,"url":"https://github.com/yishn/chinese-tokenizer","last_synced_at":"2025-04-08T04:19:28.080Z","repository":{"id":57198095,"uuid":"68175739","full_name":"yishn/chinese-tokenizer","owner":"yishn","description":"Tokenizes Chinese texts into words.","archived":false,"fork":false,"pushed_at":"2022-12-21T23:02:41.000Z","size":11776,"stargazers_count":96,"open_issues_count":1,"forks_count":25,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-24T08:10:28.427Z","etag":null,"topics":["chinese","language","tokenizer","words"],"latest_commit_sha":null,"homepage":"https://yishn.github.io/chinese-tokenizer/","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/yishn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://www.paypal.me/yishn/5"}},"created_at":"2016-09-14T05:22:05.000Z","updated_at":"2024-12-01T17:20:09.000Z","dependencies_parsed_at":"2023-01-30T05:01:01.477Z","dependency_job_id":null,"html_url":"https://github.com/yishn/chinese-tokenizer","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yishn%2Fchinese-tokenizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yishn%2Fchinese-tokenizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yishn%2Fchinese-tokenizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yishn%2Fchinese-tokenizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yishn","download_url":"https://codeload.github.com/yishn/chinese-tokenizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247773726,"owners_count":20993639,"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":["chinese","language","tokenizer","words"],"created_at":"2024-11-13T10:37:57.882Z","updated_at":"2025-04-08T04:19:28.062Z","avatar_url":"https://github.com/yishn.png","language":"JavaScript","funding_links":["https://www.paypal.me/yishn/5"],"categories":[],"sub_categories":[],"readme":"# chinese-tokenizer [![Build Status](https://travis-ci.org/yishn/chinese-tokenizer.svg?branch=master)](https://travis-ci.org/yishn/chinese-tokenizer)\n\nSimple algorithm to tokenize Chinese texts into words using [CC-CEDICT](https://cc-cedict.org/). You can try it out at [the demo page](https://yishn.github.io/chinese-tokenizer/). The code for the demo page can be found in the [`gh-pages` branch](https://github.com/yishn/chinese-tokenizer/tree/gh-pages) of this repository.\n\n## How this works\n\nThis tokenizer uses a simple greedy algorithm: It always looks for the longest word in the CC-CEDICT dictionary that matches the input, one at a time.\n\n## Installation\n\nUse npm to install:\n\n~~~\nnpm install chinese-tokenizer --save\n~~~\n\n## Usage\n\nMake sure to provide the [CC-CEDICT](https://cc-cedict.org/) data.\n\n~~~js\nconst tokenize = require('chinese-tokenizer').loadFile('./cedict_ts.u8')\n\nconsole.log(JSON.stringify(tokenize('我是中国人。'), null, '  '))\nconsole.log(JSON.stringify(tokenize('我是中國人。'), null, '  '))\n~~~\n\nOutput:\n\n~~~js\n[\n  {\n    \"text\": \"我\",\n    \"traditional\": \"我\",\n    \"simplified\": \"我\",\n    \"position\": { \"offset\": 0, \"line\": 1, \"column\": 1 },\n    \"matches\": [\n      {\n        \"pinyin\": \"wo3\",\n        \"pinyinPretty\": \"wǒ\",\n        \"english\": \"I/me/my\"\n      }\n    ]\n  },\n  {\n    \"text\": \"是\",\n    \"traditional\": \"是\",\n    \"simplified\": \"是\",\n    \"position\": { \"offset\": 1, \"line\": 1, \"column\": 2 },\n    \"matches\": [\n      {\n        \"pinyin\": \"shi4\",\n        \"pinyinPretty\": \"shì\",\n        \"english\": \"is/are/am/yes/to be\"\n      }\n    ]\n  },\n  {\n    \"text\": \"中國人\",\n    \"traditional\": \"中國人\",\n    \"simplified\": \"中国人\",\n    \"position\": { \"offset\": 2, \"line\": 1, \"column\": 3 },\n    \"matches\": [\n      {\n        \"pinyin\": \"Zhong1 guo2 ren2\",\n        \"pinyinPretty\": \"Zhōng guó rén\",\n        \"english\": \"Chinese person\"\n      }\n    ]\n  },\n  {\n    \"text\": \"。\",\n    \"traditional\": \"。\",\n    \"simplified\": \"。\",\n    \"position\": { \"offset\": 5, \"line\": 1, \"column\": 6 },\n    \"matches\": []\n  }\n]\n~~~\n\n## API\n\n### `chineseTokenizer.loadFile(path)`\n\nReads the [CC-CEDICT](https://cc-cedict.org/) file from given `path` and returns a tokenize function based on the dictionary.\n\n### `chineseTokenizer.load(content)`\n\nParses [CC-CEDICT](https://cc-cedict.org/) string content from `content` and returns a tokenize function based on the dictionary.\n\n### `tokenize(text)`\n\nTokenizes the given `text` string and returns an array with tokens of the following form:\n\n~~~js\n{\n  \"text\": \u003cstring\u003e,\n  \"traditional\": \u003cstring\u003e,\n  \"simplified\": \u003cstring\u003e,\n  \"position\": { \"offset\": \u003cnumber\u003e, \"line\": \u003cnumber\u003e, \"column\": \u003cnumber\u003e },\n  \"matches\": [\n    {\n      \"pinyin\": \u003cstring\u003e,\n      \"pinyinPretty\": \u003cstring\u003e,\n      \"english\": \u003cstring\u003e\n    },\n    ...\n  ]\n}\n~~~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyishn%2Fchinese-tokenizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyishn%2Fchinese-tokenizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyishn%2Fchinese-tokenizer/lists"}