Major refactoring: everything is now saved to disk using our own formats, mostly json-based, some inside zip files.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@226 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-03-07 22:37:26 +00:00
parent f7b0caa1b8
commit 694f09fb0a
56 changed files with 605 additions and 1728 deletions

View File

@ -27,7 +27,8 @@ import com.metaweb.util.signal.SignalHandler;
import com.metaweb.util.threads.ThreadPoolExecutorAdapter;
public class Gridworks extends Server {
final static public String s_version = "1.0";
private static Logger root = Logger.getRootLogger();
private static Logger logger = Logger.getLogger("com.metaweb.gridworks");

View File

@ -1,19 +1,13 @@
package com.metaweb.gridworks;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.json.JSONArray;
import org.json.JSONException;
@ -26,12 +20,11 @@ import com.codeberry.jdatapath.JDataPathSystem;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.util.JSONUtilities;
public class ProjectManager implements Serializable {
public class ProjectManager {
private static final long serialVersionUID = -2967415873336723962L;
private static final int s_expressionHistoryMax = 100; // last n expressions used across all projects
protected File _workspaceDir;
protected File _workspaceDir;
protected Map<Long, ProjectMetadata> _projectsMetadata;
protected List<String> _expressions;
@ -44,12 +37,7 @@ public class ProjectManager implements Serializable {
File dir = getProjectLocation();
Gridworks.log("Using data directory: " + dir.getAbsolutePath());
if (dir.exists()) {
singleton = load(dir);
}
if (singleton == null) {
singleton = new ProjectManager(dir);
}
singleton = new ProjectManager(dir);
}
}
@ -98,20 +86,26 @@ public class ProjectManager implements Serializable {
_projectsMetadata = new HashMap<Long, ProjectMetadata>();
_expressions = new LinkedList<String>();
_projects = new HashMap<Long, Project>();
load();
}
public File getWorkspaceDir() {
return _workspaceDir;
}
public File getProjectDir(long projectID) {
File dir = new File(_workspaceDir, projectID + ".project");
static public File getProjectDir(File workspaceDir, long projectID) {
File dir = new File(workspaceDir, projectID + ".project");
if (!dir.exists()) {
dir.mkdir();
}
return dir;
}
public File getProjectDir(long projectID) {
return getProjectDir(_workspaceDir, projectID);
}
public void registerProject(Project project, ProjectMetadata projectMetadata) {
_projects.put(project.id, project);
_projectsMetadata.put(project.id, projectMetadata);
@ -129,34 +123,7 @@ public class ProjectManager implements Serializable {
if (_projects.containsKey(id)) {
return _projects.get(id);
} else {
File file = new File(getProjectDir(id), "raw-data");
Project project = null;
FileInputStream fis = null;
ObjectInputStream in = null;
try {
fis = new FileInputStream(file);
in = new ObjectInputStream(fis);
project = (Project) in.readObject();
} catch(IOException e) {
e.printStackTrace();
} catch(ClassNotFoundException e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
}
}
if (in != null) {
try {
in.close();
} catch (Exception e) {
}
}
}
Project project = Project.load(getProjectDir(id), id);
_projects.put(id, project);
@ -177,20 +144,20 @@ public class ProjectManager implements Serializable {
}
public void save() {
Gridworks.log("Saving project metadata ...");
Gridworks.log("Saving all projects' metadata ...");
File tempFile = new File(_workspaceDir, "projects.json.temp");
File tempFile = new File(_workspaceDir, "workspace.temp.json");
try {
saveToFile(tempFile);
} catch (Exception e) {
e.printStackTrace();
Gridworks.log("Failed to save project");
Gridworks.log("Failed to save projects' metadata.");
return;
}
File file = new File(_workspaceDir, "projects.json");
File oldFile = new File(_workspaceDir, "projects.json.old");
File file = new File(_workspaceDir, "workspace.json");
File oldFile = new File(_workspaceDir, "workspace.old.json");
if (file.exists()) {
file.renameTo(oldFile);
@ -201,25 +168,25 @@ public class ProjectManager implements Serializable {
oldFile.delete();
}
Gridworks.log("Project metadata saved.");
Gridworks.log("All projects' metadata saved.");
}
public void saveToFile(File file) throws IOException, JSONException {
protected void saveToFile(File file) throws IOException, JSONException {
FileWriter writer = new FileWriter(file);
try {
JSONWriter jsonWriter = new JSONWriter(writer);
Properties options = new Properties();
options.setProperty("mode", "save");
jsonWriter.object();
jsonWriter.key("projectMetadata");
jsonWriter.key("projectIDs");
jsonWriter.array();
for (Long id : _projectsMetadata.keySet()) {
jsonWriter.object();
jsonWriter.key("id"); jsonWriter.value(id);
jsonWriter.key("metadata"); _projectsMetadata.get(id).write(jsonWriter, options);
jsonWriter.endObject();
writer.write('\n');
jsonWriter.value(id);
ProjectMetadata metadata = _projectsMetadata.get(id);
try {
metadata.save(getProjectDir(id));
} catch (Exception e) {
e.printStackTrace();
}
}
jsonWriter.endArray();
writer.write('\n');
@ -231,106 +198,78 @@ public class ProjectManager implements Serializable {
}
}
static protected ProjectManager load(File dir) {
try {
return loadFromFile(new File(dir, "projects.json"));
} catch (Exception e) {
public void saveAllProjects() {
Gridworks.log("Saving all projects ...");
for (Project project : _projects.values()) {
try {
project.save();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
return loadFromFile(new File(dir, "projects.json.temp"));
} catch (Exception e) {
}
try {
return loadFromFile(new File(dir, "projects.json.old"));
} catch (Exception e) {
}
return null;
}
static protected ProjectManager loadFromFile(File file) throws IOException, JSONException {
public void deleteProject(Project project) {
if (_projectsMetadata.containsKey(project.id)) {
_projectsMetadata.remove(project.id);
}
if (_projects.containsKey(project.id)) {
_projects.remove(project.id);
}
File dir = getProjectDir(project.id);
if (dir.exists()) {
dir.delete();
}
save();
}
protected void load() {
try {
loadFromFile(new File(_workspaceDir, "workspace.json"));
return;
} catch (Exception e) {
}
try {
loadFromFile(new File(_workspaceDir, "workspace.temp.json"));
return;
} catch (Exception e) {
}
try {
loadFromFile(new File(_workspaceDir, "workspace.old.json"));
return;
} catch (Exception e) {
}
}
protected void loadFromFile(File file) throws IOException, JSONException {
Gridworks.log("Loading project metadata from " + file.getAbsolutePath());
_projectsMetadata.clear();
_expressions.clear();
FileReader reader = new FileReader(file);
try {
JSONTokener tokener = new JSONTokener(reader);
ProjectManager pm = new ProjectManager(file.getParentFile());
JSONObject obj = (JSONObject) tokener.nextValue();
JSONArray a = obj.getJSONArray("projectMetadata");
JSONArray a = obj.getJSONArray("projectIDs");
int count = a.length();
for (int i = 0; i < count; i++) {
JSONObject obj2 = a.getJSONObject(i);
long id = a.getLong(i);
long id = obj2.getLong("id");
pm._projectsMetadata.put(id, ProjectMetadata.loadFromJSON(obj2.getJSONObject("metadata")));
File projectDir = getProjectDir(id);
ProjectMetadata metadata = ProjectMetadata.load(projectDir);
_projectsMetadata.put(id, metadata);
}
JSONUtilities.getStringList(obj, "expressions", pm._expressions);
return pm;
JSONUtilities.getStringList(obj, "expressions", _expressions);
} finally {
reader.close();
}
}
public void saveAllProjects() {
Gridworks.log("Saving all projects ...");
for (Project project : _projects.values()) {
try {
saveProject(project);
} catch (Exception e) {
e.printStackTrace();
}
}
}
protected void saveProject(Project project) {
File file = new File(getProjectDir(project.id), "raw-data");
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
fos = new FileOutputStream(file);
out = new ObjectOutputStream(fos);
out.writeObject(project);
out.flush();
} catch(IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
}
}
if (out != null) {
try {
out.close();
} catch (Exception e) {
}
}
}
}
public boolean deleteProject(Project project) {
if (_projectsMetadata.containsKey(project.id)) {
_projects.remove(project.id);
_projectsMetadata.remove(project.id);
File file = new File(getProjectDir(project.id), "raw-data");
if (file.exists()) {
file.delete();
}
save();
return true;
} else {
return false;
}
}
}

View File

@ -1,5 +1,10 @@
package com.metaweb.gridworks;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@ -7,6 +12,7 @@ import java.util.Properties;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.json.JSONWriter;
import com.metaweb.gridworks.util.JSONUtilities;
@ -24,21 +30,6 @@ public class ProjectMetadata implements Jsonizable {
private int _encodingConfidence;
private List<String> _expressions = new LinkedList<String>();
static public ProjectMetadata loadFromJSON(JSONObject obj) {
ProjectMetadata pm = new ProjectMetadata(JSONUtilities.getDate(obj, "modified", new Date()));
pm._modified = JSONUtilities.getDate(obj, "modified", new Date());
pm._name = JSONUtilities.getString(obj, "name", "<Error recovering project name>");
pm._password = JSONUtilities.getString(obj, "password", "");
pm._encoding = JSONUtilities.getString(obj, "encoding", "");
pm._encodingConfidence = JSONUtilities.getInt(obj, "encodingConfidence", 0);
JSONUtilities.getStringList(obj, "expressions", pm._expressions);
return pm;
}
protected ProjectMetadata(Date date) {
_created = date;
}
@ -66,6 +57,90 @@ public class ProjectMetadata implements Jsonizable {
writer.endObject();
}
public void save(File dir) throws Exception {
File tempFile = new File(dir, "metadata.temp.json");
try {
saveToFile(tempFile);
} catch (Exception e) {
e.printStackTrace();
Gridworks.log("Failed to save project metadata");
return;
}
File file = new File(dir, "metadata.json");
File oldFile = new File(dir, "metadata.old.json");
if (file.exists()) {
file.renameTo(oldFile);
}
tempFile.renameTo(file);
if (oldFile.exists()) {
oldFile.delete();
}
}
protected void saveToFile(File file) throws Exception {
Writer writer = new OutputStreamWriter(new FileOutputStream(file));
try {
Properties options = new Properties();
options.setProperty("mode", "save");
JSONWriter jsonWriter = new JSONWriter(writer);
write(jsonWriter, options);
} finally {
writer.close();
}
}
static public ProjectMetadata load(File dir) {
try {
return loadFromFile(new File(dir, "metadata.json"));
} catch (Exception e) {
}
try {
return loadFromFile(new File(dir, "metadata.temp.json"));
} catch (Exception e) {
}
try {
return loadFromFile(new File(dir, "metadata.old.json"));
} catch (Exception e) {
}
return null;
}
static protected ProjectMetadata loadFromFile(File file) throws Exception {
FileReader reader = new FileReader(file);
try {
JSONTokener tokener = new JSONTokener(reader);
JSONObject obj = (JSONObject) tokener.nextValue();
return loadFromJSON(obj);
} finally {
reader.close();
}
}
static protected ProjectMetadata loadFromJSON(JSONObject obj) {
ProjectMetadata pm = new ProjectMetadata(JSONUtilities.getDate(obj, "modified", new Date()));
pm._modified = JSONUtilities.getDate(obj, "modified", new Date());
pm._name = JSONUtilities.getString(obj, "name", "<Error recovering project name>");
pm._password = JSONUtilities.getString(obj, "password", "");
pm._encoding = JSONUtilities.getString(obj, "encoding", "");
pm._encodingConfidence = JSONUtilities.getInt(obj, "encodingConfidence", 0);
JSONUtilities.getStringList(obj, "expressions", pm._expressions);
return pm;
}
public Date getCreated() {
return _created;
}

View File

@ -1,7 +1,6 @@
package com.metaweb.gridworks.commands.edit;
import java.io.IOException;
import java.lang.reflect.Method;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.ServletException;
@ -46,28 +45,15 @@ public class ApplyOperationsCommand extends Command {
}
protected void reconstructOperation(Project project, JSONObject obj) {
try {
String op = obj.getString("op");
Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op);
if (klass == null) {
return;
}
Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class);
if (reconstruct == null) {
return;
}
AbstractOperation operation = (AbstractOperation) reconstruct.invoke(null, project, obj);
if (operation != null) {
AbstractOperation operation = OperationRegistry.reconstruct(project, obj);
if (operation != null) {
try {
Process process = operation.createProcess(project, new Properties());
project.processManager.queueProcess(process);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -15,9 +15,9 @@ public class DeleteProjectCommand extends Command {
throws ServletException, IOException {
try {
boolean result = ProjectManager.singleton.deleteProject(getProject(request));
respond(response, "{ \"code\" : " + (result ? "\"ok\"" : "\"error\"") + " }");
ProjectManager.singleton.deleteProject(getProject(request));
respond(response, "{ \"code\" : \"ok\" }");
} catch (Exception e) {
respondException(response, e);

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
package com.metaweb.gridworks.history;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.Serializable;
import java.io.Writer;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.LinkedList;
@ -11,14 +12,15 @@ import java.util.Properties;
import org.json.JSONException;
import org.json.JSONWriter;
import com.metaweb.gridworks.Gridworks;
import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.ProjectManager;
import com.metaweb.gridworks.model.Project;
public class History implements Serializable, Jsonizable {
private static final long serialVersionUID = -1529783362243627391L;
public class History implements Jsonizable {
static public Change readOneChange(LineNumberReader reader) throws Exception {
/* String version = */ reader.readLine();
String className = reader.readLine();
Class<? extends Change> klass = getChangeClass(className);
@ -27,12 +29,22 @@ public class History implements Serializable, Jsonizable {
return (Change) load.invoke(null, reader);
}
static public void writeOneChange(Writer writer, Change change) throws Exception {
writer.write(Gridworks.s_version); writer.write('\n');
writer.write(change.getClass().getName()); writer.write('\n');
Properties options = new Properties();
options.setProperty("mode", "save");
change.save(writer, options);
}
@SuppressWarnings("unchecked")
static public Class<? extends Change> getChangeClass(String className) throws ClassNotFoundException {
return (Class<? extends Change>) Class.forName(className);
}
protected long _projectID;
protected long _projectID;
protected List<HistoryEntry> _pastEntries;
protected List<HistoryEntry> _futureEntries;
@ -152,4 +164,41 @@ public class History implements Serializable, Jsonizable {
writer.endObject();
}
public void save(Writer writer, Properties options) throws IOException {
writer.write("pastEntryCount="); writer.write(Integer.toString(_pastEntries.size())); writer.write('\n');
for (HistoryEntry entry : _pastEntries) {
entry.save(writer, options); writer.write('\n');
}
writer.write("futureEntryCount="); writer.write(Integer.toString(_futureEntries.size())); writer.write('\n');
for (HistoryEntry entry : _futureEntries) {
entry.save(writer, options); writer.write('\n');
}
writer.write("/e/\n");
}
public void load(Project project, LineNumberReader reader) throws Exception {
String line;
while ((line = reader.readLine()) != null && !"/e/".equals(line)) {
int equal = line.indexOf('=');
CharSequence field = line.subSequence(0, equal);
String value = line.substring(equal + 1);
if ("pastEntryCount".equals(field)) {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
_pastEntries.add(HistoryEntry.load(project, reader.readLine()));
}
} else if ("futureEntryCount".equals(field)) {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
_futureEntries.add(HistoryEntry.load(project, reader.readLine()));
}
}
}
}
}

View File

@ -3,13 +3,11 @@ package com.metaweb.gridworks.history;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.zip.ZipEntry;
@ -17,20 +15,23 @@ import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.ProjectManager;
import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.operations.OperationRegistry;
import com.metaweb.gridworks.util.ParsingUtilities;
public class HistoryEntry implements Serializable, Jsonizable {
private static final long serialVersionUID = 532766467813930262L;
final public long id;
final public long projectID;
final public String description;
final public AbstractOperation operation;
final public long id;
final public long projectID;
final public String description;
final public AbstractOperation operation;
final public Date time;
transient protected Change _change;
@ -45,15 +46,24 @@ public class HistoryEntry implements Serializable, Jsonizable {
_change = change;
}
protected HistoryEntry(long id, long projectID, String description, AbstractOperation operation, Date time) {
this.id = id;
this.projectID = projectID;
this.description = description;
this.operation = operation;
this.time = time;
}
public void write(JSONWriter writer, Properties options)
throws JSONException {
SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance();
writer.object();
writer.key("id"); writer.value(id);
writer.key("description"); writer.value(description);
writer.key("time"); writer.value(sdf.format(time));
writer.key("time"); writer.value(ParsingUtilities.dateToString(time));
if ("save".equals(options.getProperty("mode")) && operation != null) {
writer.key("operation"); operation.write(writer, options);
}
writer.endObject();
}
@ -70,7 +80,7 @@ public class HistoryEntry implements Serializable, Jsonizable {
try {
saveChange();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
_change.revert(project);
@ -94,6 +104,33 @@ public class HistoryEntry implements Serializable, Jsonizable {
}
}
public void save(Writer writer, Properties options) {
JSONWriter jsonWriter = new JSONWriter(writer);
try {
write(jsonWriter, options);
} catch (JSONException e) {
e.printStackTrace();
}
}
static public HistoryEntry load(Project project, String s) throws Exception {
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s);
AbstractOperation operation = null;
if (obj.has("operation") && !obj.isNull("operation")) {
operation = OperationRegistry.reconstruct(project, obj.getJSONObject("operation"));
}
return new HistoryEntry(
obj.getLong("id"),
project.id,
obj.getString("description"),
operation,
ParsingUtilities.stringToDate(obj.getString("time"))
);
}
protected void loadChange() {
File changeFile = getChangeFile();
@ -122,26 +159,21 @@ public class HistoryEntry implements Serializable, Jsonizable {
}
}
protected void saveChange() throws IOException {
protected void saveChange() throws Exception {
File changeFile = getChangeFile();
if (!(changeFile.exists())) {
saveChange(changeFile);
}
}
protected void saveChange(File file) throws IOException {
protected void saveChange(File file) throws Exception {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
try {
out.putNextEntry(new ZipEntry("change.txt"));
try {
Writer writer = new OutputStreamWriter(out);
try {
Properties options = new Properties();
options.setProperty("mode", "save");
writer.write(_change.getClass().getName()); writer.write('\n');
_change.save(writer, options);
History.writeOneChange(writer, _change);
} finally {
writer.flush();
}

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.util.Properties;
import org.apache.commons.lang.NotImplementedException;
@ -14,9 +13,7 @@ import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
* An abstract operation can be applied to different but similar
* projects.
*/
abstract public class AbstractOperation implements Serializable, Jsonizable {
private static final long serialVersionUID = 3916055862440019600L;
abstract public class AbstractOperation implements Jsonizable {
public Process createProcess(Project project, Properties options) throws Exception {
return new QuickHistoryEntryProcess(project, getBriefDescription(null)) {
@Override

View File

@ -16,9 +16,7 @@ import com.metaweb.gridworks.expr.ExpressionUtils;
import com.metaweb.gridworks.expr.HasFields;
import com.metaweb.gridworks.util.ParsingUtilities;
public class Cell implements Serializable, HasFields, Jsonizable {
private static final long serialVersionUID = -5891067829205458102L;
public class Cell implements HasFields, Jsonizable {
final public Serializable value;
final public Recon recon;

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
@ -14,9 +13,7 @@ import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.model.recon.ReconConfig;
import com.metaweb.gridworks.util.ParsingUtilities;
public class Column implements Serializable, Jsonizable {
private static final long serialVersionUID = -1063342490951563563L;
public class Column implements Jsonizable {
final private int _cellIndex;
final private String _originalName;
private String _name;

View File

@ -2,25 +2,25 @@ package com.metaweb.gridworks.model;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.io.Writer;
import java.util.LinkedList;
import java.util.List;
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.util.ParsingUtilities;
public class ColumnGroup implements Serializable, Jsonizable {
private static final long serialVersionUID = 2161780779920066118L;
final public int startColumnIndex;
public class ColumnGroup implements Jsonizable {
final public int startColumnIndex;
final public int columnSpan;
final public int keyColumnIndex; // could be -1 if there is no key cell
transient public ColumnGroup parentGroup;
transient public List<ColumnGroup> subgroups;
transient public List<ColumnGroup> subgroups;
public ColumnGroup(int startColumnIndex, int columnSpan, int keyColumnIndex) {
this.startColumnIndex = startColumnIndex;
@ -38,14 +38,15 @@ public class ColumnGroup implements Serializable, Jsonizable {
writer.key("columnSpan"); writer.value(columnSpan);
writer.key("keyColumnIndex"); writer.value(keyColumnIndex);
if (subgroups != null && subgroups.size() > 0) {
writer.key("subgroups"); writer.array();
for (ColumnGroup g : subgroups) {
g.write(writer, options);
if (!"save".equals(options.get("mode"))) {
if (subgroups != null && subgroups.size() > 0) {
writer.key("subgroups"); writer.array();
for (ColumnGroup g : subgroups) {
g.write(writer, options);
}
writer.endArray();
}
writer.endArray();
}
writer.endObject();
}
@ -54,6 +55,25 @@ public class ColumnGroup implements Serializable, Jsonizable {
g.startColumnIndex < startColumnIndex + columnSpan);
}
public void save(Writer writer) {
JSONWriter jsonWriter = new JSONWriter(writer);
try {
write(jsonWriter, new Properties());
} catch (JSONException e) {
e.printStackTrace();
}
}
static public ColumnGroup load(String s) throws Exception {
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s);
return new ColumnGroup(
obj.getInt("startColumnIndex"),
obj.getInt("columnSpan"),
obj.getInt("keyColumnIndex")
);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
internalInitialize();

View File

@ -1,8 +1,8 @@
package com.metaweb.gridworks.model;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.io.LineNumberReader;
import java.io.Writer;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@ -16,18 +16,16 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable;
public class ColumnModel implements Serializable, Jsonizable {
private static final long serialVersionUID = 7679639795211544511L;
public class ColumnModel implements Jsonizable {
final public List<Column> columns = new LinkedList<Column>();
final public List<ColumnGroup> columnGroups = new LinkedList<ColumnGroup>();
final public List<Column> columns = new LinkedList<Column>();
final public List<ColumnGroup> columnGroups = new LinkedList<ColumnGroup>();
private int _maxCellIndex;
private int _keyColumnIndex;
private int _maxCellIndex;
private int _keyColumnIndex;
transient protected Map<String, Column> _nameToColumn;
transient protected Map<Integer, Column> _cellIndexToColumn;
transient protected List<ColumnGroup> _rootColumnGroups;
transient protected Map<String, Column> _nameToColumn;
transient protected Map<Integer, Column> _cellIndexToColumn;
transient protected List<ColumnGroup> _rootColumnGroups;
public ColumnModel() {
internalInitialize();
@ -90,11 +88,52 @@ public class ColumnModel implements Serializable, Jsonizable {
writer.endObject();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
internalInitialize();
public void save(Writer writer, Properties options) throws IOException {
writer.write("maxCellIndex="); writer.write(Integer.toString(_maxCellIndex)); writer.write('\n');
writer.write("keyColumnIndex="); writer.write(Integer.toString(_keyColumnIndex)); writer.write('\n');
writer.write("columnCount="); writer.write(Integer.toString(columns.size())); writer.write('\n');
for (Column column : columns) {
column.save(writer); writer.write('\n');
}
writer.write("columnGroupCount="); writer.write(Integer.toString(columnGroups.size())); writer.write('\n');
for (ColumnGroup group : columnGroups) {
group.save(writer); writer.write('\n');
}
writer.write("/e/\n");
}
public void load(LineNumberReader reader) throws Exception {
String line;
while ((line = reader.readLine()) != null && !"/e/".equals(line)) {
int equal = line.indexOf('=');
CharSequence field = line.subSequence(0, equal);
String value = line.substring(equal + 1);
if ("maxCellIndex".equals(field)) {
_maxCellIndex = Integer.parseInt(value);
} else if ("keyColumnIndex".equals(field)) {
_keyColumnIndex = Integer.parseInt(value);
} else if ("columnCount".equals(field)) {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
columns.add(Column.load(reader.readLine()));
}
} else if ("columnGroupCount".equals(field)) {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
columnGroups.add(ColumnGroup.load(reader.readLine()));
}
}
}
internalInitialize();
}
protected void internalInitialize() {
generateMaps();

View File

@ -1,13 +1,23 @@
package com.metaweb.gridworks.model;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Properties;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import com.metaweb.gridworks.Gridworks;
import com.metaweb.gridworks.ProjectManager;
import com.metaweb.gridworks.ProjectMetadata;
import com.metaweb.gridworks.expr.ExpressionUtils;
@ -15,42 +25,183 @@ import com.metaweb.gridworks.history.History;
import com.metaweb.gridworks.process.ProcessManager;
import com.metaweb.gridworks.protograph.Protograph;
public class Project implements Serializable {
private static final long serialVersionUID = -5089046824819472570L;
final public long id;
public class Project {
final public long id;
final public ColumnModel columnModel = new ColumnModel();
final public List<Row> rows = new ArrayList<Row>();
final public List<Row> rows = new ArrayList<Row>();
final public History history;
public Protograph protograph;
transient public ProcessManager processManager;
public Project() {
id = Math.round(Math.random() * 1000000) + System.currentTimeMillis();
id = System.currentTimeMillis() + Math.round(Math.random() * 1000000000000L);
history = new History(this);
internalInitialize();
processManager = new ProcessManager();
}
protected Project(long id) {
this.id = id;
this.history = new History(this);
this.processManager = new ProcessManager();
}
public ProjectMetadata getMetadata() {
return ProjectManager.singleton.getProjectMetadata(id);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
internalInitialize();
public void save() {
Gridworks.log("Saving project " + id + " ...");
File dir = ProjectManager.singleton.getProjectDir(id);
File tempFile = new File(dir, "data.temp.zip");
try {
saveToFile(tempFile);
} catch (Exception e) {
e.printStackTrace();
Gridworks.log("Failed to save project data");
return;
}
File file = new File(dir, "data.zip");
File oldFile = new File(dir, "data.old.zip");
if (file.exists()) {
file.renameTo(oldFile);
}
tempFile.renameTo(file);
if (oldFile.exists()) {
oldFile.delete();
}
Gridworks.log("Project saved.");
}
protected void internalInitialize() {
processManager = new ProcessManager();
recomputeRowContextDependencies();
protected void saveToFile(File file) throws Exception {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
try {
out.putNextEntry(new ZipEntry("data.txt"));
try {
Writer writer = new OutputStreamWriter(out);
try {
Properties options = new Properties();
options.setProperty("mode", "save");
saveToWriter(writer, options);
} finally {
writer.flush();
}
} finally {
out.closeEntry();
}
} finally {
out.close();
}
}
protected void saveToWriter(Writer writer, Properties options) throws IOException {
writer.write(Gridworks.s_version); writer.write('\n');
writer.write("columnModel=\n"); columnModel.save(writer, options);
writer.write("history=\n"); history.save(writer, options);
if (protograph != null) {
writer.write("protograph="); protograph.save(writer, options); writer.write('\n');
}
writer.write("rowCount="); writer.write(Integer.toString(rows.size())); writer.write('\n');
for (Row row : rows) {
row.save(writer); writer.write('\n');
}
}
static public Project load(File dir, long id) {
try {
File file = new File(dir, "data.zip");
if (file.exists()) {
return loadFromFile(file, id);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
File file = new File(dir, "data.temp.zip");
if (file.exists()) {
return loadFromFile(file, id);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
File file = new File(dir, "data.old.zip");
if (file.exists()) {
return loadFromFile(file, id);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
static protected Project loadFromFile(File file, long id) throws Exception {
ZipInputStream in = new ZipInputStream(new FileInputStream(file));
try {
ZipEntry entry = in.getNextEntry();
assert "data.txt".equals(entry.getName());
LineNumberReader reader = new LineNumberReader(new InputStreamReader(in));
try {
return loadFromReader(reader, id);
} finally {
reader.close();
}
} finally {
in.close();
}
}
static protected Project loadFromReader(LineNumberReader reader, long id) throws Exception {
/* String version = */ reader.readLine();
Project project = new Project(id);
String line;
while ((line = reader.readLine()) != null) {
int equal = line.indexOf('=');
CharSequence field = line.subSequence(0, equal);
String value = line.substring(equal + 1);
if ("columnModel".equals(field)) {
project.columnModel.load(reader);
} else if ("history".equals(field)) {
project.history.load(project, reader);
} else if ("protograph".equals(field)) {
project.protograph = Protograph.load(project, value);
} else if ("rowCount".equals(field)) {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
project.rows.add(Row.load(reader.readLine()));
}
}
}
project.recomputeRowContextDependencies();
return project;
}
static protected class Group {
int[] cellIndices;
int[] cellIndices;
int keyCellIndex;
}

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -15,9 +14,7 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.expr.HasFields;
public class Recon implements Serializable, HasFields, Jsonizable {
private static final long serialVersionUID = 8906257833709315762L;
public class Recon implements HasFields, Jsonizable {
static public enum Judgment {
None,
Matched,

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.util.Properties;
import org.json.JSONException;
@ -11,9 +10,7 @@ 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;
public class ReconCandidate implements HasFields, Jsonizable {
final public String topicID;
final public String topicGUID;
final public String topicName;

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.io.Writer;
import java.util.Properties;
@ -12,9 +11,7 @@ import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.expr.ExpressionUtils;
import com.metaweb.gridworks.model.Recon.Judgment;
public class ReconStats implements Serializable, Jsonizable {
private static final long serialVersionUID = -4831409797104437854L;
public class ReconStats implements Jsonizable {
static public ReconStats load(JSONObject obj) throws Exception {
return new ReconStats(
obj.getInt("nonBlanks"),

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
@ -15,9 +14,7 @@ import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.expr.HasFields;
import com.metaweb.gridworks.util.ParsingUtilities;
public class Row implements Serializable, HasFields, Jsonizable {
private static final long serialVersionUID = -689264211730915507L;
public class Row implements HasFields, Jsonizable {
public boolean flagged;
public boolean starred;
final public List<Cell> cells;

View File

@ -7,7 +7,7 @@ import java.util.Properties;
import com.metaweb.gridworks.model.Cell;
public class CellAtRow implements Serializable {
public class CellAtRow {
private static final long serialVersionUID = 7280920621006690944L;
final public int row;

View File

@ -24,8 +24,6 @@ import com.metaweb.gridworks.model.Recon.Judgment;
import com.metaweb.gridworks.util.ParsingUtilities;
public class GuidBasedReconConfig extends StrictReconConfig {
private static final long serialVersionUID = 1857895989346775294L;
static public ReconConfig reconstruct(JSONObject obj) throws Exception {
return new GuidBasedReconConfig();
}

View File

@ -1,7 +1,6 @@
package com.metaweb.gridworks.model.recon;
import java.io.InputStream;
import java.io.Serializable;
import java.io.StringWriter;
import java.net.URL;
import java.net.URLConnection;
@ -28,11 +27,7 @@ import com.metaweb.gridworks.protograph.FreebaseProperty;
import com.metaweb.gridworks.util.ParsingUtilities;
public class HeuristicReconConfig extends ReconConfig {
private static final long serialVersionUID = 423145327938373362L;
static public class ColumnDetail implements Serializable {
private static final long serialVersionUID = -8996704822460155543L;
static public class ColumnDetail {
final public String columnName;
final public FreebaseProperty property;
@ -85,10 +80,10 @@ public class HeuristicReconConfig extends ReconConfig {
}
}
final public String service; // either "recon" or "relevance"
final public String service; // either "recon" or "relevance"
final public String typeID;
final public String typeName;
final public boolean autoMatch;
final public boolean autoMatch;
final public List<ColumnDetail> columnDetails;
public HeuristicReconConfig(

View File

@ -24,8 +24,6 @@ import com.metaweb.gridworks.model.Recon.Judgment;
import com.metaweb.gridworks.util.ParsingUtilities;
public class IdBasedReconConfig extends StrictReconConfig {
private static final long serialVersionUID = 1857895989346775294L;
static public ReconConfig reconstruct(JSONObject obj) throws Exception {
return new IdBasedReconConfig();
}

View File

@ -25,8 +25,6 @@ import com.metaweb.gridworks.protograph.FreebaseTopic;
import com.metaweb.gridworks.util.ParsingUtilities;
public class KeyBasedReconConfig extends StrictReconConfig {
private static final long serialVersionUID = 2363754609522023900L;
final public FreebaseTopic namespace;
static public ReconConfig reconstruct(JSONObject obj) throws Exception {

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model.recon;
import java.io.Serializable;
import java.io.Writer;
import java.util.List;
import java.util.Properties;
@ -15,9 +14,7 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Recon;
import com.metaweb.gridworks.model.Row;
abstract public class ReconConfig implements Serializable, Jsonizable {
private static final long serialVersionUID = -4831409797104437854L;
abstract public class ReconConfig implements Jsonizable {
static public ReconConfig reconstruct(JSONObject obj) throws Exception {
String mode = obj.getString("mode");
if ("heuristic".equals(mode)) {

View File

@ -3,8 +3,6 @@ package com.metaweb.gridworks.model.recon;
import org.json.JSONObject;
abstract public class StrictReconConfig extends ReconConfig {
private static final long serialVersionUID = 4454059850557793074L;
final static protected String s_mqlreadService = "http://api.freebase.com/api/service/mqlread";
static public ReconConfig reconstruct(JSONObject obj) throws Exception {

View File

@ -26,8 +26,6 @@ import com.metaweb.gridworks.model.changes.CellAtRow;
import com.metaweb.gridworks.model.changes.ColumnAdditionChange;
public class ColumnAdditionOperation extends EngineDependentOperation {
private static final long serialVersionUID = -5672677479629932356L;
final protected String _baseColumnName;
final protected String _expression;
final protected OnError _onError;

View File

@ -14,8 +14,6 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.changes.ColumnRemovalChange;
public class ColumnRemovalOperation extends AbstractOperation {
private static final long serialVersionUID = 8422079695048733734L;
final protected String _columnName;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {

View File

@ -16,8 +16,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.MassCellChange;
abstract public class EngineDependentMassCellOperation extends EngineDependentOperation {
private static final long serialVersionUID = -8962461328087299452L;
final protected String _columnName;
final protected boolean _updateRowContextDependencies;

View File

@ -9,8 +9,6 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.util.ParsingUtilities;
abstract public class EngineDependentOperation extends AbstractOperation {
private static final long serialVersionUID = -2800091595856881731L;
final private String _engineConfigString;
transient protected JSONObject _engineConfig;

View File

@ -26,14 +26,10 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.util.ParsingUtilities;
public class MassEditOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -7698202759999537298L;
final protected String _expression;
final protected List<Edit> _edits;
static public class Edit implements Serializable, Jsonizable {
private static final long serialVersionUID = -4799990738910328002L;
static public class Edit implements Jsonizable {
final public List<String> from;
final public Serializable to;

View File

@ -18,11 +18,9 @@ import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.MassRowChange;
public class MultiValuedCellJoinOperation extends AbstractOperation {
private static final long serialVersionUID = 3134524625206033285L;
final protected String _columnName;
final protected String _keyColumnName;
final protected String _separator;
final protected String _separator;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
return new MultiValuedCellJoinOperation(

View File

@ -18,10 +18,8 @@ import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.MassRowChange;
public class MultiValuedCellSplitOperation extends AbstractOperation {
private static final long serialVersionUID = 8217930220439070322L;
final protected String _columnName;
final protected String _keyColumnName;
final protected String _columnName;
final protected String _keyColumnName;
final protected String _separator;
final protected String _mode;

View File

@ -1,9 +1,13 @@
package com.metaweb.gridworks.operations;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;
import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Project;
public abstract class OperationRegistry {
static public Map<String, Class<? extends AbstractOperation>> s_opNameToClass;
@ -37,4 +41,21 @@ public abstract class OperationRegistry {
register("text-transform", TextTransformOperation.class);
register("mass-edit", MassEditOperation.class);
}
static public AbstractOperation reconstruct(Project project, JSONObject obj) {
try {
String op = obj.getString("op");
Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op);
if (klass != null) {
Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class);
if (reconstruct != null) {
return (AbstractOperation) reconstruct.invoke(null, project, obj);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -20,8 +20,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.ReconChange;
public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = 6799029731665369179L;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
String columnName = obj.getString("columnName");

View File

@ -25,12 +25,10 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.ReconChange;
public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -5205694623711144436L;
final protected String _similarValue;
final protected String _similarValue;
final protected Judgment _judgment;
final protected ReconCandidate _match;
final protected boolean _shareNewTopics;
final protected ReconCandidate _match;
final protected boolean _shareNewTopics;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
JSONObject engineConfig = obj.getJSONObject("engineConfig");

View File

@ -22,8 +22,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.ReconChange;
public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -5205694623711144436L;
final protected boolean _shareNewTopics;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {

View File

@ -20,8 +20,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.ReconChange;
public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = 5393888241057341155L;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
String columnName = obj.getString("columnName");

View File

@ -22,8 +22,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.ReconChange;
public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -5205694623711144436L;
final protected ReconCandidate match;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {

View File

@ -30,8 +30,6 @@ import com.metaweb.gridworks.process.LongRunningProcess;
import com.metaweb.gridworks.process.Process;
public class ReconOperation extends EngineDependentOperation {
private static final long serialVersionUID = 838795186905314865L;
final protected String _columnName;
final protected ReconConfig _reconConfig;

View File

@ -20,8 +20,6 @@ import com.metaweb.gridworks.model.changes.MassChange;
import com.metaweb.gridworks.model.changes.RowStarChange;
public class RowStarOperation extends EngineDependentOperation {
private static final long serialVersionUID = 7047630960948704761L;
final protected boolean _starred;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {

View File

@ -17,8 +17,6 @@ import com.metaweb.gridworks.protograph.Protograph;
import com.metaweb.gridworks.util.ParsingUtilities;
public class SaveProtographOperation extends AbstractOperation {
private static final long serialVersionUID = 3134524625206033285L;
final protected Protograph _protograph;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {

View File

@ -20,8 +20,6 @@ import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.CellChange;
public class TextTransformOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -7698202759999537298L;
final protected String _expression;
final protected OnError _onError;
final protected boolean _repeat;

View File

@ -8,8 +8,6 @@ import org.json.JSONException;
import org.json.JSONWriter;
public class AnonymousNode implements Node, NodeWithLinks {
private static final long serialVersionUID = -6956243664838720646L;
final public FreebaseType type;
final public List<Link> links = new LinkedList<Link>();

View File

@ -6,8 +6,6 @@ import org.json.JSONException;
import org.json.JSONWriter;
public class CellKeyNode extends CellNode {
private static final long serialVersionUID = 1684854896739592911L;
final public FreebaseTopic namespace;
public CellKeyNode(

View File

@ -1,8 +1,6 @@
package com.metaweb.gridworks.protograph;
abstract public class CellNode implements Node {
private static final long serialVersionUID = 5820786756175547307L;
final public String columnName;
public CellNode(

View File

@ -8,10 +8,8 @@ import org.json.JSONException;
import org.json.JSONWriter;
public class CellTopicNode extends CellNode implements NodeWithLinks {
private static final long serialVersionUID = 1684854896739592911L;
final public boolean createForNoReconMatch;
final public FreebaseType type;
final public FreebaseType type;
final public List<Link> links = new LinkedList<Link>();
public CellTopicNode(

View File

@ -6,8 +6,6 @@ import org.json.JSONException;
import org.json.JSONWriter;
public class CellValueNode extends CellNode {
private static final long serialVersionUID = 7311884925532708576L;
final public String valueType;
final public String lang;

View File

@ -1,8 +1,6 @@
package com.metaweb.gridworks.protograph;
public class FreebaseProperty extends FreebaseTopic {
private static final long serialVersionUID = 7909539492956342421L;
//final protected FreebaseType _expectedType;
public FreebaseProperty(String id, String name) {

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.protograph;
import java.io.Serializable;
import java.util.Properties;
import org.json.JSONException;
@ -8,9 +7,7 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable;
public class FreebaseTopic implements Serializable, Jsonizable {
private static final long serialVersionUID = -3427885694129112432L;
public class FreebaseTopic implements Jsonizable {
final public String id;
final public String name;

View File

@ -8,8 +8,6 @@ import org.json.JSONException;
import org.json.JSONWriter;
public class FreebaseTopicNode implements Node, NodeWithLinks {
private static final long serialVersionUID = 8418548867745587387L;
final public FreebaseTopic topic;
final public List<Link> links = new LinkedList<Link>();

View File

@ -1,8 +1,6 @@
package com.metaweb.gridworks.protograph;
public class FreebaseType extends FreebaseTopic {
private static final long serialVersionUID = -3070300264980791404L;
public FreebaseType(String id, String name) {
super(id, name);
}

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.protograph;
import java.io.Serializable;
import java.util.Properties;
import org.json.JSONException;
@ -8,9 +7,7 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable;
public class Link implements Serializable, Jsonizable {
private static final long serialVersionUID = 2908086768260322876L;
public class Link implements Jsonizable {
final public FreebaseProperty property;
final public Node target;

View File

@ -1,8 +1,6 @@
package com.metaweb.gridworks.protograph;
import java.io.Serializable;
import com.metaweb.gridworks.Jsonizable;
public interface Node extends Serializable, Jsonizable {
public interface Node extends Jsonizable {
}

View File

@ -1,6 +1,6 @@
package com.metaweb.gridworks.protograph;
import java.io.Serializable;
import java.io.Writer;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@ -11,10 +11,10 @@ import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.util.ParsingUtilities;
public class Protograph implements Serializable, Jsonizable {
private static final long serialVersionUID = 706700643851582450L;
public class Protograph implements Jsonizable {
final protected List<Node> _rootNodes = new LinkedList<Node>();
public int getRootNodeCount() {
@ -137,4 +137,18 @@ public class Protograph implements Serializable, Jsonizable {
writer.endObject();
}
public void save(Writer writer, Properties options) {
JSONWriter jsonWriter = new JSONWriter(writer);
try {
write(jsonWriter, options);
} catch (JSONException e) {
e.printStackTrace();
}
}
static public Protograph load(Project project, String s) throws Exception {
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s);
return reconstruct(obj);
}
}

View File

@ -6,8 +6,6 @@ import org.json.JSONException;
import org.json.JSONWriter;
public class ValueNode implements Node {
private static final long serialVersionUID = -5626883493437735688L;
final public Object value;
final public String valueType;
final public String lang;

View File

@ -1,23 +0,0 @@
package gridworks;
option java_package = "com.metaweb.gridworks.data";
option java_outer_classname = "Model";
message Expression {
required string value = 1;
}
message Project {
required string name = 1;
required int64 created = 2;
required int64 modified = 3;
required string encoding = 4;
optional int32 encoding_confidence = 5;
optional string creator = 6;
optional string password = 7;
repeated Expression expression = 8;
}
message ProjectManager {
repeated Project projects = 1;
}