Skip to content

Commit

Permalink
fix 你还爱我吗?
Browse files Browse the repository at this point in the history
  • Loading branch information
peterolson committed Nov 30, 2019
1 parent 26631fa commit 9115f53
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions spec/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe("Pinyinify", () => {
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("hǎo ba, wǒ zhì​shǎo hái yǒu​xiē péng​you.");
expect("你还爱我吗?").becomes("nǐ hái ài wǒ ma?");
// 只
expect("他是一只鸟。").becomes("tā shì yī zhī niǎo.");
// 长
Expand Down
1 change: 1 addition & 0 deletions src/pinyinify.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function decideAmbiguousChar(char, cuts, cutIndex) {
case "还":
case "還":
nextTags = tag(afterText.join(""));
console.log(nextTags);
if (nextTags && nextTags.length) {
let afterTag = nextTags[0].tag;
if (afterText[0][0] === "有") break;
Expand Down
2 changes: 1 addition & 1 deletion src/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function tag(text) {
let tokens = nodejieba.tag(text);
let outTokens = [];
for (let { word, tag } of tokens) {
if (word.length > 1 && tag === "x") {
if (word.length > 1 && (tag === "x" || (tag === "n" && word.includes("吗")))) {
for (let char of word) {
outTokens.push(nodejieba.tag(char)[0]);
}
Expand Down

0 comments on commit 9115f53

Please sign in to comment.