zh-lx / pinyin-pro Goto Github PK
View Code? Open in Web Editor NEW中文转拼音、拼音音调、拼音声母、拼音韵母、多音字拼音、姓氏拼音、拼音匹配
Home Page: https://pinyin-pro.cn
License: MIT License
中文转拼音、拼音音调、拼音声母、拼音韵母、多音字拼音、姓氏拼音、拼音匹配
Home Page: https://pinyin-pro.cn
License: MIT License
请输入内容……
pinyin('汉语2拼音11', {pattern: 'first', toneType: 'none'}); // 期望: h y p y 去除 11 2
错误 输出,哼 h ng hng
"pinyin-pro": "^3.10.0",
(请告诉我们,如何最快的复现该 bug)
let wd = "哼";
let sheng = pinyin(wd, { pattern: "initial", toneType: "none", v: true }),
yun = pinyin(wd, { pattern: "final", toneType: "none", v: true });
console.log(wd, sheng, yun, pinyin(wd));
##安装🇬🇧百度输入法🐾应用 ##https://srf.baidu.com/?c=j&e=d&from=1000e&platform=ubuntu&ref=index_entrance_android_click sudo gdebi fcitx-baidupinyin.deb
- Originally posted by @englianhu in scibrokes/mytools#1 (comment)
杀猿者巫,亡巫者猿
,本人中华民族雷欧
,并非美猴王洋人雷猴
。npm install pinyin-pro # 或 yarn add pinyin-pro作者:德育处主任
链接:前端中文汉字转拼音
来源:慕课网
本文原创发布于慕课网 ,转载请注明出处,谢谢合作
- Originally posted by @englianhu in englianhu/binary.com-interview-question#7 (comment)
sudo apt-get install *scim* *gcin* *hime* *fcitx* -y《清明》
清明时节雨纷纷,路上行人欲断魂;
借问酒家何处有,牧童遥指杏花村。出处:小学必背古诗《清明》杜牧 借问酒家何处有?牧童遥指杏花村
《寻隐者不遇》
松下问童子,言师採药去;
只在此山中,云深不知处。出处:《寻隐者不遇》
参考文献
- 字体天下 - 方正楷体拼音字库
- 「小红书」字体~方正楷体拼音字库~
- scim输入法
- 「原创」SCIM输入法架构分析(上)
- 「原创」SCIM输入法架构分析(下)
- 「转载」linux下最好用的中文输入法 scim
- 「转载」debian下安装SCIM输入法的详细文档支援很齐全的天下诸侯各种语言输入法。
- Debian下scim配置
- 安装Debian下的中文输入法
- 树莓派Scim-pinyin输入法相关(安装,不能切换中文输入法)
- 讯飞输入法9.0正式发布:免切换 打字效率提升300%
- 讯飞输入法正式登陆Linux平台 带来更好的输入体验
pinyin-pro
在线运行- 「猫城」
pinyin-pro
专业的汉语拼音转化器- Debian 中文自由軟體 (Debian Chinese Free Software)
- 聊天打字带拼音的输入法?
- Debian & Ubuntu 設定中文輸入法
- [Linux] 讓 Linux 下的中文輸入法更接近微軟新注音使用體驗(以Ubuntu、Linux Mint為例)有介绍gcin、hime、ibus,hime输入法类似改良版gcin支援好几种语言,用户界面比scim容易操作,只可惜没有支援汉语拼音输入法(咱们马来西亚政府所有国民华校都是以汉语拼音、阴阳上去标音来授教,[Issue] Encode / Decode : Running
chunk
andknit
documents。可以通过孔子学院或像愚生的大嫂越女自学中文)。- Linux上的输入法-Gcin(支持词音、注音、拼音、仓颉、呒虾米)
- Luna's Debian/Devuan/Ubuntu/Mint Archiver
- englianhu/binary.com-interview-question#7
附有汉语拼音的**话输入法。
当传值为 全特殊字符 ,不包含中文时 提示Maximum call stack size exceeded 例如 aaa
请输入内容……
请输入内容……
3.6.0
请输入内容……
浏览器 script 引入 / esmodule(浏览器 import 引入) / commonjs(node require 引入)
(请告诉我们,如何最快的复现该 bug)
请输入遇到的问题...
例如输出的是: a ya,不能输出成:aya ?
希望增加对古诗词拼音的支持
请输入内容……
比如古诗鹿柴读音是lu zhai,而不是lu chai
请问想要获取 hao-hao-xue-xi
,拼音之间用 -
分隔如何实现呢
使用当前的方法时 let nameList = pinyin("三九二",{ pattern: 'initial', type: 'array' }); 输出的为 [ 's', 'j', '' ],当前的首字母不对
[ 's', 'j', 'e' ]
@3.3.1
const { pinyin } = require('pinyin-pro');
let nameList = pinyin("三九二",{ pattern: 'initial', type: 'array' });
浏览器 script 引入 / esmodule(浏览器 import 引入) / commonjs(node require 引入)
(请告诉我们,如何最快的复现该 bug)
建议增强match方法的功能
1.增加一个配置项,允许设置不分词匹配,如:match('汉语拼音', 'hanpin')在不分词匹配的情况下应该返回null;
2.增加对中文的匹配,如:match('汉语拼音', '语拼')应该返回[1, 2],虽然可以自己通过字符串匹配来实现,但是还是希望match方法可以兼容
使用pattern: final模式获取类似“序”(xu),“局”(ju),“与”(yu)等字的韵母时,得到的结果是“u”。
然而这些字事实上的韵母应该是是“ü”。
Since pinyin-pro
doesn't support segment
feature, it seems you shouldn't compare pinyin-pro
with segment
options enabled in pinyin
and @napi-rs/pinyin
.
The results from my computer without segment
enabled in pinyin
and @napi-rs/pinyin
:
OS: macOS 12.3.1 21E258 arm64
Host: MacBookPro18,2
Kernel: 21.4.0
Shell: zsh 5.8
CPU: Apple M1 Max
GPU: Apple M1 Max
Memory: 9539MiB / 65536MiB
node speed.js
pinyin-pro 转换 5000 字数时间: 3.193ms
pinyin 转换 5000 字数时间: 1.835ms
@napi-rs/pinyin 转换 5000 字数时间: 0.584ms
node speed.js
pinyin-pro 转换 10000 字数时间: 9.691ms
pinyin 转换 10000 字数时间: 5.644ms
@napi-rs/pinyin 转换 10000 字数时间: 1.093ms
node speed.js
pinyin-pro 转换 1000000 字数时间: 313.71ms
pinyin 转换 1000000 字数时间: 185.946ms
@napi-rs/pinyin 转换 1000000 字数时间: 135.24ms
This result is matched with benchmark results in @napi-rs/pinyin
查岗: 'zhā gǎng',
查核: 'zhā hé',
查缉: 'zhā jī',
应用场景:可以输入汉字或者英文,但是如果是汉字的话,需要转成拼音,中间用“”来连接,若是英文的话,就保持原样。如: 输入“负责人”,则转换成“fu_ze_ren”,若是输入的“changeBy”,输入应该还是“changeBy”,但是转换出来的结果却是c h a r g e B y,中间自动加了空格,前端做正则需要将空格替换成"",结果就成“c_h_a_r_g_e_B_y”,所以可以适配下英文状态下的转换规则么?,
The @napi-rs/pinyin
indeed supports esm project:
package.json
{
"type": "module",
"dependencies": {
"@napi-rs/pinyin": "^1.7.3"
}
}
index.js
import { pinyin } from '@napi-rs/pinyin'
console.log(pinyin("你好👋")) // [ 'ni', 'hao', '👋' ]
Can not convert the string of "一丁点儿\n" to Pinyin.
I would appreciate it if you could tell me the cause or solve it. 🙂
const { pinyin } = require('pinyin-pro')
const res = pinyin("一丁点儿\n")
TypeError: Cannot read properties of undefined (reading 'result')
at {workspace}/node_modules/pinyin-pro/dist/index.js:1:286390
at E ({workspace}/node_modules/pinyin-pro/dist/index.js:1:286561)
“将”字 的拼音缺少 jiàng
支持 html 拼音字符串输出
String.split 无法将多字节的 Unicode 扩展汉字正常转换到数组,而是按照两个字符处理,导致返回两个乱码
像正常情况下匹配不到拼音时一样,返回原字符
v3.7.2
不影响
pinyinPro.pinyin('龥') // 字库中没有的双字节字符\u9fa5,返回"龥"
pinyinPro.pinyin('𧒽') // 字库中没有的四字节字符\ud85d\udcbd,返回"� �"
如题,类似 https://www.npmjs.com/package/pinyin
console.log(pinyin("中心", {
heteronym: true // 启用多音字模式
})); // [ [ 'zhōng', 'zhòng' ], [ 'xīn' ] ]
const { pinyin } = require("pinyin-pro");
console.log(pinyin('foo/汉字/bar/123', {
pattern: 'pinyin',
toneType: 'none',
type: 'array',
nonZh: 'spaced'
}));
/*
This correct
[
'f', 'o', 'o', '/',
'han', 'zi', '/', 'b',
'a', 'r', '/', '1',
'2', '3'
]
*/
console.log(pinyin('foo/汉字/bar/123', {
pattern: 'initial',
toneType: 'none',
type: 'array',
nonZh: 'spaced'
}));
/*
[
'f', '', '', '', 'h',
'z', '', 'b', '', 'r',
'', '', '', ''
]
*/
console.log(pinyin('foo/汉字/bar/123', {
pattern: 'first',
toneType: 'none',
type: 'array',
nonZh: 'spaced'
}));
/*
[
'f', 'o', 'o', '/',
'h', 'z', '/', 'b',
'a', 'r', '/', '1',
'2', '3'
]
*/
非常感谢作者,你的这个实现非常高效,但多少有那么一点儿瑕玼。
例如如下代码
pinyin("a", { multiple: true, type: "array" })
报错
Cannot read property 'split' of undefined
建议在dict中未发现对应拼音的时候直接返回原词.
目前这个包,没有在 package.json 中 指定 exports 的描述,在 esm 中,导入时,会获得一个错误
类似如下错误
SyntaxError: Named export 'xx' not found. The requested module 'xx' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'xx';
const { b, a } = pkg;
这是我在 Nuxt 中得到的错误,他默认使用 Vite
@acme/nuxt:dev: ERROR [worker reload] [worker init] The requested module 'file:///Users/baboon/iduo/iduo-scheme-store/node_modules/pinyin-pro/dist/index.js' does not provide an export named 'pinyin'
@acme/nuxt:dev:
@acme/nuxt:dev: import { pinyin } from '/Users/baboon/iduo/iduo-scheme-store/node_modules/pinyin-pro/dist/index.js';
@acme/nuxt:dev: ^^^^^^
@acme/nuxt:dev: SyntaxError: The requested module '/Users/baboon/iduo/iduo-scheme-store/node_modules/pinyin-pro/dist/index.js' does not provide an export named 'pinyin'
@acme/nuxt:dev: at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
@acme/nuxt:dev: at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
@acme/nuxt:dev:
相关资料
https://es6.ruanyifeng.com/#docs/module-loader#package-json-%E7%9A%84-exports-%E5%AD%97%E6%AE%B5
https://juejin.cn/post/7132326156329549838
https://nodejs.org/api/packages.html#exports
这个也是目前对于多格式输出的库的主流用法
这是 Vue https://github.com/vuejs/core/blob/main/packages/vue/package.json#L22-L70
当然还有一些其他库
如果你没有时间,我愿意帮助你做这件事情。
最后 感谢你维护了这个库,为众多开发者节省了时间😄
1.需要增加的字
'乥':'hol',
'乲':'cɑ lo',
'兙':'shi2 ke3',
'兛':'qian1 ke4',
'兝':'gong1 fen1',
'兞':'hao2 ke4',
'兡':'bai3 ke4',
'兣':'gong1 li3',
'兺':'bun1',
'叾':'du1',
'唜':'mas5',
'嗧':'jia1 lun2',
'怾':'gi0',
'朩':'pin4',
'烪':'zhen4',
'瓧':'shi2 wa3',
'瓩':'qian1 wa3',
'瓰':'fen1 wa3',
'瓱':'mao2 wa3',
'瓲':'tun2 wa3',
'瓼':'li3 wa3',
'甅':'li2 wa3',
'硛':'ceok0',
'莻':'neus0',
'襨':'e0',
'覅':'fiao4',
'迲':'ke0',
'黁':'nun2',
'龥':'yu4',
2.bug,'呣'字,num模式输出结果不正确应为'm2',实际结果是'ḿ'
pinyinPro.pinyin('呣', { toneType: 'num' }) //ḿ
pinyin('价廉物美')
returns jià lián wù měi
which is correct.
But, pinyin('物美价廉')
also return jià lián wù měi
which is incorrect (wrongly ordered).
pinyin('物美价廉')
should return wù měi jià lián
.
v3.7.1
Tested both in browser and node environment. For browser, ViteJS is used.
var {pinyin} = require("pinyin-pro")
console.log(pinyin('物美价廉') + ' -- ' + pinyin('价廉物美'))
Here's a RunKit: https://runkit.com/cheeaun/6205478538a7f900084c18ca
Notes: I'm not sure if this affect other idioms too. I found that this idiom is inside main/data/dict3.ts
, and the library seems to only check if characters exists without looking at the indices?
请输入遇到的问题...
试用了下,支持繁体字。其他库(比如 https://github.com/hotoo/pinyin )提到“简单的繁体支持”,请问 pinyin-pro "完整"地支持繁体字吗?
例如,如果使用pattern: final模式获取”状“字的拼音,得到的结果是”uang“,由介音”u“和韵尾”ang“构成。希望能够增加一个新功能,可以将韵母的这两部分分离。
因为「姓氏」汉子存在多音字,如下:
const pinyin = require('pinyin-pro');
pinyin.pinyin('曾', { multiple: true, type: 'array' });
[ 'céng', 'zēng' ]
是否可提供一个功能,如下:
const pinyin = require('pinyin-pro');
pinyin.pinyin('曾', { multiple: true, type: 'array', kind: 'lastname' });
[ 'zēng' ]
customPinyin 和 multiple 参数同时使用时失效:
pinyinPro.customPinyin({
嗯: 'en',
});
console.log(
pinyinPro.pinyin('嗯', {
multiple: true,
type: 'array',
nonZh: 'removed',
toneTyp: 'num',
})
);
姓氏模式下如果自定义拼音包含了姓氏,则无法生效
应先判断自定义拼音再判断姓氏
3.6.1
esmodule
customPinyin({
乐嘉: 'lè jiā',
乐毅: 'yuè yì'
})
pinyin('乐嘉') // 输出 "lè jiā"
pinyin('乐嘉', { mode: 'surname' }) // 输出 "yuè jiā"
包含下列儿化音短句的字符串,如果短句后有任意字符(包括空格/换行),在转换时一定会报错
( mode: "surname"
时 那阵儿
、那会儿
因为包含姓氏不报错)
"pinyin-pro": "^3.13.0"
commonjs(node require 引入)
想做城市列表根据首字母查询的,目前可以按照获取拼音再截取字符串第一个,可以支持直接获取首字母功能吗?
输出字母能不能把空格去掉呢
感谢作者的贡献 🌹🌹🌹🌹
pinyin('李乐', { toneType: 'none' }); // 'li le'
● 希望也能得到其它形式的拼音 // 如把通过“李乐”得到 'li le' 和 'li yue' 这样的多种可能性
● 因为我遇到的工程有一个输入拼音首字母来快速检索的功能,之前用手段经常不能匹配到“会计”功能,因为程序以为那个是 hui ji
在微信小程序上使用,整个程序崩溃。
目前的版本是否有考虑将韵母ü
修改为v
的选项支持?甚至默认将ü
修改为v
?因为ü
在很多环境下使用会有问题
例如
pinyin('吕布', { toneType: 'none' }) // 'lü bu'
当然,这个问题显然可以通过字符串替换来达成。
如果有支持当然就更好了。
例如
nv3, hai2, er -> nǚ,hái,ér
请输入遇到的问题...
test case:
console.log(pinyin('xxxxx', { toneType: 'none', type: 'array' }));
error:
TypeError: Cannot read property 'xxxxx' of undefined
“略”我们会输入“lue”,但是只能输出 “lüe”。
皇甫: 姓氏拼音不正确
比如“百度网盘”四个字,这里面只有“度”是多音字,也就是说可以是,baiduwangpan、baiduowangpan,首字母是bdwp,我输入oa两个字母的时候也能match上,很费解,虽然是有duo这个拼音,但是起码是我输入duo之后再匹配上。
感谢项目贡献者的工作!我认为可以对本项目的一些功能做出改进:
本项目对于多音词处理上有一些小bug.而且根据文档,multiple
属性不能解决此问题
例如
pinyin("朝阳");
//输出"zhāo cháo yáng"
其中“朝”字被自动检测出两种读音。
如果关闭multiple
属性为false,输出结果仍然是zhāo cháo yáng
,一行出现了三个拼音。
"朝阳"一词有两种正确读音:zhao yang和chao yang均正确。对于其他多音词也可能会出现这个问题。
我认为可以把多音词的各种读音都返回到一个数组中。
第二个问题就是,项目中的多音词库似乎不足。比如“增长”,有zeng zhang
和zeng chang
两种读音。程序只能得到zeng zhang
读音。再比如"大夫",有da fu
(古代官职名)和dai fu
(医生称谓),项目中只能返回dai fu一词。
我认为可以在现有的权威拼音数据库中更新一些数据,可以解决这个问题。
有三个文本框,第一个输入姓氏,第个输入名字,第三个框自动输出拉丁化的姓名拼音,如姓氏:刘,名字:德华,输出:Liu Dehua
这个效果怎么实现呢?
当获取拼音首字母时 同时获取音调num时,只会出现首字母
首字母并携带音调num
最新版
node require 引入
pinyin.pinyin('山西',{pattern:'first',toneType:'num'})
pinyin.pinyin('陕西',{pattern:'first',toneType:'num'})
使用 AC 自动机优化字符串匹配效率
import pinyinPro from 'pinyin-pro';
console.log(pinyinPro.pinyin('莞'))
输出结果是dōng wǎn,正确是dōng guǎn
希望增加打包后的ESM文件,
有些环境下没有办法用webpack之类的打包工具, 也不能用requirejs,只希望直接用ESM动态导入使用,如:
import('/lib/pinyin-pro.js').then(exports=>{
let pinyin=exports.pinyin('测试');
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.