From 549f04599e486951c353e4f81b8120d70a986f22 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Sun, 20 Mar 2022 15:33:35 +0900 Subject: [PATCH 1/9] Update README.en.md --- README.en.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.en.md b/README.en.md index 9c15c19..aadb228 100644 --- a/README.en.md +++ b/README.en.md @@ -1,7 +1,7 @@ # What -This is an attempt to detect [gomamayo](https://thinaticsystem.com/glossary/gomamayo/), a play on words, using MeCab. -Only work on Japanese. +This is an attempt to detect [gomamayo](https://thinaticsystem.com/glossary/gomamayo/), a play on words, using MeCab. +Only works in Japanese. # Getting Started @@ -9,8 +9,8 @@ Only work on Japanese. - deno - MeCab -- MeCab dictionary - We recommend the use of mecab-ipadic-neologd. (https://github.com/neologd/mecab-ipadic-neologd) +- MeCab dictionary + Use of mecab-ipadic-neologd is recommended (https://github.com/neologd/mecab-ipadic-neologd) ## Example From 51eafe8ed4dc230709a95dd61ad68c0e76b23942 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Mon, 21 Mar 2022 22:51:43 +0900 Subject: [PATCH 2/9] =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E5=8C=96?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mod.ts | 2 +- src/cli.ts | 6 +- src/example.ts | 4 +- src/index.ts | 177 +++++++++++++++++++++++++------------------------ 4 files changed, 100 insertions(+), 89 deletions(-) diff --git a/mod.ts b/mod.ts index bd0d55a..1bd063b 100644 --- a/mod.ts +++ b/mod.ts @@ -1 +1 @@ -export { analyse } from "./src/index.ts"; +export { Gomamayo } from "./src/index.ts"; \ No newline at end of file diff --git a/src/cli.ts b/src/cli.ts index badd701..e60af19 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,4 +1,6 @@ -import { analyse } from "./index.ts"; +import { Gomamayo } from "./index.ts"; const inputString:string = Deno.args[0]; -console.log(await analyse(inputString)); \ No newline at end of file +const gomamayo = new Gomamayo(); + +console.log(await gomamayo.analyse(inputString)); \ No newline at end of file diff --git a/src/example.ts b/src/example.ts index 1ddf5da..eaf9257 100644 --- a/src/example.ts +++ b/src/example.ts @@ -1,4 +1,6 @@ -import * as gomamayo from "https://deno.land/x/gomamayo_deno/mod.ts"; +import {Gomamayo} from "../mod.ts"; + +const gomamayo = new Gomamayo(); const inputString:string = Deno.args[0]; diff --git a/src/index.ts b/src/index.ts index 0d6409d..e602efa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,5 @@ import { MeCab } from "https://deno.land/x/deno_mecab@v1.1.1/mod.ts"; // assets/vowel_define.jsonを読み込む -const vowelDefine = await Deno.readTextFile("./assets/vowel_define.json"); -const mecab = new MeCab(["mecab"]); type gomamayoResult = { isGomamayo: boolean; @@ -16,99 +14,108 @@ type gomamayoDetail = { rawResult2: any; // mecab.parseの結果 気持ち的にはMeCabのParsedWordって型を使いたい。 }; -/** - * @param {string} inputString - * @return {MeCab.ParsedWord[]} - */ -async function parse(inputString: string) { - const rawResult = await mecab.parse(inputString); +class Gomamayo { + private vowelDefine: string; + private mecab = new MeCab(["mecab"]); + + constructor() { + this.vowelDefine = Deno.readTextFileSync("./assets/vowel_define.json"); + } - // rawResult.pronunciationがundefinedの場合、rawResult.pronunciation = rawResult.surfaceとなるようにする - const parseResult = rawResult.map((raw) => { - if (raw.pronunciation === undefined) { - raw.pronunciation = raw.surface; - } - if (raw.reading === undefined) { - raw.reading = raw.surface; - } - return raw; - }); - return parseResult; -} + /** + * @param {string} inputString + * @return {MeCab.ParsedWord[]} + */ + public async parse(inputString: string) { + const rawResult = await this.mecab.parse(inputString); -/** - * @param {string} rawReading - * @return {string} - */ -function prolongedSoundMarkVowelize(rawReading: string): string { - const vowelDefineJSON = JSON.parse(vowelDefine); - // readingに長音が含まれている場合はすべてカタカナに変換する - let returnReading = ""; - rawReading.replace(/[ぁ-ゖ]/g, (s) => { - return String.fromCharCode(s.charCodeAt(0) + 0x60); - }); - for (let i = 0; i < rawReading.length; i++) { - const prev = rawReading[i - 1]; - const current = rawReading[i]; - returnReading += (current === "ー") ? vowelDefineJSON[prev] : current; + // rawResult.pronunciationがundefinedの場合、rawResult.pronunciation = rawResult.surfaceとなるようにする + const parseResult = rawResult.map((raw) => { + if (raw.pronunciation === undefined) { + raw.pronunciation = raw.surface; + } + if (raw.reading === undefined) { + raw.reading = raw.surface; + } + return raw; + }); + return parseResult; } - return returnReading; -} -/** - * @param {string} 判定したい文字列 - * @return 分析結果 - */ -async function analyse(inputString: string): Promise { - const gomamayoResult: gomamayoResult = { - isGomamayo: false, - combo: 0, - detail: [], - }; - const rawParseResult = await parse(inputString); + /** + * @param {string} rawReading + * @return {string} + */ + public prolongedSoundMarkVowelize(rawReading: string): string { + const vowelDefineJSON = JSON.parse(this.vowelDefine); + // readingに長音が含まれている場合はすべてカタカナに変換する + let returnReading = ""; + rawReading.replace(/[ぁ-ゖ]/g, (s) => { + return String.fromCharCode(s.charCodeAt(0) + 0x60); + }); + for (let i = 0; i < rawReading.length; i++) { + const prev = rawReading[i - 1]; + const current = rawReading[i]; + returnReading += (current === "ー") ? vowelDefineJSON[prev] : current; + } + return returnReading; + } - // rawParseResult[i].readingに「ー」が含まれていたらprolongedSoundMarkVowelizeを実行し、それに置き換える - rawParseResult.map((raw) => { - if (typeof raw.reading !== "undefined") { - if (raw.reading.includes("ー")) { - raw.reading = prolongedSoundMarkVowelize(raw.reading); + /** + * @param {string} 判定したい文字列 + * @return 分析結果 + */ + public async analyse(inputString: string): Promise { + const gomamayoResult: gomamayoResult = { + isGomamayo: false, + combo: 0, + detail: [], + }; + const rawParseResult = await this.parse(inputString); + + // rawParseResult[i].readingに「ー」が含まれていたらprolongedSoundMarkVowelizeを実行し、それに置き換える + rawParseResult.map((raw) => { + if (typeof raw.reading !== "undefined") { + if (raw.reading.includes("ー")) { + raw.reading = this.prolongedSoundMarkVowelize(raw.reading); + } } - } - return raw; - }); + return raw; + }); - for (let i = 0; i < rawParseResult.length - 1; i++) { - const first = rawParseResult[i]; - const second = rawParseResult[i + 1]; - if ( - first.feature !== "名詞" && first.feature !== "数詞" || - second.surface === first.surface - ) { - continue; - } - // first.readingを後ろから1文字ずつ見ていく - // 同時に、second.readingを先頭から1文字ずつ見ていく - // 一致したら、gomamayoResultにpushする - if (first.reading && second.reading) { - // firstとsecondのreading.lengthのうち、短い方を - const minLength = Math.min(first.reading.length, second.reading.length); - for (let j = 1; j < minLength; j++) { - const firstReading = first.reading.slice(first.reading.length - j); - const secondReading = second.reading.slice(0, j); - if (firstReading === secondReading) { - gomamayoResult.isGomamayo = true; - gomamayoResult.detail.push({ - surface: first.surface + "|" + second.surface, - dimension: j, - rawResult1: first, - rawResult2: second, - }); - gomamayoResult.combo++; + for (let i = 0; i < rawParseResult.length - 1; i++) { + const first = rawParseResult[i]; + const second = rawParseResult[i + 1]; + if ( + first.feature !== "名詞" && first.feature !== "数詞" || + second.surface === first.surface + ) { + continue; + } + // first.readingを後ろから1文字ずつ見ていく + // 同時に、second.readingを先頭から1文字ずつ見ていく + // 一致したら、gomamayoResultにpushする + if (first.reading && second.reading) { + // firstとsecondのreading.lengthのうち、短い方を + const minLength = Math.min(first.reading.length, second.reading.length); + for (let j = 1; j < minLength; j++) { + const firstReading = first.reading.slice(first.reading.length - j); + const secondReading = second.reading.slice(0, j); + if (firstReading === secondReading) { + gomamayoResult.isGomamayo = true; + gomamayoResult.detail.push({ + surface: first.surface + "|" + second.surface, + dimension: j, + rawResult1: first, + rawResult2: second, + }); + gomamayoResult.combo++; + } } } } + return gomamayoResult; } - return gomamayoResult; } -export { analyse }; +export { Gomamayo }; \ No newline at end of file From 93d67e95948a7c28157bf18b2225345812bdc2e9 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Mon, 21 Mar 2022 22:56:24 +0900 Subject: [PATCH 3/9] =?UTF-8?q?=EF=BD=BA=EF=BE=9E=EF=BE=8F=EF=BE=8F?= =?UTF-8?q?=EF=BE=96ignore=E3=81=AE=E6=BA=96=E5=82=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index e602efa..7f66c4f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,10 +62,11 @@ class Gomamayo { } /** - * @param {string} 判定したい文字列 + * @param {string} inputString 判定したい文字列 + * @param {boolean} isIgnored 除外設定を使うかどうか。指定した文字列を除外する場合はtrue。デフォルトはtrue。 * @return 分析結果 */ - public async analyse(inputString: string): Promise { + public async analyse(inputString: string, isIgnored?: boolean): Promise { const gomamayoResult: gomamayoResult = { isGomamayo: false, combo: 0, From d1a55572f2d6aa042dcdc1b1c17215d8b09413ec Mon Sep 17 00:00:00 2001 From: na2na-p Date: Mon, 21 Mar 2022 23:03:15 +0900 Subject: [PATCH 4/9] wip --- .vscode/settings.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index da82814..8351aef 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,8 @@ "deno.lint": true, "deno.unstable": false, "cSpell.words": [ - "Deno" + "Deno", + "ipadic", + "neologd" ] } \ No newline at end of file From 35714f5c47e6423b4c283e6920cdf318b9a32398 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Mon, 21 Mar 2022 23:03:21 +0900 Subject: [PATCH 5/9] =?UTF-8?q?=E4=B8=BB=E3=81=AB=E5=9E=8B=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7f66c4f..a042e82 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,18 +1,36 @@ import { MeCab } from "https://deno.land/x/deno_mecab@v1.1.1/mod.ts"; // assets/vowel_define.jsonを読み込む -type gomamayoResult = { +interface ParsedWord { + // 0 + surface: string; + // 1 + feature: string; + // 2..4 + featureDetails: string[]; + // 5..6 + conjugationForms: string[]; + // 7 + originalForm: string; + // 8 + reading?: string; + // 9 + pronunciation?: string; +} + +interface gomamayoResult { isGomamayo: boolean; combo: number; // inputString中にあるゴママヨの総数 detail: gomamayoDetail[]; -}; +} -type gomamayoDetail = { +interface gomamayoDetail { surface: string; // 該当の2語を入れる dimension: number; // n次ゴママヨのn - rawResult1: any; // mecab.parseの結果 気持ち的にはMeCabのParsedWordって型を使いたい。 - rawResult2: any; // mecab.parseの結果 気持ち的にはMeCabのParsedWordって型を使いたい。 -}; + rawResult1: ParsedWord; // mecab.parseの結果 気持ち的にはMeCabのParsedWordって型を使いたい。 + rawResult2: ParsedWord; // mecab.parseの結果 気持ち的にはMeCabのParsedWordって型を使いたい。 +} + class Gomamayo { private vowelDefine: string; @@ -24,7 +42,7 @@ class Gomamayo { /** * @param {string} inputString - * @return {MeCab.ParsedWord[]} + * @return {ParsedWord[]} */ public async parse(inputString: string) { const rawResult = await this.mecab.parse(inputString); @@ -66,7 +84,7 @@ class Gomamayo { * @param {boolean} isIgnored 除外設定を使うかどうか。指定した文字列を除外する場合はtrue。デフォルトはtrue。 * @return 分析結果 */ - public async analyse(inputString: string, isIgnored?: boolean): Promise { + public async analyse(inputString: string, isIgnored = true): Promise { const gomamayoResult: gomamayoResult = { isGomamayo: false, combo: 0, @@ -74,6 +92,10 @@ class Gomamayo { }; const rawParseResult = await this.parse(inputString); + if (isIgnored) { + console.log("除外設定を使用します。"); + } + // rawParseResult[i].readingに「ー」が含まれていたらprolongedSoundMarkVowelizeを実行し、それに置き換える rawParseResult.map((raw) => { if (typeof raw.reading !== "undefined") { From 9be24fd000d6616ef45065219f3da5210d6bbdf9 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Mon, 21 Mar 2022 23:05:40 +0900 Subject: [PATCH 6/9] =?UTF-8?q?=E5=9E=8B=E5=AE=9A=E7=BE=A9=E8=A6=8B?= =?UTF-8?q?=E7=9B=B4=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index a042e82..e866740 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,7 +81,7 @@ class Gomamayo { /** * @param {string} inputString 判定したい文字列 - * @param {boolean} isIgnored 除外設定を使うかどうか。指定した文字列を除外する場合はtrue。デフォルトはtrue。 + * @param isIgnored 除外設定を使うかどうか。指定した文字列を除外する場合はtrue。デフォルトはtrue。 * @return 分析結果 */ public async analyse(inputString: string, isIgnored = true): Promise { From f128584c2be02155dad8575e07d8b5e8e0865b1f Mon Sep 17 00:00:00 2001 From: na2na-p Date: Mon, 21 Mar 2022 23:56:20 +0900 Subject: [PATCH 7/9] wip --- .gitignore | 1 + README.md | 6 ++++-- src/cli.ts | 22 +++++++++++++++++++--- src/index.ts | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index e69de29..6320cd2 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +data \ No newline at end of file diff --git a/README.md b/README.md index d0cb9fc..dc57277 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,10 @@ - Deno - MeCab -- MeCab 辞書 - [mecab-ipadic-neologd](https://github.com/neologd/mecab-ipadic-neologd)がおすすめです。 +- MeCab 辞書 + - [mecab-ipadic-neologd](https://github.com/neologd/mecab-ipadic-neologd)がおすすめです。 +- 除外設定用設定ファイル + - 必須ではありません。 ## 実行例 diff --git a/src/cli.ts b/src/cli.ts index e60af19..0d4295b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,6 +1,22 @@ import { Gomamayo } from "./index.ts"; -const inputString:string = Deno.args[0]; +const mode = Deno.args[0]; // "analyse" or "addIgnore" +const inputString: string = Deno.args[1]; -const gomamayo = new Gomamayo(); +// "../data/ignoreWords.json"に設定ファイルがあると想定しています。 +// なければ作成してください。 +const gomamayo = new Gomamayo("../data/ignoreWords.json"); -console.log(await gomamayo.analyse(inputString)); \ No newline at end of file +switch (mode) { + case "addIgnore": + console.log("addIgnore"); + console.log(await gomamayo.addIgnoreWord(inputString)); + break; + + case "analyse": + console.log(await gomamayo.analyse(inputString)); + break; + + default: + console.log(await gomamayo.analyse(inputString)); + break; +} diff --git a/src/index.ts b/src/index.ts index e866740..2721c3c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { MeCab } from "https://deno.land/x/deno_mecab@v1.1.1/mod.ts"; -// assets/vowel_define.jsonを読み込む +import { Database } from "https://deno.land/x/aloedb@0.9.0/mod.ts"; interface ParsedWord { // 0 @@ -31,20 +31,30 @@ interface gomamayoDetail { rawResult2: ParsedWord; // mecab.parseの結果 気持ち的にはMeCabのParsedWordって型を使いたい。 } +interface ignoreWord { + surface: string; +} class Gomamayo { private vowelDefine: string; private mecab = new MeCab(["mecab"]); - - constructor() { + private db: Database | null = null; + + constructor(dbPath: string | null = null) { this.vowelDefine = Deno.readTextFileSync("./assets/vowel_define.json"); + if (dbPath) { + this.db = new Database(dbPath); + console.log(`${dbPath} を読み込みました。`); + } else { + this.db = null; + } } - + /** * @param {string} inputString * @return {ParsedWord[]} */ - public async parse(inputString: string) { + public async parse(inputString: string): Promise { const rawResult = await this.mecab.parse(inputString); // rawResult.pronunciationがundefinedの場合、rawResult.pronunciation = rawResult.surfaceとなるようにする @@ -84,7 +94,10 @@ class Gomamayo { * @param isIgnored 除外設定を使うかどうか。指定した文字列を除外する場合はtrue。デフォルトはtrue。 * @return 分析結果 */ - public async analyse(inputString: string, isIgnored = true): Promise { + public async analyse( + inputString: string, + isIgnored = true, + ): Promise { const gomamayoResult: gomamayoResult = { isGomamayo: false, combo: 0, @@ -139,6 +152,30 @@ class Gomamayo { } return gomamayoResult; } + + /** + * ゴママヨではない語を設定する。設定ファイルが必要。 + * @param word + * @returns + */ + public addIgnoreWord(word: string): Promise { + if (this.db) { + this.db.insertOne({ + surface: word, + }) + .then(() => { + console.log(`${word} を除外設定に追加しました。`); + }) + .catch((err) => { + console.error(err); + return false; + }); + console.log(this.db); + return Promise.resolve(true); + } else { + return Promise.resolve(false); + } + } } -export { Gomamayo }; \ No newline at end of file +export { Gomamayo }; From 8ff3546f1807d8ac21a23a79243e9b94944b2bf2 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Tue, 22 Mar 2022 00:26:57 +0900 Subject: [PATCH 8/9] =?UTF-8?q?=E3=83=89=E3=82=AD=E3=83=A5=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88=E7=B3=BB=E3=81=AE=E6=95=B4=E5=82=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/cli.ts | 4 ++-- src/example.ts | 25 +++++++++++++++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index dc57277..5df86d2 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ - MeCab 辞書 - [mecab-ipadic-neologd](https://github.com/neologd/mecab-ipadic-neologd)がおすすめです。 - 除外設定用設定ファイル - - 必須ではありません。 + - 必須ではありません。作成する場合は空ファイルのjsonを作成してください。AloeDBを使用しています。そちらの設定を確認してもらうのもいいかもしれません。 ## 実行例 -`deno run --allow-run --allow-read https://deno.land/x/gomamayo_deno/src/cli.ts 株式公開買付` +`deno run --allow-run --allow-read https://deno.land/x/gomamayo_deno/src/cli.ts analyse 株式公開買付` あるいは、`https://deno.land/x/gomamayo_deno/src/example.ts`を参考にしてください。 ## 実行結果 diff --git a/src/cli.ts b/src/cli.ts index 0d4295b..dbddd78 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -4,7 +4,7 @@ const inputString: string = Deno.args[1]; // "../data/ignoreWords.json"に設定ファイルがあると想定しています。 // なければ作成してください。 -const gomamayo = new Gomamayo("../data/ignoreWords.json"); +const gomamayo = new Gomamayo("./data/ignoreWords.json"); switch (mode) { case "addIgnore": @@ -17,6 +17,6 @@ switch (mode) { break; default: - console.log(await gomamayo.analyse(inputString)); + console.log("第一引数で、実行モード(analyse/addIgnore)の指定をしてください。"); break; } diff --git a/src/example.ts b/src/example.ts index eaf9257..99debf6 100644 --- a/src/example.ts +++ b/src/example.ts @@ -1,7 +1,24 @@ -import {Gomamayo} from "../mod.ts"; +import { Gomamayo } from "https://deno.land/x/gomamayo_deno/mod.ts"; -const gomamayo = new Gomamayo(); +const ignoreSettingsPath = "./data/ignoreWords.json"; // 除外ファイル設定を書いてください。設定しない場合はnull、あるいは new Gomamayo(ignoreSettingsPath) としてください。 +const gomamayo = new Gomamayo(ignoreSettingsPath); +const mode = Deno.args[0]; // "analyse" or "addIgnore" +const inputString: string = Deno.args[1]; -const inputString:string = Deno.args[0]; +// deno run --allow-run --allow-read https://deno.land/x/gomamayo_deno/src/cli.ts analyse 株式公開買付 +// deno run --allow-run --allow-read https://deno.land/x/gomamayo_deno/src/cli.ts addIgnore 株式公開買付 -console.log(await gomamayo.analyse(inputString)); \ No newline at end of file +switch (mode) { + case "addIgnore": + console.log("addIgnore"); + console.log(await gomamayo.addIgnoreWord(inputString)); + break; + + case "analyse": + console.log(await gomamayo.analyse(inputString)); + break; + + default: + console.log("第一引数で、実行モード(analyse/addIgnore)の指定をしてください。"); + break; +} From 2cbca3f2ee359da960cdb6b94b18e01674fa2cd8 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Tue, 22 Mar 2022 00:27:11 +0900 Subject: [PATCH 9/9] =?UTF-8?q?=E9=99=A4=E5=A4=96=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=82=92=E5=88=A9=E7=94=A8=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 2721c3c..cdfb933 100644 --- a/src/index.ts +++ b/src/index.ts @@ -107,6 +107,16 @@ class Gomamayo { if (isIgnored) { console.log("除外設定を使用します。"); + if (this.db) { + const ignoreWords = await this.db.findMany(); + // ignoreWords[i].surfaceが、inputStringに含まれているかどうかを判定する + for (let i = 0; i < ignoreWords.length; i++) { + if (inputString.includes(ignoreWords[i].surface)) { + console.log(`除外ワード\n${ignoreWords[i].surface}\nが含まれていたため、判定を中断します。`); + return gomamayoResult; + } + } + } } // rawParseResult[i].readingに「ー」が含まれていたらprolongedSoundMarkVowelizeを実行し、それに置き換える @@ -170,7 +180,6 @@ class Gomamayo { console.error(err); return false; }); - console.log(this.db); return Promise.resolve(true); } else { return Promise.resolve(false);