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

ljacqu / wordeval / 14562991048

20 Apr 2025 08:19PM UTC coverage: 55.116% (+1.7%) from 53.367%
14562991048

push

github

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

269 of 568 branches covered (47.36%)

212 of 313 new or added lines in 36 files covered. (67.73%)

6 existing lines in 5 files now uncovered.

738 of 1339 relevant lines covered (55.12%)

3.27 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.export.EvaluatorExportUtil;
6
import ch.jalu.wordeval.evaluators.result.WordWithScore;
7
import ch.jalu.wordeval.language.Language;
8
import ch.jalu.wordeval.language.LetterType;
9
import com.google.common.collect.ListMultimap;
10
import lombok.Getter;
11
import lombok.ToString;
12

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

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

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

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

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

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

66
    Set<Double> uniqueValues = new HashSet<>();
×
67
    ListMultimap<Object, Object> filteredResults = EvaluatorExportUtil.newListMultimap();
×
68
    for (WordWithScore wordWithScore : sortedResult) {
×
NEW
69
      if (uniqueValues.add(wordWithScore.score()) && uniqueValues.size() > topScores) {
×
70
        break;
×
71
      }
NEW
72
      filteredResults.put((int) wordWithScore.score(), wordWithScore.word().getRaw());
×
73
      if (filteredResults.size() >= maxLimit) {
×
74
        break;
×
75
      }
76
    }
×
77

78
    return filteredResults;
×
79
  }
80

81
  @Override
82
  public String getId() {
83
    return switch (letterType) {
×
84
      case VOWELS -> "vowels.consecutiveCount";
×
85
      case CONSONANTS -> "consonants.consecutiveCount";
×
86
    };
87
  }
88
}
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