textlint-ja / analyze-desumasu-dearu

文の敬体(ですます調)、常体(である調)を解析するJavaScriptライブラリ
MIT License
18 stars 5 forks source link

Analyzing "masu" failed? #8

Closed 0x6b closed 5 years ago

0x6b commented 5 years ago

Hi,

Although the module description says it will detect "desu-masu" and "dearu", it seems not to handle "masu" case. I'm not sure this is designated behavior or not. Could you give me your thought on this.

Tested versions:

Steps to reproduce:

  1. Clone testing repository
    $ git clone https://github.com/0x6b/testing-analyze-desumasu-dearu.git
  2. Install dependencies
    $ npm install
  3. Run test
    $ npm test

Expected result:

Phrase "iOSに対応します。" will print some object dump which contains conjugated_type: '特殊・マス'.

Actual result:

$ npm test

> testing-analyze-desumasu-dearu@1.0.0 test /Users/.../test-mix-dearu-desumasu/testing-analyze-desumasu-dearu
> node index.js

iOSに対応だ。
[]
iOSに対応です。
[ { type: '特殊・デス',
    value: 'です。',
    surface: 'です',
    index: 6,
    token:
     { word_id: 23760,
       word_type: 'KNOWN',
       word_position: 7,
       surface_form: 'です',
       pos: '助動詞',
       pos_detail_1: '*',
       pos_detail_2: '*',
       pos_detail_3: '*',
       conjugated_type: '特殊・デス',
       conjugated_form: '基本形',
       basic_form: 'です',
       reading: 'デス',
       pronunciation: 'デス' } } ]
iOSに対応します。
[]

Following local fix could solve my issue.

diff --git a/src/analyze.js b/src/analyze.js
index 24aff80..51b9d36 100644
--- a/src/analyze.js
+++ b/src/analyze.js
@@ -33,6 +33,7 @@ const defaultOptions = {
  */
 export const Types = {
     desu: "特殊・デス",
+    masu: "特殊・マス",
     dearu: "特殊・ダ"
 };
 /**
@@ -40,7 +41,7 @@ export const Types = {
  * @returns {boolean}
  */
 export function isDesumasu(resultObject) {
-    return resultObject.type === Types.desu;
+    return (resultObject.type === Types.desu || resultObject.type === Types.masu);
 }
 /**
  * @param {AnalyzedResultObject} resultObject
@@ -153,7 +154,7 @@ export function analyze(text, options = defaultOptions) {
                         }
                     }
                 }
-            } else if (conjugatedType === Types.desu) {
+            } else if (conjugatedType === Types.desu || conjugatedType === Types.masu) {
                 // TODO: can omit?
                 if (token["conjugated_form"] === "基本形") {
                     // 文末の"です"のみを許容する場合は、文末であるかどうかを調べる
azu commented 5 years ago

Yes. you're correct. We should add 特殊・マス type to Types.

https://github.com/azu/analyze-desumasu-dearu/blob/d9f2fc7dc16f7b53f17653d83547b5cbace51e32/src/analyze.js#L42-L44

Also, we need to change this line.

-            } else if (conjugatedType === Types.desu) {
+            } else if (conjugatedType === Types.desu || conjugatedType === Types.masu) {

https://github.com/azu/analyze-desumasu-dearu/blob/d9f2fc7dc16f7b53f17653d83547b5cbace51e32/src/analyze.js#L156

It is good that We add isDesumasuType and isDearuType and use it.

0x6b commented 5 years ago

@azu thanks for your investigation! Allow me open a new pull request.

0x6b commented 5 years ago

Note: open a pull request to textlint-rule-no-mix-dearu-desumasu as well.