2010-01-24 22:09:50 +01:00
|
|
|
package com.metaweb.gridlock.model;
|
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
import java.io.Serializable;
|
2010-01-24 22:09:50 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2010-01-27 02:48:42 +01:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2010-01-24 22:09:50 +01:00
|
|
|
|
2010-02-01 00:15:50 +01:00
|
|
|
import com.metaweb.gridlock.expr.HasFields;
|
|
|
|
|
|
|
|
public class Recon implements Serializable, HasFields {
|
2010-01-25 23:51:25 +01:00
|
|
|
private static final long serialVersionUID = 8906257833709315762L;
|
|
|
|
|
2010-01-24 22:09:50 +01:00
|
|
|
static public enum Judgment {
|
|
|
|
None,
|
|
|
|
Approve,
|
|
|
|
New
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, Object> features = new HashMap<String, Object>();
|
|
|
|
public List<ReconCandidate> candidates = new LinkedList<ReconCandidate>();
|
2010-01-27 02:48:42 +01:00
|
|
|
public Judgment judgment = Judgment.None;
|
2010-02-01 00:15:50 +01:00
|
|
|
public ReconCandidate match = null;
|
2010-01-27 02:48:42 +01:00
|
|
|
|
|
|
|
public JSONObject getJSON(Properties options) throws JSONException {
|
|
|
|
JSONObject o = new JSONObject();
|
2010-02-01 00:15:50 +01:00
|
|
|
o.put("j", judgmentToString());
|
2010-01-27 02:48:42 +01:00
|
|
|
|
2010-02-01 00:15:50 +01:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getField(String name, Properties bindings) {
|
|
|
|
if ("best".equals(name)) {
|
|
|
|
return candidates.size() > 0 ? candidates.get(0) : null;
|
|
|
|
} else if ("judgment".equals(name) || "judgement".equals(name)) {
|
|
|
|
return judgmentToString();
|
|
|
|
} else if ("approved".equals(name)) {
|
|
|
|
return judgment == Judgment.Approve;
|
|
|
|
} else if ("new".equals(name)) {
|
|
|
|
return judgment == Judgment.New;
|
|
|
|
} else if ("match".equals(name)) {
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String judgmentToString() {
|
|
|
|
if (judgment == Judgment.Approve) {
|
|
|
|
return "approve";
|
2010-01-27 02:48:42 +01:00
|
|
|
} else if (judgment == Judgment.New) {
|
2010-02-01 00:15:50 +01:00
|
|
|
return "new";
|
|
|
|
} else {
|
|
|
|
return "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class Features implements HasFields {
|
|
|
|
@Override
|
|
|
|
public Object getField(String name, Properties bindings) {
|
|
|
|
return features.get(name);
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|