Browse Source

[Fixed] typo correction preferring longer words over perfect fits

master
Paul Glaß 3 years ago
parent
commit
5d63d60210
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java

+ 6
- 4
app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java View File

@ -55,7 +55,8 @@ public class PlayCommand extends YoshiCommand {
sendErrorMessage("Konnte keinen Audiochannel auswählen."); sendErrorMessage("Konnte keinen Audiochannel auswählen.");
return false; 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); YoshiBot.getInstance().playSound(file, vc);
} }
@ -63,11 +64,12 @@ public class PlayCommand extends YoshiCommand {
} }
private String getBestMatch(String word, List<String> choices) { private String getBestMatch(String word, List<String> choices) {
Map<String, Integer> hammingDists =
Map<String, Double> hammingDists =
choices.parallelStream() choices.parallelStream()
.collect(Collectors.toMap(file -> file, .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() return hammingDists.keySet().stream()
.max((file1, file2) -> (int) Math.signum(hammingDists.get(file1) - hammingDists.get(file2))) .max((file1, file2) -> (int) Math.signum(hammingDists.get(file1) - hammingDists.get(file2)))
.orElse(choices.get(0)); .orElse(choices.get(0));


Loading…
Cancel
Save