feat: 全面移除OpenCC组件的引用,使用lua重构,现在将拥有更为灵活的转换策略,使用数据库常态化工作,自定义码表更简单,不用担心键值对的重复空格的敏感等问题

This commit is contained in:
amzxyz
2026-01-14 14:22:27 +08:00
parent 3749dded72
commit e41805ea21
27 changed files with 162572 additions and 104375 deletions

View File

@@ -106,11 +106,7 @@ engine:
- lua_filter@*super_filter #comment前,相关功能见Lua文件
- lua_filter@*super_english #comment前,负责英文方案及中英混输中英文单词格式化,语句流,自动加空格等策略
- lua_filter@*super_comment_preedit #OpenCC前超级注释模块、超级preedit支持错词提示、辅助码显示部件组字读音注释有声调、无声调全拼编码的转换支持个性化配置和关闭相应的功能详情搜索super_comment_preedit进行详细配置
- simplifier@emoji #Emoji滤镜
- simplifier@s2t #简繁切换通繁
- simplifier@s2tw #简繁切换台繁
- simplifier@s2hk #简繁切换港繁
- simplifier@chinese_english #中英翻译滤镜
- lua_filter@*super_replacer #用来替代OpenCC的处理器
- lua_filter@*super_sequence*F #手动排序,对高亮候选 ctrl+j左移动 ctrl+k 右移动 ctrl+0 移除位移
- uniquifier #去重
@@ -144,6 +140,62 @@ kp_number_mode: auto
# "compose" : 小键盘数字始终不上屏参与编码
# "auto" : 输入中 push空闲时 commit默认
super_replacer:
db_name: lua/replacer
delimiter: "|"
comment_format: "%s"
chain: true #true表示流水线作业上一个option产出交给下一个处理典型的s2t>t2hk=s2hkfalse就是并行直接用text转换
types:
# 场景1输入 '哈哈' -> 变成 '1.哈哈 2.😄'
- option: emoji # 开关名称与上面开关名称保持一致
mode: append # 新增候选append 替换原候选replace 替换注释comment
comment_mode: none # 注释模式: "append"(默认), "text"(原文), "none"(无)
tags: [abc] # 生效的tag
prefix: "_em_" # 前缀用于区分同一个数据库的不同用途数据
files:
- lua/data/emoji.txt
# 场景2输入 'hello' -> 显示 'hello 〔你好 | 哈喽〕'
- option: chinese_english
mode: append # <--- 添加注释模式
comment_mode: none
tags: [abc]
prefix: "_en_"
files:
- lua/data/english_chinese.txt
- lua/data/chinese_english.txt
# 场景3用于常驻的直接替换 option: true
- option: true
mode: append # <--- 新增候选模式
comment_mode: none
tags: [abc]
prefix: "_ot_"
files:
- lua/data/others.txt
# 场景4用于简繁转换的直接替换
- option: [ s2t, s2hk, s2tw ] #后面依赖这条流水线有一个开关为true这条流水线就能工作
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2t_"
files:
- lua/data/STCharacters.txt
- lua/data/STPhrases.txt
- option: s2hk
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2hk_"
files:
- lua/data/HKVariants.txt
- lua/data/HKVariantsRevPhrases.txt
- option: s2tw
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2tw_"
files:
- lua/data/TWVariants.txt
- lua/data/TWVariantsRevPhrases.txt
#shijian:仅仅作为提示使用编码已经写死引导键可以在key_binder下修改前缀
#时间osj 或者 /sj
#日期orq 或者 /rq
@@ -419,37 +471,6 @@ wanxiang_mixedcode:
comment_format: #这里很重要如果残留带声调字母,剩余编码提示计算出错引发程序崩溃
- xform/^~.+$//
# Emoji
emoji:
option_name: emoji
opencc_config: emoji.json
tags: [abc]
inherit_comment: false
#中文转英文
chinese_english:
option_name: chinese_english
opencc_config: chinese_english.json
tips: char
inherit_comment: false
# 简繁切换
s2t:
option_name: s2t
opencc_config: s2t.json # s2t.json | s2hk.json | s2tw.json | s2twp.json
tips: none # 转换提示: all 都显示 | char 仅单字显示 | none 不显示。
tags: [ abc ] # 限制在对应 tag不对其他如反查的内容做简繁转换
s2hk:
opencc_config: s2hk.json
option_name: s2hk
tags: [abc]
s2tw:
opencc_config: s2tw.json
option_name: s2tw
tags: [abc]
# 部件拆字反查
wanxiang_reverse:
tag: wanxiang_reverse

View File

@@ -67866,7 +67866,7 @@ user user
users users
userdb userdb
username username
UserAgent
User-Agent UserAgent
uses uses
usher usher
ushered ushered

63
lua/data/HKVariants.txt Normal file
View File

@@ -0,0 +1,63 @@
僞 偽
兌 兑
叄 叁
只 只|衹
啓 啓|啟
喫 吃
囪 囱
妝 妝|粧
媼 媪
嬀 媯
悅 悦
慍 愠
戶 户
挩 捝
搵 揾
擡 抬
敓 敚
敘 敍|敘
柺 枴
梲 棁
棱 稜|棱
榲 榅
檯 枱
氳 氲
涗 涚
溫 温
溼 濕
潙 溈
潨 潀
熅 煴
爲 為
癡 痴
皁 皂
祕 秘
稅 税
竈 灶
糉 粽|糉|糭
縕 緼
纔 才
脣 唇
脫 脱
膃 腽
臥 卧
臺 台
菸 煙
蒕 蒀
蔥 葱
蔿 蒍
蘊 藴
蛻 蜕
衆 眾
衛 衞
覈 核
說 説
踊 踴
轀 輼
醞 醖
鉢 缽
鉤 鈎
銳 鋭
鍼 針
閱 閲
鰮 鰛

