Skip to content

Commit

Permalink
fix(deps): update to kuromojin@3 (#35)
Browse files Browse the repository at this point in the history
* fix(deps): update to kuromojin@3

* CI: Move to GitHub Actions

* style: apply prettier
  • Loading branch information
azu authored Apr 24, 2021
1 parent eaef736 commit 9834912
Show file tree
Hide file tree
Showing 8 changed files with 1,621 additions and 1,530 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: test
on: [push, pull_request]
jobs:
test:
name: "Test on Node.js ${{ matrix.node-version }}"
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12, 14]
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: yarn install
- name: Test
run: yarn test
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# textlint-rule-no-doubled-joshi [![Build Status](https://travis-ci.org/textlint-ja/textlint-rule-no-doubled-joshi.svg?branch=master)](https://travis-ci.org/textlint-ja/textlint-rule-no-doubled-joshi)
# textlint-rule-no-doubled-joshi [![Actions Status: test](https://github.com/textlint-ja/textlint-rule-no-doubled-joshi/workflows/test/badge.svg)](https://github.com/textlint-ja/textlint-rule-no-doubled-joshi/actions?query=workflow%3A"test")

1つの文中に同じ助詞が連続して出てくるのをチェックする[textlint](https://github.com/textlint/textlint)ルールです。

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
"textlintrule"
],
"devDependencies": {
"@textlint/types": "^1.2.3",
"@types/node": "^12.12.14",
"@textlint/types": "^1.5.4",
"@types/node": "^14.14.41",
"husky": "^3.1.0",
"lint-staged": "^9.5.0",
"prettier": "^1.19.1",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"textlint-scripts": "^3.0.0",
"ts-node": "^8.5.4",
"typescript": "^3.7.3"
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
},
"dependencies": {
"kuromojin": "^2.0.0",
"sentence-splitter": "^3.2.0",
"kuromojin": "^3.0.0",
"sentence-splitter": "^3.2.1",
"textlint-rule-helper": "^2.1.1",
"textlint-util-to-string": "^3.0.0"
},
Expand Down
25 changes: 13 additions & 12 deletions src/no-doubled-joshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
create読点Matcher,
concatJoishiTokens,
createKeyFromKey,
restoreToSurfaceFromKey, is括弧Token
restoreToSurfaceFromKey,
is括弧Token,
} from "./token-utils";
import { TxtNode } from "@textlint/ast-node-types";
import { TextlintRuleModule } from "@textlint/types";
Expand Down Expand Up @@ -71,12 +72,12 @@ const defaultOptions = {
"?", // question mark
"!", // exclamation mark
"?", // (ja) zenkaku question mark
"!" // (ja) zenkaku exclamation mark
"!", // (ja) zenkaku exclamation mark
],
commaCharacters: [
"、",
"," // 全角カンマ
]
",", // 全角カンマ
],
};

export interface Options {
Expand Down Expand Up @@ -124,7 +125,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
const allow = options.allow || defaultOptions.allow;
const separatorCharacters = options.separatorCharacters || defaultOptions.separatorCharacters;
const commaCharacters = options.commaCharacters || defaultOptions.commaCharacters;
const {Syntax, report, RuleError} = context;
const { Syntax, report, RuleError } = context;
const is読点Token = create読点Matcher(commaCharacters);
return {
[Syntax.Paragraph](node) {
Expand All @@ -136,8 +137,8 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
};
const txtParentNode = splitSentences(node, {
SeparatorParser: {
separatorCharacters
}
separatorCharacters,
},
});
const sentences = txtParentNode.children.filter(isSentenceNode);
return getTokenizer().then((tokenizer: any) => {
Expand All @@ -150,7 +151,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
// 連語(助詞)の対応
// 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 countableTokens = concatTokens.filter((token) => {
if (isStrict) {
return is助詞Token(token);
}
Expand Down Expand Up @@ -178,7 +179,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
"で:助詞.係助詞": [tokenB, tokenD, tokenF]
}
*/
Object.keys(joshiTokenSurfaceKeyMap).forEach(key => {
Object.keys(joshiTokenSurfaceKeyMap).forEach((key) => {
const tokens: KuromojiToken[] = joshiTokenSurfaceKeyMap[key];
const joshiName = restoreToSurfaceFromKey(key);
// check allow
Expand Down Expand Up @@ -209,7 +210,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
new RuleError(
`一文に二回以上利用されている助詞 "${joshiName}" がみつかりました。`,
{
index: originalIndex
index: originalIndex,
}
)
);
Expand All @@ -218,9 +219,9 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
});
});
};
sentences.forEach(node => checkSentence(node));
sentences.forEach((node) => checkSentence(node));
});
}
},
};
};
export default report;
6 changes: 3 additions & 3 deletions src/token-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const is助詞Token = (token: KuromojiToken) => {
};

export const is括弧Token = (token: KuromojiToken) => {
return token && token.pos === "記号" && (token.pos_detail_1 === "括弧開" || token.pos_detail_1 === "括弧閉")
}
return token && token.pos === "記号" && (token.pos_detail_1 === "括弧開" || token.pos_detail_1 === "括弧閉");
};

