• 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

58.33
/src/main/java/ch/jalu/wordeval/evaluators/impl/RepeatedSegmentConsecutive.java
1
package ch.jalu.wordeval.evaluators.impl;
2

3
import ch.jalu.wordeval.dictionary.Word;
4
import ch.jalu.wordeval.evaluators.PostEvaluator;
5
import ch.jalu.wordeval.evaluators.export.EvaluatorExportUtil;
6
import ch.jalu.wordeval.evaluators.processing.EvaluatorCollection;
7
import ch.jalu.wordeval.evaluators.result.WordWithKey;
8
import ch.jalu.wordeval.util.StreamUtils;
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.HashMap;
15
import java.util.HashSet;
16
import java.util.List;
17
import java.util.Map;
18
import java.util.Set;
19
import java.util.regex.Matcher;
20
import java.util.regex.Pattern;
21

22
/**
23
 * Finds words with repeating, consecutive sequences,
24
 * such as "elijk" in nl. "gelijkelijk".
25
 */
26
public class RepeatedSegmentConsecutive implements PostEvaluator {
2✔
27

28
  private static final Pattern REPETITION_AT_START = Pattern.compile("^(.{2,})(\\1+)");
4✔
29

30
  @Getter
6✔
31
  private final List<WordWithKey> results = new ArrayList<>();
32

33
  @Override
34
  public void evaluate(EvaluatorCollection evaluators) {
35
    evaluators.getWordEvaluatorOrThrow(RepeatedSegment.class).getResults().stream()
7✔
36
        .filter(StreamUtils.distinctByKey(entry -> entry.word().getLowercase()))
8✔
37
        .forEach(result -> processWord(result.word()));
6✔
38
  }
1✔
39

40
  private void processWord(Word wordObject) {
41
    String word = wordObject.getLowercase();
3✔
42
    Map<String, String> results = new HashMap<>();
4✔
43
    for (int i = 0; i < word.length() - 2; ++i) {
10✔
44
      Matcher matcher = REPETITION_AT_START.matcher(word.substring(i));
6✔
45
      if (matcher.find()) {
3✔
46
        String segment = matcher.group(1);
4✔
47
        String repetition = segment + matcher.group(2);
6✔
48
        addResult(results, segment, repetition);
4✔
49
      }
50
    }
51
    results.values().forEach(v -> this.results.add(new WordWithKey(wordObject, v)));
16✔
52
  }
1✔
53

54
  @Override
55
  public ListMultimap<Object, Object> getTopResults(int topScores, int maxLimit) {
56
    List<WordWithKey> sortedResult = results.stream()
×
NEW
57
        .sorted(Comparator.<WordWithKey>comparingInt(wordWithKey -> wordWithKey.key().length()).reversed())
×
58
        .toList();
×
59

60
    Set<Integer> uniqueValues = new HashSet<>();
×
61
    ListMultimap<Object, Object> filteredResults = EvaluatorExportUtil.newListMultimap();
×
62
    for (WordWithKey wordWithKey : sortedResult) {
×
NEW
63
      int score = wordWithKey.key().length();
×
64
      if (uniqueValues.add(score) && uniqueValues.size() > topScores) {
×
65
        break;
×
66
      }
NEW
67
      filteredResults.put(score, wordWithKey.word().getRaw() + " (" + wordWithKey.key() + ")");
×
68
      if (filteredResults.size() >= maxLimit) {
×
69
        break;
×
70
      }
71
    }
×
72

73
    return filteredResults;
×
74
  }
75

76
  @Override
77
  public String getId() {
78
    return "repeatedSegment.consecutive";
×
79
  }
80

81
  private static void addResult(Map<String, String> results, String segment, String repetition) {
82
    String storedRepetition = results.get(segment);
5✔
83
    if (storedRepetition == null || storedRepetition.length() < repetition.length()) {
7✔
84
      results.put(segment, repetition);
5✔
85
    }
86
  }
1✔
87
}
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