diff --git a/app/src/main/java/de/lmu/navigator/search/FuzzyWuzzyStringMetric.java b/app/src/main/java/de/lmu/navigator/search/FuzzyWuzzyStringMetric.java new file mode 100644 index 0000000..f6be623 --- /dev/null +++ b/app/src/main/java/de/lmu/navigator/search/FuzzyWuzzyStringMetric.java @@ -0,0 +1,44 @@ +package de.lmu.navigator.search; + +import java.util.Locale; + +import me.xdrop.fuzzywuzzy.FuzzySearch; +import uk.ac.shef.wit.simmetrics.similaritymetrics.AbstractStringMetric; + +/** + * See: https://github.com/xdrop/fuzzywuzzy + */ +public class FuzzyWuzzyStringMetric extends AbstractStringMetric { + + @Override + public String getLongDescriptionString() { + return null; + } + + @Override + public String getShortDescriptionString() { + return null; + } + + @Override + public float getSimilarity(String compString, String searchString) { + // Give score independent of position in word and order of search words + return FuzzySearch.tokenSortPartialRatio(searchString.toLowerCase(Locale.GERMAN), compString.toLowerCase(Locale.GERMAN)) / 100f; + } + + @Override + public String getSimilarityExplained(String arg0, String arg1) { + return null; + } + + @Override + public float getSimilarityTimingEstimated(String arg0, String arg1) { + return 0; + } + + @Override + public float getUnNormalisedSimilarity(String compString, + String searchString) { + return 0; + } +} diff --git a/app/src/main/java/de/lmu/navigator/search/SearchScore.java b/app/src/main/java/de/lmu/navigator/search/SearchScore.java index e3d36a5..97b72b9 100644 --- a/app/src/main/java/de/lmu/navigator/search/SearchScore.java +++ b/app/src/main/java/de/lmu/navigator/search/SearchScore.java @@ -1,8 +1,11 @@ package de.lmu.navigator.search; +import uk.ac.shef.wit.simmetrics.similaritymetrics.AbstractStringMetric; + public class SearchScore implements Comparable { private final static float MATCH_THRESHOLD = 0.5f; - private static MyPrefixLevenshtein mSimilarityMeasure = new MyPrefixLevenshtein(); + private final static boolean FUZZYWUZZY_STRING_METRIC = true; + private static AbstractStringMetric mSimilarityMeasure = FUZZYWUZZY_STRING_METRIC ? new FuzzyWuzzyStringMetric() : new MyPrefixLevenshtein(); private Searchable mSearchable; private float simPrimary = 1f; diff --git a/app/src/main/res/raw/licences b/app/src/main/res/raw/licences index 64cfe52..625eee4 100644 --- a/app/src/main/res/raw/licences +++ b/app/src/main/res/raw/licences @@ -72,6 +72,12 @@ Copyright 2013 Philip Schiffer Apache Software License 2.0 + + JavaWuzzy + https://github.com/xdrop/fuzzywuzzy + + Apache Software License 2.0 + SimMetrics http://sourceforge.net/projects/simmetrics/