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:
parent
cccfbf9ad8
commit
de25ddfe41
@ -124,25 +124,25 @@ public class GuidBasedReconConfig extends StrictReconConfig {
|
|||||||
|
|
||||||
jsonWriter.object();
|
jsonWriter.object();
|
||||||
jsonWriter.key("query");
|
jsonWriter.key("query");
|
||||||
jsonWriter.array();
|
jsonWriter.array();
|
||||||
jsonWriter.object();
|
jsonWriter.object();
|
||||||
|
|
||||||
jsonWriter.key("id"); jsonWriter.value(null);
|
jsonWriter.key("id"); jsonWriter.value(null);
|
||||||
jsonWriter.key("name"); jsonWriter.value(null);
|
jsonWriter.key("name"); jsonWriter.value(null);
|
||||||
jsonWriter.key("guid"); jsonWriter.value(null);
|
jsonWriter.key("guid"); jsonWriter.value(null);
|
||||||
jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray();
|
jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray();
|
||||||
|
|
||||||
jsonWriter.key("guid|=");
|
jsonWriter.key("guid|=");
|
||||||
jsonWriter.array();
|
jsonWriter.array();
|
||||||
for (ReconJob job : jobs) {
|
for (ReconJob job : jobs) {
|
||||||
jsonWriter.value(((GuidBasedReconJob) job).guid);
|
jsonWriter.value(((GuidBasedReconJob) job).guid);
|
||||||
}
|
}
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
|
|
||||||
jsonWriter.endObject();
|
|
||||||
jsonWriter.endArray();
|
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
|
jsonWriter.endArray();
|
||||||
|
jsonWriter.endObject();
|
||||||
|
|
||||||
query = stringWriter.toString();
|
query = stringWriter.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,36 +160,38 @@ 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);
|
||||||
JSONArray results = o.getJSONArray("result");
|
if (o.has("result")) {
|
||||||
int count = results.length();
|
JSONArray results = o.getJSONArray("result");
|
||||||
|
int count = results.length();
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
JSONObject result = results.getJSONObject(i);
|
for (int i = 0; i < count; i++) {
|
||||||
|
JSONObject result = results.getJSONObject(i);
|
||||||
String guid = result.getString("guid");
|
|
||||||
|
String guid = result.getString("guid");
|
||||||
JSONArray types = result.getJSONArray("type");
|
|
||||||
String[] typeIDs = new String[types.length()];
|
JSONArray types = result.getJSONArray("type");
|
||||||
for (int j = 0; j < typeIDs.length; j++) {
|
String[] typeIDs = new String[types.length()];
|
||||||
typeIDs[j] = types.getString(j);
|
for (int j = 0; j < typeIDs.length; j++) {
|
||||||
}
|
typeIDs[j] = types.getString(j);
|
||||||
|
}
|
||||||
ReconCandidate candidate = new ReconCandidate(
|
|
||||||
result.getString("id"),
|
ReconCandidate candidate = new ReconCandidate(
|
||||||
result.getString("name"),
|
result.getString("id"),
|
||||||
typeIDs,
|
result.getString("name"),
|
||||||
100
|
typeIDs,
|
||||||
);
|
100
|
||||||
|
);
|
||||||
Recon recon = Recon.makeFreebaseRecon(historyEntryID);
|
|
||||||
recon.addCandidate(candidate);
|
Recon recon = Recon.makeFreebaseRecon(historyEntryID);
|
||||||
recon.service = "mql";
|
recon.addCandidate(candidate);
|
||||||
recon.judgment = Judgment.Matched;
|
recon.service = "mql";
|
||||||
recon.judgmentAction = "auto";
|
recon.judgment = Judgment.Matched;
|
||||||
recon.match = candidate;
|
recon.judgmentAction = "auto";
|
||||||
recon.matchRank = 0;
|
recon.match = candidate;
|
||||||
|
recon.matchRank = 0;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,47 +164,52 @@ 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);
|
||||||
JSONArray results = o.getJSONArray("result");
|
if (o.has("result")) {
|
||||||
int count = results.length();
|
JSONArray results = o.getJSONArray("result");
|
||||||
|
int count = results.length();
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
JSONObject result = results.getJSONObject(i);
|
for (int i = 0; i < count; i++) {
|
||||||
|
JSONObject result = results.getJSONObject(i);
|
||||||
String id = result.getString("id");
|
|
||||||
|
String id = result.getString("id");
|
||||||
JSONArray types = result.getJSONArray("type");
|
|
||||||
String[] typeIDs = new String[types.length()];
|
JSONArray types = result.getJSONArray("type");
|
||||||
for (int j = 0; j < typeIDs.length; j++) {
|
String[] typeIDs = new String[types.length()];
|
||||||
typeIDs[j] = types.getString(j);
|
for (int j = 0; j < typeIDs.length; j++) {
|
||||||
}
|
typeIDs[j] = types.getString(j);
|
||||||
|
}
|
||||||
ReconCandidate candidate = new ReconCandidate(
|
|
||||||
id,
|
ReconCandidate candidate = new ReconCandidate(
|
||||||
result.getString("name"),
|
id,
|
||||||
typeIDs,
|
result.getString("name"),
|
||||||
100
|
typeIDs,
|
||||||
);
|
100
|
||||||
|
);
|
||||||
Recon recon = Recon.makeFreebaseRecon(historyEntryID);
|
|
||||||
recon.addCandidate(candidate);
|
Recon recon = Recon.makeFreebaseRecon(historyEntryID);
|
||||||
recon.service = "mql";
|
recon.addCandidate(candidate);
|
||||||
recon.judgment = Judgment.Matched;
|
recon.service = "mql";
|
||||||
recon.judgmentAction = "auto";
|
recon.judgment = Judgment.Matched;
|
||||||
recon.match = candidate;
|
recon.judgmentAction = "auto";
|
||||||
recon.matchRank = 0;
|
recon.match = candidate;
|
||||||
|
recon.matchRank = 0;
|
||||||
idToRecon.put(id, recon);
|
|
||||||
|
idToRecon.put(id, recon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
is.close();
|
is.close();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user