RepetitionChecker extends AbstractTypedChecker { public List<Mistake> check(Sentence sentence) { List<Mistake> mistakes = new LinkedList<Mistake>(); int offset = sentence.getSpan().getStart(); List<Token> tokens = sentence.getTokens(); String token = tokens.get(0).getLexeme().toLowerCase(); for (int i = 1; i < tokens.size(); i++) { String next = tokens.get(i).getLexeme().toLowerCase(); if (token.equals(next) && !isException(tokens, i)) { int start = tokens.get(i-1).getSpan().getStart() + offset; int end = tokens.get(i).getSpan().getEnd() + offset; mistakes.add(createMistake(ID, createSuggestion(tokens.get(i-1) .getLexeme()), start, end, sentence.getSentence())); } token = next; } return mistakes; } RepetitionChecker(); String getIdPrefix(); List<Mistake> check(Sentence sentence); int getPriority();  }
@Test public void testCorrectWordSe() { Sentence sentence = createSentence("Se se morre de amor .", Class.SUBORDINATING_CONJUNCTION, Class.PERSONAL_PRONOUN, Class.FINITIVE_VERB, Class.PREPOSITION, Class.NOUN, Class.PUNCTUATION_MARK); RepetitionChecker checker = new RepetitionChecker(); List<Mistake> errors = checker.check(sentence); assertEquals(0, errors.size()); }
@Test public void testPronounRepetition() { String error = "Ele ele se foi ."; StringBuilder strBuilder = new StringBuilder(error); Sentence sentence = createSentence(error, Class.PERSONAL_PRONOUN, Class.PERSONAL_PRONOUN, Class.PERSONAL_PRONOUN, Class.FINITIVE_VERB, Class.PUNCTUATION_MARK); RepetitionChecker checker = new RepetitionChecker(); List<Mistake> errors = checker.check(sentence); assertEquals(1, errors.size()); Mistake mistake = errors.get(0); strBuilder.replace(mistake.getStart(),mistake.getEnd(), mistake.getSuggestions()[0]); assertEquals("Ele se foi .", strBuilder.toString()); }
@Test public void testRuleDetails() { String error = "Ele ele se foi ."; StringBuilder strBuilder = new StringBuilder(error); Sentence sentence = createSentence(error, Class.PERSONAL_PRONOUN, Class.PERSONAL_PRONOUN, Class.PERSONAL_PRONOUN, Class.FINITIVE_VERB, Class.PUNCTUATION_MARK); RepetitionChecker checker = new RepetitionChecker(); List<Mistake> errors = checker.check(sentence); assertEquals(1, errors.size()); Mistake mistake = errors.get(0); assertEquals(RepetitionChecker.ID, mistake.getRuleIdentifier()); assertTrue(mistake.getFullMessage().contains(RepetitionChecker.MESSAGE)); assertEquals(RepetitionChecker.SHORT, mistake.getShortMessage()); assertNotNull(mistake.getSuggestions()); strBuilder.replace(mistake.getStart(),mistake.getEnd(), mistake.getSuggestions()[0]); assertEquals("Ele se foi .", strBuilder.toString()); }
@Test public void testAllRepetition() { Sentence sentence = createSentence( "Ela ela se se portava portava calmamente calmamente por por lá lá .", Class.PERSONAL_PRONOUN, Class.PERSONAL_PRONOUN, Class.PERSONAL_PRONOUN, Class.PERSONAL_PRONOUN, Class.FINITIVE_VERB, Class.FINITIVE_VERB, Class.ADVERB, Class.ADVERB, Class.PREPOSITION, Class.PREPOSITION, Class.ADVERB, Class.ADVERB, Class.PUNCTUATION_MARK); RepetitionChecker checker = new RepetitionChecker(); List<Mistake> errors = checker.check(sentence); assertEquals(6, errors.size()); }
@Test public void testGraveAccent() { Sentence sentence = createSentence( "Caminhava a a tarde toda .", Class.FINITIVE_VERB, Class.PREPOSITION, Class.ARTICLE, Class.ADVERB, Class.ADVERB, Class.PUNCTUATION_MARK); RepetitionChecker checker = new RepetitionChecker(); List<Mistake> errors = checker.check(sentence); assertEquals(0, errors.size()); }
@Test public void testNumber() { Sentence sentence = createSentence( "Dia 11 .", Class.NOUN, Class.NUMERAL, Class.PUNCTUATION_MARK); RepetitionChecker checker = new RepetitionChecker(); List<Mistake> errors = checker.check(sentence); assertEquals(0, errors.size()); }