Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我做了Unihan字库,可能有用 #116

Closed
zeng-y-l opened this issue Mar 30, 2023 · 3 comments
Closed

我做了Unihan字库,可能有用 #116

zeng-y-l opened this issue Mar 30, 2023 · 3 comments
Labels
dict 词库相关

Comments

@zeng-y-l
Copy link

啥东西?

关于Unihan:UAX #38: Unicode Han Database (Unihan)
大概是Unicode搞的一个东西,和汉字有关。里面有我们(至少我)需要的数据:拼音。

对于没有的词,可以养词库;但是,对于没有的字,只能修改词典。罪魁祸首是大量的生僻字。只要扩大字库,就能解决这个问题。

Unihan的数据,格式清晰、数量可观、质量可靠,处理起来省心省力效果好。将其制成字库,“长尾”的字有了保障。

我将其中Readings文件的kMandarin字段(普通话,可于上述网页查找规范)的拼音,通过NodeJS写的脚本,制成词库。

成品共有四万多个字。不过,其没有词频信息,无法替代基础词库。可作为殿后,提供补充。

其没有词频,自动放在最后,仅在英文前面,对一般打字没有影响。

我发现Go代码中,有用到”汉字拼音映射“文件。我不知道Go代码作何用,但或许这个大词库能发挥作用。

注意,字库中有“n”(如:嗯)“m”(如:呣)拼音。这两个格式反常的拼音(或许还有其他),虽然是正确的,但可能会带来副作用。

此外,同个文件中还有别的字段,也包括汉语拼音,甚至也有频率信息。但是,别的拼音都比普通话少,似乎也没什么可以互补的;频率更是只有3800字。因此我没有选它们。

怎么用?

  1. 已经安装NodeJS。我使用Git Bash,可能需要使用类似的终端,否则我也不知道命令能否运行。

  2. 下载并解压https://www.unicode.org/Public/15.0.0/ucd/Unihan.zip。其中的Unihan_Readings.txt是需要的。

  3. 保存下面的JS代码,假设于同一个文件夹的unihan.js中。代码的工作类似grep,从stdin输入文件,stdout输出词库的主体数据。

  4. 在此运行命令:

    cat ./Unihan_Readings.txt | node ./unihan.js > ./unihan.dict.yaml

    现在unihan.dict.yaml的头几行应该如下,往前面加入其他信息即可:

    㐀	qiu
    㐁	tian
    㐄	kua
    㐅	wu
    
const { createInterface } = require('readline')

createInterface(process.stdin).on('line', line => {
	const data = line.match(/^U\+([0-9A-F]*)\tkMandarin\t(.*)$/)
	if (data == null) return // 不是普通话发音部分

	const char = String.fromCodePoint(Number.parseInt(data[1], 16))
	const pinyinList = data[2].split(' ').map(word =>
		word.normalize('NFD').replace(/[^a-z]/g, '')) // 去掉声调

	for (const pinyin of new Set(pinyinList)) { // 去重
		process.stdout.write(`${char}\t${pinyin}\n`) // 输出
	}
})

此外……

  • 如果采纳,希望能在词库中标注我的名称(ZengYL)或网址(https://www.zengyulin.cn

  • 如果遇到问题,我也有已经制好的词库,可以提交(那么我需要学习一下怎么提PR

@iDvel iDvel added the dict 词库相关 label Mar 30, 2023
@iDvel
Copy link
Owner

iDvel commented Mar 30, 2023

谢谢,可以的,作为第二个字表殿后也不错。
不过不准备默认启用,大部分人用《通用规范汉字表》即可,有大字表需求的可以启动这个字表。

import_tables:
  - cn_dicts/8105     # 字表
  - cn_dicts/41448    # 大字表

@iDvel iDvel closed this as completed in bda1265 Mar 30, 2023
@yisibl
Copy link

yisibl commented Apr 8, 2024

@zeng-y-l 这里面有新加坡汉字、越南汉字之类的,可能需要去掉

@zeng-y-l
Copy link
Author

zeng-y-l commented Apr 8, 2024

@yisibl 我觉得问题不大,因为这个字库总是排在后面

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dict 词库相关
Projects
None yet
Development

No branches or pull requests

3 participants