test_class.file: lib/Duke/duke-core/src/test/java/no/priv/garshol/duke/comparators/JaroWinklerTest.java
test_class.identifier: JaroWinklerTest
test_case.body: @Test
    public void testWikipedia3() {
      double score = (3/5.0 + 3/5.0 + (3-0)/3.0)/3.0;
      assertEquals(score, JaroWinkler.similarity("CRATE", "TRACE"));
    }
test_case.class_method_signature: JaroWinklerTest.testWikipedia3()
test_case.full_signature: @Test public void testWikipedia3()
test_case.identifier: testWikipedia3
test_case.invocations: assertEquals similarity
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testWikipedia3()
focal_class.file: lib/Duke/duke-core/src/main/java/no/priv/garshol/duke/comparators/JaroWinkler.java
focal_class.identifier: JaroWinkler
focal_class.interfaces: implements Comparator
focal_class.class_method_signature: JaroWinkler.compare(String s1, String s2)
focal_class.full_signature: @Override public double compare(String s1, String s2)
focal_class.identifier: compare
focal_class.modifiers: @Override public
focal_class.parameters: (String s1, String s2)
focal_class.return: double
focal_class.signature: double compare(String s1, String s2)
focal_class.class_method_signature: JaroWinkler.isTokenized()
focal_class.full_signature: @Override public boolean isTokenized()
focal_class.identifier: isTokenized
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isTokenized()
focal_class.class_method_signature: JaroWinkler.similarity(String s1, String s2)
focal_class.full_signature: public static double similarity(String s1, String s2)
focal_class.identifier: similarity
focal_class.modifiers: public static
focal_class.parameters: (String s1, String s2)
focal_class.return: double
focal_class.signature: double similarity(String s1, String s2)
focal_method.body: public static double similarity(String s1, String s2) {
      if (s1.equals(s2))
        return 1.0;
  
      // ensure that s1 is shorter than or same length as s2
      if (s1.length() > s2.length()) {
        String tmp = s2;
        s2 = s1;
        s1 = tmp;
      }
  
      // (1) find the number of characters the two strings have in common.
      // note that matching characters can only be half the length of the
      // longer string apart.
      int maxdist = s2.length() / 2;
      int c = 0; // count of common characters
      int t = 0; // count of transpositions
      int prevpos = -1;
      for (int ix = 0; ix < s1.length(); ix++) {
        char ch = s1.charAt(ix);
  
        // now try to find it in s2
        for (int ix2 = Math.max(0, ix - maxdist);
             ix2 < Math.min(s2.length(), ix + maxdist);
             ix2++) {
          if (ch == s2.charAt(ix2)) {
            c++; // we found a common character
            if (prevpos != -1 && ix2 < prevpos)
              t++; // moved back before earlier 
            prevpos = ix2;
            break;
          }
        }
      }
  
      // we don't divide t by 2 because as far as we can tell, the above
      // code counts transpositions directly.
  
      // System.out.println("c: " + c);
      // System.out.println("t: " + t);
      // System.out.println("c/m: " + (c / (double) s1.length()));
      // System.out.println("c/n: " + (c / (double) s2.length()));
      // System.out.println("(c-t)/c: " + ((c - t) / (double) c));
      
      // we might have to give up right here
      if (c == 0)
        return 0.0;
  
      // first compute the score
      double score = ((c / (double) s1.length()) +
                      (c / (double) s2.length()) +
                      ((c - t) / (double) c)) / 3.0;
  
      // (2) common prefix modification
      int p = 0; // length of prefix
      int last = Math.min(4, s1.length());
      for (; p < last && s1.charAt(p) == s2.charAt(p); p++)
        ;
  
      score = score + ((p * (1 - score)) / 10);
  
      // (3) longer string adjustment
      // I'm confused about this part. Winkler's original source code includes
      // it, and Yancey's 2005 paper describes it. However, Winkler's list of
      // test cases in his 2006 paper does not include this modification. So
      // is this part of Jaro-Winkler, or is it not? Hard to say.
      //
      //   if (s1.length() >= 5 && // both strings at least 5 characters long
      //       c - p >= 2 && // at least two common characters besides prefix
      //       c - p >= ((s1.length() - p) / 2)) // fairly rich in common chars
      //     {
      //     System.out.println("ADJUSTED!");
      //     score = score + ((1 - score) * ((c - (p + 1)) /
      //                                     ((double) ((s1.length() + s2.length())
      //                                                - (2 * (p - 1))))));
      // }
  
      // (4) similar characters adjustment
      // the same holds for this as for (3) above.
      
      return score;
    }
focal_method.class_method_signature: JaroWinkler.similarity(String s1, String s2)
focal_method.full_signature: public static double similarity(String s1, String s2)
focal_method.identifier: similarity
focal_method.invocations: equals length length length length charAt max min length charAt length length min length charAt charAt
focal_method.modifiers: public static
focal_method.parameters: (String s1, String s2)
focal_method.return: double
focal_method.signature: double similarity(String s1, String s2)