Skip to content

Commit

Permalink
Fix canto handler
Browse files Browse the repository at this point in the history
  • Loading branch information
hockyy committed Jul 25, 2024
1 parent c5e52f4 commit cedd47f
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions main/handler/chinese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from "path";
import fs from "fs";
import {pinyin} from "pinyin-pro";
import ToJyutping from "to-jyutping";
import { loadDict, cut } from '@node-rs/jieba'
import {loadDict, cut} from '@node-rs/jieba'


interface JyutpingResult {
Expand Down Expand Up @@ -107,31 +107,33 @@ class Chinese {
}


static async getJyutpingForSentence(sentence: string): Promise<JyutpingResult[]> {
const segments = cut(sentence);
const result: JyutpingResult[] = [];
static getJyutpingForSentence(sentence: string): Promise<JyutpingResult[]> {
return Promise.resolve().then(() => {
const segments = cut(sentence);
const result: JyutpingResult[] = [];

for (const segment of segments) {
const jyutpingList = ToJyutping.getJyutpingList(segment);
const jyutping = jyutpingList.map(([, jp]) => jp).join(' ');
const separation = jyutpingList.map(([char, jp]) => ({
main: char,
jyutping: jp
}));
for (const segment of segments) {
const jyutpingList = ToJyutping.getJyutpingList(segment);
const jyutping = jyutpingList.map(([, jp]) => jp).join(' ');
const separation = jyutpingList.map(([char, jp]) => ({
main: char,
jyutping: jp
}));

result.push({
origin: segment,
jyutping: jyutping,
separation: separation
});
}
result.push({
origin: segment,
jyutping: jyutping,
separation: separation
});
}

return result;
return result;
});
}

static registerCantoJieba() {
ipcMain.handle('tokenizeUsingCantoneseJieba', async (event, sentence) => {
const res = this.getJyutpingForSentence(sentence);
const res = await this.getJyutpingForSentence(sentence);
return res;
});

Expand Down

0 comments on commit cedd47f

Please sign in to comment.