zh-lx / pinyin-pro

中文转拼音、拼音音调、拼音声母、拼音韵母、多音字拼音、姓氏拼音、拼音匹配、中文分词
https://pinyin-pro.cn
MIT License
3.82k stars 332 forks source link

标注某个词时报错,可能字典有错 #224

Closed tansongchen closed 4 months ago

tansongchen commented 4 months ago

bug 描述

import { pinyin, addDict } from 'pinyin-pro';
import CompleteDict from '@pinyin-pro/data/complete.json';
addDict(CompleteDict);
pinyin('连杆式', { toneType: 'none' });

运行以上脚本,报错

TypeError: Cannot read properties of undefined (reading 'replace')
    at J (/math/home/songchen/文档/rime-snow-pinyin/snow/node_modules/pinyin-pro/dist/index.js:1:264366)
    at /math/home/songchen/文档/rime-snow-pinyin/snow/node_modules/pinyin-pro/dist/index.js:1:266739
    at Array.forEach (<anonymous>)
    at on (/math/home/songchen/文档/rime-snow-pinyin/snow/node_modules/pinyin-pro/dist/index.js:1:266708)
    at tn (/math/home/songchen/文档/rime-snow-pinyin/snow/node_modules/pinyin-pro/dist/index.js:1:268521)
    at CompleteDict (/math/home/songchen/文档/rime-snow-pinyin/snow/test.ts:4:1)
    at Object.<anonymous> (/math/home/songchen/文档/rime-snow-pinyin/snow/test.ts:4:35)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Object.S (/math/home/songchen/.nvm/versions/node/v20.11.1/lib/node_modules/tsx/dist/cjs/index.cjs:1:1292)
    at Module.load (node:internal/modules/cjs/loader:1207:32)

Node.js v20.11.1

你预期的样子是?

正确标注拼音

pinyin-pro 版本号

3.20.0

引入方式

ES Module

最小成本的复现步骤

将上述文件放到一个脚本里,运行

tsx test.ts
zh-lx commented 4 months ago

感谢反馈~已在 3.20.1 版本中修复了该问题,辛苦安装新版本体验一下

tansongchen commented 4 months ago

好快,赞一个

tansongchen commented 4 months ago

今天又测试了一下,似乎 3.20.2 中仍然有此问题。在更大的词库上测试了一下,这些词语都报错:

连杆式
连杆机构
多连杆式
多连杆式独立悬挂
多连杆式独立悬架
曲柄连杆机构
tansongchen commented 4 months ago

感觉这应该是一个 CompleteDict 中的问题?如果去掉 addDict(CompleteDict); 这一行,就没错了

tansongchen commented 4 months ago

哦,明白了,是我只更新了 pinyin-pro,没有更新相应的 data。现在好了

zh-lx commented 4 months ago

好嘞好嘞

---- 回复的原邮件 ---- | 发件人 | Songchen @.> | | 日期 | 2024年04月19日 04:55 | | 收件人 | @.> | | 抄送至 | @.>、State @.> | | 主题 | Re: [zh-lx/pinyin-pro] 标注某个词时报错,可能字典有错 (Issue #224) |

哦,明白了,是我只更新了 pinyin-pro,没有更新相应的 data。现在好了

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you modified the open/close state.Message ID: @.***>