@Test void testWithoutSynonym() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SuggestExpression").addProperty("map", "{like,such " + "as}, {info,information}")) .build(); Validator validator = ValidatorFactory.getInstance(config.getValidatorConfigs().get(0), config); List<ValidationError> errors = new ArrayList<>(); validator.validate(new Sentence("it loves a piece of a cake.", 0)); assertEquals(0, errors.size()); }
@Override public void validate(Sentence sentence) { String text = sentence.getContent(); getMap("map").keySet().stream().forEach(value -> { int start = text.indexOf(value); if (start < 0) return; int end = start + value.length(); boolean hasWordBoundaries = (start == 0 || !isLetter(text.charAt(start - 1))) && (end == text.length() || !isLetter(text.charAt(end))); if (isProbablyJapanese(text.charAt(start)) || hasWordBoundaries) { addLocalizedErrorWithPosition(sentence, start, end, value, getMap("map").get(value)); } }); }
SuggestExpressionValidator extends KeyValueDictionaryValidator { @Override public void validate(Sentence sentence) { String text = sentence.getContent(); getMap("map").keySet().stream().forEach(value -> { int start = text.indexOf(value); if (start < 0) return; int end = start + value.length(); boolean hasWordBoundaries = (start == 0 || !isLetter(text.charAt(start - 1))) && (end == text.length() || !isLetter(text.charAt(end))); if (isProbablyJapanese(text.charAt(start)) || hasWordBoundaries) { addLocalizedErrorWithPosition(sentence, start, end, value, getMap("map").get(value)); } }); } }
SuggestExpressionValidator extends KeyValueDictionaryValidator { @Override public void validate(Sentence sentence) { String text = sentence.getContent(); getMap("map").keySet().stream().forEach(value -> { int start = text.indexOf(value); if (start < 0) return; int end = start + value.length(); boolean hasWordBoundaries = (start == 0 || !isLetter(text.charAt(start - 1))) && (end == text.length() || !isLetter(text.charAt(end))); if (isProbablyJapanese(text.charAt(start)) || hasWordBoundaries) { addLocalizedErrorWithPosition(sentence, start, end, value, getMap("map").get(value)); } }); } SuggestExpressionValidator(); }
SuggestExpressionValidator extends KeyValueDictionaryValidator { @Override public void validate(Sentence sentence) { String text = sentence.getContent(); getMap("map").keySet().stream().forEach(value -> { int start = text.indexOf(value); if (start < 0) return; int end = start + value.length(); boolean hasWordBoundaries = (start == 0 || !isLetter(text.charAt(start - 1))) && (end == text.length() || !isLetter(text.charAt(end))); if (isProbablyJapanese(text.charAt(start)) || hasWordBoundaries) { addLocalizedErrorWithPosition(sentence, start, end, value, getMap("map").get(value)); } }); } SuggestExpressionValidator(); @Override void validate(Sentence sentence); }
SuggestExpressionValidator extends KeyValueDictionaryValidator { @Override public void validate(Sentence sentence) { String text = sentence.getContent(); getMap("map").keySet().stream().forEach(value -> { int start = text.indexOf(value); if (start < 0) return; int end = start + value.length(); boolean hasWordBoundaries = (start == 0 || !isLetter(text.charAt(start - 1))) && (end == text.length() || !isLetter(text.charAt(end))); if (isProbablyJapanese(text.charAt(start)) || hasWordBoundaries) { addLocalizedErrorWithPosition(sentence, start, end, value, getMap("map").get(value)); } }); } SuggestExpressionValidator(); @Override void validate(Sentence sentence);  }