当前位置: 首页 > news >正文

Linux下的拼音输入法 (2)

此贴介绍sunpinyin. 它的用户词典是~/.sunpinyin/userdict,下面的程序往里面加词:

// -I/usr/include/sunpinyin-2.0 add-word.cpp -lsunpinyin

#include <ime-core/userdict.h>
#include <pinyin/pinyin_data.h>TSyllable (*py2i)(const char*) = CPinyinData::encodeSyllable;int main(int argc, char** argv) {if (argc != 2) return 0;CUserDict ud;ud.load(argv[1]); // 文件可以不存在
CSyllables slbs; // typedef vector<TSyllable> CSyllablesslbs.resize(2);slbs[0] = py2i("yi");slbs[1] = py2i("er");// If locale is an empty string, ""... is set according to the environment variablessetlocale(LC_CTYPE, "");unsigned  wcs[3] = {};int n = mbstowcs((wchar_t*)wcs, "①②", 2);ud.addWord(slbs, wcs);return 0;
}
View Code

多次加同一个词不会出来n条。

userdict是个sqlite数据库,里面有且仅有一张表dict. 下面是常用sqlite 命令:

导入导出sqlite3 file.db .dump >dump.sql
sqlite3 file.db <dump.sql.tables - 查看所有表名 
.schema 表名 - 查看特定表结构select * from dict ;
View Code

不用编译它的源码,用现成的程序也能训练出online用的数据。程序在包sunpinyin-utils里:

  • genpyt - generate the PINYIN lexicon
  • getwordfreq - print word freq information from language model
  • idngram_merge - merge idngram file into one
  • ids2ngram - generate n-gram data file from ids file
  • mmseg - maximum matching segment Chinese text
  • slmbuild - generate language model from idngram file
  • slminfo - get information of a back-off language model
  • slmpack - convert the ARPA format of SunPinyin back-off language model to its binary representation
  • slmprune - prune the back-off language model to a reasonable size
  • slmseg - maximum matching segment Chinese text. slmthread add back-off-state for each slm node in the primitive_slm. Also it compresses 32-bit float into 16 bit representation. These processing speeds up the looking up. The primitive_slm is always generated by slmprune. And the threaded_slm can be used to feed slmseg as a reference to segment Chinese text.
  • slmthread - threads the language model
  • tslmendian - change the byte-order of sunpinyin's threaded back-off language model
  • tslminfo - get information of a threaded back-off language model

不是所有的程序都要用到。

在github能下载到phrase-pinyin-data-master.zip和chinese-dictionary-main.zip.

106666 cc_cedict.txt
6850 di.txt
411960 large_pinyin.txt
872 overwrite.txt
47115 pinyin.txt
348513 zdic_cibs.txt
32633 zdic_cybs.txt
954609 总计㹴犬: gěng quǎn
View Code
http://www.hskmm.com/?act=detail&tid=38315

相关文章:

  • 数字人平台:重点推荐优质数字人公司
  • SpringBoot整合缓存2-Redis
  • 数字人企业:推荐数字人TOP3公司
  • NOI25D2T2
  • 时钟同步
  • 深入解析:【Java系列课程Java学前须知】第3课 JDK,JVM,JRE的区别和优缺
  • 10.24 CSP-S 模拟37 改题记录
  • 数字人企业:数字人公司重点推荐与选择指南
  • C++实验二
  • 据说每邀请一位朋友加入Comet,您可以获得10刀乐奖励:D
  • 2025.10.24NOIP
  • 小程序 访问第三方网页
  • 王炸!OpenAI 发布 Atlas 浏览器!!
  • 国产开源数据库调研项目的LaTeX专业排版实践
  • Asterix cat-062 ,航班号字段的编码解码
  • AI优化企业:GEO公司技术先驱
  • 题3
  • 课后作业4
  • 吴恩达深度学习课程一:神经网络和深度学习 第四周:深度神经网络的关键概念
  • CompletableFuture串联多个异步任务实践
  • 城市基础设施安全运行监管平台
  • 第171-172天:代理通讯篇无外网或不可达SockS全协议规则配置C2正反向上线解决方案
  • SpringBoot整合缓存1-Ehcache
  • 【开题答辩全过程】以 M11289生鲜商城为例,具备答辩的问题和答案
  • ZR 2025 NOIP 二十连测 Day 7
  • CSP-S 37
  • Offsec Nibbles CTF 实战解析:PostgreSQL漏洞利用与权限提升
  • 如何在一台 Linux 机器上管理不同版本的 CMake
  • 90 天打造可持续交付:12 条 DevOps 实践要点与避坑
  • CSharp: word,excel,powerpoint convert to pdf,hrml etc using Aspose.Office