• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ljacqu / wordeval / 14540892325

18 Apr 2025 07:50PM UTC coverage: 51.4% (-12.1%) from 63.456%
14540892325

push

github

ljacqu
Merge remote-tracking branch 'origin/master' into dependencies

239 of 546 branches covered (43.77%)

93 of 383 new or added lines in 27 files covered. (24.28%)

5 existing lines in 4 files now uncovered.

679 of 1321 relevant lines covered (51.4%)

3.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.67
/src/main/java/ch/jalu/wordeval/evaluators/impl/ConsecutiveVowelCount.java
1
package ch.jalu.wordeval.evaluators.impl;
2

3
import ch.jalu.wordeval.dictionary.Word;
4
import ch.jalu.wordeval.evaluators.WordEvaluator;
5
import ch.jalu.wordeval.evaluators.result.WordWithScore;
6
import ch.jalu.wordeval.language.Language;
7
import ch.jalu.wordeval.language.LetterType;
8
import com.google.common.collect.ArrayListMultimap;
9
import com.google.common.collect.ListMultimap;
10
import lombok.Getter;
11

12
import java.util.ArrayList;
13
import java.util.Comparator;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Set;
17

18
/**
19
 * Searches words for clusters of vowels or consonants, e.g. "ngstschw" in
20
 * German "Angstschweiss". The same word can appear multiple times in the
21
 * results, e.g. "poignée" will count twice ("oi", "ée").
22
 */
23
public class ConsecutiveVowelCount implements WordEvaluator {
24

25
  private final Set<String> lettersToConsider;
26
  @Getter
27
  private final LetterType letterType;
28
  @Getter
5✔
29
  private final List<WordWithScore> results = new ArrayList<>();
30

31
  /**
32
   * Creates a new VowelCount evaluator instance.
33
   *
34
   * @param letterType the letter type to consider
35
   * @param language the language of the words to evaluate
36
   */
37
  public ConsecutiveVowelCount(LetterType letterType, Language language) {
2✔
38
    this.lettersToConsider = new HashSet<>(letterType.getLetters(language));
8✔
39
    this.letterType = letterType;
3✔
40
  }
1✔
41

42
  @Override
43
  public void evaluate(Word wordObject) {
44
    String word = wordObject.getWithoutAccents();
3✔
45
    int count = 0;
2✔
46
    for (int i = 0; i <= word.length(); ++i) {
8✔
47
      if (i == word.length() || !lettersToConsider.contains(word.substring(i, i + 1))) {
14✔
48
        if (count > 1) {
3✔
49
          results.add(new WordWithScore(wordObject, count));
10✔
50
        }
51
        count = 0;
3✔
52
      } else {
53
        ++count;
1✔
54
      }
55
    }
56
  }
1✔
57

58
  @Override
59
  public ListMultimap<Object, Object> getTopResults(int topScores, int maxLimit) {
NEW
60
    List<WordWithScore> sortedResult = results.stream()
×
NEW
61
        .sorted(Comparator.comparing(WordWithScore::getScore).reversed())
×
NEW
62
        .toList();
×
63

NEW
64
    Set<Double> uniqueValues = new HashSet<>();
×
NEW
65
    ListMultimap<Object, Object> filteredResults = ArrayListMultimap.create();
×
NEW
66
    for (WordWithScore wordWithScore : sortedResult) {
×
NEW
67
      if (uniqueValues.add(wordWithScore.getScore()) && uniqueValues.size() > topScores) {
×
NEW
68
        break;
×
69
      }
NEW
70
      filteredResults.put((int) wordWithScore.getScore(), wordWithScore.getWord().getRaw());
×
NEW
71
      if (filteredResults.size() >= maxLimit) {
×
NEW
72
        break;
×
73
      }
NEW
74
    }
×
75

NEW
76
    return filteredResults;
×
77
  }
78

79
  @Override
80
  public String getId() {
NEW
81
    return switch (letterType) {
×
NEW
82
      case VOWELS -> "ConsecutiveVowelCount";
×
NEW
83
      case CONSONANTS -> "ConsecutiveConsonantCount";
×
84
    };
85
  }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc