Issue 328 - extend solution for key-based recon to guid & id recon

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1998 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Tom Morris 2011-02-04 02:08:38 +00:00
parent cccfbf9ad8
commit de25ddfe41
4 changed files with 105 additions and 90 deletions

View File

@ -160,6 +160,7 @@ public class GuidBasedReconConfig extends StrictReconConfig {
try { try {
String s = ParsingUtilities.inputStreamToString(is); String s = ParsingUtilities.inputStreamToString(is);
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
if (o.has("result")) {
JSONArray results = o.getJSONArray("result"); JSONArray results = o.getJSONArray("result");
int count = results.length(); int count = results.length();
@ -191,6 +192,7 @@ public class GuidBasedReconConfig extends StrictReconConfig {
guidToRecon.put(guid, recon); guidToRecon.put(guid, recon);
} }
}
} finally { } finally {
is.close(); is.close();
} }
@ -198,9 +200,12 @@ public class GuidBasedReconConfig extends StrictReconConfig {
e.printStackTrace(); e.printStackTrace();
} }
for (int i = 0; i < jobs.size(); i++) { for (ReconJob job : jobs) {
String guid = ((GuidBasedReconJob) jobs.get(i)).guid; String guid = ((GuidBasedReconJob) job).guid;
Recon recon = guidToRecon.get(guid); Recon recon = guidToRecon.get(guid);
if (recon == null) {
recon = createNoMatchRecon(historyEntryID);
}
recons.add(recon); recons.add(recon);
} }

View File

@ -164,6 +164,7 @@ public class IdBasedReconConfig extends StrictReconConfig {
try { try {
String s = ParsingUtilities.inputStreamToString(is); String s = ParsingUtilities.inputStreamToString(is);
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
if (o.has("result")) {
JSONArray results = o.getJSONArray("result"); JSONArray results = o.getJSONArray("result");
int count = results.length(); int count = results.length();
@ -195,6 +196,7 @@ public class IdBasedReconConfig extends StrictReconConfig {
idToRecon.put(id, recon); idToRecon.put(id, recon);
} }
}
} finally { } finally {
is.close(); is.close();
} }
@ -202,9 +204,12 @@ public class IdBasedReconConfig extends StrictReconConfig {
e.printStackTrace(); e.printStackTrace();
} }
for (int i = 0; i < jobs.size(); i++) { for (ReconJob job : jobs) {
String id = ((IdBasedReconJob) jobs.get(i)).id; String id = ((IdBasedReconJob) job).id;
Recon recon = idToRecon.get(id); Recon recon = idToRecon.get(id);
if (recon == null) {
recon = createNoMatchRecon(historyEntryID);
}
recons.add(recon); recons.add(recon);
} }

View File

@ -221,12 +221,8 @@ public class KeyBasedReconConfig extends StrictReconConfig {
for (ReconJob job : jobs) { for (ReconJob job : jobs) {
String key = ((KeyBasedReconJob) job).key; String key = ((KeyBasedReconJob) job).key;
Recon recon = keyToRecon.get(key); Recon recon = keyToRecon.get(key);
if (recon == null) { // add a no-match recon if none if (recon == null) {
recon = Recon.makeFreebaseRecon(historyEntryID); recon = createNoMatchRecon(historyEntryID);
recon.service = "mql";
recon.judgment = Judgment.None;
recon.matchRank = -1;
keyToRecon.put(key, recon);
} }
recons.add(recon); recons.add(recon);
} }

View File

@ -36,6 +36,7 @@ package com.google.refine.freebase.model.recon;
import org.json.JSONObject; import org.json.JSONObject;
import com.google.refine.model.Recon; import com.google.refine.model.Recon;
import com.google.refine.model.Recon.Judgment;
import com.google.refine.model.recon.ReconConfig; import com.google.refine.model.recon.ReconConfig;
abstract public class StrictReconConfig extends ReconConfig { abstract public class StrictReconConfig extends ReconConfig {
@ -57,4 +58,12 @@ abstract public class StrictReconConfig extends ReconConfig {
public Recon createNewRecon(long historyEntryID) { public Recon createNewRecon(long historyEntryID) {
return Recon.makeFreebaseRecon(historyEntryID); return Recon.makeFreebaseRecon(historyEntryID);
} }
protected Recon createNoMatchRecon(long historyEntryID) {
Recon recon = createNewRecon(historyEntryID);
recon.service = "mql";
recon.judgment = Judgment.None;
recon.matchRank = -1;
return recon;
}
} }