GithubHelp home page GithubHelp logo

Comments (5)

zh-lx avatar zh-lx commented on September 3, 2024

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

from pinyin-pro.

yisibl avatar yisibl commented on September 3, 2024

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

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

from pinyin-pro.

yisibl avatar yisibl commented on September 3, 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, }); // 为变调读音输出单独的字段标识。

from pinyin-pro.

zh-lx avatar zh-lx commented on September 3, 2024

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

from pinyin-pro.

yisibl avatar yisibl commented on September 3, 2024

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

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

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

from pinyin-pro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.