Skip to content

add separatorChars to options for sentenceSplitter's argument #14

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 3, 2017
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ textlint --rule no-doubled-joshi README.md
// 例外を許可するかどうか
"strict": false,
// 助詞のうち「も」「や」は複数回の出現を許す
"allow": ["も","や"]
"allow": ["も","や"],
// 文区切り文字の配列
"separatorChars": ["。",,"?","!","?","!"]
}
}
}
Expand All @@ -68,6 +70,8 @@ textlint --rule no-doubled-joshi README.md
- 下記参照。例外としているものもエラーとするかどうか
- `allow`(default: []) :複数回の出現を許す助詞
- 並立の助詞など、複数回出現しても無視する助詞を指定します。
- `separatorChars`(default: ["。","?","!","?","!"]) : 文の区切り文字として使用する文字の配列
- ピリオドや全角ピリオドを句点とする文章を評価するときは明示的に指定します。

> 私**は**彼**は**好き

Expand Down
6 changes: 4 additions & 2 deletions src/no-doubled-joshi.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ function matchExceptionRule(tokens) {
const defaultOptions = {
min_interval: 1,
strict: false,
allow: []
allow: [],
separatorChars: ["。", "?", "!", "?", "!"]
};

/*
Expand All @@ -68,6 +69,7 @@ export default function(context, options = {}) {
const minInterval = options.min_interval || defaultOptions.min_interval;
const isStrict = options.strict || defaultOptions.strict;
const allow = options.allow || defaultOptions.allow;
const separatorChars = options.separatorChars || defaultOptions.separatorChars;
const {Syntax, report, getSource, RuleError} = context;
return {
[Syntax.Paragraph](node){
Expand All @@ -80,7 +82,7 @@ export default function(context, options = {}) {
return node.type === SentenceSyntax.Sentence;
};
let sentences = splitSentences(text, {
charRegExp: /[。\?\!?!]/
separatorChars: separatorChars
}).filter(isSentenceNode);
return getTokenizer().then(tokenizer => {
const checkSentence = (sentence) => {
Expand Down
5 changes: 5 additions & 0 deletions test/no-doubled-joshi-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ tester.run("no-double-joshi", rule, {
{
text: "太字も強調も同じように無視されます。",
options: {allow: ["も"]}
},
// 全角ピリオドを文区切り文字に含める
{
text: "画面に表示されます.それ以外には表示されません.",
options: {separatorChars: ["。",".","?","!","?","!"]}
}
],
invalid: [
Expand Down