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

type: 'all' 选项输出增加多音字标记字段 #206

Open
yisibl opened this issue Mar 28, 2024 · 5 comments · Fixed by #208
Open

type: 'all' 选项输出增加多音字标记字段 #206

yisibl opened this issue Mar 28, 2024 · 5 comments · Fixed by #208

Comments

@yisibl
Copy link
Collaborator

yisibl commented Mar 28, 2024

功能描述

通过新增一个多音字标记字段,可以快速知道哪些是多音字,进而再通过单独的 polyphonic 函数来获取每个多音字的所有读音。

@zh-lx
Copy link
Owner

zh-lx commented Mar 29, 2024

#208 中新增了 polyphonic 字段支持该功能

@yisibl
Copy link
Collaborator Author

yisibl commented Mar 29, 2024

我看到目前新增的 polyphonic 字段是一个数组 2fd861f#diff-2bac67505471502a69cd648252b7abb10b354f6f4daaf451976c012b630e0bbeR185

这会增加一些遍历成本,我其实更希望这个字段是一个布尔值,具体的有几个读音可以单独获取,这样不影响第一次的渲染效率。

@yisibl
Copy link
Collaborator Author

yisibl commented Mar 29, 2024

理想情况下,API 可考虑如下设计:

  • isPolyphonic 判断某个字是否为多音字,不包含变调的字,因为变调字并不是多音字。
  • isToneSandhi 判断某个字的读音在当前上下文中是否产生了变调。

最终字多音字的读音还是统一通过 polyphonic() 获取:

  • polyphonic() 增加布尔选项 toneSandhi,默认 false,只有 true 的时候才返回所有的变调读音。
import { polyphonic } from 'pinyin-pro';

const resultString = polyphonic('一', { toneSandhi: true, } ); // 返回所有读音包含变调读音:['yī', 'yí', 'yì']

const resultAll = polyphonic('一', { type: 'all',  toneSandhi: true, }); // 为变调读音输出单独的字段标识。

@yisibl yisibl reopened this Mar 29, 2024
@zh-lx
Copy link
Owner

zh-lx commented Mar 29, 2024

经测试目前在 type: all 模式下添加 polyphonic 后对性能整体影响不是很大(不到1/10),主要原因是 type: 'all' 中有部分其他信息影响了性能。考虑出一个针对 type: 'all' 的单独要获取的信息的配置。

@yisibl
Copy link
Collaborator Author

yisibl commented Mar 29, 2024

考虑出一个针对 type: 'all' 的单独要获取的信息的配置。

这个可以有,因为 pinyin() 函数默认还是尽量保持更高效为好,我找不到在这个 API 一次性输出所有读音的使用场景。

另外,轻声也不是多音字,可能也需要单独的标记字段。

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

Successfully merging a pull request may close this issue.

2 participants