From 5d63d602102caa928d19a71552f253e38e6303de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Gla=C3=9F?= Date: Mon, 10 Jan 2022 18:39:24 +0100 Subject: [PATCH] [Fixed] typo correction preferring longer words over perfect fits --- .../yoshibot/command/commands/PlayCommand.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java b/app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java index 3aeb2c8..e800d2e 100644 --- a/app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java +++ b/app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java @@ -55,7 +55,8 @@ public class PlayCommand extends YoshiCommand { sendErrorMessage("Konnte keinen Audiochannel auswählen."); return false; } - context.getEvent().getMessage().getTextChannel().sendMessage("Spiele '" + requestedFile + "' in '" + vc.getName() + "' ab").queue(); + context.getEvent().getMessage().getTextChannel() + .sendMessage("Spiele '" + requestedFile + "' in '" + vc.getName() + "' ab").queue(); YoshiBot.getInstance().playSound(file, vc); } @@ -63,11 +64,12 @@ public class PlayCommand extends YoshiCommand { } private String getBestMatch(String word, List choices) { - Map hammingDists = + Map hammingDists = choices.parallelStream() .collect(Collectors.toMap(file -> file, - file -> maximalMatchingChars(file, word) * choices.size() + - file.length())); + file -> (double) maximalMatchingChars(file, word) / + Math.max(file.length(), + word.length()))); return hammingDists.keySet().stream() .max((file1, file2) -> (int) Math.signum(hammingDists.get(file1) - hammingDists.get(file2))) .orElse(choices.get(0));