Skip to content

Commit

Permalink
Merge pull request #245 from zh-lx/feature-support-reduplication
Browse files Browse the repository at this point in the history
Feature support reduplication
  • Loading branch information
zh-lx authored Jun 9, 2024
2 parents d65c36b + 35932f3 commit 5d2219e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/data/special.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,20 @@ export function processToneSandhiLiao(cur: string, pre: string) {
}
}

// 处理叠字符[々]
function processReduplicationChar(cur: string, pre: string) {
if (cur === '々') {
if (!pre || !DICT1.get(pre)) {
return 'tóng';
} else {
return DICT1.get(pre).split(' ')[0];
}
}
}

export function processSepecialPinyin(cur: string, pre: string, next: string) {
return (
processReduplicationChar(cur, pre) ||
processToneSandhiLiao(cur, pre) ||
processToneSandhi(cur, pre, next) ||
getSingleWordPinyin(cur)
Expand Down
11 changes: 11 additions & 0 deletions test/special.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,15 @@ describe('[special tone sandhi]绕口令', () => {
const result = pinyin('了吧');
expect(result).to.be.equal('liǎo ba');
});

it('[special 々]々', () => {
const result = pinyin('天々向上,好々学习');
expect(result).to.be.equal('tiān tiān xiàng shàng , hǎo hǎo xué xí');

const result1 = pinyin('々々');
expect(result1).to.be.equal('tóng tóng');

const result2 = pinyin('々,々');
expect(result2).to.be.equal('tóng , tóng');
});
});

0 comments on commit 5d2219e

Please sign in to comment.