diff --git a/auto-cream-api.iml b/auto-cream-api.iml index f79f6a4..e634122 100644 --- a/auto-cream-api.iml +++ b/auto-cream-api.iml @@ -34,5 +34,6 @@ + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5b15b08..956008e 100644 --- a/pom.xml +++ b/pom.xml @@ -131,5 +131,10 @@ unirest-java 3.1.02 + + me.xdrop + fuzzywuzzy + 1.3.1 + \ No newline at end of file diff --git a/src/main/java/util/SteamAppsListCache.java b/src/main/java/util/SteamAppsListCache.java index eae4bc8..c154519 100644 --- a/src/main/java/util/SteamAppsListCache.java +++ b/src/main/java/util/SteamAppsListCache.java @@ -20,6 +20,8 @@ import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; import kong.unirest.HttpResponse; import kong.unirest.Unirest; +import me.xdrop.fuzzywuzzy.FuzzySearch; +import me.xdrop.fuzzywuzzy.model.BoundExtractedResult; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -32,10 +34,7 @@ import java.io.*; import java.lang.reflect.Type; import java.time.Duration; import java.time.Instant; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; public class SteamAppsListCache { @@ -94,7 +93,17 @@ public class SteamAppsListCache { } public App findGame(String name) { - for (App app : list.getSteamAppsList()) { + List> match = FuzzySearch.extractTop(name, list.getSteamAppsList(), app -> + app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""), 25); + System.out.println("\n\n\n==== Top 25 results for \"" + name + "\": ===="); + for (BoundExtractedResult result : match) { + System.out.println(result.getReferent().getName() + " - " + + result.getIndex() + " - " + + result.getScore()); + } + System.out.println("\n\n\n"); + return match.get(0).getReferent(); + /*for (App app : list.getSteamAppsList()) { if (app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", "") .startsWith(name.toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""))) { return app; @@ -105,8 +114,8 @@ public class SteamAppsListCache { .contains(name.toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""))) { return app; } - } - return null; + }*/ + //return null; } private void getListFromApi() {