View File

@@ -0,0 +1,156 @@
一口吃個 一口喫個
一口吃成 一口喫成
一家三口 一家三口
一家五口 一家五口
一家六口 一家六口
一家四口 一家四口
七星巖 七星巖
世胄 世胄
介胄 介冑
傅巖 傅巖
免胄 免冑
冠胄 冠冑
千巖競秀 千巖競秀
千巖萬壑 千巖萬壑
千巖萬谷 千巖萬谷
口吃 口吃
台山 台山
台州 台州
台州地區 台州地區
台州市 台州市
吃口 喫口|吃口
吃口令 吃口令
吃口飯 喫口飯
吃吃 喫喫|吃吃
吃子 喫子|吃子
名胄 名胄
國胄 國胄
圍巖 圍巖
地胄 地胄
壓胄子 壓冑子
士胄 士胄
大巖桐 大巖桐
天台女 天台女
天台宗 天台宗
天台山 天台山
天台縣 天台縣
天潢貴胄 天潢貴胄
奇巖 奇巖
寶胄 寶胄
小巖洞 小巖洞
岫巖縣 岫巖縣
峯巖 峯巖
嵌巖 嵌巖
巉巖 巉巖
巖壁 巖壁
巖居 巖居
巖居穴處 巖居穴處
巖居谷飲 巖居谷飲
巖岸 巖岸
巖巉 巖巉
巖巖 巖巖
巖徼 巖徼
巖手縣 巖手縣
巖村 巖村
巖洞 巖洞
巖流圈 巖流圈
巖牆 巖牆
巖牆之下 巖牆之下
巖畫 巖畫
巖穴 巖穴
巖穴之士 巖穴之士
巖薔薇 巖薔薇
巖邑 巖邑
巖郎 巖郎
巖阻 巖阻
巖陛 巖陛
帝胄 帝胄
幽巖 幽巖
幽棲巖谷 幽棲巖谷
張口 張口
懸巖 懸巖
懸巖峭壁 懸巖峭壁
懸胄 懸冑
攀巖 攀巖
支胄 支胄
教胄 教胄
景胄 景胄
望胄 望胄
末胄 末胄
村胄 村胄
枕巖漱流 枕巖漱流
枝胄 枝胄
氏胄 氏胄
洪胄 洪胄
浙江天台縣 浙江天台縣
清胄 清胄
灰巖殘丘 灰巖殘丘
玄胄 玄胄
甲胄 甲冑
甲胄魚類 甲冑魚類
皇胄 皇胄
石灰巖洞 石灰巖洞
神胄 神胄
簪纓世胄 簪纓世胄
系胄 系胄
紅巖 紅巖
絕巖 絕巖
緒胄 緒胄
纂胄 纂胄
胃口 胃口
胄嗣 胄嗣
胄子 胄子
胄序 胄序
胄族 胄族
胄甲 冑甲
胄監 胄監
胄科 冑科
胄緒 胄緒
胄胤 胄胤
胄裔 胄裔
胄裔繁衍 胄裔繁衍
胄閥 胄閥
胡雪巖 胡雪巖
胤胄 胤胄
苗胄 苗胄
英胄 英胄
華胄 華胄
血胄 血胄
裔胄 裔胄
訓胄 訓胄
試胄 試胄
豪門貴胄 豪門貴胄
貝胄 貝冑
貴胄 貴胄
賢胄 賢胄
蹇吃 蹇吃
躬擐甲胄 躬擐甲冑
遐胄 遐胄
遙胄 遙胄
遙遙華胄 遙遙華胄
遠胄 遠胄
遺胄 遺胄
鄧艾吃 鄧艾吃
重巖疊嶂 重巖疊嶂
金胄 金胄
鎧胄 鎧冑
鑿巖 鑿巖
門胄 門胄
開口 開口
雲巖區 雲巖區
非層巖 非層巖
韓侂胄 韓侂冑
飮胄 飮冑
骨巖巖 骨巖巖
高胄 高胄
魚胄 魚冑
鮮胄 鮮胄
鴻胄 鴻胄
黃巖區 黃巖區
黃巖島 黃巖島
黃炎貴胄 黃炎貴胄
齒胄 齒胄
龍巖 龍巖
龍巖市 龍巖市
龍巖村 龍巖村
龍胄 龍胄

3980
lua/data/STCharacters.txt Normal file

File diff suppressed because it is too large Load Diff

49096
lua/data/STPhrases.txt Normal file

File diff suppressed because it is too large Load Diff

4113
lua/data/TSCharacters.txt Normal file

File diff suppressed because it is too large Load Diff

278
lua/data/TSPhrases.txt Normal file
View File

