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

@ -124,25 +124,25 @@ public class GuidBasedReconConfig extends StrictReconConfig {
jsonWriter.object();
jsonWriter.key("query");
jsonWriter.array();
jsonWriter.object();
jsonWriter.key("id"); jsonWriter.value(null);
jsonWriter.key("name"); jsonWriter.value(null);
jsonWriter.key("guid"); jsonWriter.value(null);
jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray();
jsonWriter.key("guid|=");
jsonWriter.array();
for (ReconJob job : jobs) {
jsonWriter.value(((GuidBasedReconJob) job).guid);
}
jsonWriter.endArray();
jsonWriter.endObject();
jsonWriter.endArray();
jsonWriter.array();
jsonWriter.object();
jsonWriter.key("id"); jsonWriter.value(null);
jsonWriter.key("name"); jsonWriter.value(null);
jsonWriter.key("guid"); jsonWriter.value(null);
jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray();
jsonWriter.key("guid|=");
jsonWriter.array();
for (ReconJob job : jobs) {
jsonWriter.value(((GuidBasedReconJob) job).guid);
}
jsonWriter.endArray();
jsonWriter.endObject();
jsonWriter.endArray();
jsonWriter.endObject();
query = stringWriter.toString();
}
@ -160,36 +160,38 @@ public class GuidBasedReconConfig 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 guid = result.getString("guid");
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;
guidToRecon.put(guid, 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 guid = result.getString("guid");
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;
guidToRecon.put(guid, recon);
}
}
} finally {
is.close();
@ -198,9 +200,12 @@ public class GuidBasedReconConfig extends StrictReconConfig {
e.printStackTrace();
}
for (int i = 0; i < jobs.size(); i++) {
String guid = ((GuidBasedReconJob) jobs.get(i)).guid;
for (ReconJob job : jobs) {
String guid = ((GuidBasedReconJob) job).guid;
Recon recon = guidToRecon.get(guid);
if (recon == null) {
recon = createNoMatchRecon(historyEntryID);
}
recons.add(recon);
}

View File

@ -164,47 +164,52 @@ public class IdBasedReconConfig 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 id = result.getString("id");
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(
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;
idToRecon.put(id, 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 id = result.getString("id");
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(
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;
idToRecon.put(id, recon);
}
}
} finally {
is.close();
is.close();
}
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
for (int i = 0; i < jobs.size(); i++) {
String id = ((IdBasedReconJob) jobs.get(i)).id;
for (ReconJob job : jobs) {
String id = ((IdBasedReconJob) job).id;
Recon recon = idToRecon.get(id);
if (recon == null) {
recon = createNoMatchRecon(historyEntryID);
}
recons.add(recon);
}

View File

@ -221,12 +221,8 @@ public class KeyBasedReconConfig extends StrictReconConfig {
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);
if (recon == null) {
recon = createNoMatchRecon(historyEntryID);
}
recons.add(recon);
}

View File

@ -36,6 +36,7 @@ package com.google.refine.freebase.model.recon;
import org.json.JSONObject;
import com.google.refine.model.Recon;
import com.google.refine.model.Recon.Judgment;
import com.google.refine.model.recon.ReconConfig;
abstract public class StrictReconConfig extends ReconConfig {
@ -57,4 +58,12 @@ abstract public class StrictReconConfig extends ReconConfig {
public Recon createNewRecon(long 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;
}
}