Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Levenshtein string comparison score with FuzzyWuzzy (#6, #20) #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 4 additions & 1 deletion app/src/main/java/de/lmu/navigator/search/SearchScore.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package de.lmu.navigator.search;

import uk.ac.shef.wit.simmetrics.similaritymetrics.AbstractStringMetric;

public class SearchScore implements Comparable<SearchScore> {
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;
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/raw/licences
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
<copyright>Copyright 2013 Philip Schiffer</copyright>
<license>Apache Software License 2.0</license>
</notice>
<notice>
<name>JavaWuzzy</name>
<url>https://github.com/xdrop/fuzzywuzzy</url>
<copyright/>
<license>Apache Software License 2.0</license>
</notice>
<notice>
<name>SimMetrics</name>
<url>http://sourceforge.net/projects/simmetrics/</url>
Expand Down