From 52e1e138334cbe3f6f1dfe62b769b88af4f9bc31 Mon Sep 17 00:00:00 2001 From: azu Date: Thu, 16 Jan 2025 09:55:15 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20"=E3=82=84=E3=81=99"=20=E3=81=AF=20?= =?UTF-8?q?=E3=81=A7=E3=81=99=E3=81=BE=E3=81=99=E8=AA=BF=E3=81=AE=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E3=81=8B=E3=82=89=E9=99=A4=E5=A4=96=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 6 +++--- package.json | 3 ++- src/analyze.js | 16 +++++++++++++--- test/analyze-test.js | 6 ++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 170443f..ae01ba4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,12 +6,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [12, 14] + node-version: [ 20, 22 ] steps: - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: setup Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Install diff --git a/package.json b/package.json index ae6d6b5..c49a95e 100644 --- a/package.json +++ b/package.json @@ -57,5 +57,6 @@ "*.{js,jsx,ts,tsx,css}": [ "prettier --write" ] - } + }, + "packageManager": "yarn@1.22.22+sha256.c17d3797fb9a9115bf375e31bfd30058cac6bc9c3b8807a3d8cb2094794b51ca" } diff --git a/src/analyze.js b/src/analyze.js index 747656c..712a7b7 100644 --- a/src/analyze.js +++ b/src/analyze.js @@ -50,11 +50,16 @@ export function isDearu({ type }) { } /** - * typeが敬体(ですます調)か常体(である調)かを判定する + * typeが敬体(ですます調)なら true を返す * @param {string} type * @returns {boolean} */ const isDesumasuType = (type) => type === Types.desu || type === Types.masu; +/** + * typeが常体(である調)なら true を返す + * @param type + * @returns {boolean} + */ const isDearuType = (type) => type === Types.dearu; /** @@ -122,8 +127,7 @@ const mapToAnalyzedResult = (tokens) => { return { type: token["conjugated_type"], value: value, - surface: token["surface_form"], - // index start with 0 + surface: token["surface_form"], // index start with 0 index: token["word_position"] - 1, /** * @type {AnalyzedToken} @@ -160,6 +164,12 @@ export function analyze(text, options = defaultOptions) { } } } else if (isDesumasuType(conjugatedType)) { + // "やす" は "特殊・マス" として認識されるが、誤判定を避けるために除外する + // https://github.com/textlint-ja/textlint-rule-no-mix-dearu-desumasu/issues/52 + if (token["basic_form"] === "やす") { + return false; + } + // TODO: can omit? if (token["conjugated_form"] === "基本形") { // 文末の"です"のみを許容する場合は、文末であるかどうかを調べる diff --git a/test/analyze-test.js b/test/analyze-test.js index 0b81901..a835c7d 100644 --- a/test/analyze-test.js +++ b/test/analyze-test.js @@ -139,6 +139,12 @@ describe("analyze-test", function () { }); }); }); + it("'やす'はですます調としては認識しない", function () { + let text = "構成物の崩れやすさ、脆さに注意が必要である。"; + return analyzeDesumasu(text).then((results) => { + assert(results.length === 0); + }); + }); }); }); describe("analyzeDearu", function () {