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

Feat change tone #181

Merged
merged 3 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ npm install pinyin-pro
</tr>
<tr>
<td rowspan="2" colspan="2">准确率</td>
<td>😕 Node 版: 97.331%</td>
<td rowspan="2">😕 97.279%</td>
<td rowspan="2">🤩 99.795%</td>
<td>😕 Node 版: 95.277%</td>
<td rowspan="2">😕 95.123%</td>
<td rowspan="2">🤩 99.846%</td>
</tr>
<tr>
<td>😕 Web 版: 94.353% </td>
<td>😕 Web 版: 92.197% </td>
</tr>
<tr>
<td rowspan="3">性能</td>
Expand Down
8 changes: 4 additions & 4 deletions benchmark/accuracy.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/common/ac.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PatternNumberDict } from '@/data/dict-number';
import { PatternNumberDict } from '@/data/special';
import { Pattern2 } from '@/data/dict2';
import { Pattern3 } from '@/data/dict3';
import { Pattern4 } from '@/data/dict4';
Expand Down
10 changes: 8 additions & 2 deletions lib/core/pinyin/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SpecialFinalMap,
SpecialFinalList,
doubleFinalList,
getSepecialChangeTone,
} from '@/data/special';
import Surnames from '@/data/surname';
import DICT1 from '@/data/dict1';
Expand All @@ -21,7 +22,7 @@ import {
* @return {string}
*/
type GetSingleWordPinyin = (word: string) => string;
const getSingleWordPinyin: GetSingleWordPinyin = (word) => {
export const getSingleWordPinyin: GetSingleWordPinyin = (word) => {
const wordCode = word.charCodeAt(0);
const pinyin = DICT1[wordCode];
// 若查到, 则返回第一个拼音; 若未查到, 返回原字符
Expand Down Expand Up @@ -89,7 +90,12 @@ export const getPinyin = (
matchIndex++;
} else {
const char = word[i];
const pinyin = getSingleWordPinyin(char);
let pinyin: string = '';
if (!match || match.index > i + 1) {
pinyin = getSepecialChangeTone(char, word[i - 1], word[i + 1]);
} else {
pinyin = getSingleWordPinyin(char);
}
list[i] = {
origin: char,
result: pinyin,
Expand Down
54 changes: 0 additions & 54 deletions lib/data/dict-number.ts

This file was deleted.

29 changes: 11 additions & 18 deletions lib/data/dict2.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { Priority } from '@/common/constant';
import type { Pattern } from '../../lib/common/ac';
const DICT2: { [prop: string]: string } = {
一个: 'yí gè',
这个: 'zhè ge',
不是: 'bú shì',
成为: 'chéng wéi',
认为: 'rèn wéi',
作为: 'zuò wéi',
部分: 'bù fèn',
要求: 'yāo qiú',
应该: 'yīng gāi',
增长: 'zēng zhǎng',
不会: 'bú huì',
提供: 'tí gōng',
觉得: 'jué de',
任务: 'rèn wu',
Expand Down Expand Up @@ -105,7 +102,6 @@ const DICT2: { [prop: string]: string } = {
路上: 'lù shang',
只怕: 'zhǐ pà',
能量: 'néng liàng',
一度: 'yí dù',
储量: 'chǔ liàng',
供应: 'gōng yìng',
挑战: 'tiǎo zhàn',
Expand Down Expand Up @@ -318,7 +314,6 @@ const DICT2: { [prop: string]: string } = {
车子: 'chē zi',
上将: 'shàng jiàng',
恶心: 'ě xin',
不对: 'bú duì',
担子: 'dàn zi',
应届: 'yīng jiè',
行列: 'háng liè',
Expand All @@ -338,7 +333,6 @@ const DICT2: { [prop: string]: string } = {
吐蕃: 'tǔ bō',
钻进: 'zuān jìn',
乐队: 'yuè duì',
不当: 'bù dàng',
亮相: 'liàng xiàng',
被子: 'bèi zi',
舍得: 'shě de',
Expand Down Expand Up @@ -383,7 +377,6 @@ const DICT2: { [prop: string]: string } = {
为数: 'wéi shù',
勾当: 'gòu dàng',
削减: 'xuē jiǎn',
一发: 'yī fà',
间谍: 'jiàn dié',
埋怨: 'mán yuàn',
结实: 'jiē shi',
Expand All @@ -403,7 +396,7 @@ const DICT2: { [prop: string]: string } = {
王八: 'wáng ba',
切割: 'qiē gē',
间隔: 'jiàn gé',
一晃: ' huǎng',
一晃: ' huǎng',
长假: 'cháng jià',
令狐: 'líng hú',
为害: 'wéi hài',
Expand Down Expand Up @@ -489,7 +482,6 @@ const DICT2: { [prop: string]: string } = {
看中: 'kàn zhòng',
议长: 'yì zhǎng',
风筝: 'fēng zheng',
一应: 'yī yīng',
辟邪: 'bì xié',
空隙: 'kòng xì',
更迭: 'gēng dié',
Expand All @@ -502,7 +494,7 @@ const DICT2: { [prop: string]: string } = {
无量: 'wú liàng',
空地: 'kòng dì',
调度: 'diào dù',
一曲: ' qǔ',
一曲: ' qǔ',
散射: 'sǎn shè',
太行: 'tài háng',
创伤: 'chuāng shāng',
Expand Down Expand Up @@ -533,7 +525,6 @@ const DICT2: { [prop: string]: string } = {
悄声: 'qiǎo shēng',
曲子: 'qǔ zi',
情调: 'qíng diào',
一着: 'yī zhāo',
挑衅: 'tiǎo xìn',
代为: 'dài wéi',
了结: 'liǎo jié',
Expand Down Expand Up @@ -788,7 +779,6 @@ const DICT2: { [prop: string]: string } = {
疟疾: 'nüè ji',
唠叨: 'láo dao',
限量: 'xiàn liàng',
一打: 'yī dá',
屏息: 'bǐng xī',
重逢: 'chóng féng',
器乐: 'qì yuè',
Expand Down Expand Up @@ -885,7 +875,6 @@ const DICT2: { [prop: string]: string } = {
处世: 'chǔ shì',
中风: 'zhòng fēng',
等量: 'děng liàng',
不菲: 'bù fěi',
放量: 'fàng liàng',
腔调: 'qiāng diào',
老少: 'lǎo shào',
Expand Down Expand Up @@ -1151,7 +1140,6 @@ const DICT2: { [prop: string]: string } = {
着迷: 'zháo mí',
挑担: 'tiāo dàn',
纹路: 'wén lu',
一沓: 'yī dá',
还俗: 'huán sú',
强横: 'qiáng hèng',
着数: 'zhāo shù',
Expand Down Expand Up @@ -1522,7 +1510,6 @@ const DICT2: { [prop: string]: string } = {
瘠薄: 'jí bó',
浆糊: 'jiàng hu',
嘎吱: 'gā zhī',
不遂: 'bù suí',
调令: 'diào lìng',
法帖: 'fǎ tiè',
淋病: 'lìn bìng',
Expand Down Expand Up @@ -1644,7 +1631,6 @@ const DICT2: { [prop: string]: string } = {
解送: 'jiè sòng',
反间: 'fǎn jiàn',
少壮: 'shào zhuàng',
一服: 'yī fù',
留空: 'liú kòng',
告假: 'gào jià',
咳血: 'ké xiě',
Expand Down Expand Up @@ -2170,13 +2156,20 @@ const DICT2: { [prop: string]: string } = {
臧否: 'zāng pǐ',
否泰: 'pǐ tài',
变得: 'biàn de',
不住: 'bú zhù',
丈夫: 'zhàng fu',
豆腐: 'dòu fu',
不再: 'bú zài',
笔杆: 'bǐ gǎn',
枞阳: 'zōng yáng',
行人: 'xíng rén',
打着: 'dǎ zhe',
第一: 'dì yī',
万一: 'wàn yī',
之一: 'zhī yī',
统一: 'tǒng yī',
如一: 'rú yī',
初一: 'chū yī',
一一: 'yī yī',
高一: 'gāo yī',
};
export default DICT2;
export const Pattern2: Pattern[] = Object.keys(DICT2).map((key) => ({
Expand Down
15 changes: 2 additions & 13 deletions lib/data/dict3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const DICT3: { [prop: string]: string } = {
发脾气: 'fā pí qi',
士大夫: 'shì dà fū',
三部曲: 'sān bù qǔ',
少不了: 'shǎo bù liǎo',
仡佬族: 'gē lǎo zú',
交响曲: 'jiāo xiǎng qǔ',
鸭绿江: 'yā lù jiāng',
Expand All @@ -42,7 +41,6 @@ const DICT3: { [prop: string]: string } = {
发行量: 'fā xíng liàng',
兴冲冲: 'xìng chōng chōng',
分子量: 'fēn zǐ liàng',
大不了: 'dà bù liǎo',
国子监: 'guó zǐ jiàn',
老大难: 'lǎo dà nán',
党内外: 'dǎng nèi wai',
Expand All @@ -66,7 +64,6 @@ const DICT3: { [prop: string]: string } = {
车行道: 'chē háng dào',
中郎将: 'zhōng láng jiàng',
照明弹: 'zhào míng dàn',
一溜烟: 'yī liù yān',
烟幕弹: 'yān mù dàn',
没奈何: 'mò nài hé',
乱哄哄: 'luàn hōng hōng',
Expand All @@ -86,7 +83,6 @@ const DICT3: { [prop: string]: string } = {
劳什子: 'láo shí zi',
摇滚乐: 'yáo gǔn yuè',
夹竹桃: 'jiā zhú táo',
一刀切: 'yī dāo qiē',
闹哄哄: 'nào hōng hōng',
三连冠: 'sān lián guàn',
重头戏: 'zhòng tóu xì',
Expand Down Expand Up @@ -114,13 +110,11 @@ const DICT3: { [prop: string]: string } = {
曳光弹: 'yè guāng dàn',
少林拳: 'shào lín quán',
咏叹调: 'yǒng tàn diào',
一个劲: 'yī gè jìn',
少先队: 'shào xiān duì',
灵长目: 'líng zhǎng mù',
对着干: 'duì zhe gàn',
蒙蒙亮: 'mēng mēng liàng',
软骨头: 'ruǎn gǔ tou',
不省得: 'bù xǐng de',
铺盖卷: 'pū gài juǎn',
和稀泥: 'huò xī ní',
背黑锅: 'bēi hēi guō',
Expand All @@ -141,7 +135,7 @@ const DICT3: { [prop: string]: string } = {
占便宜: 'zhàn pián yi',
打主意: 'dǎ zhǔ yi',
多弹头: 'duō dàn tóu',
露一手: 'lòu shǒu',
露一手: 'lòu shǒu',
堰塞湖: 'yàn sè hú',
保得住: 'bǎo de zhù',
趵突泉: 'bào tū quán',
Expand All @@ -150,7 +144,6 @@ const DICT3: { [prop: string]: string } = {
禁不起: 'jīn bu qǐ',
什刹海: 'shí chà hǎi',
莲花落: 'lián huā lào',
一场空: 'yī cháng kōng',
前奏曲: 'qián zòu qǔ',
见世面: 'xiàn shì miàn',
豁出去: 'huō chu qu',
Expand All @@ -174,7 +167,6 @@ const DICT3: { [prop: string]: string } = {
看得起: 'kàn de qǐ',
糊涂账: 'hú tu zhàng',
大猩猩: 'dà xīng xing',
一溜儿: 'yī liù ér',
禁得起: 'jīn de qǐ',
法相宗: 'fǎ xiāng zōng',
可怜相: 'kě lián xiàng',
Expand Down Expand Up @@ -227,14 +219,12 @@ const DICT3: { [prop: string]: string } = {
数得着: 'shǔ de zháo',
傻劲儿: 'shǎ jìn er',
铅玻璃: 'qiān bō li',
抹不开: 'mò bù kāi',
可的松: 'kě dì sōng',
划得来: 'huá de lái',
晕乎乎: 'yùn hū hū',
屎壳郎: 'shǐ ke làng',
尥蹶子: 'liào juě zi',
藏红花: 'zàng hóng huā',
说不着: 'shuō bù zháo',
闷罐车: 'mèn guàn chē',
卡脖子: 'qiǎ bó zi',
红澄澄: 'hóng deng deng',
Expand Down Expand Up @@ -280,7 +270,6 @@ const DICT3: { [prop: string]: string } = {
泥娃娃: 'ní wá wa',
内切圆: 'nèi qiē yuán',
哪会儿: 'něi huì er',
摸不着: 'mō bù zháo',
闷头儿: 'mèn tou er',
没谱儿: 'méi pǔ er',
铆劲儿: 'mǎo jìn er',
Expand Down Expand Up @@ -321,7 +310,7 @@ const DICT3: { [prop: string]: string } = {
骨朵儿: 'gū duǒ er',
功劳簿: 'gōng láo bù',
都江堰: 'dū jiāng yàn',
一担水: ' dàn shuǐ',
一担水: ' dàn shuǐ',
否极泰: 'pǐ jí tài',
泰来否: 'tài lái pǐ',
咳特灵: 'ké tè líng',
Expand Down
Loading
Loading