Eliminate hash maps from recon objects--they are expensive.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@88 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
5cd147ea3c
commit
d227db0cc6
@ -22,20 +22,60 @@ public class Recon implements Serializable, HasFields, Jsonizable {
|
|||||||
New
|
New
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> features = new HashMap<String, Object>();
|
static public int Feature_typeMatch = 0;
|
||||||
|
static public int Feature_nameMatch = 1;
|
||||||
|
static public int Feature_nameLevenshtein = 2;
|
||||||
|
static public int Feature_nameWordDistance = 3;
|
||||||
|
static public int Feature_max = 4;
|
||||||
|
|
||||||
|
static protected Map<String, Integer> s_featureMap;
|
||||||
|
static {
|
||||||
|
s_featureMap = new HashMap<String, Integer>();
|
||||||
|
s_featureMap.put("typeMatch", Feature_typeMatch);
|
||||||
|
s_featureMap.put("nameMatch", Feature_nameMatch);
|
||||||
|
s_featureMap.put("nameLevenshtein", Feature_nameLevenshtein);
|
||||||
|
s_featureMap.put("nameWordDistance", Feature_nameWordDistance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] features = new Object[Feature_max];
|
||||||
public List<ReconCandidate> candidates = new LinkedList<ReconCandidate>();
|
public List<ReconCandidate> candidates = new LinkedList<ReconCandidate>();
|
||||||
public Judgment judgment = Judgment.None;
|
public Judgment judgment = Judgment.None;
|
||||||
public ReconCandidate match = null;
|
public ReconCandidate match = null;
|
||||||
|
|
||||||
public Recon dup() {
|
public Recon dup() {
|
||||||
Recon r = new Recon();
|
Recon r = new Recon();
|
||||||
r.features.putAll(new HashMap<String, Object>(features));
|
|
||||||
|
System.arraycopy(features, 0, r.features, 0, features.length);
|
||||||
|
|
||||||
r.candidates.addAll(candidates);
|
r.candidates.addAll(candidates);
|
||||||
r.judgment = judgment;
|
r.judgment = judgment;
|
||||||
r.match = match;
|
r.match = match;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getFeature(int feature) {
|
||||||
|
return feature < features.length ? features[feature] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeature(int feature, Object v) {
|
||||||
|
if (feature >= features.length) {
|
||||||
|
if (feature >= Feature_max) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We deserialized this object from an older version of the class
|
||||||
|
// that had fewer features, so we can just try to extend it
|
||||||
|
|
||||||
|
Object[] newFeatures = new Object[Feature_max];
|
||||||
|
|
||||||
|
System.arraycopy(features, 0, newFeatures, 0, features.length);
|
||||||
|
|
||||||
|
features = newFeatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
features[feature] = v;
|
||||||
|
}
|
||||||
|
|
||||||
public Object getField(String name, Properties bindings) {
|
public Object getField(String name, Properties bindings) {
|
||||||
if ("best".equals(name)) {
|
if ("best".equals(name)) {
|
||||||
return candidates.size() > 0 ? candidates.get(0) : null;
|
return candidates.size() > 0 ? candidates.get(0) : null;
|
||||||
@ -48,11 +88,7 @@ public class Recon implements Serializable, HasFields, Jsonizable {
|
|||||||
} else if ("match".equals(name)) {
|
} else if ("match".equals(name)) {
|
||||||
return match;
|
return match;
|
||||||
} else if ("features".equals(name)) {
|
} else if ("features".equals(name)) {
|
||||||
return new HasFields() {
|
return new Features();
|
||||||
public Object getField(String name, Properties bindings) {
|
|
||||||
return features.get(name);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -69,7 +105,8 @@ public class Recon implements Serializable, HasFields, Jsonizable {
|
|||||||
|
|
||||||
public class Features implements HasFields {
|
public class Features implements HasFields {
|
||||||
public Object getField(String name, Properties bindings) {
|
public Object getField(String name, Properties bindings) {
|
||||||
return features.get(name);
|
int index = s_featureMap.get(name);
|
||||||
|
return index < features.length ? features[index] : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,14 +317,14 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
// best match
|
// best match
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
recon.features.put("nameMatch", text.equalsIgnoreCase(candidate.topicName));
|
recon.setFeature(Recon.Feature_nameMatch, text.equalsIgnoreCase(candidate.topicName));
|
||||||
recon.features.put("nameLevenshtein", StringUtils.getLevenshteinDistance(text, candidate.topicName));
|
recon.setFeature(Recon.Feature_nameLevenshtein, StringUtils.getLevenshteinDistance(text, candidate.topicName));
|
||||||
recon.features.put("nameWordDistance", wordDistance(text, candidate.topicName));
|
recon.setFeature(Recon.Feature_nameWordDistance, wordDistance(text, candidate.topicName));
|
||||||
|
|
||||||
recon.features.put("typeMatch", false);
|
recon.setFeature(Recon.Feature_typeMatch, false);
|
||||||
for (String typeID : candidate.typeIDs) {
|
for (String typeID : candidate.typeIDs) {
|
||||||
if (_typeID.equals(typeID)) {
|
if (_typeID.equals(typeID)) {
|
||||||
recon.features.put("typeMatch", true);
|
recon.setFeature(Recon.Feature_typeMatch, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user