@Test void testSingleSentence() throws RedPenException { WeakExpressionValidator validator = (WeakExpressionValidator) ValidatorFactory.getInstance("WeakExpression"); List<Document> documents = new ArrayList<>(); documents.add( Document.builder(new WhiteSpaceTokenizer()) .addSection(1) .addParagraph() .addSentence(new Sentence("As a matter of fact, some things are very small.", 1)) .addSentence(new Sentence("Things are mentioned a lot.", 2)) .build()); Sentence st = documents.get(0).getLastSection().getParagraph(0).getSentence(0); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(st); assertEquals(4, errors.size(), st.toString()); st = documents.get(0).getLastSection().getParagraph(0).getSentence(1); errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(st); assertEquals(2, errors.size(), st.toString()); }
@Override public void validate(Sentence sentence) { TokenElement tokens[] = new TokenElement[]{null, null, null, null, null, null}; for (int i = 0; i < sentence.getTokens().size(); i++) { for (int j = 0; j < tokens.length - 1; j++) { tokens[j] = i + j < sentence.getTokens().size() ? sentence.getTokens().get(i + j) : null; } if (tokens[0] != null) { String expression = ""; for (int j = 0; (j < tokens.length) && (tokens[j] != null); j++) { expression += ((j > 0) ? " " : "") + tokens[j].getSurface(); if (weakExpressions.contains(expression.toLowerCase())) { addLocalizedErrorWithPosition( "WeakExpression", sentence, tokens[0].getOffset(), tokens[j].getOffset() + tokens[j].getSurface().length(), expression); } } } } }
WeakExpressionValidator extends Validator { @Override public void validate(Sentence sentence) { TokenElement tokens[] = new TokenElement[]{null, null, null, null, null, null}; for (int i = 0; i < sentence.getTokens().size(); i++) { for (int j = 0; j < tokens.length - 1; j++) { tokens[j] = i + j < sentence.getTokens().size() ? sentence.getTokens().get(i + j) : null; } if (tokens[0] != null) { String expression = ""; for (int j = 0; (j < tokens.length) && (tokens[j] != null); j++) { expression += ((j > 0) ? " " : "") + tokens[j].getSurface(); if (weakExpressions.contains(expression.toLowerCase())) { addLocalizedErrorWithPosition( "WeakExpression", sentence, tokens[0].getOffset(), tokens[j].getOffset() + tokens[j].getSurface().length(), expression); } } } } } }
WeakExpressionValidator extends Validator { @Override public void validate(Sentence sentence) { TokenElement tokens[] = new TokenElement[]{null, null, null, null, null, null}; for (int i = 0; i < sentence.getTokens().size(); i++) { for (int j = 0; j < tokens.length - 1; j++) { tokens[j] = i + j < sentence.getTokens().size() ? sentence.getTokens().get(i + j) : null; } if (tokens[0] != null) { String expression = ""; for (int j = 0; (j < tokens.length) && (tokens[j] != null); j++) { expression += ((j > 0) ? " " : "") + tokens[j].getSurface(); if (weakExpressions.contains(expression.toLowerCase())) { addLocalizedErrorWithPosition( "WeakExpression", sentence, tokens[0].getOffset(), tokens[j].getOffset() + tokens[j].getSurface().length(), expression); } } } } }  }
WeakExpressionValidator extends Validator { @Override public void validate(Sentence sentence) { TokenElement tokens[] = new TokenElement[]{null, null, null, null, null, null}; for (int i = 0; i < sentence.getTokens().size(); i++) { for (int j = 0; j < tokens.length - 1; j++) { tokens[j] = i + j < sentence.getTokens().size() ? sentence.getTokens().get(i + j) : null; } if (tokens[0] != null) { String expression = ""; for (int j = 0; (j < tokens.length) && (tokens[j] != null); j++) { expression += ((j > 0) ? " " : "") + tokens[j].getSurface(); if (weakExpressions.contains(expression.toLowerCase())) { addLocalizedErrorWithPosition( "WeakExpression", sentence, tokens[0].getOffset(), tokens[j].getOffset() + tokens[j].getSurface().length(), expression); } } } } }  @Override void validate(Sentence sentence); }
WeakExpressionValidator extends Validator { @Override public void validate(Sentence sentence) { TokenElement tokens[] = new TokenElement[]{null, null, null, null, null, null}; for (int i = 0; i < sentence.getTokens().size(); i++) { for (int j = 0; j < tokens.length - 1; j++) { tokens[j] = i + j < sentence.getTokens().size() ? sentence.getTokens().get(i + j) : null; } if (tokens[0] != null) { String expression = ""; for (int j = 0; (j < tokens.length) && (tokens[j] != null); j++) { expression += ((j > 0) ? " " : "") + tokens[j].getSurface(); if (weakExpressions.contains(expression.toLowerCase())) { addLocalizedErrorWithPosition( "WeakExpression", sentence, tokens[0].getOffset(), tokens[j].getOffset() + tokens[j].getSurface().length(), expression); } } } } }  @Override void validate(Sentence sentence);  }