@Test void testLatinSymbolWithoutSpace() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SpaceBetweenAlphabeticalWord")) .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(0, errors.get(documents.get(0)).size()); }
@Override public void validate(Sentence sentence) { if (!getBoolean("forbidden")) { char prevCharacter = ' '; int idx = 0; for (char character : sentence.getContent().toCharArray()) { if (notHasWhiteSpaceBeforeLeftParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("Before", sentence, idx, idx + 1); } else if (notHasWhiteSpaceAfterRightParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("After", sentence, idx, idx + 1); } prevCharacter = character; idx++; } } else { final Matcher m = pat.matcher(sentence.getContent()); while (m.find()) { final String word = m.group(1); if (!word.contains(" ")) { addLocalizedError("Forbidden", sentence, word); } } } }
SpaceBetweenAlphabeticalWordValidator extends Validator { @Override public void validate(Sentence sentence) { if (!getBoolean("forbidden")) { char prevCharacter = ' '; int idx = 0; for (char character : sentence.getContent().toCharArray()) { if (notHasWhiteSpaceBeforeLeftParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("Before", sentence, idx, idx + 1); } else if (notHasWhiteSpaceAfterRightParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("After", sentence, idx, idx + 1); } prevCharacter = character; idx++; } } else { final Matcher m = pat.matcher(sentence.getContent()); while (m.find()) { final String word = m.group(1); if (!word.contains(" ")) { addLocalizedError("Forbidden", sentence, word); } } } } }
SpaceBetweenAlphabeticalWordValidator extends Validator { @Override public void validate(Sentence sentence) { if (!getBoolean("forbidden")) { char prevCharacter = ' '; int idx = 0; for (char character : sentence.getContent().toCharArray()) { if (notHasWhiteSpaceBeforeLeftParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("Before", sentence, idx, idx + 1); } else if (notHasWhiteSpaceAfterRightParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("After", sentence, idx, idx + 1); } prevCharacter = character; idx++; } } else { final Matcher m = pat.matcher(sentence.getContent()); while (m.find()) { final String word = m.group(1); if (!word.contains(" ")) { addLocalizedError("Forbidden", sentence, word); } } } } SpaceBetweenAlphabeticalWordValidator(); }
SpaceBetweenAlphabeticalWordValidator extends Validator { @Override public void validate(Sentence sentence) { if (!getBoolean("forbidden")) { char prevCharacter = ' '; int idx = 0; for (char character : sentence.getContent().toCharArray()) { if (notHasWhiteSpaceBeforeLeftParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("Before", sentence, idx, idx + 1); } else if (notHasWhiteSpaceAfterRightParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("After", sentence, idx, idx + 1); } prevCharacter = character; idx++; } } else { final Matcher m = pat.matcher(sentence.getContent()); while (m.find()) { final String word = m.group(1); if (!word.contains(" ")) { addLocalizedError("Forbidden", sentence, word); } } } } SpaceBetweenAlphabeticalWordValidator(); @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence); }
SpaceBetweenAlphabeticalWordValidator extends Validator { @Override public void validate(Sentence sentence) { if (!getBoolean("forbidden")) { char prevCharacter = ' '; int idx = 0; for (char character : sentence.getContent().toCharArray()) { if (notHasWhiteSpaceBeforeLeftParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("Before", sentence, idx, idx + 1); } else if (notHasWhiteSpaceAfterRightParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("After", sentence, idx, idx + 1); } prevCharacter = character; idx++; } } else { final Matcher m = pat.matcher(sentence.getContent()); while (m.find()) { final String word = m.group(1); if (!word.contains(" ")) { addLocalizedError("Forbidden", sentence, word); } } } } SpaceBetweenAlphabeticalWordValidator(); @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence);  }