p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #0326cc}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4e9072}
span.s1 {color: #931a68}
span.s2 {color: #0326cc}
span.s3 {color: #7e504f}
span.s4 {color: #000000}
span.Apple-tab-span {white-space:pre}
import java.util.HashMap;
class LevenshteinBase {
private String a;
private String b;
public Integer edit_distance=0;
HashMap
public LevenshteinBase (String a, String b) {
this.a = a;
this.b = b;
LevInteger l=new LevInteger(a.length(), b.length());
edit_distance=lev(l);
}
public Integer getEdit_distance() {
return edit_distance;
}
public void setEdit_distance(Integer edit_distance) {
this.edit_distance = edit_distance;
}
public Integer lev (LevInteger l) {
//System.out.println(memo);
if(memo.containsKey(l.ab)) {
//System.out.println(“cache hit”);
int value=0;
value=memo.get(l.ab);
return value;
}
else {
int res=0;
if (l.a == 0)
return l.b;
else if (l.b == 0)
return l.a;
else if (a.charAt(l.a – 1) == b.charAt(l.b – 1)) {
res=Math.min(1 + Math.min (lev(new LevInteger(l.a – 1, l.b)),lev(new LevInteger(l.a, l.b – 1))),lev(new LevInteger(l.a – 1, l.b – 1)));
memo.put(l.ab, res);
return res;
}
else {
res=Math.min(1 + Math.min (lev(new LevInteger(l.a – 1, l.b)),lev(new LevInteger(l.a, l.b – 1))),1 + lev (new LevInteger(l.a – 1, l.b – 1)));
memo.put(l.ab, res);
return res;
}
}
}
}