@Test void testWithShortSentence() { WordNumberValidator maxWordNumberValidator = new WordNumberValidator(); Sentence str = new Sentence( "this sentence is short.", 0); List<ValidationError> errors = new ArrayList<>(); maxWordNumberValidator.setErrorList(errors); maxWordNumberValidator.validate(str); assertNotNull(errors); assertEquals(0, errors.size()); }
@Override public void validate(Sentence sentence) { List<TokenElement> words = sentence.getTokens(); int wordNum = 0; for (TokenElement word : words) { if (!word.getSurface().equals(",") && !word.getSurface().equals(",") && !word.getSurface().equals("?") && !word.getSurface().equals("!") && !word.getSurface().equals(":") && !word.getSurface().equals(";") && !word.getSurface().equals("\"") && !word.getSurface().equals("'")) { wordNum++; } } int maxNum = getInt("max_num"); if (wordNum > maxNum) { addLocalizedError(sentence, wordNum, maxNum); } }
WordNumberValidator extends Validator { @Override public void validate(Sentence sentence) { List<TokenElement> words = sentence.getTokens(); int wordNum = 0; for (TokenElement word : words) { if (!word.getSurface().equals(",") && !word.getSurface().equals(",") && !word.getSurface().equals("?") && !word.getSurface().equals("!") && !word.getSurface().equals(":") && !word.getSurface().equals(";") && !word.getSurface().equals("\"") && !word.getSurface().equals("'")) { wordNum++; } } int maxNum = getInt("max_num"); if (wordNum > maxNum) { addLocalizedError(sentence, wordNum, maxNum); } } }
WordNumberValidator extends Validator { @Override public void validate(Sentence sentence) { List<TokenElement> words = sentence.getTokens(); int wordNum = 0; for (TokenElement word : words) { if (!word.getSurface().equals(",") && !word.getSurface().equals(",") && !word.getSurface().equals("?") && !word.getSurface().equals("!") && !word.getSurface().equals(":") && !word.getSurface().equals(";") && !word.getSurface().equals("\"") && !word.getSurface().equals("'")) { wordNum++; } } int maxNum = getInt("max_num"); if (wordNum > maxNum) { addLocalizedError(sentence, wordNum, maxNum); } } WordNumberValidator(); }
WordNumberValidator extends Validator { @Override public void validate(Sentence sentence) { List<TokenElement> words = sentence.getTokens(); int wordNum = 0; for (TokenElement word : words) { if (!word.getSurface().equals(",") && !word.getSurface().equals(",") && !word.getSurface().equals("?") && !word.getSurface().equals("!") && !word.getSurface().equals(":") && !word.getSurface().equals(";") && !word.getSurface().equals("\"") && !word.getSurface().equals("'")) { wordNum++; } } int maxNum = getInt("max_num"); if (wordNum > maxNum) { addLocalizedError(sentence, wordNum, maxNum); } } WordNumberValidator(); @Override void validate(Sentence sentence); }
WordNumberValidator extends Validator { @Override public void validate(Sentence sentence) { List<TokenElement> words = sentence.getTokens(); int wordNum = 0; for (TokenElement word : words) { if (!word.getSurface().equals(",") && !word.getSurface().equals(",") && !word.getSurface().equals("?") && !word.getSurface().equals("!") && !word.getSurface().equals(":") && !word.getSurface().equals(";") && !word.getSurface().equals("\"") && !word.getSurface().equals("'")) { wordNum++; } } int maxNum = getInt("max_num"); if (wordNum > maxNum) { addLocalizedError(sentence, wordNum, maxNum); } } WordNumberValidator(); @Override void validate(Sentence sentence);  }