Skip to content

Commit

Permalink
Fix fuzzy matcher mixing up Streuner & StreuneR (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
Punikekk authored Oct 29, 2023
1 parent 0b1271d commit 65b5e39
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/com/github/manolo8/darkbot/gui/utils/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Strings {
private static final Pattern SIMPLIFY_NAME_MATCHES = Pattern.compile("^[^\\d]+\\d{1,3}$");
private static final Pattern SIMPLIFY_NAME_REPLACEMENT = Pattern.compile("\\d{1,3}$");

private static final String[] GEAR_FUZZY_MATCHER_EXCLUDES = {"StreuneR"};

public static String fileName(String path) {
if (path == null || path.isEmpty()) return "-";
int split = path.lastIndexOf(File.separatorChar);
Expand All @@ -34,14 +36,25 @@ public static String simplifyName(String name) {
}

public static String fuzzyMatcher(String string) {
string = string.toLowerCase(Locale.ROOT)
if (shouldUseLowerCase(string))
string = string.toLowerCase(Locale.ROOT);

string = string
.replace("-x-", "") // Fixes "-x-[ NAME ]-x-", used in frozen labyrinth
.replace("xx", "") // Fixes Chaos Protegit
.replace("referee binary bot", "referee bot");
string = NON_CHARACTER_REPLACEMENT.matcher(string).replaceAll(""); // Keep only alphanumerical
return MIMESIS_REPLACEMENT.matcher(string).replaceAll("mimesis"); // Replace mim35i5 with mimesis
}

private static boolean shouldUseLowerCase(String name) {
for (String s : GEAR_FUZZY_MATCHER_EXCLUDES) {
if (name.contains(s))
return false;
}
return true;
}

public static boolean isEmpty(String s) {
return s == null || s.isEmpty();
}
Expand Down

0 comments on commit 65b5e39

Please sign in to comment.