当前位置: 首页 > 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.rkmt.cn/news/29647.html

相关文章:

  • 拉格朗日插值优化DP
  • 容斥练习笔记
  • 数字人企业:推荐数字人TOP3公司
  • 数字人平台:重点推荐优质数字人公司
  • 深入解析:【Java系列课程Java学前须知】第3课 JDK,JVM,JRE的区别和优缺
  • 395.至少有K个重复字符的最长字串
  • 详细介绍:云手机远程控制的作用
  • 10.24模拟赛
  • 2025.10.24NOIP
  • writing sentences
  • 小程序 访问第三方网页
  • 国产开源数据库调研项目的LaTeX专业排版实践
  • CompletableFuture串联多个异步任务实践
  • 城市基础设施安全运行监管平台
  • ZR 2025 NOIP 二十连测 Day 7
  • CSP-S 37
  • CSharp: word,excel,powerpoint convert to pdf,hrml etc using Aspose.Office
  • Offsec Nibbles CTF 实战解析:PostgreSQL漏洞利用与权限提升
  • MySQLdump 常用参数说明 - 实践
  • 2025 10 24日报
  • 一天一款实用的AI工具,第9期,AI转黏土风格
  • 生产环节最容易出问题的三个点,老板必须盯紧
  • CS50ai: week2 Uncertainty我的笔记A版 - 实践
  • 2025年搬家纸箱权威推荐榜单:物流包装/电商纸箱/平口纸箱源头厂家精选
  • 【LTDC】在 RGBLCD 屏上实现任意位置画点和读点
  • 使用C# 控制ethercat从站设备
  • 2025 年坡口机源头厂家最新推荐排行榜:欧盟 CE 认证企业领衔,含 15 年工业服务经验品牌,自走式/自动/板材/管道坡口机厂家推荐
  • 实战练习:小软件页面间跳转传值 子页面数据渲染
  • 2025 年气凝胶生产厂家最新推荐排行榜:含气凝胶毡 / 粉 / 隔热板 / 保温罩 / 陶瓷板品牌,优质厂家推荐
  • 详细介绍:Uvicorn - Python ASGI Web 服务器