From d7b482be066eee5fd7443bd99c1c9d1ff706dc51 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Thu, 20 Jan 2011 22:49:36 +0000 Subject: [PATCH] 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 --- main/src/com/google/refine/model/Recon.java | 10 +++---- main/src/com/google/refine/util/Pool.java | 32 ++++----------------- main/webapp/modules/core/scripts/project.js | 17 ----------- 3 files changed, 10 insertions(+), 49 deletions(-) diff --git a/main/src/com/google/refine/model/Recon.java b/main/src/com/google/refine/model/Recon.java index 96e55fb92..7e9588305 100644 --- a/main/src/com/google/refine/model/Recon.java +++ b/main/src/com/google/refine/model/Recon.java @@ -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)); } } diff --git a/main/src/com/google/refine/util/Pool.java b/main/src/com/google/refine/util/Pool.java index 1ce4e17df..3981580ff 100644 --- a/main/src/com/google/refine/util/Pool.java +++ b/main/src/com/google/refine/util/Pool.java @@ -56,10 +56,12 @@ import com.google.refine.model.Recon; import com.google.refine.model.ReconCandidate; public class Pool implements Jsonizable { - final protected Map candidates = new HashMap(); final protected Map recons = new HashMap(); - public void pool(ReconCandidate candidate) { + // This is only for backward compatibility while loading old project files + final protected Map candidates = new HashMap(); + + 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 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 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 candidates = new HashMap(); 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 entry : candidates.entrySet()) { - writer.key(entry.getKey()); - entry.getValue().write(writer, options); - } - writer.endObject(); - writer.key("recons"); writer.object(); for (Entry entry : recons.entrySet()) { @@ -195,7 +176,6 @@ public class Pool implements Jsonizable { entry.getValue().write(writer, options); } writer.endObject(); - writer.endObject(); } } diff --git a/main/webapp/modules/core/scripts/project.js b/main/webapp/modules/core/scripts/project.js index a7adca65c..013d50658 100644 --- a/main/webapp/modules/core/scripts/project.js +++ b/main/webapp/modules/core/scripts/project.js @@ -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++) {