/**
* 読点を判定する関数を返す
Expand Down Expand Up @@ -48,7 +48,7 @@ const concatToken = (aToken: KuromojiToken, bToken: KuromojiToken) => {
*/
export const concatJoishiTokens = (tokens: KuromojiToken[]) => {
const newTokens: KuromojiToken[] = [];
tokens.forEach(token => {
tokens.forEach((token) => {
const prevToken = newTokens[newTokens.length - 1];
if (is助詞Token(token) && is助詞Token(prevToken)) {
newTokens[newTokens.length - 1] = concatToken(prevToken, token);
Expand Down
108 changes: 54 additions & 54 deletions test/no-doubled-joshi-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ tester.run("no-double-joshi", rule, {
// "プロパティを削除しようとするとエラーが発生します。",
{
text: "太字も強調も同じように無視されます。",
options: {allow: ["も"]}
options: { allow: ["も"] },
},
// 区切り文字をカスタムする
// ♪を区切り文字としたので、次の文は2つのセンテンスになる
{
text: "これはペンです♪これは鉛筆です♪",
options: {separatorCharacters: ["♪"]}
options: { separatorCharacters: ["♪"] },
},
// ,を読点とみなす
{
text: "これがiPhone,これがAndroidです。",
options: {commaCharacters: [","]}
options: { commaCharacters: [","] },
},
],
invalid: [
Expand All @@ -63,116 +63,116 @@ tester.run("no-double-joshi", rule, {
message: `一文に二回以上利用されている助詞 "は" がみつかりました。`,
// last match
line: 1,
column: 4
}
]
column: 4,
},
],
},
{
text: "材料不足で代替素材で製品を作った。",
errors: [
{
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
line: 1,
column: 10
}
]
column: 10,
},
],
},
{
text: "クォートで囲むことで文字列を作成できる点は、他の文字列リテラルと同じです。",
errors: [
{
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
index: 9
}
]
index: 9,
},
],
},
{
text: "列車事故でバスで振り替え輸送を行った。 ",
errors: [
{
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
line: 1,
column: 8
}
]
column: 8,
},
],
},
{
text: "洋服をドラム式洗濯機でお湯と洗剤で洗い、乾燥機で素早く乾燥させる。",
options: {
min_interval: 2
min_interval: 2,
},
errors: [
{
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
line: 1,
column: 17
column: 17,
},
{
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
line: 1,
column: 24
}
]
column: 24,
},
],
},
{
text: "法律案は十三日の衆議院本会議で賛成多数で可決され、参議院に送付されます",
errors: [
{
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
line: 1,
column: 20
}
]
column: 20,
},
],
},
{
// 、 で間隔値が+1されるが、strictでは+されない
text: "彼女は困り切った表情で、小声で尋ねた。",
options: {
strict: true
strict: true,
},
errors: [
{
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
line: 1,
column: 15
}
]
column: 15,
},
],
},
{
text: "白装束で重力のない足どりでやってくる",
options: {
min_interval: 2
min_interval: 2,
},
errors: [
{
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
line: 1,
column: 13
}
]
column: 13,
},
],
},
{
text: "既存のコードの利用",
options: {
strict: true
strict: true,
},
errors: [
{
message: `一文に二回以上利用されている助詞 "の" がみつかりました。`,
line: 1,
column: 7
}
]
column: 7,
},
],
},
{
text: "これは`obj.method`は何をしているかを示します。",
errors: [
{
message: `一文に二回以上利用されている助詞 "は" がみつかりました。`,
line: 1,
column: 16
}
]
column: 16,
},
],
},
{
// に + は と に + は
Expand All @@ -182,9 +182,9 @@ tester.run("no-double-joshi", rule, {
{
message: `一文に二回以上利用されている助詞 "には" がみつかりました。`,
line: 1,
column: 8
}
]
column: 8,
},
],
},
//
{
Expand All @@ -197,32 +197,32 @@ tester.run("no-double-joshi", rule, {
errors: [
{
message: `一文に二回以上利用されている助詞 "は" がみつかりました。`,
index: 19
}
]
index: 19,
},
],
},
// オプションで、全角ピリオドを読点として認識させなくする
// 次のtextは1つのセンテンスとして認識されるので、"は"が重複する
{
text: "これはペンです.これは鉛筆です.",
options: {separatorCharacters: ["。"]},
options: { separatorCharacters: ["。"] },
errors: [
{
message: `一文に二回以上利用されている助詞 "は" がみつかりました。`,
index: 10
}
]
index: 10,
},
],
},
// 、を読点と認識させなくする
{
text: "これがiPhone、これがAndroidです。",
options: {commaCharacters: []},
options: { commaCharacters: [] },
errors: [
{
message: `一文に二回以上利用されている助詞 "が" がみつかりました。`,
index: 12
}
]
}
]
index: 12,
},
],
},
],
});
Loading

0 comments on commit 9834912

Please sign in to comment.