@Test void testJapaneseInvalidEndOfSentence() throws RedPenException { Configuration config = Configuration.builder("ja") .addValidatorConfig(new ValidatorConfiguration("EndOfSentence")) .build(); List<Document> documents = new ArrayList<>();documents.add( Document.builder(new NeologdJapaneseTokenizer()) .addSection(1) .addParagraph() .addSentence(new Sentence("彼は言った，“今日は誕生日”。", 1)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(1, errors.get(documents.get(0)).size()); }
@Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } }
EndOfSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } } }
EndOfSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } }  }
EndOfSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } }  @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence); }
EndOfSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } }  @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence);  }