@@ -4,22 +4,10 @@ import {RuleHelper} from "textlint-rule-helper";
4
4
import { getTokenizer } from "kuromojin" ;
5
5
import splitSentences , { Syntax as SentenceSyntax } from "sentence-splitter" ;
6
6
import StringSource from "textlint-util-to-string" ;
7
- // 助詞どうか
8
- const is助詞Token = ( token ) => {
9
- return token . pos === "助詞" ;
10
- } ;
11
- const is読点Token = ( token ) => {
12
- return token . surface_form === "、" && token . pos === "名詞" ;
13
- } ;
14
- // 助詞tokenから品詞細分類1までを元にしたkeyを作る
15
- const createKeyFromKey = ( token ) => {
16
- // e.g.) は:助詞.係助詞
17
- return `${ token . surface_form } :${ token . pos } .${ token . pos_detail_1 } `
18
- } ;
19
- // keyからsurfaceを取り出す
20
- const restoreToSurfaceFromKey = ( key ) => {
21
- return key . split ( ":" ) [ 0 ] ;
22
- } ;
7
+ import {
8
+ is助詞Token , is読点Token ,
9
+ createKeyFromKey , restoreToSurfaceFromKey
10
+ } from "./token-utils" ;
23
11
/**
24
12
* Create token map object
25
13
* {
@@ -128,7 +116,7 @@ export default function (context, options = {}) {
128
116
}
129
117
// if found differenceIndex less than
130
118
// tokes are sorted ascending order
131
- tokens . reduce ( ( prev , current ) => {
119
+ var reduder = ( prev , current ) => {
132
120
const startPosition = countableTokens . indexOf ( prev ) ;
133
121
const otherPosition = countableTokens . indexOf ( current ) ;
134
122
// 助詞token同士の距離が設定値以下ならエラーを報告する
@@ -148,7 +136,8 @@ export default function (context, options = {}) {
148
136
report ( node , new RuleError ( `一文に二回以上利用されている助詞 "${ joshiName } " がみつかりました。` , padding ) ) ;
149
137
}
150
138
return current ;
151
- } ) ;
139
+ } ;
140
+ tokens . reduce ( reduder ) ;
152
141
} ) ;
153
142
} ;
154
143
sentences . forEach ( checkSentence ) ;
0 commit comments