Browse Source

Jaccard-Distanz hat leider nicht ausgereicht für Strings mit gleichen Substrings und unterschiedlicher Länge und so. Naja hier is was besseres

Yannic Link 3 years ago
parent
commit
70a1cb5777
1 changed files with 15 additions and 7 deletions
  1. +15
    -7
      app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java

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

@ -113,17 +113,25 @@ public class PlayCommand extends YoshiCommand {
}
private String getBestMatch(String word, List<String> choices) {
double bestScore = 1.0;
String bestMatching = null;
double bestJaccardScore = 1.0;
double bestLengthSimilarity = 0.0;
int originalLength = word.length();
String bestMatch = null;
for (String file : choices) {
double score = (new JaccardDistance()).apply(word, file);
if (score < bestScore) {
bestScore = score;
bestMatching = file;
if(file.equals(word)) return file;
int fileLength = file.length();
double jaccardScore = (new JaccardDistance()).apply(word, file);
double lengthSimilarity = (float)(Math.min(originalLength, fileLength))
/ (float)(Math.max(originalLength, fileLength));
if (jaccardScore < bestJaccardScore
|| ((jaccardScore == bestJaccardScore) && (lengthSimilarity > bestLengthSimilarity))) {
bestJaccardScore = jaccardScore;
bestLengthSimilarity = lengthSimilarity;
}
}
return bestMatching;
return bestMatch;
}
private List<String> getAllFiles() {


Loading…
Cancel
Save