Skip to content

Commit

Permalink
pinyinify fixes (得只, 雪地, 美的)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterolson committed Sep 25, 2019
1 parent 8ee19d5 commit b724a3a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions spec/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/pinyinDict.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions src/pinyinify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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ǐ";
}
}

Expand Down

0 comments on commit b724a3a

Please sign in to comment.