Skip to content
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

Add list property of JapaneseJoyoKanji #805

Merged
merged 1 commit into from
Oct 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import cc.redpen.model.Sentence;
import cc.redpen.validator.Validator;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -43,9 +45,13 @@ public class JapaneseJoyoKanjiValidator extends Validator {

@Override
public void validate(Sentence sentence) {
Set<String> customSkipList = getSet("list");
final Matcher m = nonJoyoKanji.matcher(sentence.getContent());
while (m.find()) {
addLocalizedError(sentence, m.group());
String kanji = m.group();
if (customSkipList == null || !customSkipList.contains(kanji)) {
addLocalizedError(sentence, kanji);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down Expand Up @@ -71,4 +72,22 @@ void testInvalid() throws RedPenException {
assertEquals("JapaneseJoyoKanji", errors.get(0).getValidatorName());
assertEquals("JapaneseJoyoKanji", errors.get(1).getValidatorName());
}

@Test
void testSkipWordList() throws RedPenException {
Configuration config = Configuration.builder("ja")
.addValidatorConfig(new ValidatorConfiguration("JapaneseJoyoKanji").addProperty("list", "圭,昌"))
.build();

List<Document> documents = new ArrayList<>();documents.add(
Document.builder(new JapaneseTokenizer())
.addSection(1)
.addParagraph()
.addSentence(new Sentence("圭や昌は常用漢字ではありませんが、人名漢字であるため許可します。", 1))
.build());

RedPen redPen = new RedPen(config);
List<ValidationError> errors = redPen.validate(documents).get(documents.get(0));
assertEquals(0, errors.size());
}
}