MCPcopy Create free account
hub / github.com/Aghajari/MathParser / similarity

Method similarity

MathParser/src/com/aghajari/math/Utils.java:124–136  ·  view source on GitHub ↗

Calculates the similarity (a number within 0 and 1) between two strings. https://stackoverflow.com/a/16018452/9187189

(String s1, String s2)

Source from the content-addressed store, hash-verified

122 * https://stackoverflow.com/a/16018452/9187189
123 */
124 public static double similarity(String s1, String s2) {
125 String longer = s1, shorter = s2;
126 if (s1.length() < s2.length()) { // longer should always have greater length
127 longer = s2;
128 shorter = s1;
129 }
130 int longerLength = longer.length();
131 if (longerLength == 0) {
132 return 1.0; /* both strings are zero length */
133 }
134 return (longerLength - getLevenshteinDistance(longer, shorter)) / (double) longerLength;
135
136 }
137
138 /**
139 * java.org.apache.commons.lang3.StringUtils#getLevenshteinDistance(CharSequence, CharSequence)

Callers 1

couldNotFindVariablesMethod · 0.95

Calls 1

Tested by

no test coverage detected