File tree Expand file tree Collapse file tree 1 file changed +4
-8
lines changed
src/main/java/info/debatty/java/stringsimilarity Expand file tree Collapse file tree 1 file changed +4
-8
lines changed Original file line number Diff line number Diff line change @@ -93,15 +93,11 @@ protected static double norm(final int[] profile) {
93
93
protected static double dotProduct (
94
94
final int [] profile1 , final int [] profile2 ) {
95
95
96
- // Make a copy to ensure both profiles have the same size
97
- // this is actually quite dirty and should be corrected!
98
- int length = Math .max (profile1 .length , profile2 .length );
99
- int [] copy1 = java .util .Arrays .copyOf (profile1 , length );
100
- int [] copy2 = java .util .Arrays .copyOf (profile2 , length );
101
-
96
+ // profiles may not have the same length
97
+ int length = Math .min (profile1 .length , profile2 .length );
102
98
double agg = 0 ;
103
99
for (int i = 0 ; i < length ; i ++) {
104
- agg += 1.0 * copy1 [i ] * copy2 [i ];
100
+ agg += 1.0 * profile1 [i ] * profile2 [i ];
105
101
}
106
102
return agg ;
107
103
}
@@ -112,7 +108,7 @@ protected static double dotProduct(
112
108
* @param s2
113
109
* @return
114
110
*/
115
- public double distance (final String s1 , final String s2 ) {
111
+ public final double distance (final String s1 , final String s2 ) {
116
112
return 1.0 - similarity (s1 , s2 );
117
113
}
118
114
You can’t perform that action at this time.
0 commit comments