;;; pyim-pymap-utils.el --- Utils used to develop pyim-pymap.el file  -*- lexical-binding: t; -*-

;; * Header
;; Copyright (C) 2015-2020 Free Software Foundation, Inc.

;; Author: Feng Shu <tumashu@163.com>
;; Maintainer: Feng Shu <tumashu@163.com>
;; URL: https://github.com/tumashu/pyim
;; Keywords: convenience, Chinese, pinyin, input-method

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; * 说明文档                                                              :doc:

;; 这个文件中包含工具函数 `pyim-pymap-build-pymap'，用于更新 pyim-pymap.el 中
;; `pyim-pymap' 的定义，它使用 libpinyin 项目的 data 文件。
;; 1. [[https://github.com/libpinyin/libpinyin/releases/download/2.6.0/libpinyin-2.6.0.tar.gz][libpinyin-2.6.0.tar.gz]]

;;; Code:
;; * 代码                                                                 :code:
(require 'pyim-common)
(require 'pyim-pymap)

;; 如果改变这个变量的取值，那么 pyim-tests.el 中，许多 tests 都可能需要更新。
(defvar pyim-pymap--commonly-used-cchar
  (cl-remove-if-not
   (lambda (char)
     (string-match-p "\\cc" char))
   (split-string "
的一国在人了有中是年和大业不为发会工经上地市要个产这出行作生家以
成到日民来我部对进多全建他公开们场展时理新方主企资实学报制政济用
同于法高长现本月定化加动合品重关机分力自外者区能设后就等体下万元
社过前面农也得与说之员而务利电文事可种总改三各好金第司其从平代当
天水提商十管内小技位目起海所立已通入量子问度北保心还科委都术使明
着次将增基名向门应里美由规今题记点计去强两些表系办教正条最达特革
收二期并程厂如道际及西口京华任调性导组东路活广意比投决交统党南安
此领结营项情解议义山先车然价放世间因共院步物界集把持无但城相书村
求治取原处府研质信四运县军件育局干队团又造形级标联专少费效据手施
权江近深更认果格几看没职服台式益想数单样只被亿老受优常销志战流很
接乡头给至难观指创证织论别五协变风批见究支那查张精林每转划准做需
传争税构具百或才积势举必型易视快李参回引镇首推思完消值该走装众责
备州供包副极整确知贸己环话反身选亚么带采王策真女谈严斯况色打德告
仅它气料神率识劳境源青护列兴许户马港则节款拉直案股光较河花根布线
土克再群医清速律她族历非感占续师何影功负验望财类货约艺售连纪按讯
史示象养获石食抓富模始住赛客越闻央席坚份士热限米银息校均房周游千
失八检足配存九命尔即防钱评复考依断范础油照段落访未额双让切须儿便
空往你层低奖注黄英承远版维算破铁乐边初满病响药助致善突爱容香称购
届余素请白宣健牌促培竞巴稳继紧字困刘旅声超随例担友号显却监材且春
居适除红半买充陈火搞图阳六察试太什执片古七球修尽控讲排粮武预亲挥
卖审措荣洲卫希店良属险曾围域令站苏龙念罗吨器汇康减习演普田班待星
飞写矿轻扩言章汽靠毛终仍景置底福止离泽波兰核降训逐票菜座献钢眼损
宁像苦印融独湖早予夫编换欧努著顾征升态套介送某斗状画留航派室临兵
补宝略黑综云差纳密贫剧犯阿击遇岁阶烈督吃丰馆招害官树听庭另沙私针
胜贷网愿托缺园假酒音巨既判输讨测读洋括筑欢刚庆久陆找楼激晚绝压故
互签汉草木亩短绍迎吸警藏疗贵纷授登探索湾宏录申诉秀序顺死卡歌午孩
桥喜川邓扬津温船库订练候退违否彩棉帮拿罪币角召灾妇杨奋绩虽煤免笔
够永圳停奥鲜朝吴岛觉移尼急博贯拥束左细舞幅语俄奇般简拍脑债固威券
追筹刻映繁伟甚饭右彻烟沿街血冲洪植誉刊玉厅救潮迅伍怎付倍顿述播励
斤乎纸振旧障鼓艰呼吉男绿尚夏亏季松哈祖典韩遍夜轮板抗摄杂皮贡借幕
罚伤岸扶乱曲脱践危澳童散味叶累谢孙邮雄兼微呢谁惠偿署择染答块徐鱼
赞课盛延瑞怀堂驻零辆齐胡途封似润守毕坦母雨败朱污趋械纺租灵拓残含
握跨衣储瓦蒙鉴析竟骨档秘禁赵宾异伊智钟键辉跃冷倒庄毒仪哪涉泛宗鹏
归岗雷礼尤休泰疾肥珠叫牛宜抵挂寻父攻佳塞架符裁虑肉启丽露鲁秋昌估
射册若宽厚盾硬末轨饮勤茶诗郑冠涨篇泥唱纯坡熟浙晓抢丝锦载笑勇杰患
乌坐雪戏背塔翻沈遗聚渠哥享迹森辽衡掌牧附操赶览野盟殊仁错萨夺梅误
词董潜卷矛腐亮冒盖旗井凡震峰坏倾距壮惊盘梁摆径忠冰峡丹避珍乘刑扎
透迫箱莫跑穿祝乏厦渐软询折浪朋敢诚弱疑邀沉端床络疆缩脚甘贴勒荒唐
静缓侵句尊塑肃怕耕痛援劣伙挑洗暴冬龄乔餐肯廉跟阵伐悉忘闭奔恢宋泉
杯渡吗奉婚赴恩盐掉洁亡洛聘蔬混摩抽鸡剂胆麦谋雅废贺羊阔唯捐返隆穷
辛猪帐饰郭颁灯绕诸伴顶祥谓恶番敏旦劲缴麻屋跳码鞋扣迈忙趣盈棋勃敬
辑摊旺纠炼梦偏渔牙侨黎赔裕宫谷概稿柱弹殖秩凭拨幸洞伪沟姓遭涌陶迁
诺拔畅忧胞丁蓄贝舍腾杀煌圆伦横薄畜毫豪弟呈佛邦您墨徽惯循蓝烧触陕
拖伯盲宪净卢炭籍秦粉妻爆欣释玩俊欠蛋猛迪苗暂貌遵锡楚桂昆杜皇醒燃
凤截铺液撤胶慢杭虚辞曼毅咨俗糖忽芳姐耗妈谊浦频阻允宅窗默胀弃倡灭
甲症埃滨赏莱拒淡坛陵绘虎竹赢锋篮迷纽轿贩递娘圈挖炉替幼乃郊颇戴滑
徒崇涛焦凝墙吧炎刀玻寿履圣昨酸朗媒桑铜仲亦诞揭纵漫愈辟赠旱奶泳枪
骗虫池镜浓拆艾扫娱钻碍寒迟邻曹盗穆豆赚晨浩彭耳瓜扭脸燕摇寄仿炮晋
泪欲饱壁锁刷柬诊磨捕寨滚膨孔添帝辖炸旨吁址驶抱嘉拜扰袋佩阴辈锅赖
剩押怪浮枚栏毁柳恐敦孟旁仓岩伸岭耐懂捷璃溪暖纤汗疫巧旋侧冶陪鸣瓶
纲挤旬舆喝陷缘稻饲滩隔慰朴隐灌拟偷闲赫恰慧蒋闹邹牵柴刺滞彰俱勘填
琛尝贾搬淮奏荷滋覆役秒踏巩摸荡辅惜柜肖颗搏氏姑弄姜君舒兑宇割哲摘
钦逃漠忆敌宿啊凌耀闯阅贪赤汪悲抑瓷冯厉粗菲琴堡斌掘稀衰驾雕牢氛驱
妥悄郎巡臣羽灰癌颖姆漏袭贤鸟暗茂孤惩榜袁桌卓傅剑堆兆狠轰拳妹绒裂
潘兄洽叹涵贿侯岚熊绪阁尾碑尖腿涂栽坝犹铸肩闪诱辩芬睡奠伏妙乙绸廷
夕恒梯赁霞攀枝译描湘磁吕硕爸肝峻葡衷搭唤薪挺逝狗蔡宴蓬撞铝牲舰胁
崛桃斜丧烂屏砖墓详逾函跌抚插戈凉啤脉滥赋柏堤腰泊寺尘蒂削仙踪冻汤
睛艳荐劫框廊惑页拼堪携丈乳挪谱舶埔遥菌塘氧晶洒株颜虹岳胸忍甜匹瞩
懈爷丛莲叙鸿逢抬嘴弘炒喷吊窝衔吹霸仔垦胎慎脏歧疏悠慕漂杆萍舟吐玲
凯戒盼偶盆慨弊箭茅衫罐串辐腹钩碰昂酬晰姿彼锻飘嫁竣缝蹈悬紫浅缆喊
昔驰湿剪侦坑姚魏扑挣焕皆狂泡骤堵膜禽锐芝帽擅沪晤婆埋劝碗玛顷鸭娃
豫匆魂哭庞亭屡逼尺撒鹿讼弥坊碎缔霍壤萄铃稍丘肿烦苹庙雇汛孝辰吞汰
怨酿耶咱欺丢琼棚披渴屈弗疲帕昭盒仰萧牺撑抛鼠纱翼兹骑糊契铭淘顽撰
乒淑妆窑柔姻苍谨卿灿栋敲窃菊郁催眉邱揽鼎韦肤娜俏呀拚寸爬悟尿罢圭
葬聪沃肠厕慈恋绵橡圾垃翁粤脂歹憾阐甸巷蜂轴艘垄衬阜惨冀幽厘崭筋寓
迄渗碘碧赌袖奈崔悦捞剥孕逆婴脆缅艇谭笼儒粒诈遣垂磋卸帜枣幢淀帆蛇
宰殿猎叔夹帅沧魅俩牟钓葛罕渤汕溢擦袱嫩桶殷酷呆卧暑骄幻囊掀醉牡饼
扇蒸赣俭椅枢彦樊吾仗彬砂绳巾喀勋愁碱谦壳轧潭浆挽邢啥焊钞烤廖猫狱
腔喻御蕴坎魔刮瘤茫竭莉链淫愤纹咸睐睹裤夸滴雾搜拘龚凶茨傲鞍鹤蚀颈
翠卉汁冈狮隧弯胃沛募琳疼蚕泼磷捧炳绣朵涯掏奎聂孜韵浑翔魄掩斥敞腊
愧粘丑溉斑啦柯谐烯禄浴涝鬼薛瘦挡昏鹅湛逻虾沂辱叉鼻厨鲍鞭辣潇乓肺
尹颂邵澜桐鹰妨闽屠畏翰塌亟寂赂犬聊暨垫泄漆旭蕾坪涤挫佐瞄拦硫棒杏
爽碳畔熙襄祸乾淹臂莎辜阎庸砍捉勾垒衍坤噪毯倪扮铅遏哀愉瑶咬嫌闸恳
齿杠怒兽浇肇鄂溶哄棵盯梨灶屯狭陋啡浸淋濒脊戚勉膏氨墅沸挨蔓抄芒秉
刹饶厢咖魁骚缚遂恨跻螺辨菇帷凰椒汝瞬淄舱馈桩炬誓卜麟岂兔眠泵拐肚
匪芦匈霉蜜荆雁窄秧枯仆嘱壶谅哨肌贬叠稽岐沫肆醇菱彪躺摔膀甫逊凑渊
喂藤砸悔杉霜厄忌桔筒丙臭拾芜禹丸蟹嘛俞翅尸澄骂睦馨郝贮陌钧轩赃笋
歉逸歪巍萃崖窟踢锣萎庐剖籽甩饥苑恼渣痕莞硅晴巢瘫缠隶筛穴昼埠宠肢
饿仑逮兢趟糕妮邪抹俑萌匠扔酱葱礁掺雀髓悼挚蔚枫庚伞侃僵捆蒜溜傻蔗
谜斋蝶沾闷驳耿槽黔吓肾芽栗朽荫榆皖曰徊奴迭僻蓉靖氟滔羡愚尧俺徘罩
磊镑舌曙纶粪匙钉佼扯踊躲猴纬咽酝挠宛瑰歇抒茧穗祭鑫趁痴裙猜耘碌锈
晒潍弦稼狼拢梧芯眷哑宙厌逛谴邯呵蜡寥钥耸媳熏蚁惕颠娟亨吟蒲梭瞻渝
喉遮慌夷韶焰尉珊胖蕉粹裹琦秽侠奸挝绑曝棍婉镶熬傍燥氯骆晃鸽疯琢聋
瑟暇绥禅溃腺垮阀撼煮佣滕淤蹲栖硝睁荟荧抖坟芭臻锭晖倦倘喘邑锤惧荔
毗觅矮恭钙氮缸瞧颤萝佑怡瘾寡烹摧棠缪雏韧喇兜坯坷贞仇缉帘竖糟猖懒
凿洼喧谣驼烫锌椰崩沥汾磅霖棘扛彗矩瞒陇绎诫斐卵铮钾宵簿秤畴斧擂剔
躁冤讳寅焚漳鳖哺耻僧琅粟怖咏蜀淳柑缕烁氢蔽琪泣阮镀殴虞虐炊搁诀掠
坠屿髦酋躯吵遐寞仕稚僚楠矶筝彝叮熔槐潢芹郸匾咋玄裔陡哗怜襟刃脾嵌
拱慷痪跋孚峪钊滇苟晕墩膝羞乍腻詹讶敷肴莹衢柿朔袜枕烘匀歼泻樱吻翟
堰苯隙娇獗汲蛙斩靡沁乞姨翩沼嘎畸矫骏薯绚窜藻矗皂楷腕篷徇耽娼犁榻
茄棕汹峨蹄昧奢涩灼踩粥拣旷簇溯攒沓呕梳搅砌纫渭澡撕漓葆辍肪祁鞠蛮
捏诵娣岱瀑啸裸鸦瑛躬舜忱豹纂恤惟赐俯犀媚嫂嗓蚊茬驭缀皱凳钮蚂姬扒
嫖跪凹揣尬沦尴豁玫殡淌叭唇啃裘卑琐矢拯忡勿盎茵椎脖拂骅葫迢薇龟绞
眶沐傣浊舅叛浚窘栓酶笛泌榄惹铲碟捡恪酯滤匿酵砚贼匮熠鳞麓镁氓苇廓
巫踵竿蘑翘梓贻鳗帼冉泓狐涟崎窍瑜讽逗铎掷璀泗浏陲醋苛攘璧瀚哩暮矣
蚌悖扼漯烛蝴屑墟俘侣庇陀煎秸弓捣譬炜炯拌扁彤锚禾侮秆绮嚣樟咐枉窦
桦寇哉狸耍馒驹隋冕疮咄妄峙娄溥腑钠栩糙滦呐鲻娶祺刨褒橙茹谎抉慑媛
橄戎迩雯璨雍惶扳桢霓账梗炕裴韬杖痹缤沽燎煞删辙爵缭劈烨槌媲凛莆颅
锯膳澎坞瓣婷絮酌涡唁秃禺膊棣芸忻炽榨篆憨戍圩爹蹊饪胺贱睫蝇惫拇赈
泾盏弧剿硒毓皓菏灸湄炙祠荻捍嚼朦屹紊藜驴寝兮隘祈榕臧蝉绢瞎闵鳌娥
藉娅烽楂摒凄凸熄孵叩渎胳匡袍卒怠桓莽倩泸藕陨辗骋峭冥饺亢圃颐擒铵
鳄簧愣璜钰拙瘠靳隽罹岑镭榴恕毋囤汀绽窖筷擎猿诲碾夭筐邃藩诬芙胚哇
垣胧帖殉毙壑绰憋亥涅屁璞缮侍倚稠棺棱葵诣笨橱寰郡垢徕眺胰谆窥霄栉
舸蹦坂瞪珲釉跤挟侄肘嘲刁缎嚷痒敛祛绅孰痫闺椿噶恍伶峦酥萦苎癫涪锲
蜚拎嵩昊娴涣烙璋笃囚祯篱讴舷纭锄巅卦摹眸柄踞焉辄褚褐湃夙堕岔惦疚
谍奕羚帧澈濮捎漾吼锰趴菩簸仃渲札谙咕桨咀郴咳呜蛟拧莘驯庵弼逞蹬姥
撂镍晏疡爪骥楞钳懋寐淇琉杞菠铨翌靶侗瑙馅丐痊娓侈苓聆睿偌釜噬曦燮
哟瑾瞿璇拮憬鹊勺憧嗜啼檐柚呱渍镌妃溺鸥粕沱榭隅毡禧瞅鲸淆阪茁渺瞥
茜瘟礴伺谛锹蔼虔莺迸磕赡泱栈甄镐抠嬉诿甬绊饵谬梢颍揪琶褥佟腥辊溅
琵鄯拴喃笙酰粱卤芮膛斓潼鸵侥讷婿吆羁嗣蜒栅疙拷戳镛芷钛蜿铀夯摞雌
酣荼蝎锥姊瓢祀玺弛犷哦茸鱿绷茎惋亘珑莓掂迥鲤殃瘩叨螃奄腈疟沭钨昕
膺涿糠氰揉狩檀悍缫哮衙瑚潞谤搀洱涓袤痰乖冗芋甭骸幌涮俨敖槛狄牒恺
雹赎庶熨蛛佰蓦鄱煽腌黯疤倔剌斡诽锵筱妍掖铿脐捅弈邸湟眯赦拄啪玮轶
蛾麋炫赊靴箔菁撬裳戌缨蝗撇奚瀛噩怯蓓匕咚瞰佬泞扉皋晾麒姗跚瘀鄙猕
拭鲟祷脯砺驿陛瘁搓舵汞哼胫珀邬磺馏馍铢诧涧吏苔潺邳烷囿斟滁殆酚狡
孺恬沅铬湍啧囱蒿鹃柠漱胥妖洙珂茉蹒圻鬓搂葩佘渥诙袒捂瞠妓铐澧袂馁
汐匣逍谚窒蔑糯汶壹岖盔嘘迂嘀锢讥吭抨屎獭褪咫稷迦檬塬蠢蓟咎皿驮俐
坍惭垛鹭鸾蹴撩诠恙臃遨睬踌浒搪郧竺翡宦冽憩萱拽卞槟躇蘸肋呛濡酮眨
撮矸垸蛀黛涸脓徙撷曳峥渚镖钴骊袅磐掣沌埂嘿琏楣豚诡悸麝煦矾羲唉溧
呻覃兖吱惰羹钝枸姣颓铣梆骇淅孢叱谧泯谟恃薹筵鏖栾鹜哽掬辘茗瓯绛筠
铤袄殚梵挎遴榈蜕癣垠厮幄偕焱攥裨炖旮旯蔺骡娩伫猝窿虏屉缜咒筏骼璐
剃涕猗淼侬阙嗅鸳嘈霏珩沮捺硼荃驷漩嘻眩掰伽脍婪煜鹄壕崂翎痞兀婺鸯
楹咤徜嫉篓烃铂咪掐匝杼蕃箍荤砾嘶皑宕荪哎汴貂邡淦蕙弩堑惬偃徉箴赘
啻凋穹酗憎芥唾闫晔苞昶甙笺吝蕊鳝衅猩薰昱趾淞坳怅翱汩琥岌阑粼羌霆
篡塾酉裱韭唠廿闰攸黝蛤厥荞瑕柘祚疵愕蕨牦飨疹嗷癖芪漕隍徨逵泠嵘嗡
岫岷擞陂颊咔卯婶椭惘歙幺臆叽缰睽勐暄弋痔秭煲琮嘟犊玖怦丕溴罂瓮丞
惮癜晦攫镰镯柞舫铆蹼妩熹铱褂丫笆妒噢噙琬冼荀蟾捶嗒町嫣肮皎旖恣钚
砥吩茯馥钎甥嗦蜗浔谒辫亳彷珏咯淖妊佤玷嘹崴於辕贲扈伎旎孽耙娠戊冢
跷砷焘羔圪耄钼悻荥唑稞邝莅杷醛嗽唆拗碴馋胱琨茏糜懦骞蜘嚓怵抡唢腆
涎灏臼墒暹椽牍钒猾榔懵枇樵锶籼箫漪帚钵赓捻郅儋烬锂剽锑鄢鄞臾喳胄
耋阱笠瓴啬杳萤莠嶂浜傩遒轼睢倜矽仉唬旌酪腼罄嬗畲祟桅悴讹憔龋嵊绶
邕忖箩咆晌愫猷帛麾莒觑吮蟋庥懊阂蒯阡腮潸晟蟀臀罔骁崽绉粽忿肛蠡遛
蜓煊蚜坻滹銮悯鼐撵噼忐湮侏粳矍铄坨铉盂锗阖溟俟忑赝鬃敝宸哆靓揩瘸
鲅篝氦嚎浃缙飚锷癸柩蛎濂榷鲨钡盹鲫诘诩迤桎遁尕梏楫赳飒锃雉怆痼劾
痢喽霹昙畹胭佚狈瘪姹吠铧谏雳咙畦荠娑褶忏惚痉橘漉诏呗晁惆砀馄戟峁
昵拈蠕虱洵鹦蛹铛挛倏澍濉钅噜咛俳磬蜷霎肽砼聿怔砭谌箕蹶孪蔷糅挞饨
惴禀淙哒枷楝闾蜻嗖淬垩矜郗蚤嫦喋镉饯髋潦镂簌偎鹉岙踱诃籁宓膘飙涞
耆荏渑豌琰俎绌埭幡赅锆崮碣珞腋滢蓖伉馗聩幔锨蓥鹑砝酩枰鞘苋粑蹭倌
犟俪嶙砻嵋滂葺苒枭翊婀飓阚喟傈藐蜃怂稣亵诒蜇岜霁瞌沏卅舀鹌俸嵇蟒
汨砰鞣唏陉佯恿竽瘴祉焙诋濠螂叻垅谩朐稔芍瞳惺萸盅啄眈偻爿蟠炔垭噎
蛰擘锏茭悌喔谑峋妪恽韫褓镳饽杈戛鸠萋襁榫霭苄跺杲嗨珉哌娆孀恸缄夔
佗饷苷郜鼾颌訇谲溘咧褛逄颦洮逶嫡蠹碓烩醴栎鎏瓤伢蔫怿甾摈畈镣螨秣
搔盱痍搐蹉佃绂疽骝霾悚缃懿咂奘轱邗蚝瘘醚湎瞑掮羟仨砣郢砧鳟跛踝轲
窠郦踉躏戮篾骐鳍蹂郯跎倭诅鄄褴阆缈嗯妞沤跄箐苕窕楔饴峄腴圄谕揍踹
罡佝颔觊篑鲢綦妾镗啕蚬窈揖眙蟑诛钗绯讣睾媾嗬祜镢囹苜坭蛐髯搡叟蹋
觎捱碉呋罘荚鹫岿寮扪焖狞鳅嗄嗤擀痂嗟颉蚧儆锴龛嗑锟俚枥懑讫橇嗪虬
跆骧陟灞恻涔酐鸪牯钜萘鲶缥曜蚓诤埕墀麸蝠蛊遑厩趄沔耦疱匍揿蚯讪唰
舔呷蓿鹧膑刍耷鞑裆趸孑鲲绫埝嘭舢鸢螯吡蝙疸匐桁铠羸鲈囵唛仫庖劭郓
骜粲峒腓鹳鳜蚶囫茴峤蟆蘖癯纾僳皙隰缬馐谪捭汊碜塍艮睑狍苫篦蜍锉沣
诰晗喙麂謇蹇觐啾踽邈壬燧娲猥歆镒茔昝赭狰孳哧舛噔鹗蚣逅洹腱锒纰蛆
蕤姝邰纣嘣钹衩婵孱蹿鲷萼椁浣镓遽赉趔蕲剜邂仡氤獐幛俾铋嗔茌氡诂豢
桧畿倥捋仞忒疃浯蜈榛偬稗菖鲳厝踮叼痱貉玑婕琚疴掳钤垧氵黠跹怏揄氲
铡濯芾笈崆钕菽隼傥仝囗芗埙簪暧桉镝蚪蜉藁笳菅龃喹橹抿啮蹑逖唔樨巽
揶黟訾钣嵯凼恫掇剁珙沆噱揆耒铌泅疝葳隗滟龉钺殒蒡觇黜澹酊垡奂珈濑
馕馊嚏痿岘氩茱滓焯抻豉敕掸碲靛摁淝鳏盥皈鲑颢犄翦铰椐胯屺邛庹猬蓊
骛浠桠胤鸩痣蛭噌杵啜靼啶煅枋觥毂刽蝈蘅芨戬醮疖忾骷洌呤荦觞谡瀣蝣
糌倬碚蹙痘砘绀虢蕻肓蛔唧桀蝌侩棂樯挈轫巳崧蓑藓鳕瑗帙馔豺痤郇殓髅
轳逯嗫戕嚅蛳琊嘤疣蚱钯钿碇咣毽迳喱逦廪邙囡匏扦亻咝凇纨涠庠溆醺炀
烊肄龈谀锱瘢枞皴贰晷闳斛屐讦婧苣蔻绺渌瑁螟叵颀穑膻羧螳绦誊蜥楦恂
靥咿翳瓒枳啭樽嫒婊搽铒跗凫菡篁髻裾栲癞蓼氖孬喏砒姘衽缛嵬挹缢慵呦
箸蹩槎榇舂嗲胴谔岢圹娌潋蛉酃鲵鲇娉亓碛芊忪谇笤韪勰呓俣圜愠仄炷毖
筚伧棰磴滏篙肱笕堇馑荩榘哐傀崃罱痨儡鹂檩垴仵檄芎阉刈壅馀庾妯躅獒
阊笞饬钏硐椴泔硌鹘鳇豇狙戡莨啉辇臬殇舐黍薮眭佻嗵煨莴蚴妤瘐擢蛏蹰
龊辏绐氘骶莪珐缟聒讧岬胛桷谰戾撸鸬雒嘧囔铍骈掊茕噻铯柁艉龌硖罅魇
酽咦嶷羿轸趵荸薜踟玳啖蔸槁鲛疥砬唳弭曩黏镊泮霈淠柒颧瘙痧辋郄燹泫
郾鹞钇殪痈甑踯翥婢檗柽啐菪嶝腭嗝剐笏蟥戢阄噘撅尻贶辚蜢颞忸胼阕竦
焐揠邺鳙啁稹徵诌隹舨哔卟伥苌鹚箪缍锇蝮诟洄浍诨犍硷噤垲郐椤嫫伲脲
殍噗溱箬厍钽钍恹鬻爰砦蓁胝颛褙鳊邴铖镫腚钭颚鲂悱狒佶偈堀绔醪坜疠
椋犸暝佞哝瞟荨芩逡溽裟挲抟暾崦芫荑薏莸欤栀斫镞嗳鸨跸骠俦谠簟棼驸
掼倨橛犒邋耧蝼虻铙郫汔诮楸阒绻叁臊钐腧闩菘阗忝橐翕阋踅窨鹬鼋樾錾
吒旃弁侪坼蚩嘬糍骢氐呃榧玢绋蚨钆岣菰罟嘏埚绗嚯藿笄袈羯肼暌啷蒗蜊
獠鬣熳黾乜镆怩驽旆髂仟芡谯恁鳃艄莳艏趿遢鲐醍僮氽刎芴喑墉昀箦鄣摺
钲贽缵鏊锛瓿廛瘳亍遄褡垌椟酆砩桴赙坩臌曷跽湫榉黧猁钌镏缦殁赧埤悭
缱衾鲭铩猞眚铈谥耜飕饕餮骰乇绾鹇鲞爻蜴镱铟莜祗濞镔逋谄谶酲茺樗憷
莼撺柢阏砜垓旰妫衮嗥郏鞯徼孓钪侉夼跬铼嫘蟊茆睨怄蹁谝嘌綮嫱筇犰穰
铷筲哂炻豕秫笥涑铊帏闱鋈舾屣狎哓噫璎铕宥阈豸辎趑龇捌秕荜愎窆镲谗
踔苁酢呔聃镦屙鲱鬲膈铪醐獾鲩虺葭牮礓苴讵颏裉诳栌氇镙哞柰袢帔睥苤
嫔笸氆佥箧跫蚋鲥扌狲桫溏铽殄脘洧肟绡咻洫癔洇嵛磔胗肫赀眦吖瑷埯畚
妣飑豳髌砗铳楮蔟毳锝堞疔葑缶菔疳彀胍磙顸薅翮猢怙蒺廑妗髁醌粝魉旒
蝥缗衲呸醅芘蚍圮榀萁苘逑诎劬蕖朊剡蟮椹饣酞帑葶菟魍庑葸氙谖鞅狺夤
嬴瘿饔雩鹆橼赜潴骓缁诹怍杓艹檫媸氚呲殂矬笪迨纛簦玎苊轭匚鼢呒缑诖
炅鲧唿戽鬟恚袷瘕枧洚桕雎蠲剀诓瘌镧铑鳓蓠呖跞裢裣埒捩鲮熘嵝瘰镘脒
腩筢耪辔牝嘁蛴戗蛩巯悫葚熵绱蛸螫毹妁纟嗾鳎绨粜菀沩鼯牾螅顼泶蕈鼹
繇苡悒廴吲喁卣牖笮舴罾棹鸷碡锕嗌媪龅甏箅傧啵鹁晡氅魑篪怛籴礅蒽珥
钫绠觚鸹涫颃篌锪蠖乩咭赍嵴铗湔槿赆僦皲佧箜蒉缧酹嘞疬臁膦泷蒌泺荬
颟旄泖镅蠓冖幂耱襻鼙攵炝愀蘧氍犭禳桡糁馓酾槊狻锬羰鼗鹈畋髫萜堍璺
怃崤囟睚痖菸餍徭瘗唷圉蜮砟谵澶朕摭轵诼笫廒聱庳髀笾龀裎雠蝽腠妲刂
铥黩怼沲蘩趺苻拊阝鲋戆纥哏鲠笱瞽庋簋刿掴猓蚵槲觳萑癀蟪钬虮掎鲣囝
裥踺茳糨鹪狷麇芤刳愦髡悃缡鲡鳢奁墚尥柃胪镥脔杩劢墁玟蝻呶搦湓罴蜱
俜鲆皤镨槭镪黢洳枘芟埏渖筮殳飧溻饧樘醣酡圬粞觋莶霰榍薤髹曛疋迓衤
欹佾埸霪茚鼬伛瘵骣畛卮轾彘觯锺邾槠谘嵫髭蕞犴鞴畀滗煸褊冫孛羼耖褫
彳艟辶茈璁爨榱萏坫鸫篼簖裰哚蹯瀵怫陔筻廾蛄绲崞蜾盍荭黉糇骺後鲎煳
鹕冱瓠逭漶耠镬齑殛鲚跏蛱搛缣鹣僬噍衿缂喾狯纩栝蛞稂塄嫠詈蠊鹩躐鹨
簏膂脶嬷昴瞀浼艨祢縻蘼芈糸宀眄鹋杪咩愍麽瘼鍪硇猱茑脬蟛貔仳犏钋芑
葜愆锓蠼筌鬈蚺荛埽潲诜埘弑嗍蒴鸶缌澌姒蔌睃缇梃彖鼍芄隈鲔硪忤痦欷
僖醯鼷跣枵忄擤勖痃碹谳轺铘圯纡窬窳饫蓣瀹趱驵缯揸笊絷跖舯螽籀舳粢
驺陬阼揞菝魃癍鹎坌狴萆嬖襞碥髟鳔醭螬馇虿瘥惝怊鸱螭瘛帱徂汆脞瘅忉
羝睇瓞鲽岽胨芏佴燔偾稃郛莩幞澉槔袼搿茛鞲觏酤牿鲴宄匦呙馘焓瘊虍岵
鹱咴隳缋溷夥剞洎恝蒹谫僭艽挢敫卺冂扃锔窭锩觖劂氪骒哙悝蝰诔苈篥娈
瞵锍栊癃舻辂稆猡蛑甍艋敉眇蠛侔镎肭艿蛲疒陧衄锘堋庀擗甓螵钷攴桤褰
凵肷锖鞒吣黥俅蝤璩悛辁肜颡谂礻摅汜溲嗉荽闼骀炱螗耥裼铫莛亠箨蕹迕
杌寤穸饩舄禊猃绁渫廨獬硎荇鸺貅糈揎镟獯讠厣罨蛘鳐崾舣媵尢蚰侑狳螈
龠昃痄搌浈埴夂黹酎橥丶缒窀菹锿砹茇勹邶鐾舭忭缏灬瘭踣钸礤骖黪艚锸
猹镡躔蒇冁鬯屮枨眵傺搋巛舡楱镩鹾戥觌阽铞垤揲蹀耵髑憝鸸鲕篚镄鲼唪
祓艴黻黼鳆尜戤塥哿虼遘桄丨胲醢撖嚆薨堠烀轷锾缳擐哕阍劐攉丌墼蕺彐
芰哜戋趼楗耩喈卩鲒骱刭弪獍鬏鞫犋屦醵桊爝捃胩锎蒈莰闶钶锞眍筘阃漤
铹栳耢仂泐檑轹蔹懔垆锊倮蠃鞔硭漭猸鹛钔瞢礞喵苠鳘貊貘毪坶攮猊嬲肀
聍甯狃耨孥胬恧蒎锫陴氕丿裒镤蜞岍搴箝慊椠蜣硗劁缲檎螓圊檠謦銎赇鼽
糗麴鸲磲畎狨蝾薷襦颥蓐脎毵磉鳋唼歃彡骟滠矧胂蓍鲺贳搠厶兕锼螋瞍觫
赕铴瑭慝掭祧龆蜩鲦茼酴煺柝腽軎阌阢诶菥蓰柙祆筅葙蟓魈躞砉醑儇岈砑
珧酏劓堙撄潆舁蝓燠眢箢掾刖狁拶唣迮帻谮哳齄膪嫜忮骘膣踬荮瘃麈疰丬
浞禚觜耔腙鄹鲰躜撙胙省啰瞭乂丏夬匜厾玕玙抔抃㧐芼旸吽牤沚沨纴玡玭
玠玥玦拤劼拃㧟茓茀杻旻昉呣䏝炘㤘祎祇垱挦剋柈𠳐眊峣郤饸饹疭竑闿羑
浕恓牁姮珰珣琤栟彧眬鸮䥽盉俵俶訚烜浥牂骎琇捯埵捽堉棻梿棁晞唵崚秾
鸻馃阇焗惇郿欸琫琯揳塆靰靸椪雱睄嗞嵖嵎铻媭鲀颎焜湜湲湉愔祾翚瑄蒟
楯跶跐嗐锜鹐亶瘆滫滃滪窣璈叆摽榖靺靿僰豨䁖嘡嘚箓魆粿熥嫚奭鋆瞋颙
踒𥻗熜潟褟璟璠璘縠嚄螠䦃镚镠膙獴赟澥窸璪鞡鞬罽鳀鞨鞧藠蹚鹮霨蹽蹾
齁㸆巉镴臜瓘镵齉卬𠙶毌邘圢伋冮氿汈氾讱扞圲圫芃朳朸𨙸邨屼屾辿伣伈
癿甪邠汋䜣讻孖玒玓玘玚刬坉扽坋扺㧑毐芣苉芠𫇭杕杙杄杧尪尨轪𫐄坒旴
旵㕮岠呇冏觃伾㑇伭佖佁飏汧汫𣲘𣲗沄沘汭㳇沇忳忺祃诇邲诐屃岊䢺妧妘
𨚕纮驲𫘜纻𫘝纼玤玞玱邽邿坥坰坬坽弆䢼𦭜茋苧苾枅㭎枍矼矻匼旿昇昄昒
昈咉咇咍岨岞峂㟃囷钖牥垈侁侹佸佺㑊侂佽侘郈舠郃攽肸狉狝饳忞炌炆泙
沺泂泜泃泇峃祋祊𫍣鸤弢弨陑陎乸妭姈叕䌹𫠊㛃玶珇珅珋玹珌玿韨垚垯垙
垍耇垎垟垞挓垵垏荖荁荙茽荄荓𦰡㭕柷柊枹栐柖郚剅䴓迺厖砆砄耏奓䶮昺
𪾢昽盷咡咺昳昣昤昫昡咥昪虷虸哃峘峏峛𪨰峗峧帡钘𫓧秬俫俙俍垕衎弇侴
鸧䏡胠𦙶胈胣朏飐訄饻庤疢炣炟㶲洭洘洓洿㳚泚浉洸洑洢洈洺洨浐㳘洴洣
恔宬扂袆祏祐祕叚陞娀姞姱姤姶姽枲绖骃𫄧骉珪珛珹玼珖𪟝珽珦珫珒珢珕
珝埗垾垺埆垿埌埇茝鄀莝䓖莙栻梠栴梴栒𫠆砵砠砫硁翃郪𨐈辀剕哢晅晊唝
哱冔晐畖蚄蚆𫑡崁峿𪨶崄帨崀甡倻倴脩倕倞倓倧衃虒舥鸰朓虓鱽峱𫗧勍竘
羖羓烠烔烶烻涍浡浭浬涄涢涐浰浟浛浲涘悈悢宧窅窊窎扅扆袪袗袯隺堲疍
𨺙烝砮㛚翀翂剟𫄨绤骍䂮琎珸珵琄琈琀珺堎堐埼埫堌晢掞埪壸㙍萚莿䓫勚
䓬菂菍菼萣䓨菉䓛梼梽桲梾桯梣梌桹敔硔硙硚硊硍勔䴕龁逴啫翈㫰晙畤跂
蛃蚲啴䎃崟崒崌崡铏𫓯𫟹𫟼铚牻笯偰偡偭偲偁㿠鄅偓徛衒舲鸼悆鄃瓻䝙脟
䏲鱾猇猄𠅤庱庼痓䴔竫堃羕焆烺焌淏淟淜淴淯湴涴㥄惛惔悰惙寁𫍯裈祲𫍲
谞弸弶隃婞娵婼媖婳婍婌婫婤婘婠𫘦绹𫟅骕𫘧絜珷琲琡琟琔琭堾堼揕㙘堧
喆堨塅𪣻𡎚惎萳靬葴鄚蓇萩蒐葰葎鄑葖蒄萹棤棽棫椓椑鹀椆棓棬棪椀甦酦
奡皕詟𫐐辌棐龂牚睎晫晪晱𧿹畯斝喤崶嵁嵅崿嵚翙𫖮圌圐赑赒𨱇𫓶犇颋稌
筀筜筥傃傉翛傒傕畬𫖯脿腘䐃腒鲃猰𫛭猯㺄馉凓鄗廋廆鄌遆旐焞欻𣸣溚溁
湝渰㴔渟溠渼溇湣湑溞愐愃敩棨扊祼婻媆媞㛹媓媂媄矞𫘨缊缐骙瑃瑓瑅瑆
䴖瑖瑝瑔瑀𤧛瑳瑂嶅瑑髢堽赪摛塝搒蒱蒨蓏蔀蓢蓂蒻楪榃榅楒楩椸楙歅碃
碏碈䃅硿鄠辒𫐓䣘暕鹍㬊暅跱蜐蜎嵲赗𫓹锳锧稑稙䅟筼筶筦筤僇艅谼貆腨
腯鲉鲊鲌䲟鲏雊猺飔觟𦝼馌裛鄘鹒鄜麀阘𫔶煁煃煴煋煟煓溍溹滆滉溦溵漷
滧滘滍愭慥慆塱𫌀禋禔禘禒鹔𫖳嫄媱勠戣𫘪𫘬缞耤瑧𫞩瑨瑱瑢斠摏墕墈墐
墘摴𡐓𪤗靽鞁蔈蔊榰榑槚𣗋槜疐酺碶䃎碨𥔲𫚖䴗鹖㬎幖嶍圙𨱏锽镃馝鹙箖
劄僔僎槃㙦𫚕鲖鲗鲘鲙𩽾夐飗凘廙鲝鄫熇漹漖潩漼漴㽏漈漋漻慬㮾褕禛隩
嫕嫭嫪㻬麹璆漦叇墣墦墡薁蕰蔃鼒槱鹝磏殣慭霅暵暲暶踦䗖蝘蝲噇噂噀罶
嶲嶓㠇嶟嶒镈镋镕皞皛䴘艎鹟𩾃鲪鲬觭鹠鹡鹢熛潖潵㵐澂澛瑬潽潾潏憭憕
戭褯禤𫍽嫽遹璥璲璒憙薳黇蕗薢橞橑橦觱磡𥕢磜豮𫟦𫠜虤暿曌曈㬚蹅踶䗛
疁㠓幪𪩘嶦𨱑馞穄篯簉衠盦螣縢鲯鲹𫗴亸羱糒燋熻燊燚燏濩濋澪澽澴澭澼
憺嬛翯𫄷璱𤩽璬璮髽擿薿薸櫆檞醨繄磹磻瞫蹐蟏㘎𫔍𨱔𫔎矰穙穜穟簕簃儦
魋斶谿䲠鲾鲿鳁鳂鳈鳉䗪襕襚螱嬬嬥𦈡𫄸瓀釐鬶爇鞳鞮藟藦藨鹲黡礌𥖨蹢
蹜蟫䗴嚚髃镮酂馧簠簝簰鼫鼩皦臑䲢鳑鳒鹯癗𦒍旞翷䎖瀔瀍瀌襜䴙嚭㰀鬷
蠋翾儳儴𩾌鳚鳛麑麖彟嬿鬒蘘欂甗𨟠巇酅髎犨𨭉㸌爔瀱瀼襫孅骦耰𤫉瓖鬘
趯罍鼱鳠鳡鳣爟爚灈韂糵礵鹴皭龢鳤亹籥𫚭玃醾齇觿" ""))
  "常用汉字")

(defun pyim-pymap-build-pymap ()
  "使用 libpinyin 自带的 data 文件创建 `pyim-pymap'.
这个函数运行估计需要5分钟。"
  (interactive)
  (let* ((dir (read-directory-name "请输入 libpinyin 的 data 目录："))
         (hash-table (make-hash-table :test #'equal))
         (file1 (expand-file-name "gb_char.table" dir))
         (file2 (expand-file-name "gbk_char.table" dir)))
    (with-temp-buffer
      (when (and (file-exists-p file1)
                 (file-exists-p file2))
        (insert-file-contents file1)
        (insert-file-contents file2)
        (goto-char (point-min))
        (while (not (eobp))
          (let* ((contents (pyim-dline-parse))
                 (code (replace-regexp-in-string
                        "'" "-"
                        (car contents)))
                 (word (cadr contents)))
            (unless (string-match-p "-" code)
              (puthash code (push word (gethash code hash-table))
                       hash-table)))
          (forward-line 1))))
    (insert
     (with-temp-buffer
       (maphash
        (lambda (key value)
          (let* ((n (- (length pyim-pymap--commonly-used-cchar) 1))
                 (value (reverse (delete-dups value)))
                 (seps (mapcar
                        (lambda (n)
                          (propertize (nth n pyim-pymap--commonly-used-cchar)
                                      'sep t))
                        (list 4000 7000 n)))
                 (string
                  (string-join
                   (mapcar (lambda (str)
                             (if (get-text-property 0 'sep str)
                                 "|"
                               str))
                           (sort (append seps value) #'pyim-pymap--cchar<)))))
            (insert (format "(%S %S)\n" key string))))
        hash-table)
       (sort-lines nil (point-min) (point-max))
       (goto-char (point-min))
       (insert "(defvar pyim-pymap\n'(")
       (goto-char (point-max))
       (delete-char -1)
       (insert ")\n\"拼音汉字对照表.

第一个元素为拼音，第二个元素为拼音对应的汉字组成的字符串，字符串
中汉字按照使用频率排序，字符串用 “|” 隔开，分成一级常用汉字，二级
常用汉字，三级常用汉字和不常用汉字。分类方式参考了国务院公布的
《通用规范汉字表》:

    国务院关于公布《通用规范汉字表》的通知(国发〔2013〕23号)
    http://www.gov.cn/zwgk/2013-08/19/content_2469793.htm

但不是完全一致。\")")
       (emacs-lisp-mode)
       (indent-region (point-min) (point-max))
       (buffer-string)))))

(defun pyim-pymap--sort-pymap ()
  "对 `pyim-pymap' 重新排序, 这个函数主要用于维护 `pyim-pymap'."
  (let (pymap)
    (dolist (py pyim-pymap)
      (push (list (car py)
                  (string-join
                   (sort (split-string (cadr py) "")
                         #'pyim-pymap--cchar<)))
            pymap))
    (reverse pymap)))

(defun pyim-pymap--cchar< (a b)
  "如果汉字 A 的使用频率大于汉字 B 的使用频率时，返回 non-nil"
  (< (or (cl-position a pyim-pymap--commonly-used-cchar :test #'equal) 1000000)
     (or (cl-position b pyim-pymap--commonly-used-cchar :test #'equal) 1000000)))

(defvar pyim-dhashcache-code2word)

(defun pyim-pymap-get-duoyinzi-words ()
  (interactive)

  (pyim-pymap--py2duoyinzi-cache-create t)

  (let (code2word output)
    (maphash
     (lambda (key value)
       (let* ((pys (split-string key "-"))
              (length (length pys)))
         (when (and (> length 1)
                    (< length 3))
           (push (cons pys value) code2word))))
     pyim-dhashcache-code2word)

    (dolist (x code2word)
      (let ((words (cdr x)))
        (dolist (word words)
          (let ((chars (remove "" (split-string word "")))
                (i 0))
            (dolist (char chars)
              (when-let* (;; 找到这个汉字所有得拼音
                          (char-pinyins (pyim-pymap-cchar2py-get char))
                          ;; 判断是不是多音字
                          (lengthp (> (length char-pinyins) 1))
                          ;; 剔除已经设置为 fallback 拼音
                          (char-pinyins (cl-remove-if
                                         (lambda (py)
                                           (member char (pyim-pymap--py2duoyinzi-get py t)))
                                         char-pinyins))
                          ;; 找到 code2word 词库中，这个字对应得拼音
                          (pinyin (nth i (car x)))
                          ;; 看这个拼音是否需要特殊处理
                          (need (member pinyin char-pinyins)))
                (setf (alist-get pinyin output nil nil #'equal)
                      (sort (delete-dups `(,@(alist-get pinyin output nil nil #'equal) ,word)) #'string<)))
              (setq i (1+ i)))))))

    (pp (sort output (lambda (a b) (string< (car a) (car b)))))))

;; * Footer
(provide 'pyim-pymap-utils)

;;; pyim-pymap-utils.el ends here
