@Test void testSkipBeforeAndAfter() throws RedPenException { SpaceBetweenAlphabeticalWordValidator validator = new SpaceBetweenAlphabeticalWordValidator(); validator.preInit(new ValidatorConfiguration("SpaceBetweenAlphabeticalWord").addProperty("skip_before", "・「").addProperty("skip_after", "・」"), Configuration.builder().build()); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(new Sentence("きょうは「Coke・Pepsi」を飲みたい。", 0)); assertEquals(0, errors.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);  }