2010-02-03 03:29:47 +01:00
|
|
|
package com.metaweb.gridworks.model;
|
2010-01-24 22:09:50 +01:00
|
|
|
|
2010-01-27 02:48:42 +01:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
2010-03-06 08:43:45 +01:00
|
|
|
import org.json.JSONObject;
|
2010-02-01 20:16:09 +01:00
|
|
|
import org.json.JSONWriter;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-02-03 03:29:47 +01:00
|
|
|
import com.metaweb.gridworks.Jsonizable;
|
|
|
|
import com.metaweb.gridworks.expr.HasFields;
|
2010-03-06 08:43:45 +01:00
|
|
|
import com.metaweb.gridworks.util.JSONUtilities;
|
2010-02-01 00:15:50 +01:00
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
public class ReconCandidate implements HasFields, Jsonizable {
|
2010-03-03 05:19:58 +01:00
|
|
|
final public String topicID;
|
|
|
|
final public String topicGUID;
|
2010-03-06 08:43:45 +01:00
|
|
|
final public String topicName;
|
|
|
|
final public String[] typeIDs;
|
|
|
|
final public double score;
|
2010-03-03 05:19:58 +01:00
|
|
|
|
|
|
|
public ReconCandidate(String topicID, String topicGUID, String topicName, String[] typeIDs, double score) {
|
|
|
|
this.topicID = topicID;
|
|
|
|
this.topicGUID = topicGUID;
|
|
|
|
this.topicName = topicName;
|
|
|
|
this.typeIDs = typeIDs;
|
|
|
|
this.score = score;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object getField(String name, Properties bindings) {
|
|
|
|
if ("id".equals(name)) {
|
|
|
|
return topicName;
|
|
|
|
} else if ("guid".equals(name)) {
|
|
|
|
return topicGUID;
|
|
|
|
} else if ("name".equals(name)) {
|
|
|
|
return topicName;
|
|
|
|
} else if ("type".equals(name)) {
|
|
|
|
return typeIDs;
|
|
|
|
} else if ("score".equals(name)) {
|
|
|
|
return score;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2010-02-01 20:16:09 +01:00
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
|
|
|
|
|
|
|
writer.object();
|
|
|
|
writer.key("id"); writer.value(topicID);
|
|
|
|
writer.key("guid"); writer.value(topicGUID);
|
|
|
|
writer.key("name"); writer.value(topicName);
|
|
|
|
writer.key("score"); writer.value(score);
|
|
|
|
writer.key("types"); writer.array();
|
|
|
|
for (String typeID : typeIDs) {
|
|
|
|
writer.value(typeID);
|
|
|
|
}
|
|
|
|
writer.endArray();
|
|
|
|
|
|
|
|
writer.endObject();
|
|
|
|
}
|
2010-03-06 08:43:45 +01:00
|
|
|
|
|
|
|
static public ReconCandidate load(JSONObject obj) throws Exception {
|
|
|
|
if (obj == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReconCandidate candidate = new ReconCandidate(
|
|
|
|
obj.getString("id"),
|
|
|
|
obj.getString("guid"),
|
|
|
|
obj.getString("name"),
|
|
|
|
JSONUtilities.getStringArray(obj, "types"),
|
|
|
|
obj.getDouble("score")
|
|
|
|
);
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
}
|