Skip to content

fix: 〜かどうか を例外として許容する #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ textlint --rule no-doubled-joshi README.md

並立助詞(`たり`)は連続するのが意図した助詞であるため許可します。

### 〜かどうか

> これにする**かどう**か**検討する

このような場合、助詞(**か**)が連続していますが、"〜かどうか"表現は一般的であるため許可します。

- Issue: [質問: ~かどうか、について · Issue #62 · textlint-ja/textlint-rule-no-doubled-joshi](https://github.com/textlint-ja/textlint-rule-no-doubled-joshi/issues/62)
- [文節中の「か」の用法](https://jumonji-u.repo.nii.ac.jp/record/700/files/22-1.pdf)
- [かどうか/疑問詞・・・か](https://www.jpf.go.jp/j/urawa/j_rsorcs/textbook/setsumei_pdf/setsumei16_2.pdf>)

### 連語(助詞)

- [連語(助詞) - 修飾語 - 品詞の分類 - Weblio 辞書](http://www.weblio.jp/parts-of-speech/%E9%80%A3%E8%AA%9E(%E5%8A%A9%E8%A9%9E)_1 "連語(助詞) - 修飾語 - 品詞の分類 - Weblio 辞書")
Expand Down
32 changes: 23 additions & 9 deletions src/no-doubled-joshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function createSurfaceKeyMap(tokens: KuromojiToken[]): { [index: string]: Kuromo
);
}

function matchExceptionRule(tokens: KuromojiToken[]) {
const token = tokens[0];
function matchExceptionRule(joshiTokens: KuromojiToken[], allTokens: KuromojiToken[]) {
const token = joshiTokens[0];
// "の" の重なりは例外
if (token.pos_detail_1 === "連体化") {
return true;
Expand All @@ -61,9 +61,23 @@ function matchExceptionRule(tokens: KuromojiToken[]) {
}
// 並立助詞は例外
// 登ったり降りたり
if (tokens.length === 2 && tokens[0].pos_detail_1 === "並立助詞" && tokens[1].pos_detail_1 === "並立助詞") {
if (
joshiTokens.length === 2 &&
joshiTokens[0].pos_detail_1 === "並立助詞" &&
joshiTokens[1].pos_detail_1 === "並立助詞"
) {
return true;
}
// 〜か〜か のパターン
// 〜かどうか は例外 として許容する
if (joshiTokens.length === 2 && joshiTokens[0].surface_form === "か" && joshiTokens[1].surface_form === "か") {
// 〜|か|どう|か|
const lastかIndex = allTokens.indexOf(joshiTokens[1]);
const douToken = allTokens[lastかIndex - 1];
if (douToken && douToken.surface_form === "どう") {
return true;
}
}
return false;
}

Expand Down Expand Up @@ -216,8 +230,8 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
// https://github.com/textlint-ja/textlint-rule-no-doubled-joshi/issues/15
// 連語(助詞)の対応
// http://www.weblio.jp/parts-of-speech/%E9%80%A3%E8%AA%9E(%E5%8A%A9%E8%A9%9E)_1
const concatTokens = concatJoishiTokens(tokens);
const countableTokens = concatTokens.filter((token) => {
const concatedJoshiTokens = concatJoishiTokens(tokens);
const countableJoshiTokens = concatedJoshiTokens.filter((token) => {
if (isStrict) {
return is助詞Token(token);
}
Expand All @@ -242,7 +256,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
}
return is助詞Token(token);
});
const joshiTokenSurfaceKeyMap = createSurfaceKeyMap(countableTokens);
const joshiTokenSurfaceKeyMap = createSurfaceKeyMap(countableJoshiTokens);
/*
# Data Structure

Expand All @@ -261,7 +275,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
}
// strict mode ではない時例外を除去する
if (!isStrict) {
if (matchExceptionRule(joshiTokenSurfaceTokens)) {
if (matchExceptionRule(joshiTokenSurfaceTokens, tokens)) {
return;
}
}
Expand All @@ -271,8 +285,8 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
// if found differenceIndex less than
// tokes are sorted ascending order
joshiTokenSurfaceTokens.reduce((prev, current) => {
const startPosition = countableTokens.indexOf(prev);
const otherPosition = countableTokens.indexOf(current);
const startPosition = countableJoshiTokens.indexOf(prev);
const otherPosition = countableJoshiTokens.indexOf(current);
// 助詞token同士の距離が設定値以下ならエラーを報告する
const differenceIndex = otherPosition - startPosition;
if (differenceIndex <= minInterval) {
Expand Down
8 changes: 8 additions & 0 deletions test/no-doubled-joshi-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ tester.run("no-double-joshi", rule, {
// 並立助詞
"台に登ったり降りたりする",
"AとBとCを持ってきて",
// "〜か〜か" のパターン
// "〜かどうか" は例外として許容する(誤検知が起きにくいため)
// https://jumonji-u.repo.nii.ac.jp/record/700/files/22-1.pdf
// Issue: https://github.com/textlint-ja/textlint-rule-no-doubled-joshi/issues/62
// https://www.jpf.go.jp/j/urawa/j_rsorcs/textbook/setsumei_pdf/setsumei16_2.pdf
"これにするかどうか検討する",
"ここがわたしたちの席かどうか確かめましょう。",
"日本料理が好きかどうか聞いてください",
// fix regression - https://travis-ci.org/textlint-ja/textlint-rule-preset-ja-technical-writing/builds/207700760#L720
"慣用的表現、熟語、概数、固有名詞、副詞など、漢数字を使用することが一般的な語句では漢数字を使います。",
// カッコ内は別のセンテンスとしてみなす
Expand Down