• 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

0.0
/src/main/java/ch/jalu/wordeval/DictionaryRenamer.java
1
package ch.jalu.wordeval;
2

3
import com.google.common.collect.ImmutableMap;
4
import com.google.common.io.Files;
5
import lombok.extern.slf4j.Slf4j;
6

7
import java.io.File;
8
import java.util.Arrays;
9
import java.util.Map;
10
import java.util.Set;
11

12
/**
13
 * Utility class to rename the dictionaries from the Hunspell
14
 * repository at https://github.com/titoBouzout/Dictionaries
15
 * to the language code of the dictionary, as used in <i>wordeval</i>.
16
 */
NEW
17
@Slf4j
×
18
public class DictionaryRenamer {
19
  
20
  private static final File DICT_DIRECTORY = new File("./dict");
×
21
  private static final Set<String> USE_EXTENSIONS = Set.of("aff", "dic", "txt");
×
22
  private static final Map<String, String> REPLACEMENTS = initReplacements();
×
23
  
24
  private DictionaryRenamer() {
25
  }
26

27
  /**
28
   * Scans the /dict folder and renames files to the codes.
29
   * @param args .
30
   */
31
  public static void main(String[] args) {
32
    if (!DICT_DIRECTORY.exists()) {
×
33
      throw new IllegalStateException("Directory '" + DICT_DIRECTORY + "' does not exist");
×
34
    }
35

36
    File[] files = DICT_DIRECTORY.listFiles();
×
37
    if (files == null) {
×
38
      throw new IllegalStateException("Could not read files from dictionary " + DICT_DIRECTORY);
×
39
    }
40
    Arrays.stream(files)
×
41
      .filter(file -> USE_EXTENSIONS.contains(Files.getFileExtension(file.getName())))
×
42
      .forEach(file -> applyReplacement(file));
×
43
    
44
    log.info("End renaming files");
×
45
  }
×
46
  
47
  private static void applyReplacement(File f) {
48
    String fileName = Files.getNameWithoutExtension(f.getName()).replace("%20", " ");
×
49

50
    if (!REPLACEMENTS.containsKey(fileName)) {
×
51
      log.info("No replacement for '{}'", fileName);
×
52
      return;
×
53
    }
54
    
55
    String newName = fileName.replace(fileName, REPLACEMENTS.get(fileName))
×
56
        + "." + Files.getFileExtension(f.getName());
×
57
    File newFile = new File(DICT_DIRECTORY + File.separator + newName);
×
58
    if (newFile.exists() && !newFile.isDirectory()) {
×
59
      log.warn("Not renaming '{}' to '{}': file with such name already exists", fileName, newName);
×
60
    } else {
61
      boolean couldRename = f.renameTo(newFile);
×
62
      if (couldRename) {
×
63
        log.info("Renamed '{}' to '{}'", fileName, newName);
×
64
      } else {
65
        log.warn("Could not rename '{}' to '{}'", fileName, newName);
×
66
      }
67
    }
68
  }
×
69
  
70
  private static Map<String, String> initReplacements() {
71
    return ImmutableMap.<String, String>builder()
×
72
    .put("Basque", "eu")
×
73
    .put("Bulgarian", "bg")
×
74
    .put("Catalan", "ca")
×
75
    .put("Croatian", "hr")
×
76
    .put("Czech", "cs")
×
77
    .put("Danish", "da")
×
78
    .put("Dutch", "nl")
×
79
    .put("English (American)", "en-us")
×
80
    .put("English (Australian)", "en-au")
×
81
    .put("English (British)", "en-uk")
×
82
    .put("English (Canadian)", "en-ca")
×
83
    .put("Estonian", "et")
×
84
    .put("Finnish", "fi")
×
85
    .put("French", "fr")
×
86
    .put("Galego", "gl")
×
87
    .put("German", "de")
×
88
    .put("German_de_AT", "de-at")
×
89
    .put("German_de_CH", "de-ch")
×
90
    .put("German_de_DE", "de-de")
×
91
    .put("Greek", "el")
×
92
    .put("Hungarian", "hu")
×
93
    .put("Italian", "it")
×
94
    .put("Lithuanian", "lt")
×
95
    .put("Luxembourgish", "lb")
×
96
    .put("Mongolian", "mn")
×
97
    .put("Norwegian (Bokmal)", "nb")
×
98
    .put("Norwegian (Nynorsk)", "nn")
×
99
    .put("Polish", "pl")
×
100
    .put("Portuguese (Brazilian)", "pt-br")
×
101
    .put("Portuguese (European)", "pt-pt")
×
102
    .put("Romanian", "ro")
×
103
    .put("Romanian (Modern)", "ro")
×
104
    .put("Russian", "ru")
×
105
    .put("Serbian (Cyrillic)", "sr-cyrl")
×
106
    .put("Serbian (Latin)", "sr-latn")
×
107
    .put("Slovak_sk_SK", "sk")
×
108
    .put("Slovenian", "sl")
×
109
    .put("Spanish", "es")
×
110
    .put("Swedish", "sv")
×
111
    .put("Turkish", "tr")
×
112
    .put("Ukrainian_uk_UA", "uk")
×
113
    .put("Vietnamese_vi_VN", "vi")
×
114
    .build();
×
115
  }
116
  
117
}
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