Skip to content

Commit

Permalink
fix(analyze): "である" の判定を"である"のみ限定
Browse files Browse the repository at this point in the history
"ではなく" というような表現は常体(である調)として認識しない

fix textlint-ja/textlint-rule-no-mix-dearu-desumasu#10
  • Loading branch information
azu committed May 6, 2016
1 parent c167a87 commit 4d1ce70
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"url": "https://github.com/azu/analyze-desumasu-dearu/issues"
},
"version": "3.0.3",
"description": "文の敬体(ですます調)、常体(である調)を解析",
"description": "文の敬体(ですます調)、常体(である調)を解析",
"main": "lib/analyze.js",
"files": [
"lib",
Expand Down
10 changes: 7 additions & 3 deletions src/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ export function analyze(text) {
return getTokenizer().then(tokenizer => {
const tokens = _tokensCacheMap[text] ? _tokensCacheMap[text] : tokenizer.tokenizeForSentence(text);
_tokensCacheMap[text] = tokens;
const filterByType = tokens.filter(token => {
const filterByType = tokens.filter((token, index) => {
const nextToken = tokens[index + 1];
// token[特殊・ダ] + nextToken[アル] なら 常体(である調) として認識する
const conjugatedType = token["conjugated_type"];
if (conjugatedType === Types.dearu) {
if (token["conjugated_form"] === "連用形" || token["conjugated_form"] === "連用タ接続") {
return true;
if (token["pos"] === "助動詞" && token["conjugated_form"] === "連用形") {
if (nextToken && nextToken["conjugated_type"] === "五段・ラ行アル") {
return true;
}
}
} else if (conjugatedType === Types.desu) {
// TODO: can omit?
Expand Down
24 changes: 18 additions & 6 deletions test/analyze-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,24 @@ describe("analyze-test", function () {
});
});
describe("analyzeDearu", function () {
it("should not match である", function () {
// "な" は マッチしない
// "conjugated_type": "特殊・ダ",
// "conjugated_form": "体言接続",
return analyzeDearu("これを使い簡単なものを作る").then(results => {
assert(results.length === 0);
context("when no match", function () {
it("このパターンだけ**では**難しい", function () {
return analyzeDearu("このパターンだけでは難しい").then(results => {
assert(results.length === 0);
});
});
it("ではなく", function () {
return analyzeDearu("動的にメソッドを追加するだけではなく、既存の実装を上書きする。").then(results => {
assert(results.length === 0);
});
});
it("簡単**な***ものを作る", function () {
// "な" は マッチしない
// "conjugated_type": "特殊・ダ",
// "conjugated_form": "体言接続",
return analyzeDearu("これを使い簡単なものを作る").then(results => {
assert(results.length === 0);
});
});
});
it("should found である 後ろに明示的なストッパーがない場合", function () {
Expand Down

0 comments on commit 4d1ce70

Please sign in to comment.