@@ -0,0 +1,278 @@
一目瞭然 一目了然
上鍊 上链
不瞭解 不了解
么麼 幺麽
么麽 幺麽
乾乾淨淨 干干净净
乾乾脆脆 干干脆脆
乾元 乾元
乾卦 乾卦
乾嘉 乾嘉
乾圖 乾图
乾坤 乾坤
乾坤一擲 乾坤一掷
乾坤再造 乾坤再造
乾坤大挪移 乾坤大挪移
乾宅 乾宅
乾斷 乾断
乾旦 乾旦
乾曜 乾曜
乾清宮 乾清宫
乾盛世 乾盛世
乾紅 乾红
乾綱 乾纲
乾縣 乾县
乾象 乾象
乾造 乾造
乾道 乾道
乾陵 乾陵
乾隆 乾隆
乾隆年間 乾隆年间
乾隆皇帝 乾隆皇帝
二噁英 二𫫇英
以免藉口 以免借口
以功覆過 以功复过
侔德覆載 侔德复载
傢俱 家具
傷亡枕藉 伤亡枕藉
八濛山 八濛山
凌藉 凌借
出醜狼藉 出丑狼藉
函覆 函复
千鍾粟 千锺粟
反反覆覆 反反复复
反覆 反复
反覆思維 反复思维
反覆思量 反复思量
反覆性 反复性
名覆金甌 名复金瓯
哪吒 哪吒
回覆 回复
壺裏乾坤 壶里乾坤
大目乾連冥間救母變文 大目乾连冥间救母变文
宫商角徵羽 宫商角徵羽
射覆 射复
尼乾子 尼乾子
尼乾陀 尼乾陀
幺麼 幺麽
幺麼小丑 幺麽小丑
幺麼小醜 幺麽小丑
康乾 康乾
張法乾 张法乾
彷彿 仿佛
彷徨 彷徨
徵弦 徵弦
徵絃 徵弦
徵羽摩柯 徵羽摩柯
徵聲 徵声
徵調 徵调
徵音 徵音
情有獨鍾 情有独钟|情有独锺
憑藉 凭借
憑藉着 凭借着
手鍊 手链
扭轉乾坤 扭转乾坤
找藉口 找借口
拉鍊 拉链
拉鍊工程 拉链工程
拜覆 拜复
據瞭解 据了解
文錦覆阱 文锦复阱
於世成 於世成
於乎 於乎
於仲完 於仲完
於倫 於伦
於其一 於其一
於則 於则
於勇明 於勇明
於呼哀哉 於呼哀哉
於單 於单
於坦 於坦
於崇文 於崇文
於忠祥 於忠祥
於惟一 於惟一
於戲 於戏
於敖 於敖
於梨華 於梨华
於清言 於清言
於潛 於潜
於琳 於琳
於穆 於穆
於竹屋 於竹屋
於菟 於菟
於邑 於邑
於陵子 於陵子
旋乾轉坤 旋乾转坤
旋轉乾坤 旋转乾坤
旋轉乾坤之力 旋转乾坤之力
明瞭 明了
明覆 明复
書中自有千鍾粟 书中自有千锺粟
有序 有序
朝乾夕惕 朝乾夕惕
木吒 木吒
李乾德 李乾德
李澤鉅 李泽钜
李鍊福 李链福
李鍾郁 李锺郁
樊於期 樊於期
沈沒 沉没
沈沒成本 沉没成本
沈積 沉积
沈船 沉船
沈默 沉默
流徵 流徵
浪蕩乾坤 浪荡乾坤
滑藉 滑借
無序 无序
牴牾 抵牾
牴觸 抵触
狐藉虎威 狐借虎威
珍珠項鍊 珍珠项链
甚鉅 甚钜
申覆 申复
畢昇 毕昇
發覆 发复
瞭如 了如
瞭如指掌 了如指掌
瞭望 瞭望
瞭然 了然
瞭然於心 了然于心
瞭若指掌 了若指掌
瞭解 了解
瞭解到 了解到
示覆 示复
神祇 神祇
稟覆 禀复
竺乾 竺乾
答覆 答复
篤麼 笃麽
簡單明瞭 简单明了
籌畫 筹划
素藉 素借
老態龍鍾 老态龙钟|老态龙锺
肘手鍊足 肘手链足
茵藉 茵借
萬鍾 万锺
蒜薹 蒜薹
蕓薹 芸薹
蕩覆 荡复
蕭乾 萧乾
藉代 借代
藉以 借以
藉助 借助
藉助於 借助于
藉卉 借卉
藉口 借口
藉喻 借喻
藉寇兵 借寇兵
藉寇兵齎盜糧 借寇兵赍盗粮
藉手 借手
藉據 借据
藉故 借故
藉故推辭 借故推辞
藉方 借方
藉條 借条
藉槁 借槁
藉機 借机
藉此 借此
藉此機會 借此机会
藉甚 借甚
藉由 借由
藉着 借着
藉端 借端
藉端生事 借端生事
藉箸代籌 借箸代筹
藉草枕塊 借草枕块
藉藉 藉藉
藉藉无名 藉藉无名
藉詞 借词
藉讀 借读
藉資 借资
衹得 只得
衹見樹木 只见树木
衹見樹木不見森林 只见树木不见森林
袖裏乾坤 袖里乾坤
覆上 复上
覆住 复住
覆信 复信
覆冒 复冒
覆呈 复呈
覆命 复命
覆墓 复墓
覆宗 复宗
覆帳 复帐
覆幬 复帱
覆成 复成
覆按 复按
覆文 复文
覆杯 复杯
覆校 复校
覆瓿 复瓿
覆盂 复盂
覆盆 覆盆
覆盆子 覆盆子
覆盤 覆盘
覆育 复育
覆蕉尋鹿 复蕉寻鹿
覆逆 复逆
覆醢 复醢
覆醬瓿 复酱瓿
覆電 复电
覆露 复露
覆鹿尋蕉 复鹿寻蕉
覆鹿遺蕉 复鹿遗蕉
覆鼎 复鼎
見覆 见复
角徵 角徵
角徵羽 角徵羽
計畫 计划
變徵 变徵
變徵之聲 变徵之声
變徵之音 变徵之音
貂覆額 貂复额
買臣覆水 买臣复水
踅門瞭戶 踅门了户
躪藉 躏借
郭子乾 郭子乾
酒逢知己千鍾少 酒逢知己千锺少
酒逢知己千鍾少話不投機半句多 酒逢知己千锺少话不投机半句多
醞藉 酝借
重覆 重复
金吒 金吒
金鍊 金链
鈞覆 钧复
鉅子 钜子
鉅萬 钜万
鉅防 钜防
鉸鍊 铰链
銀鍊 银链
錢鍾書 钱锺书
鍊墜 链坠
鍊子 链子
鍊形 链形
鍊條 链条
鍊錘 链锤
鍊鎖 链锁
鍛鍾 锻锺
鍾繇 钟繇|锺繇
鍾萬梅 锺万梅
鍾重發 锺重发
鍾鍛 锺锻
鍾馗 锺馗
鎖鍊 锁链
鐵鍊 铁链
鑽石項鍊 钻石项链
雁杳魚沈 雁杳鱼沉
雖覆能復 虽覆能复
電覆 电复
露覆 露复
項鍊 项链
頗覆 颇复
頸鍊 颈链
顛乾倒坤 颠乾倒坤
顛倒乾坤 颠倒乾坤
顧藉 顾借
麼些族 麽些族
黄鍾公 黄锺公
龍鍾 龙钟|龙锺

