@Test void testDetectEnDoubleNegativeWithDistance() throws Exception { String sampleText = "unless that is not true, I will go there."; Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("DoubleNegative")) .build(); DocumentParser parser = DocumentParser.MARKDOWN; List<Document> documents = new ArrayList<>(); Document document = parser.parse(sampleText, new SentenceExtractor(config.getSymbolTable()), config.getTokenizer()); documents.add(document); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(1, errors.get(documents.get(0)).size()); assertEquals(1, errors.get(documents.get(0)).get(0).getLineNumber()); assertEquals("DoubleNegative", errors.get(documents.get(0)).get(0).getValidatorName()); }
@Override public void validate(Sentence sentence) { for (ExpressionRule rule : invalidExpressions) { if (rule.match(sentence.getTokens())) { addLocalizedError(sentence, rule.toSurface() ); return; } } int count = 0; String errorPart = ""; List<TokenElement> tokens = sentence.getTokens(); for (TokenElement token : tokens) { if (negativeWords.contains(token.getSurface().toLowerCase())) { count++; errorPart += " " + token.getSurface().toLowerCase(); } if (count >= 2) { addLocalizedError(sentence, errorPart); return; } } }
DoubleNegativeValidator extends Validator { @Override public void validate(Sentence sentence) { for (ExpressionRule rule : invalidExpressions) { if (rule.match(sentence.getTokens())) { addLocalizedError(sentence, rule.toSurface() ); return; } } int count = 0; String errorPart = ""; List<TokenElement> tokens = sentence.getTokens(); for (TokenElement token : tokens) { if (negativeWords.contains(token.getSurface().toLowerCase())) { count++; errorPart += " " + token.getSurface().toLowerCase(); } if (count >= 2) { addLocalizedError(sentence, errorPart); return; } } } }
DoubleNegativeValidator extends Validator { @Override public void validate(Sentence sentence) { for (ExpressionRule rule : invalidExpressions) { if (rule.match(sentence.getTokens())) { addLocalizedError(sentence, rule.toSurface() ); return; } } int count = 0; String errorPart = ""; List<TokenElement> tokens = sentence.getTokens(); for (TokenElement token : tokens) { if (negativeWords.contains(token.getSurface().toLowerCase())) { count++; errorPart += " " + token.getSurface().toLowerCase(); } if (count >= 2) { addLocalizedError(sentence, errorPart); return; } } }  }
DoubleNegativeValidator extends Validator { @Override public void validate(Sentence sentence) { for (ExpressionRule rule : invalidExpressions) { if (rule.match(sentence.getTokens())) { addLocalizedError(sentence, rule.toSurface() ); return; } } int count = 0; String errorPart = ""; List<TokenElement> tokens = sentence.getTokens(); for (TokenElement token : tokens) { if (negativeWords.contains(token.getSurface().toLowerCase())) { count++; errorPart += " " + token.getSurface().toLowerCase(); } if (count >= 2) { addLocalizedError(sentence, errorPart); return; } } }  @Override void validate(Sentence sentence); @Override List<String> getSupportedLanguages(); }
DoubleNegativeValidator extends Validator { @Override public void validate(Sentence sentence) { for (ExpressionRule rule : invalidExpressions) { if (rule.match(sentence.getTokens())) { addLocalizedError(sentence, rule.toSurface() ); return; } } int count = 0; String errorPart = ""; List<TokenElement> tokens = sentence.getTokens(); for (TokenElement token : tokens) { if (negativeWords.contains(token.getSurface().toLowerCase())) { count++; errorPart += " " + token.getSurface().toLowerCase(); } if (count >= 2) { addLocalizedError(sentence, errorPart); return; } } }  @Override void validate(Sentence sentence); @Override List<String> getSupportedLanguages();  }