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) {
9393 protected static double dotProduct (
9494 final int [] profile1 , final int [] profile2 ) {
9595
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 );
10298 double agg = 0 ;
10399 for (int i = 0 ; i < length ; i ++) {
104- agg += 1.0 * copy1 [i ] * copy2 [i ];
100+ agg += 1.0 * profile1 [i ] * profile2 [i ];
105101 }
106102 return agg ;
107103 }
@@ -112,7 +108,7 @@ protected static double dotProduct(
112108 * @param s2
113109 * @return
114110 */
115- public double distance (final String s1 , final String s2 ) {
111+ public final double distance (final String s1 , final String s2 ) {
116112 return 1.0 - similarity (s1 , s2 );
117113 }
118114
You can’t perform that action at this time.
0 commit comments