|
@ -113,17 +113,25 @@ public class PlayCommand extends YoshiCommand { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private String getBestMatch(String word, List<String> choices) { |
|
|
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) { |
|
|
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() { |
|
|
private List<String> getAllFiles() { |
|
|