public static void main(String[] args) throws Exception {
Pattern p1 = Pattern.compile("^(\\w{5})\tB");
Pattern p2 = Pattern.compile("^(\\w{5})(/.*)?$");
HashMap<String, Integer> words = new HashMap<>();
String path1 = "C:\\path\\to\\dictd\\freedict-deu-eng.index";
String path2 = "C:\\path\\to\\worte-de_all.txt";
try (BufferedReader br = new BufferedReader(new FileReader(path1))) {
String line;
while ((line = br.readLine()) != null) {
if (line.isBlank()) {
continue;
}
if (p1.matcher(line).find()) {
String word = line.substring(0, 5).toUpperCase(Locale.ROOT);
if (words.containsKey(word)) {
words.put(word, words.get(word) + 1);
} else {
words.put(word, 1);
}
}
}
}
try (BufferedReader br = new BufferedReader(new FileReader(path2))) {
String line;
while ((line = br.readLine()) != null) {
if (line.isBlank()) {
continue;
}
if (p2.matcher(line).find()) {
String word = line.substring(0, 5).toUpperCase(Locale.ROOT);
if (words.containsKey(word)) {
words.put(word, words.get(word) + 1);
} else {
System.out.println("New word: " + word);
words.put(word, 1);
}
}
}
}
List<Map.Entry<String, Integer>> list = new ArrayList<>(words.entrySet());
list.sort(reverseOrder(Map.Entry.comparingByValue()));
int i = 1;
for (Map.Entry<String, Integer> entry : list) {
System.out.println(entry.getKey() + " " + entry.getValue() + " " + i++);
}
}