Pool recons and recon candidates. This yields smaller project files, change files, and AJAX responses for get-rows. It should make re-loading existing projects faster.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@521 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
3e37970540
commit
f9a829758e
@ -19,6 +19,7 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.changes.CellChange;
|
||||
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
|
||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class EditOneCellCommand extends Command {
|
||||
@Override
|
||||
@ -60,12 +61,16 @@ public class EditOneCellCommand extends Command {
|
||||
* so the client side can update the cell's rendering right away.
|
||||
*/
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
|
||||
Pool pool = new Pool();
|
||||
Properties options = new Properties();
|
||||
options.put("pool", pool);
|
||||
|
||||
writer.object();
|
||||
writer.key("code"); writer.value("ok");
|
||||
writer.key("historyEntry"); historyEntry.write(writer, options);
|
||||
writer.key("cell"); process.newCell.write(writer, options);
|
||||
writer.key("pool"); pool.write(writer, options);
|
||||
writer.endObject();
|
||||
} else {
|
||||
respond(response, "{ \"code\" : \"pending\" }");
|
||||
|
@ -16,6 +16,7 @@ import com.metaweb.gridworks.browsing.RowVisitor;
|
||||
import com.metaweb.gridworks.commands.Command;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class GetRowsCommand extends Command {
|
||||
|
||||
@ -28,8 +29,11 @@ public class GetRowsCommand extends Command {
|
||||
|
||||
int start = Math.min(project.rows.size(), Math.max(0, getIntegerParameter(request, "start", 0)));
|
||||
int limit = Math.min(project.rows.size() - start, Math.max(0, getIntegerParameter(request, "limit", 20)));
|
||||
|
||||
Pool pool = new Pool();
|
||||
Properties options = new Properties();
|
||||
options.put("reconCandidateOmitTypes", true);
|
||||
options.put("pool", pool);
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
@ -87,6 +91,7 @@ public class GetRowsCommand extends Command {
|
||||
writer.key("start"); writer.value(start);
|
||||
writer.key("limit"); writer.value(limit);
|
||||
writer.key("total"); writer.value(project.rows.size());
|
||||
writer.key("pool"); pool.write(writer, options);
|
||||
|
||||
writer.endObject();
|
||||
} catch (Exception e) {
|
||||
|
@ -23,6 +23,7 @@ import com.metaweb.gridworks.model.Recon.Judgment;
|
||||
import com.metaweb.gridworks.model.changes.CellChange;
|
||||
import com.metaweb.gridworks.model.changes.ReconChange;
|
||||
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class ReconJudgeOneCellCommand extends Command {
|
||||
@Override
|
||||
@ -66,12 +67,16 @@ public class ReconJudgeOneCellCommand extends Command {
|
||||
* client side can update its UI right away.
|
||||
*/
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
|
||||
Pool pool = new Pool();
|
||||
Properties options = new Properties();
|
||||
options.put("pool", pool);
|
||||
|
||||
writer.object();
|
||||
writer.key("code"); writer.value("ok");
|
||||
writer.key("historyEntry"); historyEntry.write(writer, options);
|
||||
writer.key("cell"); process.newCell.write(writer, options);
|
||||
writer.key("pool"); pool.write(writer, options);
|
||||
writer.endObject();
|
||||
} else {
|
||||
respond(response, "{ \"code\" : \"pending\" }");
|
||||
|
@ -6,6 +6,7 @@ import java.io.Writer;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class ChangeSequence implements Change {
|
||||
final protected Change[] _changes;
|
||||
@ -42,7 +43,7 @@ public class ChangeSequence implements Change {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
String line = reader.readLine();
|
||||
if (line == null) line = "";
|
||||
int equal = line.indexOf('=');
|
||||
@ -53,7 +54,7 @@ public class ChangeSequence implements Change {
|
||||
Change[] changes = new Change[count];
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
changes[i] = History.readOneChange(reader);
|
||||
changes[i] = History.readOneChange(reader, pool);
|
||||
}
|
||||
|
||||
line = reader.readLine();
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.metaweb.gridworks.history;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@ -16,6 +20,7 @@ import com.metaweb.gridworks.Gridworks;
|
||||
import com.metaweb.gridworks.Jsonizable;
|
||||
import com.metaweb.gridworks.ProjectManager;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
/**
|
||||
* Track done and undone changes. Done changes can be undone; undone changes can be redone.
|
||||
@ -25,23 +30,42 @@ import com.metaweb.gridworks.model.Project;
|
||||
* are only loaded into memory on demand.
|
||||
*/
|
||||
public class History implements Jsonizable {
|
||||
static public Change readOneChange(LineNumberReader reader) throws Exception {
|
||||
static public Change readOneChange(InputStream in, Pool pool) throws Exception {
|
||||
LineNumberReader reader = new LineNumberReader(new InputStreamReader(in));
|
||||
try {
|
||||
return readOneChange(reader, pool);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
static public Change readOneChange(LineNumberReader reader, Pool pool) throws Exception {
|
||||
/* String version = */ reader.readLine();
|
||||
|
||||
String className = reader.readLine();
|
||||
Class<? extends Change> klass = getChangeClass(className);
|
||||
|
||||
Method load = klass.getMethod("load", LineNumberReader.class);
|
||||
Method load = klass.getMethod("load", LineNumberReader.class, Pool.class);
|
||||
|
||||
return (Change) load.invoke(null, reader);
|
||||
return (Change) load.invoke(null, reader, pool);
|
||||
}
|
||||
|
||||
static public void writeOneChange(Writer writer, Change change) throws Exception {
|
||||
static public void writeOneChange(OutputStream out, Change change, Pool pool) throws Exception {
|
||||
Writer writer = new OutputStreamWriter(out);
|
||||
try {
|
||||
History.writeOneChange(writer, change, pool);
|
||||
} finally {
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
|
||||
static public void writeOneChange(Writer writer, Change change, Pool pool) throws Exception {
|
||||
writer.write(Gridworks.getVersion()); writer.write('\n');
|
||||
writer.write(change.getClass().getName()); writer.write('\n');
|
||||
|
||||
Properties options = new Properties();
|
||||
options.setProperty("mode", "save");
|
||||
options.put("pool", pool);
|
||||
|
||||
change.save(writer, options);
|
||||
}
|
||||
|
@ -1,16 +1,13 @@
|
||||
package com.metaweb.gridworks.history;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.json.JSONException;
|
||||
@ -23,6 +20,7 @@ import com.metaweb.gridworks.model.AbstractOperation;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.operations.OperationRegistry;
|
||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
/**
|
||||
* This is the metadata of a Change. It's small, so we can load it in order to
|
||||
@ -148,20 +146,19 @@ public class HistoryEntry implements Jsonizable {
|
||||
}
|
||||
|
||||
protected void loadChange(File file) throws Exception {
|
||||
ZipInputStream in = new ZipInputStream(new FileInputStream(file));
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
try {
|
||||
ZipEntry entry = in.getNextEntry();
|
||||
Pool pool = new Pool();
|
||||
ZipEntry poolEntry = zipFile.getEntry("pool.txt");
|
||||
if (poolEntry != null) {
|
||||
pool.load(new InputStreamReader(
|
||||
zipFile.getInputStream(poolEntry)));
|
||||
} // else, it's a legacy project file
|
||||
|
||||
assert "change.txt".equals(entry.getName());
|
||||
|
||||
LineNumberReader reader = new LineNumberReader(new InputStreamReader(in));
|
||||
try {
|
||||
_change = History.readOneChange(reader);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
_change = History.readOneChange(
|
||||
zipFile.getInputStream(zipFile.getEntry("change.txt")), pool);
|
||||
} finally {
|
||||
in.close();
|
||||
zipFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,14 +172,18 @@ public class HistoryEntry implements Jsonizable {
|
||||
protected void saveChange(File file) throws Exception {
|
||||
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
|
||||
try {
|
||||
Pool pool = new Pool();
|
||||
|
||||
out.putNextEntry(new ZipEntry("change.txt"));
|
||||
try {
|
||||
Writer writer = new OutputStreamWriter(out);
|
||||
try {
|
||||
History.writeOneChange(writer, _change);
|
||||
} finally {
|
||||
writer.flush();
|
||||
}
|
||||
History.writeOneChange(out, _change, pool);
|
||||
} finally {
|
||||
out.closeEntry();
|
||||
}
|
||||
|
||||
out.putNextEntry(new ZipEntry("pool.txt"));
|
||||
try {
|
||||
pool.save(out);
|
||||
} finally {
|
||||
out.closeEntry();
|
||||
}
|
||||
|
@ -4,14 +4,12 @@ import java.io.Serializable;
|
||||
import java.io.Writer;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.codehaus.jackson.JsonFactory;
|
||||
import org.codehaus.jackson.JsonParser;
|
||||
import org.codehaus.jackson.JsonToken;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.Jsonizable;
|
||||
@ -19,6 +17,7 @@ import com.metaweb.gridworks.expr.EvalError;
|
||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||
import com.metaweb.gridworks.expr.HasFields;
|
||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class Cell implements HasFields, Jsonizable {
|
||||
final public Serializable value;
|
||||
@ -66,7 +65,10 @@ public class Cell implements HasFields, Jsonizable {
|
||||
|
||||
if (recon != null) {
|
||||
writer.key("r");
|
||||
recon.write(writer, options);
|
||||
writer.value(Long.toString(recon.id));
|
||||
|
||||
Pool pool = (Pool) options.get("pool");
|
||||
pool.pool(recon);
|
||||
}
|
||||
writer.endObject();
|
||||
}
|
||||
@ -80,34 +82,7 @@ public class Cell implements HasFields, Jsonizable {
|
||||
}
|
||||
}
|
||||
|
||||
static public Cell load(String s, Map<Long, Recon> reconCache) throws Exception {
|
||||
return s.length() == 0 ? null : load(ParsingUtilities.evaluateJsonStringToObject(s), reconCache);
|
||||
}
|
||||
|
||||
static public Cell load(JSONObject obj, Map<Long, Recon> reconCache) throws Exception {
|
||||
Serializable value = null;
|
||||
Recon recon = null;
|
||||
|
||||
if (obj.has("e")) {
|
||||
value = new EvalError(obj.getString("e"));
|
||||
} else if (obj.has("v") && !obj.isNull("v")) {
|
||||
value = (Serializable) obj.get("v");
|
||||
if (obj.has("t") && !obj.isNull("t")) {
|
||||
String type = obj.getString("t");
|
||||
if ("date".equals(type)) {
|
||||
value = ParsingUtilities.stringToDate((String) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.has("r") && !obj.isNull("r")) {
|
||||
recon = Recon.load(obj.getJSONObject("r"), reconCache);
|
||||
}
|
||||
|
||||
return new Cell(value, recon);
|
||||
}
|
||||
|
||||
static public Cell loadStreaming(String s, Map<Long, Recon> reconCache) throws Exception {
|
||||
static public Cell loadStreaming(String s, Pool pool) throws Exception {
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
JsonParser jp = jsonFactory.createJsonParser(s);
|
||||
|
||||
@ -115,10 +90,10 @@ public class Cell implements HasFields, Jsonizable {
|
||||
return null;
|
||||
}
|
||||
|
||||
return loadStreaming(jp, reconCache);
|
||||
return loadStreaming(jp, pool);
|
||||
}
|
||||
|
||||
static public Cell loadStreaming(JsonParser jp, Map<Long, Recon> reconCache) throws Exception {
|
||||
static public Cell loadStreaming(JsonParser jp, Pool pool) throws Exception {
|
||||
JsonToken t = jp.getCurrentToken();
|
||||
if (t == JsonToken.VALUE_NULL || t != JsonToken.START_OBJECT) {
|
||||
return null;
|
||||
@ -133,7 +108,14 @@ public class Cell implements HasFields, Jsonizable {
|
||||
jp.nextToken();
|
||||
|
||||
if ("r".equals(fieldName)) {
|
||||
recon = Recon.loadStreaming(jp, reconCache);
|
||||
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
|
||||
String reconID = jp.getText();
|
||||
|
||||
recon = pool.getRecon(reconID);
|
||||
} else {
|
||||
// legacy
|
||||
recon = Recon.loadStreaming(jp, pool);
|
||||
}
|
||||
} else if ("e".equals(fieldName)) {
|
||||
value = new EvalError(jp.getText());
|
||||
} else if ("v".equals(fieldName)) {
|
||||
|
@ -1,23 +1,21 @@
|
||||
package com.metaweb.gridworks.model;
|
||||
|
||||
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.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -30,6 +28,7 @@ import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||
import com.metaweb.gridworks.history.History;
|
||||
import com.metaweb.gridworks.process.ProcessManager;
|
||||
import com.metaweb.gridworks.protograph.Protograph;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class Project {
|
||||
final public long id;
|
||||
@ -98,17 +97,18 @@ public class Project {
|
||||
protected void saveToFile(File file) throws Exception {
|
||||
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
|
||||
try {
|
||||
Pool pool = new Pool();
|
||||
|
||||
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();
|
||||
}
|
||||
saveToOutputStream(out, pool);
|
||||
} finally {
|
||||
out.closeEntry();
|
||||
}
|
||||
|
||||
out.putNextEntry(new ZipEntry("pool.txt"));
|
||||
try {
|
||||
pool.save(out);
|
||||
} finally {
|
||||
out.closeEntry();
|
||||
}
|
||||
@ -117,6 +117,19 @@ public class Project {
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveToOutputStream(OutputStream out, Pool pool) throws IOException {
|
||||
Writer writer = new OutputStreamWriter(out);
|
||||
try {
|
||||
Properties options = new Properties();
|
||||
options.setProperty("mode", "save");
|
||||
options.put("pool", pool);
|
||||
|
||||
saveToWriter(writer, options);
|
||||
} finally {
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveToWriter(Writer writer, Properties options) throws IOException {
|
||||
writer.write(Gridworks.getVersion()); writer.write('\n');
|
||||
|
||||
@ -163,25 +176,37 @@ public class Project {
|
||||
return null;
|
||||
}
|
||||
|
||||
static protected Project loadFromFile(File file, long id) throws Exception {
|
||||
ZipInputStream in = new ZipInputStream(new FileInputStream(file));
|
||||
static protected Project loadFromFile(
|
||||
File file,
|
||||
long id
|
||||
) throws Exception {
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
try {
|
||||
ZipEntry entry = in.getNextEntry();
|
||||
Pool pool = new Pool();
|
||||
ZipEntry poolEntry = zipFile.getEntry("pool.txt");
|
||||
if (poolEntry != null) {
|
||||
pool.load(new InputStreamReader(
|
||||
zipFile.getInputStream(poolEntry)));
|
||||
} // else, it's a legacy project file
|
||||
|
||||
assert "data.txt".equals(entry.getName());
|
||||
|
||||
LineNumberReader reader = new LineNumberReader(new InputStreamReader(in));
|
||||
try {
|
||||
return loadFromReader(reader, id);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
return loadFromReader(
|
||||
new LineNumberReader(
|
||||
new InputStreamReader(
|
||||
zipFile.getInputStream(
|
||||
zipFile.getEntry("data.txt")))),
|
||||
id,
|
||||
pool
|
||||
);
|
||||
} finally {
|
||||
in.close();
|
||||
zipFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
static protected Project loadFromReader(LineNumberReader reader, long id) throws Exception {
|
||||
static protected Project loadFromReader(
|
||||
LineNumberReader reader,
|
||||
long id,
|
||||
Pool pool
|
||||
) throws Exception {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
/* String version = */ reader.readLine();
|
||||
@ -204,11 +229,10 @@ public class Project {
|
||||
} else if ("rowCount".equals(field)) {
|
||||
int count = Integer.parseInt(value);
|
||||
|
||||
Map<Long, Recon> reconCache = new HashMap<Long, Recon>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
line = reader.readLine();
|
||||
if (line != null) {
|
||||
Row row = Row.load(line, reconCache);
|
||||
Row row = Row.load(line, pool);
|
||||
project.rows.add(row);
|
||||
maxCellCount = Math.max(maxCellCount, row.cells.size());
|
||||
}
|
||||
|
@ -6,15 +6,15 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.codehaus.jackson.JsonFactory;
|
||||
import org.codehaus.jackson.JsonParser;
|
||||
import org.codehaus.jackson.JsonToken;
|
||||
import org.json.JSONArray;
|
||||
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.Pool;
|
||||
|
||||
public class Recon implements HasFields, Jsonizable {
|
||||
|
||||
@ -171,13 +171,13 @@ public class Recon implements HasFields, Jsonizable {
|
||||
|
||||
if (match != null) {
|
||||
writer.key("m");
|
||||
match.write(writer, options);
|
||||
writer.value(match.topicID);
|
||||
}
|
||||
if (match == null || saveMode) {
|
||||
writer.key("c"); writer.array();
|
||||
if (candidates != null) {
|
||||
for (ReconCandidate c : candidates) {
|
||||
c.write(writer, options);
|
||||
writer.value(c.topicID);
|
||||
}
|
||||
}
|
||||
writer.endArray();
|
||||
@ -195,56 +195,23 @@ public class Recon implements HasFields, Jsonizable {
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
static public Recon load(JSONObject obj, Map<Long, Recon> reconCache) throws Exception {
|
||||
if (obj == null) {
|
||||
static public Recon loadStreaming(String s, Pool pool) throws Exception {
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
JsonParser jp = jsonFactory.createJsonParser(s);
|
||||
|
||||
if (jp.nextToken() != JsonToken.START_OBJECT) {
|
||||
return null;
|
||||
}
|
||||
|
||||
long id = obj.getLong("id");
|
||||
if (reconCache.containsKey(id)) {
|
||||
return reconCache.get(id);
|
||||
}
|
||||
|
||||
Recon recon = new Recon(id);
|
||||
|
||||
if (obj.has("j")) {
|
||||
recon.judgment = stringToJudgment(obj.getString("j"));
|
||||
}
|
||||
if (obj.has("m")) {
|
||||
recon.match = ReconCandidate.load(obj.getJSONObject("m"));
|
||||
}
|
||||
if (obj.has("c")) {
|
||||
JSONArray a = obj.getJSONArray("c");
|
||||
int count = a.length();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
recon.addCandidate(ReconCandidate.load(a.getJSONObject(i)));
|
||||
}
|
||||
}
|
||||
if (obj.has("f")) {
|
||||
JSONArray a = obj.getJSONArray("f");
|
||||
int count = a.length();
|
||||
|
||||
for (int i = 0; i < count && i < Feature_max; i++) {
|
||||
if (!a.isNull(i)) {
|
||||
recon.features[i] = a.get(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reconCache.put(id, recon);
|
||||
|
||||
return recon;
|
||||
return loadStreaming(jp, pool);
|
||||
}
|
||||
|
||||
static public Recon loadStreaming(JsonParser jp, Map<Long, Recon> reconCache) throws Exception {
|
||||
|
||||
static public Recon loadStreaming(JsonParser jp, Pool pool) throws Exception {
|
||||
JsonToken t = jp.getCurrentToken();
|
||||
if (t == JsonToken.VALUE_NULL || t != JsonToken.START_OBJECT) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Recon recon = null;
|
||||
boolean old = true;
|
||||
|
||||
while (jp.nextToken() != JsonToken.END_OBJECT) {
|
||||
String fieldName = jp.getCurrentName();
|
||||
@ -252,20 +219,17 @@ public class Recon implements HasFields, Jsonizable {
|
||||
|
||||
if ("id".equals(fieldName)) {
|
||||
long id = jp.getLongValue();
|
||||
if (reconCache.containsKey(id)) {
|
||||
recon = reconCache.get(id);
|
||||
} else {
|
||||
recon = new Recon(id);
|
||||
old = false;
|
||||
}
|
||||
recon = new Recon(id);
|
||||
} else if ("j".equals(fieldName)) {
|
||||
recon.judgment = stringToJudgment(jp.getText());
|
||||
} else if ("m".equals(fieldName)) {
|
||||
if (jp.getCurrentToken() == JsonToken.START_OBJECT) {
|
||||
ReconCandidate match = ReconCandidate.loadStreaming(jp, reconCache);
|
||||
if (!old) {
|
||||
recon.match = match;
|
||||
}
|
||||
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
|
||||
String candidateID = jp.getText();
|
||||
|
||||
recon.match = pool.getReconCandidate(candidateID);
|
||||
} else {
|
||||
// legacy
|
||||
recon.match = ReconCandidate.loadStreaming(jp);
|
||||
}
|
||||
} else if ("f".equals(fieldName)) {
|
||||
if (jp.getCurrentToken() != JsonToken.START_ARRAY) {
|
||||
@ -274,7 +238,7 @@ public class Recon implements HasFields, Jsonizable {
|
||||
|
||||
int feature = 0;
|
||||
while (jp.nextToken() != JsonToken.END_ARRAY) {
|
||||
if (feature < recon.features.length && !old) {
|
||||
if (feature < recon.features.length) {
|
||||
JsonToken token = jp.getCurrentToken();
|
||||
if (token == JsonToken.VALUE_STRING) {
|
||||
recon.features[feature++] = jp.getText();
|
||||
@ -295,9 +259,13 @@ public class Recon implements HasFields, Jsonizable {
|
||||
}
|
||||
|
||||
while (jp.nextToken() != JsonToken.END_ARRAY) {
|
||||
ReconCandidate rc = ReconCandidate.loadStreaming(jp, reconCache);
|
||||
if (rc != null && !old) {
|
||||
recon.addCandidate(rc);
|
||||
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
|
||||
String candidateID = jp.getText();
|
||||
|
||||
recon.addCandidate(pool.getReconCandidate(candidateID));
|
||||
} else {
|
||||
// legacy
|
||||
recon.addCandidate(ReconCandidate.loadStreaming(jp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,16 @@ package com.metaweb.gridworks.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.codehaus.jackson.JsonFactory;
|
||||
import org.codehaus.jackson.JsonParser;
|
||||
import org.codehaus.jackson.JsonToken;
|
||||
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 HasFields, Jsonizable {
|
||||
final public String topicID;
|
||||
@ -69,22 +67,17 @@ public class ReconCandidate implements HasFields, Jsonizable {
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
static public ReconCandidate load(JSONObject obj) throws Exception {
|
||||
if (obj == null) {
|
||||
static public ReconCandidate loadStreaming(String s) throws Exception {
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
JsonParser jp = jsonFactory.createJsonParser(s);
|
||||
|
||||
if (jp.nextToken() != JsonToken.START_OBJECT) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ReconCandidate candidate = new ReconCandidate(
|
||||
obj.getString("id"),
|
||||
obj.getString("guid"),
|
||||
obj.getString("name"),
|
||||
JSONUtilities.getStringArray(obj, "types"),
|
||||
obj.getDouble("score")
|
||||
);
|
||||
return candidate;
|
||||
return loadStreaming(jp);
|
||||
}
|
||||
|
||||
static public ReconCandidate loadStreaming(JsonParser jp, Map<Long, Recon> reconCache) throws Exception {
|
||||
static public ReconCandidate loadStreaming(JsonParser jp) throws Exception {
|
||||
JsonToken t = jp.getCurrentToken();
|
||||
if (t == JsonToken.VALUE_NULL || t != JsonToken.START_OBJECT) {
|
||||
return null;
|
||||
|
@ -3,21 +3,19 @@ package com.metaweb.gridworks.model;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.codehaus.jackson.JsonFactory;
|
||||
import org.codehaus.jackson.JsonParser;
|
||||
import org.codehaus.jackson.JsonToken;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.Jsonizable;
|
||||
import com.metaweb.gridworks.expr.CellTuple;
|
||||
import com.metaweb.gridworks.expr.HasFields;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class Row implements HasFields, Jsonizable {
|
||||
public boolean flagged;
|
||||
@ -161,36 +159,12 @@ public class Row implements HasFields, Jsonizable {
|
||||
}
|
||||
}
|
||||
|
||||
static public Row load(String s, Map<Long, Recon> reconCache) throws Exception {
|
||||
static public Row load(String s, Pool pool) throws Exception {
|
||||
return s.length() == 0 ? null :
|
||||
//load(ParsingUtilities.evaluateJsonStringToObject(s), reconCache);
|
||||
loadStreaming(s, reconCache);
|
||||
loadStreaming(s, pool);
|
||||
}
|
||||
|
||||
static public Row load(JSONObject obj, Map<Long, Recon> reconCache) throws Exception {
|
||||
JSONArray a = obj.getJSONArray("cells");
|
||||
int count = a.length();
|
||||
|
||||
Row row = new Row(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!a.isNull(i)) {
|
||||
JSONObject o = a.getJSONObject(i);
|
||||
|
||||
row.setCell(i, Cell.load(o, reconCache));
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.has(STARRED)) {
|
||||
row.starred = obj.getBoolean(STARRED);
|
||||
}
|
||||
if (obj.has(FLAGGED)) {
|
||||
row.flagged = obj.getBoolean(FLAGGED);
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
static public Row loadStreaming(String s, Map<Long, Recon> reconCache) throws Exception {
|
||||
static public Row loadStreaming(String s, Pool pool) throws Exception {
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
JsonParser jp = jsonFactory.createJsonParser(s);
|
||||
|
||||
@ -216,7 +190,7 @@ public class Row implements HasFields, Jsonizable {
|
||||
}
|
||||
|
||||
while (jp.nextToken() != JsonToken.END_ARRAY) {
|
||||
Cell cell = Cell.loadStreaming(jp, reconCache);
|
||||
Cell cell = Cell.loadStreaming(jp, pool);
|
||||
|
||||
cells.add(cell);
|
||||
}
|
||||
|
@ -2,11 +2,10 @@ package com.metaweb.gridworks.model.changes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.model.Cell;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class CellAtRow {
|
||||
|
||||
@ -26,10 +25,10 @@ public class CellAtRow {
|
||||
}
|
||||
}
|
||||
|
||||
static public CellAtRow load(String s, Map<Long, Recon> reconCache) throws Exception {
|
||||
static public CellAtRow load(String s, Pool pool) throws Exception {
|
||||
int semicolon = s.indexOf(';');
|
||||
int row = Integer.parseInt(s.substring(0, semicolon));
|
||||
Cell cell = semicolon < s.length() - 1 ? Cell.loadStreaming(s.substring(semicolon + 1), reconCache) : null;
|
||||
Cell cell = semicolon < s.length() - 1 ? Cell.loadStreaming(s.substring(semicolon + 1), pool) : null;
|
||||
|
||||
return new CellAtRow(row, cell);
|
||||
}
|
||||
|
@ -3,13 +3,12 @@ package com.metaweb.gridworks.model.changes;
|
||||
import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Writer;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Cell;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class CellChange implements Change {
|
||||
final public int row;
|
||||
@ -55,7 +54,7 @@ public class CellChange implements Change {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public CellChange load(LineNumberReader reader, Map<Long, Recon> reconCache) throws Exception {
|
||||
static public CellChange load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
int row = -1;
|
||||
int cellIndex = -1;
|
||||
Cell oldCell = null;
|
||||
@ -72,9 +71,9 @@ public class CellChange implements Change {
|
||||
} else if ("cell".equals(field)) {
|
||||
cellIndex = Integer.parseInt(value);
|
||||
} else if ("new".equals(field) && value.length() > 0) {
|
||||
newCell = Cell.loadStreaming(value, reconCache);
|
||||
newCell = Cell.loadStreaming(value, pool);
|
||||
} else if ("old".equals(field) && value.length() > 0) {
|
||||
oldCell = Cell.loadStreaming(value, reconCache);
|
||||
oldCell = Cell.loadStreaming(value, pool);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,16 +4,14 @@ import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class ColumnAdditionChange extends ColumnChange {
|
||||
final protected String _columnName;
|
||||
@ -75,7 +73,7 @@ public class ColumnAdditionChange extends ColumnChange {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
String columnName = null;
|
||||
int columnIndex = -1;
|
||||
int newCellIndex = -1;
|
||||
@ -95,13 +93,11 @@ public class ColumnAdditionChange extends ColumnChange {
|
||||
} else if ("newCellCount".equals(field)) {
|
||||
int newCellCount = Integer.parseInt(line.substring(equal + 1));
|
||||
|
||||
Map<Long, Recon> reconCache = new HashMap<Long, Recon>();
|
||||
|
||||
newCells = new ArrayList<CellAtRow>(newCellCount);
|
||||
for (int i = 0; i < newCellCount; i++) {
|
||||
line = reader.readLine();
|
||||
if (line != null) {
|
||||
newCells.add(CellAtRow.load(line, reconCache));
|
||||
newCells.add(CellAtRow.load(line, pool));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,14 @@ package com.metaweb.gridworks.model.changes;
|
||||
import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Cell;
|
||||
import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class ColumnRemovalChange extends ColumnChange {
|
||||
final protected int _oldColumnIndex;
|
||||
@ -71,7 +69,7 @@ public class ColumnRemovalChange extends ColumnChange {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
int oldColumnIndex = -1;
|
||||
Column oldColumn = null;
|
||||
CellAtRow[] oldCells = null;
|
||||
@ -88,13 +86,11 @@ public class ColumnRemovalChange extends ColumnChange {
|
||||
} else if ("oldCellCount".equals(field)) {
|
||||
int oldCellCount = Integer.parseInt(line.substring(equal + 1));
|
||||
|
||||
Map<Long, Recon> reconCache = new HashMap<Long, Recon>();
|
||||
|
||||
oldCells = new CellAtRow[oldCellCount];
|
||||
for (int i = 0; i < oldCellCount; i++) {
|
||||
line = reader.readLine();
|
||||
if (line != null) {
|
||||
oldCells[i] = CellAtRow.load(line, reconCache);
|
||||
oldCells[i] = CellAtRow.load(line, pool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class ColumnRenameChange extends ColumnChange {
|
||||
final protected String _oldColumnName;
|
||||
@ -37,7 +38,7 @@ public class ColumnRenameChange extends ColumnChange {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
String oldColumnName = null;
|
||||
String newColumnName = null;
|
||||
|
||||
|
@ -5,9 +5,7 @@ import java.io.LineNumberReader;
|
||||
import java.io.Serializable;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONObject;
|
||||
@ -17,8 +15,8 @@ import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Cell;
|
||||
import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class ColumnSplitChange implements Change {
|
||||
final protected String _columnName;
|
||||
@ -214,7 +212,7 @@ public class ColumnSplitChange implements Change {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
String columnName = null;
|
||||
List<String> columnNames = null;
|
||||
List<Integer> rowIndices = null;
|
||||
@ -228,7 +226,6 @@ public class ColumnSplitChange implements Change {
|
||||
List<Row> oldRows = null;
|
||||
List<Row> newRows = null;
|
||||
|
||||
Map<Long, Recon> reconCache = new HashMap<Long, Recon>();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null && !"/ec/".equals(line)) {
|
||||
int equal = line.indexOf('=');
|
||||
@ -296,7 +293,7 @@ public class ColumnSplitChange implements Change {
|
||||
for (int i = 0; i < count; i++) {
|
||||
line = reader.readLine();
|
||||
if (line != null) {
|
||||
oldRows.add(Row.load(line, reconCache));
|
||||
oldRows.add(Row.load(line, pool));
|
||||
}
|
||||
}
|
||||
} else if ("newRowCount".equals(field)) {
|
||||
@ -306,7 +303,7 @@ public class ColumnSplitChange implements Change {
|
||||
for (int i = 0; i < count; i++) {
|
||||
line = reader.readLine();
|
||||
if (line != null) {
|
||||
newRows.add(Row.load(line, reconCache));
|
||||
newRows.add(Row.load(line, pool));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,11 @@ import java.io.LineNumberReader;
|
||||
import java.io.Serializable;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
@ -27,6 +24,7 @@ import com.metaweb.gridworks.model.Recon.Judgment;
|
||||
import com.metaweb.gridworks.model.recon.DataExtensionReconConfig;
|
||||
import com.metaweb.gridworks.protograph.FreebaseType;
|
||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
import com.metaweb.gridworks.util.FreebaseDataExtensionJob.DataExtension;
|
||||
|
||||
public class DataExtensionChange implements Change {
|
||||
@ -271,7 +269,7 @@ public class DataExtensionChange implements Change {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
String baseColumnName = null;
|
||||
int columnInsertIndex = -1;
|
||||
|
||||
@ -286,8 +284,6 @@ public class DataExtensionChange implements Change {
|
||||
|
||||
int firstNewCellIndex = -1;
|
||||
|
||||
Map<Long, Recon> reconCache = new HashMap<Long, Recon>();
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null && !"/ec/".equals(line)) {
|
||||
int equal = line.indexOf('=');
|
||||
@ -345,16 +341,7 @@ public class DataExtensionChange implements Change {
|
||||
for (int c = 0; c < columnNames.size(); c++) {
|
||||
line = reader.readLine();
|
||||
|
||||
JSONTokener t = new JSONTokener(line);
|
||||
Object o = t.nextValue();
|
||||
|
||||
if (o != JSONObject.NULL) {
|
||||
if (o instanceof JSONObject) {
|
||||
row[c] = ReconCandidate.load((JSONObject) o);
|
||||
} else {
|
||||
row[c] = o;
|
||||
}
|
||||
}
|
||||
row[c] = ReconCandidate.loadStreaming(line);
|
||||
}
|
||||
|
||||
data[r] = row;
|
||||
@ -369,7 +356,7 @@ public class DataExtensionChange implements Change {
|
||||
for (int i = 0; i < count; i++) {
|
||||
line = reader.readLine();
|
||||
if (line != null) {
|
||||
oldRows.add(Row.load(line, reconCache));
|
||||
oldRows.add(Row.load(line, pool));
|
||||
}
|
||||
}
|
||||
} else if ("newRowCount".equals(field)) {
|
||||
@ -379,7 +366,7 @@ public class DataExtensionChange implements Change {
|
||||
for (int i = 0; i < count; i++) {
|
||||
line = reader.readLine();
|
||||
if (line != null) {
|
||||
newRows.add(Row.load(line, reconCache));
|
||||
newRows.add(Row.load(line, pool));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,14 @@ package com.metaweb.gridworks.model.changes;
|
||||
import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class MassCellChange implements Change {
|
||||
final protected CellChange[] _cellChanges;
|
||||
@ -98,7 +96,7 @@ public class MassCellChange implements Change {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
String commonColumnName = null;
|
||||
boolean updateRowContextDependencies = false;
|
||||
CellChange[] cellChanges = null;
|
||||
@ -115,11 +113,9 @@ public class MassCellChange implements Change {
|
||||
} else if ("cellChangeCount".equals(field)) {
|
||||
int cellChangeCount = Integer.parseInt(line.substring(equal + 1));
|
||||
|
||||
Map<Long, Recon> reconCache = new HashMap<Long, Recon>();
|
||||
|
||||
cellChanges = new CellChange[cellChangeCount];
|
||||
for (int i = 0; i < cellChangeCount; i++) {
|
||||
cellChanges[i] = CellChange.load(reader, reconCache);
|
||||
cellChanges[i] = CellChange.load(reader, pool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import java.util.Properties;
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.history.History;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class MassChange implements Change {
|
||||
final protected List<? extends Change> _changes;
|
||||
@ -53,7 +54,7 @@ public class MassChange implements Change {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
boolean updateRowContextDependencies = false;
|
||||
List<Change> changes = null;
|
||||
|
||||
@ -69,7 +70,7 @@ public class MassChange implements Change {
|
||||
|
||||
changes = new ArrayList<Change>(changeCount);
|
||||
for (int i = 0; i < changeCount; i++) {
|
||||
changes.add(History.readOneChange(reader));
|
||||
changes.add(History.readOneChange(reader, pool));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,13 @@ import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class MassRowChange implements Change {
|
||||
final protected List<Row> _newRows;
|
||||
@ -55,12 +53,10 @@ public class MassRowChange implements Change {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
List<Row> oldRows = null;
|
||||
List<Row> newRows = null;
|
||||
|
||||
Map<Long, Recon> reconCache = new HashMap<Long, Recon>();
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null && !"/ec/".equals(line)) {
|
||||
int equal = line.indexOf('=');
|
||||
@ -73,7 +69,7 @@ public class MassRowChange implements Change {
|
||||
for (int i = 0; i < count; i++) {
|
||||
line = reader.readLine();
|
||||
if (line != null) {
|
||||
oldRows.add(Row.load(line, reconCache));
|
||||
oldRows.add(Row.load(line, pool));
|
||||
}
|
||||
}
|
||||
} else if ("newRowCount".equals(field)) {
|
||||
@ -83,7 +79,7 @@ public class MassRowChange implements Change {
|
||||
for (int i = 0; i < count; i++) {
|
||||
line = reader.readLine();
|
||||
if (line != null) {
|
||||
newRows.add(Row.load(line, reconCache));
|
||||
newRows.add(Row.load(line, pool));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,18 +6,16 @@ package com.metaweb.gridworks.model.changes;
|
||||
import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.ReconStats;
|
||||
import com.metaweb.gridworks.model.recon.ReconConfig;
|
||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class ReconChange extends MassCellChange {
|
||||
final protected ReconConfig _newReconConfig;
|
||||
@ -121,7 +119,7 @@ public class ReconChange extends MassCellChange {
|
||||
super.save(writer, options);
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
ReconConfig newReconConfig = null;
|
||||
ReconStats newReconStats = null;
|
||||
ReconConfig oldReconConfig = null;
|
||||
@ -158,11 +156,9 @@ public class ReconChange extends MassCellChange {
|
||||
} else if ("cellChangeCount".equals(field)) {
|
||||
int cellChangeCount = Integer.parseInt(value);
|
||||
|
||||
Map<Long, Recon> reconCache = new HashMap<Long, Recon>();
|
||||
|
||||
cellChanges = new CellChange[cellChangeCount];
|
||||
for (int i = 0; i < cellChangeCount; i++) {
|
||||
cellChanges[i] = CellChange.load(reader, reconCache);
|
||||
cellChanges[i] = CellChange.load(reader, pool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,13 @@ import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class RowRemovalChange implements Change {
|
||||
final protected List<Integer> _rowIndices;
|
||||
@ -71,7 +69,7 @@ public class RowRemovalChange implements Change {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
List<Integer> rowIndices = null;
|
||||
List<Row> rows = null;
|
||||
|
||||
@ -93,13 +91,11 @@ public class RowRemovalChange implements Change {
|
||||
} else if ("rowCount".equals(field)) {
|
||||
int count = Integer.parseInt(line.substring(equal + 1));
|
||||
|
||||
Map<Long, Recon> reconCache = new HashMap<Long, Recon>();
|
||||
|
||||
rows = new ArrayList<Row>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
line = reader.readLine();
|
||||
if (line != null) {
|
||||
rows.add(Row.load(line, reconCache));
|
||||
rows.add(Row.load(line, pool));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.Properties;
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class RowStarChange implements Change {
|
||||
final int rowIndex;
|
||||
@ -39,7 +40,7 @@ public class RowStarChange implements Change {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public RowStarChange load(LineNumberReader reader) throws Exception {
|
||||
static public RowStarChange load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
int row = -1;
|
||||
boolean oldStarred = false;
|
||||
boolean newStarred = false;
|
||||
|
@ -15,6 +15,7 @@ import com.metaweb.gridworks.model.AbstractOperation;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.protograph.Protograph;
|
||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||
import com.metaweb.gridworks.util.Pool;
|
||||
|
||||
public class SaveProtographOperation extends AbstractOperation {
|
||||
final protected Protograph _protograph;
|
||||
@ -79,7 +80,7 @@ public class SaveProtographOperation extends AbstractOperation {
|
||||
writer.write("/ec/\n"); // end of change marker
|
||||
}
|
||||
|
||||
static public Change load(LineNumberReader reader) throws Exception {
|
||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||
Protograph oldProtograph = null;
|
||||
Protograph newProtograph = null;
|
||||
|
||||
|
159
src/main/java/com/metaweb/gridworks/util/Pool.java
Normal file
159
src/main/java/com/metaweb/gridworks/util/Pool.java
Normal file
@ -0,0 +1,159 @@
|
||||
package com.metaweb.gridworks.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.Gridworks;
|
||||
import com.metaweb.gridworks.Jsonizable;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.ReconCandidate;
|
||||
|
||||
public class Pool implements Jsonizable {
|
||||
final protected Map<String, ReconCandidate> candidates = new HashMap<String, ReconCandidate>();
|
||||
final protected Map<String, Recon> recons = new HashMap<String, Recon>();
|
||||
|
||||
public void pool(ReconCandidate candidate) {
|
||||
candidates.put(candidate.topicID, candidate);
|
||||
}
|
||||
|
||||
public void pool(Recon recon) {
|
||||
recons.put(Long.toString(recon.id), recon);
|
||||
|
||||
if (recon.match != null) {
|
||||
pool(recon.match);
|
||||
}
|
||||
if (recon.candidates != null) {
|
||||
for (ReconCandidate candidate : recon.candidates) {
|
||||
pool(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Recon getRecon(String id) {
|
||||
return recons.get(id);
|
||||
}
|
||||
|
||||
public ReconCandidate getReconCandidate(String topicID) {
|
||||
return candidates.get(topicID);
|
||||
}
|
||||
|
||||
public void save(OutputStream out) throws IOException {
|
||||
Writer writer = new OutputStreamWriter(out);
|
||||
try {
|
||||
save(writer);
|
||||
} finally {
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void save(Writer writer) throws IOException {
|
||||
writer.write(Gridworks.getVersion()); writer.write('\n');
|
||||
|
||||
Properties options = new Properties();
|
||||
options.setProperty("mode", "save");
|
||||
options.put("pool", this);
|
||||
|
||||
Collection<ReconCandidate> candidates2 = candidates.values();
|
||||
writer.write("reconCandidateCount=" + candidates2.size()); writer.write('\n');
|
||||
|
||||
for (ReconCandidate c : candidates2) {
|
||||
JSONWriter jsonWriter = new JSONWriter(writer);
|
||||
try {
|
||||
c.write(jsonWriter, options);
|
||||
|
||||
writer.write('\n');
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Collection<Recon> recons2 = recons.values();
|
||||
writer.write("reconCount=" + recons2.size()); writer.write('\n');
|
||||
|
||||
for (Recon recon : recons2) {
|
||||
JSONWriter jsonWriter = new JSONWriter(writer);
|
||||
try {
|
||||
recon.write(jsonWriter, options);
|
||||
|
||||
writer.write('\n');
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void load(Reader reader) throws Exception {
|
||||
LineNumberReader reader2 = new LineNumberReader(reader);
|
||||
|
||||
/* String version = */ reader2.readLine();
|
||||
|
||||
String line;
|
||||
while ((line = reader2.readLine()) != null) {
|
||||
int equal = line.indexOf('=');
|
||||
CharSequence field = line.subSequence(0, equal);
|
||||
String value = line.substring(equal + 1);
|
||||
|
||||
if ("reconCandidateCount".equals(field)) {
|
||||
int count = Integer.parseInt(value);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
line = reader2.readLine();
|
||||
if (line != null) {
|
||||
ReconCandidate candidate = ReconCandidate.loadStreaming(line);
|
||||
if (candidate != null) {
|
||||
pool(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ("reconCount".equals(field)) {
|
||||
int count = Integer.parseInt(value);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
line = reader2.readLine();
|
||||
if (line != null) {
|
||||
Recon recon = Recon.loadStreaming(line, this);
|
||||
if (recon != null) {
|
||||
pool(recon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
|
||||
writer.key("reconCandidates");
|
||||
writer.object();
|
||||
for (Entry<String, ReconCandidate> entry : candidates.entrySet()) {
|
||||
writer.key(entry.getKey());
|
||||
entry.getValue().write(writer, options);
|
||||
}
|
||||
writer.endObject();
|
||||
|
||||
writer.key("recons");
|
||||
writer.object();
|
||||
for (Entry<String, Recon> entry : recons.entrySet()) {
|
||||
writer.key(entry.getKey().toString());
|
||||
entry.getValue().write(writer, options);
|
||||
}
|
||||
writer.endObject();
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
@ -296,12 +296,39 @@ Gridworks.cellIndexToColumn = function(cellIndex) {
|
||||
return null;
|
||||
};
|
||||
|
||||
Gridworks.preparePool = function(pool) {
|
||||
for (var id in pool.recons) {
|
||||
var recon = pool.recons[id];
|
||||
if (recon.m) {
|
||||
recon.m = pool.reconCandidates[recon.m];
|
||||
}
|
||||
if (recon.c) {
|
||||
for (var j = 0; j < recon.c.length; j++) {
|
||||
recon.c[j] = pool.reconCandidates[recon.c[j]];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Gridworks.fetchRows = function(start, limit, onDone) {
|
||||
$.post(
|
||||
"/command/get-rows?" + $.param({ project: theProject.id, start: start, limit: limit }),
|
||||
{ engine: JSON.stringify(ui.browsingEngine.getJSON()) },
|
||||
function(data) {
|
||||
theProject.rowModel = data;
|
||||
|
||||
// Un-pool objects
|
||||
Gridworks.preparePool(data.pool);
|
||||
for (var r = 0; r < data.rows.length; r++) {
|
||||
var row = data.rows[r];
|
||||
for (var c = 0; c < row.cells.length; c++) {
|
||||
var cell = row.cells[c];
|
||||
if ((cell) && ("r" in cell)) {
|
||||
cell.r = data.pool.recons[cell.r];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (onDone) {
|
||||
onDone();
|
||||
}
|
||||
|
@ -274,6 +274,11 @@ DataTableCellUI.prototype._postProcessOneCell = function(command, params, column
|
||||
{ columnStatsChanged: columnStatsChanged },
|
||||
{
|
||||
onDone: function(o) {
|
||||
Gridworks.preparePool(o.pool);
|
||||
if (o.cell.r) {
|
||||
o.cell.r = o.pool.recons[o.cell.r];
|
||||
}
|
||||
|
||||
self._cell = o.cell;
|
||||
self._dataTableView._updateCell(self._rowIndex, self._cellIndex, self._cell);
|
||||
self._render();
|
||||
@ -412,6 +417,11 @@ DataTableCellUI.prototype._startEdit = function(elmt) {
|
||||
{},
|
||||
{
|
||||
onDone: function(o) {
|
||||
Gridworks.preparePool(o.pool);
|
||||
if (o.cell.r) {
|
||||
o.cell.r = o.pool.recons[o.cell.r];
|
||||
}
|
||||
|
||||
self._cell = o.cell;
|
||||
self._dataTableView._updateCell(self._rowIndex, self._cellIndex, self._cell);
|
||||
self._render();
|
||||
|
Loading…
Reference in New Issue
Block a user