1 #!/usr/bin/env python2.7
8 levenshtein-distance - Calculate the Levenshtein distance of given strings
10 jaro-metric - Calculate the Jaro metric of given strings
12 jaro-winkler-metric - Calculate the Jaro-Winkler metric of given strings
28 levenshtein-distance <string-1> [<string-2>]
29 jaro-metric <string-1> [<string-2>]
30 jaro-winkler-metric <string-1> [<string-2>]
32 JARO_WINKLER_PREFIX_WEIGHT
33 Reads strings to compare from stdin unless string-2 is given.
34 Prints the resulting metric, or the <metric> TAB <string-2> if read from stdin.
45 jaro_winkler_prefix_weight = os.environ.get('JARO_WINKLER_PREFIX_WEIGHT')
46 if jaro_winkler_prefix_weight is not None: jaro_winkler_prefix_weight = float(jaro_winkler_prefix_weight)
49 if 'jaro' in sys.argv[0]:
50 if 'winkler' in sys.argv[0]:
51 method = 'jaro_winkler'
60 str2 = sys.stdin.readline()
62 str2 = str2.rstrip('\r\n')
65 if jaro_winkler_prefix_weight is not None:
66 args.append(jaro_winkler_prefix_weight)
68 print "%s\t%s" % (str(getattr(Levenshtein, method)(*args)), str2)
71 if jaro_winkler_prefix_weight is not None:
72 args.append(jaro_winkler_prefix_weight)
73 print getattr(Levenshtein, method)(*args)