Attempt at fixing issue 185. Will need someone else to verify.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@1989 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
44652a3ee2
commit
d7b482be06
@ -273,13 +273,13 @@ public class Recon implements HasFields, Jsonizable {
|
||||
writer.key("j"); writer.value(judgmentToString());
|
||||
if (match != null) {
|
||||
writer.key("m");
|
||||
writer.value(match.id);
|
||||
match.write(writer, options);
|
||||
}
|
||||
if (match == null || saveMode) {
|
||||
writer.key("c"); writer.array();
|
||||
if (candidates != null) {
|
||||
for (ReconCandidate c : candidates) {
|
||||
writer.value(c.id);
|
||||
c.write(writer, options);
|
||||
}
|
||||
}
|
||||
writer.endArray();
|
||||
@ -344,11 +344,10 @@ public class Recon implements HasFields, Jsonizable {
|
||||
recon.judgment = stringToJudgment(jp.getText());
|
||||
} else if ("m".equals(fieldName)) {
|
||||
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
|
||||
// legacy case
|
||||
String candidateID = jp.getText();
|
||||
|
||||
recon.match = pool.getReconCandidate(candidateID);
|
||||
} else {
|
||||
// legacy
|
||||
recon.match = ReconCandidate.loadStreaming(jp);
|
||||
}
|
||||
} else if ("f".equals(fieldName)) {
|
||||
@ -380,11 +379,10 @@ public class Recon implements HasFields, Jsonizable {
|
||||
|
||||
while (jp.nextToken() != JsonToken.END_ARRAY) {
|
||||
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
|
||||
// legacy case
|
||||
String candidateID = jp.getText();
|
||||
|
||||
recon.addCandidate(pool.getReconCandidate(candidateID));
|
||||
} else {
|
||||
// legacy
|
||||
recon.addCandidate(ReconCandidate.loadStreaming(jp));
|
||||
}
|
||||
}
|
||||
|
@ -56,10 +56,12 @@ import com.google.refine.model.Recon;
|
||||
import com.google.refine.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) {
|
||||
// This is only for backward compatibility while loading old project files
|
||||
final protected Map<String, ReconCandidate> candidates = new HashMap<String, ReconCandidate>();
|
||||
|
||||
private void pool(ReconCandidate candidate) {
|
||||
candidates.put(candidate.id, candidate);
|
||||
}
|
||||
|
||||
@ -103,20 +105,6 @@ public class Pool implements Jsonizable {
|
||||
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');
|
||||
|
||||
@ -141,6 +129,7 @@ public class Pool implements Jsonizable {
|
||||
|
||||
/* String version = */ reader2.readLine();
|
||||
|
||||
Map<String, ReconCandidate> candidates = new HashMap<String, ReconCandidate>();
|
||||
String line;
|
||||
while ((line = reader2.readLine()) != null) {
|
||||
int equal = line.indexOf('=');
|
||||
@ -155,6 +144,7 @@ public class Pool implements Jsonizable {
|
||||
if (line != null) {
|
||||
ReconCandidate candidate = ReconCandidate.loadStreaming(line);
|
||||
if (candidate != null) {
|
||||
// pool for backward compatibility
|
||||
pool(candidate);
|
||||
}
|
||||
}
|
||||
@ -179,15 +169,6 @@ public class Pool implements Jsonizable {
|
||||
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()) {
|
||||
@ -195,7 +176,6 @@ public class Pool implements Jsonizable {
|
||||
entry.getValue().write(writer, options);
|
||||
}
|
||||
writer.endObject();
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -384,22 +384,6 @@ Refine.columnNameToColumnIndex = function(columnName) {
|
||||
return -1;
|
||||
};
|
||||
|
||||
Refine.preparePool = function(pool) {
|
||||
for (var id in pool.recons) {
|
||||
if (pool.recons.hasOwnProperty(id)) {
|
||||
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]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Refine.fetchRows = function(start, limit, onDone, sorting) {
|
||||
var body = {
|
||||
engine: JSON.stringify(ui.browsingEngine.getJSON())
|
||||
@ -415,7 +399,6 @@ Refine.fetchRows = function(start, limit, onDone, sorting) {
|
||||
theProject.rowModel = data;
|
||||
|
||||
// Un-pool objects
|
||||
Refine.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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user