vladlev 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/levenshtein/LevenshteinDistance.java +3 -3
- data/ext/levenshtein/levenshtein.c +2 -2
- data/lib/levenshtein.bundle +0 -0
- data/lib/levenshtein.jar +0 -0
- data/lib/vladlev.rb +1 -1
- data/lib/vladlev/version.rb +1 -1
- data/spec/lib/levenshtein_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d94c0b0374e6e487abacbf6879f4cf3a03df46ec
|
4
|
+
data.tar.gz: d83790f125d8a3bfaa437868a5ca434b003c5f7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9119f6d0d06fc3be7fe6efb3a498ea43892f6f693401ec2bb11557c95a210d685ac4cc9c04b4f97463ebbf6a73cf9cb24bcd9ab8b0e70d7fed4e29f937dcf1a
|
7
|
+
data.tar.gz: 73b6bfe192420b27424dfb5409321648b56d5626a308ba586ce40a0e3f66213f7add1d206793a674299ad34f115234e47eddd5465ff5ea1acc413d30a02860ed
|
@@ -52,15 +52,15 @@ public class LevenshteinDistance {
|
|
52
52
|
return distance(str1, str2, 9999);
|
53
53
|
}
|
54
54
|
|
55
|
-
public static
|
55
|
+
public static double normalized_distance(String str1, String str2) {
|
56
56
|
return normalized_distance(str1, str2, 9999);
|
57
57
|
}
|
58
58
|
|
59
|
-
public static
|
59
|
+
public static double normalized_distance(String str1, String str2, long maximumDistance) {
|
60
60
|
int maxStringLength = (str1.length() > str2.length()) ? str1.length() : str2.length();
|
61
61
|
if(maxStringLength == 0) {
|
62
62
|
return 0;
|
63
63
|
}
|
64
|
-
return distance(str1, str2, maximumDistance) / (
|
64
|
+
return distance(str1, str2, maximumDistance) / (double)maxStringLength;
|
65
65
|
}
|
66
66
|
}
|
@@ -105,7 +105,7 @@ int levenshtein_extern(char* a, char* b, int max_distance)
|
|
105
105
|
return distance;
|
106
106
|
}
|
107
107
|
|
108
|
-
|
108
|
+
double normalized_levenshtein_extern(char* a, char* b, int max_distance)
|
109
109
|
{
|
110
110
|
int a_len = (a == NULL) ? 0 : strlen(a);
|
111
111
|
int b_len = (b == NULL) ? 0 : strlen(b);
|
@@ -114,5 +114,5 @@ float normalized_levenshtein_extern(char* a, char* b, int max_distance)
|
|
114
114
|
if(max_string_length == 0) {
|
115
115
|
return 0;
|
116
116
|
}
|
117
|
-
return
|
117
|
+
return levenshtein_extern(a, b, max_distance) / (double)max_string_length;
|
118
118
|
}
|
data/lib/levenshtein.bundle
CHANGED
Binary file
|
data/lib/levenshtein.jar
CHANGED
Binary file
|
data/lib/vladlev.rb
CHANGED
@@ -36,7 +36,7 @@ module Vladlev
|
|
36
36
|
|
37
37
|
ffi_lib native_file_path
|
38
38
|
attach_function :levenshtein_extern, [:pointer, :pointer, :int32], :int32
|
39
|
-
attach_function :normalized_levenshtein_extern, [:pointer, :pointer, :int32], :
|
39
|
+
attach_function :normalized_levenshtein_extern, [:pointer, :pointer, :int32], :double
|
40
40
|
|
41
41
|
# Calculate the levenshtein distance between two strings
|
42
42
|
#
|
data/lib/vladlev/version.rb
CHANGED
@@ -54,7 +54,7 @@ describe Vladlev do
|
|
54
54
|
specify{ expect(Vladlev.get_normalized_distance("hi", "high", 1)).to eq(1.0) }
|
55
55
|
specify{ expect(Vladlev.get_normalized_distance("hi", "high")).to eq(0.5) }
|
56
56
|
specify{ expect(Vladlev.get_normalized_distance("hello", "hello")).to eq(0.0) }
|
57
|
-
specify{ expect(Vladlev.get_normalized_distance("goodnight", "goodnite")).to
|
57
|
+
specify{ expect(Vladlev.get_normalized_distance("goodnight", "goodnite")).to be_between(0.3333, 0.3334) }
|
58
58
|
specify{ expect(Vladlev.get_normalized_distance("", "goodbye")).to eq(1.0) }
|
59
59
|
specify{ expect(Vladlev.get_normalized_distance("goodbye", "")).to eq(1.0) }
|
60
60
|
specify{ expect(Vladlev.get_normalized_distance("", "")).to eq(0.0) }
|