{"id":16973990,"url":"https://github.com/tiansh/opencc-fsm","last_synced_at":"2025-07-12T12:41:17.311Z","repository":{"id":66160821,"uuid":"247701019","full_name":"tiansh/opencc-fsm","owner":"tiansh","description":"基于 OpenCC 项目的繁简转换词典，利用最早最大匹配的分词方式，将词典转换为状态机","archived":false,"fork":false,"pushed_at":"2021-11-28T06:26:18.000Z","size":4825,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-26T15:47:34.648Z","etag":null,"topics":["chinese-translation","finite-state-machine","opencc","simplified-chinese","traditional-chinese"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/tiansh.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":"2020-03-16T12:50:21.000Z","updated_at":"2021-11-28T06:26:20.000Z","dependencies_parsed_at":"2023-03-10T20:46:04.637Z","dependency_job_id":null,"html_url":"https://github.com/tiansh/opencc-fsm","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":0.07692307692307687,"last_synced_commit":"7150170a45551332a1796646e0635ddb12a77462"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiansh%2Fopencc-fsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiansh%2Fopencc-fsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiansh%2Fopencc-fsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiansh%2Fopencc-fsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiansh","download_url":"https://codeload.github.com/tiansh/opencc-fsm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244868753,"owners_count":20523591,"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-translation","finite-state-machine","opencc","simplified-chinese","traditional-chinese"],"created_at":"2024-10-14T01:04:12.958Z","updated_at":"2025-03-21T21:14:59.346Z","avatar_url":"https://github.com/tiansh.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"基于 OpenCC 项目的繁简转换词典，利用最早最大匹配的分词方式，将词典转换为状态机。单字转换使用词汇表里的第一个结果。\n\n最早最大匹配指，当存在多条规则同时匹配时，优先匹配起始位置最早的，如果起始位置一样，匹配最长的。\n\n## 初衷\n\n做这个项目是因为我的网页小说阅读器想加一个把文字转换成简化字的功能。找了一圈繁简转换的字典，OpenCC 在版权协议上比较宽松，所以选择了这个字典。但是 OpenCC 本身的实现方式太复杂，而且性能上不尽理想。所以着手了这个项目。这里通过将转换规则事先编译成状态机，可以有效提高运行时的性能，在浏览器中转换 10MB 的小说可以在大约 2 到 3 秒内完成。\n\n## 状态机\n\n生成的状态机：\n\n* 状态机是一个数组，0索引\n* 第0个元素是状态机的起始状态\n* 每次输入一个字\n    * 如果当前状态的字典有这个字对应的键：\n        * 输出对应的文本后跳转到指定的状态\n    * 如果这个字不在字典中，且当前不是0状态：\n        * 按照空字符串对应的状态输出和跳转，之后重新处理输入的这个字\n    * 如果这个字不在字典中，且当前是0状态：\n        * 原封不动输出这个字\n* 当转换结束时，如果不在0状态，反复匹配空串对应的状态，直至到达0状态\n\n示例输出的状态机 fsm/\\*.json 由 dict 目录下对应的 txt 生成。\n\n## 词典\n\n项目需要预先将水平制表符分割的词典转换成状态机 JSON 才可以使用。转换仅支持一层的词典，对于在繁简转换后再行应用的地区用词词典，或者需要通过修改词典把他们合并到繁简转换的词典中，或者单独构建一套状态机单独执行。\n\n## 使用\n\nconv 目录下提供了使用产生的状态机的 Python 和 JavaScript 示例代码。\n\n此外任何支持 JSON 的语言都应当可以简单地参考如上的代码实现对应的功能。\n\n## About\n\n本项目使用 MIT 协议释出。但请注意附带的转换结果另有其他项目的版权，与本项目无关。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiansh%2Fopencc-fsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiansh%2Fopencc-fsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiansh%2Fopencc-fsm/lists"}