78b1eb7e73
- Made all Change classes save to and load from .zip files. - Changed Column.headerLabel to Column.name. - Save project's raw data to "raw-data" file for now. We'll make it save to a zip file next. git-svn-id: http://google-refine.googlecode.com/svn/trunk@217 7d457c2a-affb-35e4-300a-418c747d4874
77 lines
2.4 KiB
Java
77 lines
2.4 KiB
Java
package com.metaweb.gridworks.model;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.Properties;
|
|
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONWriter;
|
|
|
|
import com.metaweb.gridworks.Jsonizable;
|
|
import com.metaweb.gridworks.expr.HasFields;
|
|
import com.metaweb.gridworks.util.JSONUtilities;
|
|
|
|
public class ReconCandidate implements Serializable, HasFields, Jsonizable {
|
|
private static final long serialVersionUID = -8013997214978715606L;
|
|
|
|
final public String topicID;
|
|
final public String topicGUID;
|
|
final public String topicName;
|
|
final public String[] typeIDs;
|
|
final public double score;
|
|
|
|
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;
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |