[jira] [Work logged] (TEXT-104) Jaro Winkler Distance refers to similarity

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Work logged] (TEXT-104) Jaro Winkler Distance refers to similarity

JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/TEXT-104?focusedWorklogId=199566&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-199566 ]

ASF GitHub Bot logged work on TEXT-104:
---------------------------------------

                Author: ASF GitHub Bot
            Created on: 16/Feb/19 09:08
            Start Date: 16/Feb/19 09:08
    Worklog Time Spent: 10m
      Work Description: kinow commented on pull request #100: TEXT-104: Jaro Winkler Distance refers to similarity
URL: https://github.com/apache/commons-text/pull/100#discussion_r257453672
 
 

 ##########
 File path: src/main/java/org/apache/commons/text/similarity/JaroWinklerDistance.java
 ##########
 @@ -73,84 +57,13 @@
      * @throws IllegalArgumentException if either CharSequence input is {@code null}
      */
     @Override
-    public Double apply(final CharSequence left, final CharSequence right) {
-        final double defaultScalingFactor = 0.1;
+    public Double apply(CharSequence left, CharSequence right) {
 
         if (left == null || right == null) {
             throw new IllegalArgumentException("CharSequences must not be null");
         }
 
-        final int[] mtp = matches(left, right);
-        final double m = mtp[0];
-        if (m == 0) {
-            return 0D;
-        }
-        final double j = ((m / left.length() + m / right.length() + (m - (double) mtp[1] / 2) / m)) / 3;
-        final double jw = j < 0.7D ? j : j + defaultScalingFactor * mtp[2] * (1D - j);
-        return jw;
-    }
-
-    /**
-     * This method returns the Jaro-Winkler string matches, half transpositions, prefix array.
-     *
-     * @param first the first string to be matched
-     * @param second the second string to be matched
-     * @return mtp array containing: matches, half transpositions, and prefix
-     */
-    protected static int[] matches(final CharSequence first, final CharSequence second) {
-        CharSequence max, min;
-        if (first.length() > second.length()) {
-            max = first;
-            min = second;
-        } else {
-            max = second;
-            min = first;
-        }
-        final int range = Math.max(max.length() / 2 - 1, 0);
-        final int[] matchIndexes = new int[min.length()];
-        Arrays.fill(matchIndexes, -1);
-        final boolean[] matchFlags = new boolean[max.length()];
-        int matches = 0;
-        for (int mi = 0; mi < min.length(); mi++) {
-            final char c1 = min.charAt(mi);
-            for (int xi = Math.max(mi - range, 0), xn = Math.min(mi + range + 1, max.length()); xi < xn; xi++) {
-                if (!matchFlags[xi] && c1 == max.charAt(xi)) {
-                    matchIndexes[mi] = xi;
-                    matchFlags[xi] = true;
-                    matches++;
-                    break;
-                }
-            }
-        }
-        final char[] ms1 = new char[matches];
-        final char[] ms2 = new char[matches];
-        for (int i = 0, si = 0; i < min.length(); i++) {
-            if (matchIndexes[i] != -1) {
-                ms1[si] = min.charAt(i);
-                si++;
-            }
-        }
-        for (int i = 0, si = 0; i < max.length(); i++) {
-            if (matchFlags[i]) {
-                ms2[si] = max.charAt(i);
-                si++;
-            }
-        }
-        int halfTranspositions = 0;
-        for (int mi = 0; mi < ms1.length; mi++) {
-            if (ms1[mi] != ms2[mi]) {
-                halfTranspositions++;
-            }
-        }
-        int prefix = 0;
-        for (int mi = 0; mi < Math.min(4, min.length()); mi++) {
-            if (first.charAt(mi) == second.charAt(mi)) {
-                prefix++;
-            } else {
-                break;
-            }
-        }
-        return new int[] {matches, halfTranspositions, prefix};
+        JaroWinklerSimilarity jwSim = new JaroWinklerSimilarity();
 
 Review comment:
   Maybe `similarity` or `jaroWinklerSimilarity`?
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 199566)
    Time Spent: 0.5h  (was: 20m)

> Jaro Winkler Distance refers to similarity
> ------------------------------------------
>
>                 Key: TEXT-104
>                 URL: https://issues.apache.org/jira/browse/TEXT-104
>             Project: Commons Text
>          Issue Type: Improvement
>    Affects Versions: 1.1
>            Reporter: Nikos Karagiannakis
>            Priority: Trivial
>             Fix For: 2.0
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The 'apply' method returns the similarity score instead of the distance score as implied from the class name.
> It is stated in the javadoc, but it is not aligned with the approach of the rest similarity scores in the same package (e.g LevenshteinDetailedDistance).
> Maybe a rename of the class or the method to avoid confusion?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)