From b724a3a58eb03029ee1f2ad483dcf3c4621aa944 Mon Sep 17 00:00:00 2001 From: Peter Olson Date: Wed, 25 Sep 2019 18:32:47 +0600 Subject: [PATCH] =?UTF-8?q?pinyinify=20fixes=20(=E5=BE=97=E5=8F=AA,=20?= =?UTF-8?q?=E9=9B=AA=E5=9C=B0,=20=E7=BE=8E=E7=9A=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/spec.js | 7 +++++++ src/pinyinDict.js | 4 ++-- src/pinyinify.js | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/spec/spec.js b/spec/spec.js index e36720f..d00f8b3 100644 --- a/spec/spec.js +++ b/spec/spec.js @@ -40,16 +40,23 @@ describe("Pinyinify", () => { expect("我得去。").becomes("wǒ děi qù."); expect("我说得快。").becomes("wǒ shuō de kuài."); expect("你们觉得我画得怎么样?").becomes("nǐ​men jué​de wǒ huà de zěn​me​yàng?"); + expect("喂,睡得还好吗?").becomes("wèi, shuì de hái​hǎo ma?"); // 还 expect("我有钱了就还你。").becomes("wǒ yǒu​qián le jiù huán nǐ."); expect("我还给你。").becomes("wǒ huán​gěi nǐ."); expect("你还喜欢她吗?").becomes("nǐ hái xǐ​huan tā ma?"); expect("你得还我的东西。").becomes("nǐ děi huán wǒ de dōng​xi."); expect("他还会把钱还律师吗?").becomes("tā hái huì bǎ qián huán lǜ​shī ma?"); + // 只 + expect("他是一只鸟。").becomes("tā shì yī zhī niǎo."); expect("行了吗?").becomes("xíng le ma?"); expect("人要是行干一行行一行。").becomes("rén yào​shi xíng gàn yī háng xíng yī háng."); expect("几行代码?两行代码。行还是不行?行!").becomes("jǐ háng dài​mǎ? liǎng háng dài​mǎ. xíng hái​shi bù​xíng? xíng!"); + + expect("结果").becomes("jiéguǒ"); + expect("很美的运动。").becomes("hěn měi de yùn​dòng."); + expect("雪地上有好东西。").becomes("xuě​dì​ shàng yǒu hǎo dōng​xi."); }); it("converts punctuation and spacing", () => { diff --git a/src/pinyinDict.js b/src/pinyinDict.js index ba6bcec..ad02c06 100644 --- a/src/pinyinDict.js +++ b/src/pinyinDict.js @@ -77624,7 +77624,7 @@ let dict = [ "结束|||結束|jié​shù", "结束工作|||結束工作|jié​shù​gōng​zuò", "结束语|||結束語|jié​shù​yǔ", - "结果|||結果|jiē​guǒ", + "结果|||結果|jiéguǒ", "结核|||結核|jié​hé", "结核杆菌|||結核桿菌|jié​hé​gǎn​jūn", "结核病|||結核病|jié​hé​bìng", @@ -79867,7 +79867,6 @@ let dict = [ "美玲|||美玲|Měi​líng", "美甲|||美甲|měi​jiǎ", "美白|||美白|měi​bái", - "美的|||美的|Měi​dí", "美眄|||美眄|měi​miǎn", "美眉|||美眉|měi​méi", "美瞳|||美瞳|měi​tóng", @@ -105467,6 +105466,7 @@ let dict = [ "雪佛龙石油公司|||雪佛龍石油公司|Xuě​fó​lóng​Shí​yóu​Gōng​sī", "雪克|||雪克|xuě​kè", "雪利酒|||雪利酒|xuě​lì​jiǔ", + "雪地|||雪地|xuě​dì​", "雪地车|||雪地車|xuě​dì​chē", "雪地靴|||雪地靴|xuě​dì​xuē", "雪城|||雪城|Xuě​chéng", diff --git a/src/pinyinify.js b/src/pinyinify.js index 44fe50b..57ea962 100644 --- a/src/pinyinify.js +++ b/src/pinyinify.js @@ -67,8 +67,14 @@ function decideAmbiguousChar(char, cuts, cutIndex) { return "cháng"; case "得": nextTags = tag(afterText.join("")); + prevTags = tag(previousText.join("")); if (nextTags && nextTags.length) { let afterTag = nextTags[0].tag; + let prevTag = prevTags.length && prevTags[prevTags.length - 1].tag + if (prevTag === "v") { + break; + } + if (nextTags[0].word === "还" || nextTags[0].word === "還") { if (nextTags[1] && nextTags[1].tag[0] === "r" || nextTags[1].tag[0] === "n") { return "děi"; @@ -96,6 +102,12 @@ function decideAmbiguousChar(char, cuts, cutIndex) { return "háng"; } break; + case "只": + let prev = tag(previousText.join("")).slice(-1)[0]; + let after = tag(afterText.join(""))[0]; + if (prev && prev.tag === "m") return "zhī"; + if (after && after.tag === "n") return "zhī"; + return "zhǐ"; } }