{"id":16971010,"url":"https://github.com/timdream/jszhuyin","last_synced_at":"2025-04-09T04:04:05.570Z","repository":{"id":5754302,"uuid":"6967069","full_name":"timdream/jszhuyin","owner":"timdream","description":"JS 注音：JavaScript 自動選字注音輸入法；\"Smart\" Chinese Zhuyin Input Method in JavaScript.","archived":false,"fork":false,"pushed_at":"2024-10-10T14:22:17.000Z","size":10212,"stargazers_count":223,"open_issues_count":21,"forks_count":18,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-02T03:07:05.010Z","etag":null,"topics":["chinese","demo","input-method","javascript"],"latest_commit_sha":null,"homepage":"https://jszhuyin.timdream.org/","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/timdream.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-12-02T12:45:11.000Z","updated_at":"2025-03-30T11:49:59.000Z","dependencies_parsed_at":"2024-12-01T03:05:17.161Z","dependency_job_id":null,"html_url":"https://github.com/timdream/jszhuyin","commit_stats":{"total_commits":446,"total_committers":8,"mean_commits":55.75,"dds":0.08744394618834084,"last_synced_commit":"51806927cf504d50aaeefedcf659d9900cc82e4c"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timdream%2Fjszhuyin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timdream%2Fjszhuyin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timdream%2Fjszhuyin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timdream%2Fjszhuyin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timdream","download_url":"https://codeload.github.com/timdream/jszhuyin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974715,"owners_count":21026742,"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","demo","input-method","javascript"],"created_at":"2024-10-14T00:48:19.969Z","updated_at":"2025-04-09T04:04:05.512Z","avatar_url":"https://github.com/timdream.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSZhuyin - JS 注音 [![npm version](https://badge.fury.io/js/jszhuyin.svg)](http://badge.fury.io/js/jszhuyin)\n\n\"Smart\" Chinese Zhuyin Input Method in Javascript. Javascript 自動選字注音輸入法。[示範網頁](https://jszhuyin.timdream.org/)。\n\n已知的線上自動選字注音輸入法都是將輸入送至伺服器，這是已知的第一個完全使用前端技術完成的實作，故可支援離線使用。\n\nThis library was intially developed as part of [Mozilla Firefox OS - Gaia](https://github.com/mozilla-b2g/gaia). Desktop front-end demo was initially developed in [Gaia keyboard demo](https://github.com/timdream/gaia-keyboard-demo).\n\n## 軟體授權\n\nMIT License\n\n## CLI 介面\n\n    $ npm install --global jszhuyin\n    ...\n    $ jszhuyin ㄐㄊㄌㄞˊㄒㄧㄝˇㄓㄨˋㄧㄣㄕㄖㄈ\n    今天來寫注音輸入法\n    今天\n    家庭\n    交通\n    具體\n    檢討\n    ...\n\n## 從 NodeJS 呼叫\n\n```javascript\nconst { JSZhuyin } = require('jszhuyin');\nvar jszhuyin = new JSZhuyin();\njszhuyin.load();\n\nvar candidates = [];\njszhuyin.oncandidateschange = function(c) {\n  candidates = c;\n};\njszhuyin.handleKey('ㄐㄊㄌㄞˊㄒㄧㄝˇㄓㄨˋㄧㄣㄕㄖㄈ');\n\nconsole.log(candidates[0][0]); // '今天來寫注音輸入法'\n```\n\n[在 RunKit 試用此範例](https://npm.runkit.com/jszhuyin)。\n\n## 安裝至網站\n\n您可以直接連結 Github 上的檔案：\n\n    \u003cscript type=\"text/javascript\" src=\"https://jszhuyin.timdream.org/lib/client.js\"\u003e\u003c/script\u003e\n    \u003cscript type=\"text/javascript\" src=\"https://jszhuyin.timdream.org/lib/web.js\"\u003e\u003c/script\u003e\n\n準備基本的 HTML 元素（分別為待選字的注音，以及候選字詞），請自行加上適合的 CSS 樣式或是浮動視窗等等：\n\n    \u003cp id=\"composition\"\u003e\u003c/p\u003e\n    \u003col id=\"candidates\"\u003e\u003c/ol\u003e\n\n使用以下程式碼啟動輸入法：\n\n    JSZhuyinServerWorkerLoader.prototype.WORKER_URL =\n      'https://jszhuyin.timdream.org/lib/worker.js';\n    JSZhuyinClient.prototype.DEFAULT_LOADER = JSZhuyinServerWorkerLoader;\n    var webIME = new JSZhuyinWebIME({\n      composition: document.getElementById('composition'),\n      candidatesList: document.getElementById('candidates')\n    });\n\n啟動完成之後，JS 注音即會開始處理鍵盤輸入。\n\n### 虛擬鍵盤\n\n虛擬鍵盤可以將使用者點選的注音符號傳至 `webIME.handleKey(code)`。請確保虛擬鍵盤不會搶走 focus。\n\n## 詞庫\n\n使用 MIT License 授權的[小麥注音](http://mcbopomofo.openvanilla.org)詞庫，由 [mjhsieh](https://github.com/mjhsieh) 維護，基於 [libtabe](http://sourceforge.net/projects/libtabe/)。\n\n使用前請先執行 `npm run grunt data` 從 McBopomofo 產生適用於 JSZhuyin 的詞庫檔案。\n\n## 斷詞演算法\n\n會輸出的候選詞依序有四種：\n\n1. 資料庫中，完整符合輸入的注音組合的所有字詞\n2. 完整符合輸入的注音組合的一個組合結果\n3. 資料庫中，只符合輸入的前幾個注音組合的所有字詞\n4. 打錯的第一個音\n\n其中，(2) 只有在 (1) 沒有找到的時候才會出現，(4) 只有在前面全部都沒有找到的情況才會出現。\n\n(1) 與 (3) 是直接將注音組合切割成可能的單音組合送到資料庫查詢（資料庫存在另外設計的存在 Typed Array 的資料結構內）。\n\n(2) 比較複雜，但也只是窮舉法與積分比較而已（笑）。窮舉是用很簡單的 \u003ca href=\"http://stackoverflow.com/questions/8375439\"\u003eComposition of a natural number\u003c/a\u003e，將單音組合切割成所有可能的單詞送到資料庫查詢與累加積分。積分是小麥注音詞庫提供的。因為組合的結果只會輸出一個，且輸入新的注音符號時新的最高分的組合候選詞一定會包含舊的組合候選詞，所以使用了一系列的快取來加快每個輸入的處理速度，而不是窮舉所有可能的單詞組合再重新排名。\n\n因為是窮舉，如果有正確的詞庫應該可以做其他的 phonetic IME。\n\n## 為何範例頁互動不像正常的桌機智慧注音？\n\n因為 JS 注音是手機輸入法 :-/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimdream%2Fjszhuyin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimdream%2Fjszhuyin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimdream%2Fjszhuyin/lists"}