@Test void testDetectStartWithSmallCharacter() throws RedPenException { List<Document> documents = new ArrayList<>(); documents.add(Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("this is it.", 1)) .build()); Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("StartWithCapitalLetter")) .build(); Validator validator = ValidatorFactory.getInstance(config.getValidatorConfigs().get(0), config); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(documents.get(0).getLastSection().getParagraph(0).getSentence(0)); assertEquals(1, errors.size()); }
@Override public void validate(Sentence sentence) { String content = sentence.getContent(); List<TokenElement> tokens = sentence.getTokens(); String headWord = ""; for (TokenElement token : tokens) { if (!token.getSurface().equals("")) { headWord = token.getSurface(); break; } } if (tokens.size() == 0 || inDictionary(headWord)) { return; } char headChar = '≡'; for (char ch : content.toCharArray()) { if (ch != ' ') { headChar = ch; break; } } if (headChar == '≡') { return; } if (Character.isLowerCase(headChar)) { addLocalizedError(sentence, headChar); } }
StartWithCapitalLetterValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); List<TokenElement> tokens = sentence.getTokens(); String headWord = ""; for (TokenElement token : tokens) { if (!token.getSurface().equals("")) { headWord = token.getSurface(); break; } } if (tokens.size() == 0 || inDictionary(headWord)) { return; } char headChar = '≡'; for (char ch : content.toCharArray()) { if (ch != ' ') { headChar = ch; break; } } if (headChar == '≡') { return; } if (Character.isLowerCase(headChar)) { addLocalizedError(sentence, headChar); } } }
StartWithCapitalLetterValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); List<TokenElement> tokens = sentence.getTokens(); String headWord = ""; for (TokenElement token : tokens) { if (!token.getSurface().equals("")) { headWord = token.getSurface(); break; } } if (tokens.size() == 0 || inDictionary(headWord)) { return; } char headChar = '≡'; for (char ch : content.toCharArray()) { if (ch != ' ') { headChar = ch; break; } } if (headChar == '≡') { return; } if (Character.isLowerCase(headChar)) { addLocalizedError(sentence, headChar); } } StartWithCapitalLetterValidator(); }
StartWithCapitalLetterValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); List<TokenElement> tokens = sentence.getTokens(); String headWord = ""; for (TokenElement token : tokens) { if (!token.getSurface().equals("")) { headWord = token.getSurface(); break; } } if (tokens.size() == 0 || inDictionary(headWord)) { return; } char headChar = '≡'; for (char ch : content.toCharArray()) { if (ch != ' ') { headChar = ch; break; } } if (headChar == '≡') { return; } if (Character.isLowerCase(headChar)) { addLocalizedError(sentence, headChar); } } StartWithCapitalLetterValidator(); @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence); }
StartWithCapitalLetterValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); List<TokenElement> tokens = sentence.getTokens(); String headWord = ""; for (TokenElement token : tokens) { if (!token.getSurface().equals("")) { headWord = token.getSurface(); break; } } if (tokens.size() == 0 || inDictionary(headWord)) { return; } char headChar = '≡'; for (char ch : content.toCharArray()) { if (ch != ' ') { headChar = ch; break; } } if (headChar == '≡') { return; } if (Character.isLowerCase(headChar)) { addLocalizedError(sentence, headChar); } } StartWithCapitalLetterValidator(); @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence);  }