@Test void testValidate() throws Exception { config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration(validatorName).addProperty("list", "this,a,pen")) .build(); Document document = prepareSimpleDocument("this iz a pen"); Validator validator = ValidatorFactory.getInstance(config.getValidatorConfigs().get(0), config); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(document.getLastSection().getParagraph(0).getSentence(0)); assertEquals(1, errors.size()); }
@Override public void validate(Sentence sentence) { for (TokenElement token : sentence.getTokens()) { String surface = token.getSurface().toLowerCase(); if (surface.length() == 0 || surface.matches("\\P{L}+")) continue; if (dictionaryExists() && !inDictionary(surface)) { addLocalizedErrorFromToken(sentence, token); } } }
SpellingValidator extends SpellingDictionaryValidator { @Override public void validate(Sentence sentence) { for (TokenElement token : sentence.getTokens()) { String surface = token.getSurface().toLowerCase(); if (surface.length() == 0 || surface.matches("\\P{L}+")) continue; if (dictionaryExists() && !inDictionary(surface)) { addLocalizedErrorFromToken(sentence, token); } } } }
SpellingValidator extends SpellingDictionaryValidator { @Override public void validate(Sentence sentence) { for (TokenElement token : sentence.getTokens()) { String surface = token.getSurface().toLowerCase(); if (surface.length() == 0 || surface.matches("\\P{L}+")) continue; if (dictionaryExists() && !inDictionary(surface)) { addLocalizedErrorFromToken(sentence, token); } } }  }
SpellingValidator extends SpellingDictionaryValidator { @Override public void validate(Sentence sentence) { for (TokenElement token : sentence.getTokens()) { String surface = token.getSurface().toLowerCase(); if (surface.length() == 0 || surface.matches("\\P{L}+")) continue; if (dictionaryExists() && !inDictionary(surface)) { addLocalizedErrorFromToken(sentence, token); } } }  @Override void validate(Sentence sentence); }
SpellingValidator extends SpellingDictionaryValidator { @Override public void validate(Sentence sentence) { for (TokenElement token : sentence.getTokens()) { String surface = token.getSurface().toLowerCase(); if (surface.length() == 0 || surface.matches("\\P{L}+")) continue; if (dictionaryExists() && !inDictionary(surface)) { addLocalizedErrorFromToken(sentence, token); } } }  @Override void validate(Sentence sentence);  }