diff --git a/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java b/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java index adf136b94..0a4847776 100644 --- a/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java +++ b/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java @@ -178,36 +178,38 @@ public class KeyBasedReconConfig extends StrictReconConfig { try { String s = ParsingUtilities.inputStreamToString(is); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); - JSONArray results = o.getJSONArray("result"); - int count = results.length(); - - for (int i = 0; i < count; i++) { - JSONObject result = results.getJSONObject(i); - - String key = result.getJSONArray("key").getJSONObject(0).getString("value"); - - JSONArray types = result.getJSONArray("type"); - String[] typeIDs = new String[types.length()]; - for (int j = 0; j < typeIDs.length; j++) { - typeIDs[j] = types.getString(j); - } - - ReconCandidate candidate = new ReconCandidate( - result.getString("id"), - result.getString("name"), - typeIDs, - 100 - ); - - Recon recon = Recon.makeFreebaseRecon(historyEntryID); - recon.addCandidate(candidate); - recon.service = "mql"; - recon.judgment = Judgment.Matched; - recon.judgmentAction = "auto"; - recon.match = candidate; - recon.matchRank = 0; - - keyToRecon.put(key, recon); + if (o.has("result")) { + JSONArray results = o.getJSONArray("result"); + int count = results.length(); + + for (int i = 0; i < count; i++) { + JSONObject result = results.getJSONObject(i); + + String key = result.getJSONArray("key").getJSONObject(0).getString("value"); + + JSONArray types = result.getJSONArray("type"); + String[] typeIDs = new String[types.length()]; + for (int j = 0; j < typeIDs.length; j++) { + typeIDs[j] = types.getString(j); + } + + ReconCandidate candidate = new ReconCandidate( + result.getString("id"), + result.getString("name"), + typeIDs, + 100 + ); + + Recon recon = Recon.makeFreebaseRecon(historyEntryID); + recon.addCandidate(candidate); + recon.service = "mql"; + recon.judgment = Judgment.Matched; + recon.judgmentAction = "auto"; + recon.match = candidate; + recon.matchRank = 0; + + keyToRecon.put(key, recon); + } } } finally { is.close(); @@ -215,10 +217,17 @@ public class KeyBasedReconConfig extends StrictReconConfig { } catch (Exception e) { e.printStackTrace(); } - - for (int i = 0; i < jobs.size(); i++) { - String key = ((KeyBasedReconJob) jobs.get(i)).key; + + for (ReconJob job : jobs) { + String key = ((KeyBasedReconJob) job).key; Recon recon = keyToRecon.get(key); + if (recon == null) { // add a no-match recon if none + recon = Recon.makeFreebaseRecon(historyEntryID); + recon.service = "mql"; + recon.judgment = Judgment.None; + recon.matchRank = -1; + keyToRecon.put(key, recon); + } recons.add(recon); }