Initial implementation of fuzzy search (fuzzywuzzy library)

This commit is contained in:
Jeddunk 2020-08-23 14:58:49 +02:00
parent c76ad989f9
commit 4eda79211e
3 changed files with 22 additions and 7 deletions

View File

@ -34,5 +34,6 @@
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpasyncclient:4.1.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore-nio:4.4.10" level="project" />
<orderEntry type="library" name="Maven: me.xdrop:fuzzywuzzy:1.3.1" level="project" />
</component>
</module>

View File

@ -131,5 +131,10 @@
<artifactId>unirest-java</artifactId>
<version>3.1.02</version>
</dependency>
<dependency>
<groupId>me.xdrop</groupId>
<artifactId>fuzzywuzzy</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
</project>

View File

@ -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<BoundExtractedResult<App>> 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<App> 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() {