• 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

58.82
/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.processing.AllWordsEvaluatorProvider;
6
import ch.jalu.wordeval.evaluators.result.WordWithKey;
7
import com.google.common.collect.ArrayListMultimap;
8
import com.google.common.collect.ListMultimap;
9
import lombok.Getter;
10

11
import java.util.ArrayList;
12
import java.util.Comparator;
13
import java.util.HashMap;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.Set;
18
import java.util.regex.Matcher;
19
import java.util.regex.Pattern;
20

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

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

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

32
  @Override
33
  public void evaluate(AllWordsEvaluatorProvider allWordsEvaluatorProvider) {
34
    allWordsEvaluatorProvider.getEvaluator(RepeatedSegment.class).getResults()
7✔
35
        .forEach(result -> processWord(result.getWord()));
6✔
36
  }
1✔
37

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

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

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

NEW
71
    return filteredResults;
×
72
  }
73

74
  private static void addResult(Map<String, String> results, String segment, String repetition) {
75
    String storedRepetition = results.get(segment);
5✔
76
    if (storedRepetition == null || storedRepetition.length() < repetition.length()) {
7✔
77
      results.put(segment, repetition);
5✔
78
    }
79
  }
1✔
80
}
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