textlint-rule-no-doubled-conjunction
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -17,2 +17,6 @@ // LICENSE : MIT | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
/* | ||
@@ -63,5 +67,5 @@ 1. Paragraph Node -> text | ||
return (0, _kuromojin.getTokenizer)().then(tokenizer => { | ||
var selectConjenction = sentence => { | ||
var tokens = tokenizer.tokenizeForSentence(sentence.raw); | ||
var selectConjenction = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator(function* (sentence) { | ||
var tokens = yield (0, _kuromojin.tokenize)(sentence.raw); | ||
var conjunctionTokens = tokens.filter((token, index) => { | ||
@@ -78,33 +82,37 @@ var prevToken = tokens[index - 1]; // スペースが切れ目として認識されてしまう問題を回避 | ||
return [sentence, conjunctionTokens]; | ||
}); | ||
return function selectConjenction(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
var prev_token = null; | ||
sentences.map(selectConjenction).reduce((prev, current) => { | ||
var [sentence, current_tokens] = current; | ||
var [prev_sentence, prev_tokens] = prev; | ||
var token = prev_token; | ||
var prev_token = null; | ||
return Promise.all(sentences.map(selectConjenction)).then(result => result.reduce((prev, current) => { | ||
var [sentence, current_tokens] = current; | ||
var [prev_sentence, prev_tokens] = prev; | ||
var token = prev_token; | ||
if (prev_tokens && prev_tokens.length > 0) { | ||
token = prev_tokens[0]; | ||
} | ||
if (prev_tokens && prev_tokens.length > 0) { | ||
token = prev_tokens[0]; | ||
} | ||
if (current_tokens.length > 0) { | ||
if (token && current_tokens[0].surface_form === token.surface_form) { | ||
var conjunctionSurface = token.surface_form; | ||
var originalIndex = source.originalIndexFromPosition({ | ||
line: sentence.loc.start.line, | ||
column: sentence.loc.start.column + (current_tokens[0].word_position - 1) | ||
}); // padding position | ||
if (current_tokens.length > 0) { | ||
if (token && current_tokens[0].surface_form === token.surface_form) { | ||
var conjunctionSurface = token.surface_form; | ||
var originalIndex = source.originalIndexFromPosition({ | ||
line: sentence.loc.start.line, | ||
column: sentence.loc.start.column + (current_tokens[0].word_position - 1) | ||
}); // padding position | ||
var padding = { | ||
index: originalIndex | ||
}; | ||
report(node, new RuleError("\u540C\u3058\u63A5\u7D9A\u8A5E\uFF08".concat(conjunctionSurface, "\uFF09\u304C\u9023\u7D9A\u3057\u3066\u4F7F\u308F\u308C\u3066\u3044\u307E\u3059\u3002"), padding)); | ||
} | ||
var padding = { | ||
index: originalIndex | ||
}; | ||
report(node, new RuleError("\u540C\u3058\u63A5\u7D9A\u8A5E\uFF08".concat(conjunctionSurface, "\uFF09\u304C\u9023\u7D9A\u3057\u3066\u4F7F\u308F\u308C\u3066\u3044\u307E\u3059\u3002"), padding)); | ||
} | ||
} | ||
prev_token = token; | ||
return current; | ||
}); | ||
}); | ||
prev_token = token; | ||
return current; | ||
})); | ||
} | ||
@@ -111,0 +119,0 @@ |
{ | ||
"name": "textlint-rule-no-doubled-conjunction", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "textlint rule plugin to check duplicated conjunctions.", | ||
@@ -5,0 +5,0 @@ "main": "lib/no-doubled-conjunction.js", |
// LICENSE : MIT | ||
"use strict"; | ||
import { RuleHelper } from "textlint-rule-helper"; | ||
import { getTokenizer } from "kuromojin"; | ||
import { tokenize } from "kuromojin"; | ||
import { split as splitSentences, Syntax as SentenceSyntax } from "sentence-splitter"; | ||
@@ -45,44 +45,42 @@ import { StringSource } from "textlint-util-to-string"; | ||
} | ||
return getTokenizer().then(tokenizer => { | ||
const selectConjenction = (sentence) => { | ||
const tokens = tokenizer.tokenizeForSentence(sentence.raw); | ||
const conjunctionTokens = tokens.filter((token, index) => { | ||
const prevToken = tokens[index - 1]; | ||
// スペースが切れ目として認識されてしまう問題を回避 | ||
// https://github.com/textlint-ja/textlint-rule-no-doubled-conjunction/issues/14 | ||
if (prevToken && prevToken.pos_detail_1 === "空白" && token.pos === "接続詞") { | ||
return false; | ||
} | ||
return token.pos === "接続詞" | ||
}); | ||
return [sentence, conjunctionTokens]; | ||
}; | ||
let prev_token = null; | ||
sentences.map(selectConjenction).reduce((prev, current) => { | ||
const [sentence, current_tokens] = current; | ||
const [prev_sentence, prev_tokens] = prev; | ||
let token = prev_token; | ||
if (prev_tokens && prev_tokens.length > 0) { | ||
token = prev_tokens[0]; | ||
const selectConjenction = async (sentence) => { | ||
const tokens = await tokenize(sentence.raw); | ||
const conjunctionTokens = tokens.filter((token, index) => { | ||
const prevToken = tokens[index - 1]; | ||
// スペースが切れ目として認識されてしまう問題を回避 | ||
// https://github.com/textlint-ja/textlint-rule-no-doubled-conjunction/issues/14 | ||
if (prevToken && prevToken.pos_detail_1 === "空白" && token.pos === "接続詞") { | ||
return false; | ||
} | ||
if (current_tokens.length > 0) { | ||
if (token && current_tokens[0].surface_form === token.surface_form) { | ||
const conjunctionSurface = token.surface_form; | ||
const originalIndex = source.originalIndexFromPosition({ | ||
line: sentence.loc.start.line, | ||
column: sentence.loc.start.column + (current_tokens[0].word_position - 1) | ||
}); | ||
// padding position | ||
const padding = { | ||
index: originalIndex | ||
}; | ||
report(node, new RuleError(`同じ接続詞(${conjunctionSurface})が連続して使われています。`, padding)); | ||
} | ||
return token.pos === "接続詞" | ||
}); | ||
return [sentence, conjunctionTokens]; | ||
} | ||
let prev_token = null; | ||
return Promise.all(sentences.map(selectConjenction)).then((result) => result.reduce((prev, current) => { | ||
const [sentence, current_tokens] = current; | ||
const [prev_sentence, prev_tokens] = prev; | ||
let token = prev_token; | ||
if (prev_tokens && prev_tokens.length > 0) { | ||
token = prev_tokens[0]; | ||
} | ||
if (current_tokens.length > 0) { | ||
if (token && current_tokens[0].surface_form === token.surface_form) { | ||
const conjunctionSurface = token.surface_form; | ||
const originalIndex = source.originalIndexFromPosition({ | ||
line: sentence.loc.start.line, | ||
column: sentence.loc.start.column + (current_tokens[0].word_position - 1) | ||
}); | ||
// padding position | ||
const padding = { | ||
index: originalIndex | ||
}; | ||
report(node, new RuleError(`同じ接続詞(${conjunctionSurface})が連続して使われています。`, padding)); | ||
} | ||
prev_token = token; | ||
return current; | ||
}); | ||
}); | ||
} | ||
prev_token = token; | ||
return current; | ||
})); | ||
} | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19267
180