We tweak the penalties so that if they differ only by their casing, then
the substitution penalty is halved.
Example of the effect:
Equal weights:
SYS_close --> SYSC_close, SyS_close, SYSC_clone, SyS_clone, con_close
Half penalty for diff casing
SYS_close --> SyS_close, SYSC_close, SyS_clone, sys_close, SYSC_clone
The 'SYSC' versions rank lower. But more importantly, we see 'sys_close'
become higher rank than 'con_close'.
if (a[i-1] == b[j-1]) // match
d(i,j) = d(i-1, j-1);
else // penalties open for adjustments
- d(i,j) = min(min(
- d(i-1,j-1) + 1, // substitution
- d(i-1,j) + 1), // deletion
- d(i,j-1) + 1); // insertion
+ {
+ unsigned subpen = 2; // substitution penalty
+ // check if they are upper/lowercase related
+ if (tolower(a[i-1]) == tolower(b[j-1]))
+ subpen = 1; // half penalty
+ d(i,j) = min(min(
+ d(i-1,j-1) + subpen, // substitution
+ d(i-1,j) + 2), // deletion
+ d(i,j-1) + 2); // insertion
+ }
}
}