39
lua/data/TWVariants.txt Normal file
View File

@@ -0,0 +1,39 @@
僞 偽
啓 啟
喫 吃
嫺 嫻
嬀 媯
峯 峰
幺 么
擡 抬
棱 稜
檐 簷
污 汙
泄 洩
潙 溈
潨 潀
爲 為
牀 床
痹 痺
癡 痴
皁 皂
着 著
睾 睪
祕 秘
竈 灶
糉 粽
繮 韁
纔 才
羣 群
脣 唇
蔘 參
蔿 蒍
衆 眾
裏 裡
覈 核
踊 踴
鉢 缽
鍼 針
鮎 鯰
麪 麵
齶 顎

View File

@@ -0,0 +1,68 @@
一口吃個 一口喫個
一口吃成 一口喫成
一家三口 一家三口
一家五口 一家五口
一家六口 一家六口
一家四口 一家四口
凶事 凶事
凶信 凶信
凶兆 凶兆
凶吉 凶吉
凶地 凶地
凶多吉少 凶多吉少
凶宅 凶宅
凶年 凶年
凶德 凶德
凶怪 凶怪
凶日 凶日
凶服 凶服
凶歲 凶歲
凶死 凶死
凶氣 凶氣
凶煞 凶煞
凶燄 凶燄
凶神 凶神
凶禮 凶禮
凶耗 凶耗
凶肆 凶肆
凶荒 凶荒
凶訊 凶訊
凶豎 凶豎
凶身 凶身
凶逆 凶逆
凶門 凶門
口吃 口吃
吃口 喫口|吃口
吃口令 吃口令
吃口飯 喫口飯
吃吃 喫喫|吃吃
吃子 喫子|吃子
合著 合著
吉凶 吉凶
名著 名著
四凶 四凶
大凶 大凶
巨著 巨著
張口 張口
昭著 昭著
歲凶 歲凶
胃口 胃口
著作 著作
著名 著名
著式 著式
著志 著志
著於 著於
著書 著書
著白 著白
著稱 著稱
著者 著者
著述 著述
著錄 著錄
蹇吃 蹇吃
逢凶 逢凶
避凶 避凶
鄧艾吃 鄧艾吃
鉅著 鉅著
開口 開口
閔凶 閔凶
顯著 顯著

54169
lua/data/chinese_english.txt Normal file

File diff suppressed because it is too large Load Diff

4910
lua/data/emoji.txt Normal file

File diff suppressed because it is too large Load Diff

43788
lua/data/english_chinese.txt Normal file

File diff suppressed because it is too large Load Diff

1323
lua/data/others.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
#用户自定义优先级高相同键可以替换默认show所提供的

View File

@@ -3,7 +3,7 @@
--tags: [ abc ] # 检索当前tag的候选
--key: "`" # 输入中反查引导符
--lookup: [ wanxiang_reverse ] #反查滤镜数据库
--data_source: [ comment, db ] # 优先级写在前面优先。即使只写db只要开启enable_tone也能从注释获取声调。
--data_source: [ aux, db ] # 优先级写在前面优先。即使只写db只要开启enable_tone也能从注释获取声调。
--enable_tone: true #启用声调反查
-- 工具函数:转义正则特殊字符
@@ -339,6 +339,13 @@ function f.init(env)
end
function f.func(input, env)
local context = env.engine.context
local seg = context.composition:back()
if not seg or not f.tags_match(seg, env) then
for cand in input:iter() do yield(cand) end
return
end
if #env.data_sources == 0 then
for cand in input:iter() do yield(cand) end
return

403
lua/super_replacer.lua Normal file
View File

