[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=199567&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-199567 ]

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_r257453758
 
 

 ##########
 File path: src/main/java/org/apache/commons/text/similarity/JaroWinklerSimilarity.java
 ##########
 @@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.text.similarity;
+
+import java.util.Arrays;
+
+/**
+ * A similarity algorithm indicating the percentage of matched characters between two character sequences.
+ *
+ * <p>
+ * The Jaro measure is the weighted sum of percentage of matched characters
+ * from each file and transposed characters. Winkler increased this measure
+ * for matching initial characters.
+ * </p>
+ *
+ * <p>
+ * This implementation is based on the Jaro Winkler similarity algorithm
+ * from <a href="http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance">
+ * http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance</a>.
+ * </p>
+ *
+ * <p>
+ * This code has been adapted from Apache Commons Lang 3.3.
+ * </p>
+ *
+ * @since 1.7
+ */
+public class JaroWinklerSimilarity implements SimilarityScore<Double> {
+
+    /**
+     * Computes the Jaro Winkler Similarity between two character sequences.
+     *
+     * <pre>
+     * sim.apply(null, null)          = IllegalArgumentException
+     * sim.apply("foo", null)         = IllegalArgumentException
+     * sim.apply(null, "foo")         = IllegalArgumentException
+     * sim.apply("", "")              = 1.0
+     * sim.apply("foo", "foo")        = 1.0
+     * sim.apply("foo", "foo ")       = 0.94
+     * sim.apply("foo", "foo  ")      = 0.91
+     * sim.apply("foo", " foo ")      = 0.87
+     * sim.apply("foo", "  foo")      = 0.51
+     * sim.apply("", "a")             = 0.0
+     * sim.apply("aaapppp", "")       = 0.0
+     * sim.apply("frog", "fog")       = 0.93
+     * sim.apply("fly", "ant")        = 0.0
+     * sim.apply("elephant", "hippo") = 0.44
+     * sim.apply("hippo", "elephant") = 0.44
+     * sim.apply("hippo", "zzzzzzzz") = 0.0
+     * sim.apply("hello", "hallo")    = 0.88
+     * sim.apply("ABC Corporation", "ABC Corp") = 0.93
+     * sim.apply("D N H Enterprises Inc", "D &amp; H Enterprises, Inc.") = 0.95
+     * sim.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness") = 0.92
+     * sim.apply("PENNSYLVANIA", "PENNCISYLVNIA") = 0.88
+     * </pre>
+     *
+     * @param left the first CharSequence, must not be null
+     * @param right the second CharSequence, must not be null
+     * @return result similarity
+     * @throws IllegalArgumentException if either CharSequence input is {@code null}
+     */
+    @Override
+    public Double apply(final CharSequence left, final CharSequence right) {
+        final double defaultScalingFactor = 0.1;
+
+        if (left == null || right == null) {
+            throw new IllegalArgumentException("CharSequences must not be null");
+        }
+
+        if (left.equals(right)) {
+            return 1D;
 
 Review comment:
   Just realized in the rest of the code we have `d` instead of `D` (e.g. `JaccardDistance.`, `CosineSimilarity`), but the old code was using `D` already. We can fix it later to have a more uniform use.
 
----------------------------------------------------------------
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: 199567)
    Time Spent: 40m  (was: 0.5h)

> 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: 40m
>  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)