@@ -0,0 +1,403 @@
--[[
super_replacer.lua 一个rime OpenCC替代品更灵活地配置能力
https://github.com/amzxyz/rime_wanxiang
by amzxyz
路径检测UserDir > SharedDir
支持 option: true (常驻启用)
super_replacer:
db_name: lua/replacer
delimiter: "|"
comment_format: "%s"
chain: true #true表示流水线作业上一个option产出交给下一个处理典型的s2t>t2hk=s2hkfalse就是并行直接用text转换
types:
# 场景1输入 '哈哈' -> 变成 '1.哈哈 2.😄'
- option: emoji # 开关名称与上面开关名称保持一致
mode: append # 新增候选append 替换原候选replace 替换注释comment
comment_mode: none # 注释模式: "append"(默认), "text"(原文), "none"(无)
tags: [abc] # 生效的tag
prefix: "_em_" # 前缀用于区分同一个数据库的不同用途数据
files:
- lua/data/emoji.txt
# 场景2输入 'hello' -> 显示 'hello 〔你好 | 哈喽〕'
- option: chinese_english
mode: append # <--- 添加注释模式
comment_mode: none
tags: [abc]
prefix: "_en_"
files:
- lua/data/english_chinese.txt
- lua/data/chinese_english.txt
# 场景3用于常驻的直接替换 option: true
- option: true
mode: append # <--- 新增候选模式
comment_mode: none
tags: [abc]
prefix: "_ot_"
files:
- lua/data/others.txt
# 场景4用于简繁转换的直接替换
- option: [ s2t, s2hk, s2tw ] #后面依赖这条流水线有一个开关为true这条流水线就能工作
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2t_"
files:
- lua/data/STCharacters.txt
- lua/data/STPhrases.txt
- option: s2hk
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2hk_"
files:
- lua/data/HKVariants.txt
- lua/data/HKVariantsRevPhrases.txt
- option: s2tw
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2tw_"
files:
- lua/data/TWVariants.txt
- lua/data/TWVariantsRevPhrases.txt
]]
local M = {}
-- 性能优化:本地化常用库函数
local insert = table.insert
local concat = table.concat
local s_match = string.match
local s_gmatch = string.gmatch
local s_format = string.format
local s_byte = string.byte
local s_gsub = string.gsub
local open = io.open
local type = type
-- 基础依赖
local function safe_require(name)
local status, lib = pcall(require, name)
if status then return lib end
return nil
end
local userdb = safe_require("lib/userdb") or safe_require("userdb")
local bit = safe_require("lib/bit") or safe_require("bit")
-- 核心工具函数
local function get_file_hash(path)
local f = open(path, "rb")
if not f then return "NIL" end
if not bit then local s=f:seek("end"); f:close(); return tostring(s) end
local h = 0x811C9DC5
while true do
local chunk = f:read(4096)
if not chunk then break end
for i = 1, #chunk do h=bit.bxor(h,s_byte(chunk,i)); h=(h*0x01000193)%0x100000000; h=bit.band(h,0xFFFFFFFF) end
end
f:close()
return s_format("%08x", h)
end
local function calculate_tasks_signature(tasks)
local sig_parts = {}
for _, task in ipairs(tasks) do
local file_hash = get_file_hash(task.path)
insert(sig_parts, task.prefix .. "@" .. file_hash)
end
return concat(sig_parts, "|")
end
local function rebuild(tasks, db)
if db.empty then db:empty() end
for _, task in ipairs(tasks) do
local txt_path = task.path
local prefix = task.prefix
local f = open(txt_path, "r")
if f then
for line in f:lines() do
if line ~= "" and not s_match(line, "^%s*#") then
local k, v = s_match(line, "^(%S+)%s+(.+)")
if k and v then
v = s_match(v, "^%s*(.-)%s*$")
db:update(prefix .. k, v)
end
end
end
f:close()
else
if log and log.info then log.info("super_replacer: 无法读取文件: " .. txt_path) end
end
end
return true
end
-- 模块接口
function M.init(env)
local ns = env.name_space
ns = s_gsub(ns, "^%*", "")
local config = env.engine.schema.config
local user_dir = rime_api:get_user_data_dir()
local shared_dir = rime_api:get_shared_data_dir()
-- 1. 基础配置
local db_name = config:get_string(ns .. "/db_name") or "lua/replacer"
local delim = config:get_string(ns .. "/delimiter") or "|"
env.delimiter = delim
env.comment_format = config:get_string(ns .. "/comment_format") or "%s"
env.chain = config:get_bool(ns .. "/chain")
if env.chain == nil then env.chain = false end
if delim == " " then env.split_pattern = "%S+"
else local esc = s_gsub(delim, "[%-%.%+%[%]%(%)%$%^%%%?%*]", "%%%1"); env.split_pattern = "([^" .. esc .. "]+)" end
-- 2. 解析 Types
env.types = {}
local tasks = {}
local function resolve_path(relative)
if not relative then return nil end
local user_path = user_dir .. "/" .. relative
local f = open(user_path, "r")
if f then f:close(); return user_path end
local shared_path = shared_dir .. "/" .. relative
f = open(shared_path, "r")
if f then f:close(); return shared_path end
return user_path
end
local types_path = ns .. "/types"
local type_list = config:get_list(types_path)
if type_list then
for i = 0, type_list.size - 1 do
local entry_path = types_path .. "/@" .. i
-- 解析 triggers
local triggers = {}
local opts_keys = {"option", "options"}
for _, key in ipairs(opts_keys) do
local key_path = entry_path .. "/" .. key
local list = config:get_list(key_path)
if list then
for k = 0, list.size - 1 do
local val = config:get_string(key_path .. "/@" .. k)
if val then insert(triggers, val) end
end
else
local val = config:get_string(key_path)
if val then insert(triggers, val) else
if config:get_bool(key_path) == true then insert(triggers, true) end
end
end
end
-- 解析 Tags
local target_tags = nil
local tag_keys = {"tag", "tags"}
for _, key in ipairs(tag_keys) do
local key_path = entry_path .. "/" .. key
local list = config:get_list(key_path)
if list then
if not target_tags then target_tags = {} end
for k = 0, list.size - 1 do
local val = config:get_string(key_path .. "/@" .. k)
if val then target_tags[val] = true end
end
else
local val = config:get_string(key_path)
if val then
if not target_tags then target_tags = {} end
target_tags[val] = true
end
end
end
if #triggers > 0 then
local prefix = config:get_string(entry_path .. "/prefix") or ""
local mode = config:get_string(entry_path .. "/mode") or "append"
-- 模式: "append"(默认), "text"(原文), "none"(无)
local comment_mode = config:get_string(entry_path .. "/comment_mode")
if not comment_mode then comment_mode = "none" end
insert(env.types, {
triggers = triggers,
tags = target_tags,
prefix = prefix,
mode = mode,
comment_mode = comment_mode
})
-- 解析文件
local keys_to_check = {"files", "file"}
for _, key in ipairs(keys_to_check) do
local d_path = entry_path .. "/" .. key
local list = config:get_list(d_path)
if list then
for j = 0, list.size - 1 do
local p = resolve_path(config:get_string(d_path .. "/@" .. j))
if p then insert(tasks, { path = p, prefix = prefix }) end
end
else
local p = resolve_path(config:get_string(d_path))
if p then insert(tasks, { path = p, prefix = prefix }) end
end
end
end
end
end
-- 3. DB 初始化
if not userdb then return end
local ok, db = pcall(function() local d = userdb.LevelDb(db_name); d:open(); return d end)
if ok and db then
env.db = db
local cur_sig = calculate_tasks_signature(tasks)
local old_sig = db:meta_fetch("_sig")
local old_delim = db:meta_fetch("_delim")
if cur_sig ~= old_sig or env.delimiter ~= old_delim then
if rebuild(tasks, db) then
db:meta_update("_sig", cur_sig)
db:meta_update("_delim", env.delimiter)
end
end
else
env.db = nil
end
end
function M.fini(env)
if env.db then env.db:close(); env.db = nil end
end
function M.func(input, env)
if not env.types or #env.types == 0 or not env.db then
for cand in input:iter() do yield(cand) end
return
end
local ctx = env.engine.context
local db = env.db
local types = env.types
local split_pat = env.split_pattern
local comment_fmt = env.comment_format
local is_chain = env.chain
local seg = ctx.composition:back()
local current_seg_tags = seg and seg.tags or {}
for cand in input:iter() do
local current_text = cand.text
local show_main = true
local current_main_comment = cand.comment
local pending_candidates = {}
local comments = {}
for _, t in ipairs(types) do
local is_active = false
for _, trigger in ipairs(t.triggers) do
if trigger == true then is_active = true; break
elseif type(trigger) == "string" and ctx:get_option(trigger) then is_active = true; break end
end
local is_tag_match = true
if t.tags then
is_tag_match = false
for req_tag, _ in pairs(t.tags) do
if current_seg_tags[req_tag] then is_tag_match = true; break end
end
end
if is_active and is_tag_match then
local query_text = is_chain and current_text or cand.text
local key = t.prefix .. query_text
local val = db:fetch(key)
if val then
local mode = t.mode
-- 计算注释内容
local rule_comment = ""
if t.comment_mode == "text" then
rule_comment = cand.text
elseif t.comment_mode == "append" then
rule_comment = cand.comment
else
rule_comment = ""
end
if mode == "comment" then
local parts = {}
for p in s_gmatch(val, split_pat) do insert(parts, p) end
insert(comments, concat(parts, " "))
elseif mode == "replace" then
if is_chain then
local first = true
for p in s_gmatch(val, split_pat) do
if first then
current_text = p
-- 链式替换时更新主候选注释
if t.comment_mode == "none" then
current_main_comment = ""
elseif t.comment_mode == "text" then
current_main_comment = cand.text
end
first = false
else
insert(pending_candidates, { text=p, comment=rule_comment })
end
end
else
show_main = false
for p in s_gmatch(val, split_pat) do
insert(pending_candidates, { text=p, comment=rule_comment })
end
end
elseif mode == "append" then
for p in s_gmatch(val, split_pat) do
insert(pending_candidates, { text=p, comment=rule_comment })
end
end
end
end
end
if #comments > 0 then
local comment_str = concat(comments, " ")
local fmt = s_format(comment_fmt, comment_str)
if cand.comment and cand.comment ~= "" then
cand.comment = cand.comment .. fmt
else
cand.comment = fmt
end
end
if show_main then
if is_chain and current_text ~= cand.text then
local nc = Candidate("kv", cand.start, cand._end, current_text, current_main_comment)
nc.quality = cand.quality
yield(nc)
else
yield(cand)
end
end
for _, item in ipairs(pending_candidates) do
if not (show_main and item.text == current_text) then
local nc = Candidate("kv", cand.start, cand._end, item.text, item.comment)
nc.quality = cand.quality
yield(nc)
end
end
end
end
return M

View File

@@ -43,8 +43,8 @@ tips.status = "pending"
---@type table<string, boolean>
tips.disabled_types = {}
tips.preset_file_path = wanxiang.get_filename_with_fallback("lua/tips/tips_show.txt")
tips.user_override_path = rime_api.get_user_data_dir() .. "/lua/tips/tips_user.txt"
tips.preset_file_path = wanxiang.get_filename_with_fallback("lua/data/tips_show.txt")
tips.user_override_path = rime_api.get_user_data_dir() .. "/lua/data/tips_user.txt"
local META_KEY = {
version = "wanxiang_version",

View File

@@ -1,27 +0,0 @@
{
"name": "Chinese to English",
"segmentation": {
"type": "mmseg",
"dict": {
"type": "text",
"file": "chinese_english.txt"
}
},
"conversion_chain": [
{
"dict": {
"type": "group",
"dicts": [
{
"type": "text",
"file": "chinese_english.txt"
},
{
"type": "text",
"file": "english_chinese.txt"
}
]
}
}
]
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,27 +0,0 @@
{
"name": "Chinese to Emoji",
"segmentation": {
"type": "mmseg",
"dict": {
"type": "text",
"file": "emoji.txt"
}
},
"conversion_chain": [
{
"dict": {
"type": "group",
"dicts": [
{
"type": "text",
"file": "emoji.txt"
},
{
"type": "text",
"file": "others.txt"
}
]
}
}
]
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -101,11 +101,7 @@ engine:
- lua_filter@*super_filter #comment前,相关功能见Lua文件
- lua_filter@*super_english #comment前,负责英文方案及中英混输中英文单词格式化,语句流,自动加空格等策略
- lua_filter@*super_comment_preedit #OpenCC前超级注释模块、超级preedit支持错词提示、辅助码显示部件组字读音注释有声调、无声调全拼编码的转换支持个性化配置和关闭相应的功能详情搜索super_comment_preedit进行详细配置
- simplifier@emoji #Emoji滤镜
- simplifier@s2t #简繁切换通繁
- simplifier@s2tw #简繁切换台繁
- simplifier@s2hk #简繁切换港繁
- simplifier@chinese_english #中英翻译滤镜
- lua_filter@*super_replacer #用来替代OpenCC的处理器
- lua_filter@*super_sequence*F #手动排序,对高亮候选 ctrl+j左移动 ctrl+k 右移动 ctrl+0 移除位移
- uniquifier # 去重
@@ -123,6 +119,63 @@ super_comment: # 超级注释模块,子项配置 true 开启
corrector_type: "comment" # 随意更换左右括号,比如"comment" 不加括号为无括号comment占位不能动
chaifen: "chaifen" # 随意更换左右括号,比如"chaifen" 不加括号为无括号chaifen占位不能动
super_replacer:
db_name: lua/replacer
delimiter: "|"
comment_format: "%s"
chain: true #true表示流水线作业上一个option产出交给下一个处理典型的s2t>t2hk=s2hkfalse就是并行直接用text转换
types:
# 场景1输入 '哈哈' -> 变成 '1.哈哈 2.😄'
- option: emoji # 开关名称与上面开关名称保持一致
mode: append # 新增候选append 替换原候选replace 替换注释comment
comment_mode: none # 注释模式: "append"(默认), "text"(原文), "none"(无)
tags: [abc] # 生效的tag
prefix: "_em_" # 前缀用于区分同一个数据库的不同用途数据
files:
- lua/data/emoji.txt
# 场景2输入 'hello' -> 显示 'hello 〔你好 | 哈喽〕'
- option: chinese_english
mode: append # <--- 添加注释模式
comment_mode: none
tags: [abc]
prefix: "_en_"
files:
- lua/data/english_chinese.txt
- lua/data/chinese_english.txt
# 场景3用于常驻的直接替换 option: true
- option: true
mode: append # <--- 新增候选模式
comment_mode: none
tags: [abc]
prefix: "_ot_"
files:
- lua/data/others.txt
# 场景4用于简繁转换的直接替换
- option: [ s2t, s2hk, s2tw ] #后面依赖这条流水线有一个开关为true这条流水线就能工作
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2t_"
files:
- lua/data/STCharacters.txt
- lua/data/STPhrases.txt
- option: s2hk
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2hk_"
files:
- lua/data/HKVariants.txt
- lua/data/HKVariantsRevPhrases.txt
- option: s2tw
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2tw_"
files:
- lua/data/TWVariants.txt
- lua/data/TWVariantsRevPhrases.txt
# Tips 配置项
tips:
# 禁用的 tips 类型,初始化 tips 数据库的时候会直接忽略相关规则,修改部署后生效
@@ -417,38 +470,6 @@ wanxiang_mixedcode:
comment_format: #这里很重要如果残留带声调字母,剩余编码提示计算出错引发程序崩溃
- xform/.*//
# Emoji
emoji:
option_name: emoji
opencc_config: emoji.json
tags: [abc]
inherit_comment: false
#中文转英文
chinese_english:
option_name: chinese_english
opencc_config: chinese_english.json
tips: char
inherit_comment: false
# 简繁切换
s2t:
option_name: s2t
opencc_config: s2t.json # s2t.json | s2hk.json | s2tw.json | s2twp.json
tips: none # 转换提示: all 都显示 | char 仅单字显示 | none 不显示。
tags: [ abc ] # 限制在对应 tag不对其他如反查的内容做简繁转换
s2hk:
opencc_config: s2hk.json
option_name: s2hk
tags: [abc]
s2tw:
opencc_config: s2tw.json
option_name: s2tw
tags: [abc]
# 部件拆字反查
wanxiang_reverse:
tag: wanxiang_reverse

View File

@@ -81,11 +81,7 @@ engine:
- reverse_lookup_filter@radical_reverse_lookup #部件拆字滤镜放在super_comment前面进一步被超级注释处理以获得拼音编码的提示
- lua_filter@*super_lookup #字词输入中反查辅助筛选
- lua_filter@*super_filter #功能太多详见Lua文件
- simplifier@emoji #Emoji滤镜
- simplifier@s2t #简繁切换通繁
- simplifier@s2tw #简繁切换台繁
- simplifier@s2hk #简繁切换港繁
- simplifier@chinese_english #中英翻译滤镜
- lua_filter@*super_replacer #用来替代OpenCC的处理器
- lua_filter@*super_sequence*F #手动排序,高亮候选 ctrl+j左移动 ctrl+k 右移动 ctrl+0 移除位移
- uniquifier # 去重
@@ -93,12 +89,6 @@ t9:
isDisplayOriginalPreedit: false
super_comment: # 超级注释模块,子项配置 true 开启false 关闭
candidate_length: 1 # 候选词辅助码提醒的生效长度0为关闭 但同时清空其它,应当使用上面开关来处理
corrector_type: "comment" # 错音措字,随意更换左右括号,比如"comment" 不加括号为无括号comment占位不能动
chaifen: "chaifen" # 拆分显示,随意更换左右括号,比如"chaifen" 不加括号为无括号chaifen占位不能动
# Tips 配置项
tips:
# 禁用的 tips 类型,初始化 tips 数据库的时候会直接忽略相关规则,修改部署后生效
@@ -229,36 +219,62 @@ wanxiang_mixedcode:
comment_format:
- xform/.*//
# Emoji
emoji:
option_name: emoji
opencc_config: emoji.json
inherit_comment: false # 在反查中emoji 返回空注释
#中文转英文
chinese_english:
option_name: chinese_english
opencc_config: chinese_english.json
tips: char
inherit_comment: false
# 简繁切换
s2t:
option_name: s2t
opencc_config: s2t.json # s2t.json | s2hk.json | s2tw.json | s2twp.json
tips: none # 转换提示: all 都显示 | char 仅单字显示 | none 不显示。
tags: [ abc ] # 限制在对应 tag不对其他如反查的内容做简繁转换
s2hk:
opencc_config: s2hk.json
option_name: s2hk
tags: [abc]
s2tw:
opencc_config: s2tw.json
option_name: s2tw
tags: [abc]
super_replacer:
db_name: lua/replacer
delimiter: "|"
comment_format: "%s"
chain: true #true表示流水线作业上一个option产出交给下一个处理典型的s2t>t2hk=s2hkfalse就是并行直接用text转换
types:
# 场景1输入 '哈哈' -> 变成 '1.哈哈 2.😄'
- option: emoji # 开关名称与上面开关名称保持一致
mode: append # 新增候选append 替换原候选replace 替换注释comment
comment_mode: none # 注释模式: "append"(默认), "text"(原文), "none"(无)
tags: [abc] # 生效的tag
prefix: "_em_" # 前缀用于区分同一个数据库的不同用途数据
files:
- lua/data/emoji.txt
# 场景2输入 'hello' -> 显示 'hello 〔你好 | 哈喽〕'
- option: chinese_english
mode: append # <--- 添加注释模式
comment_mode: none
tags: [abc]
prefix: "_en_"
files:
- lua/data/english_chinese.txt
- lua/data/chinese_english.txt
# 场景3用于常驻的直接替换 option: true
- option: true
mode: append # <--- 新增候选模式
comment_mode: none
tags: [abc]
prefix: "_ot_"
files:
- lua/data/others.txt
# 场景4用于简繁转换的直接替换
- option: [ s2t, s2hk, s2tw ] #后面依赖这条流水线有一个开关为true这条流水线就能工作
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2t_"
files:
- lua/data/STCharacters.txt
- lua/data/STPhrases.txt
- option: s2hk
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2hk_"
files:
- lua/data/HKVariants.txt
- lua/data/HKVariantsRevPhrases.txt
- option: s2tw
mode: replace # <--- 替换原候选模式
comment_mode: append
tags: [abc]
prefix: "_s2tw_"
files:
- lua/data/TWVariants.txt
- lua/data/TWVariantsRevPhrases.txt
# 部件拆字反查
wanxiang_reverse:
@@ -340,8 +356,8 @@ speller:
# auto_select: true
# auto_select_pattern: ^[a-z]+/|^[a-df-zA-DF-Z]\w{3}|^e\w{4}
# 如果不想让什么标点直接上屏,可以加在 alphabet或者编辑标点符号为两个及以上的映射alphabet就是将字符纳入输入编码的范畴
alphabet: zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA987654321`/\
initials: zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA987654321
alphabet: zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210`/\
initials: zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210
delimiter: " '" # 系统配置,第一位<空格>是拼音之间的分隔符;第二位<'>表示可以手动输入单引号来分割拼音。
visual_delimiter: " " # super_preedit.lua配置是否让分隔符号跟着一起转换例如nǐ'hǎo 在实际使用中表现出视觉拥挤我们可以让delimiter平时是'转换为拼音的时候使用空格nǐ hǎo更符合实际。
tone_isolate: true # super_preedit.lua配置是否将数字声调从转换后拼音中隔离出来true=隔离, false 直接参与转换例如nǐ3