From 889245fdf4d27fd5ea3680b20a88edf66b17a6de Mon Sep 17 00:00:00 2001 From: Tom Morris Date: Wed, 4 Sep 2013 18:07:12 -0400 Subject: [PATCH] Make the number of reconciliation results configurable - closes #466 --- .../model/recon/StandardReconConfig.java | 45 +++++++++++++++++-- .../core/langs/translation-default.json | 3 +- .../modules/core/langs/translation-en.json | 4 +- .../modules/core/langs/translation-it.json | 4 +- .../standard-service-panel.html | 4 ++ .../reconciliation/standard-service-panel.js | 6 ++- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/main/src/com/google/refine/model/recon/StandardReconConfig.java b/main/src/com/google/refine/model/recon/StandardReconConfig.java index 37f3a1ed2..fe14b47bb 100644 --- a/main/src/com/google/refine/model/recon/StandardReconConfig.java +++ b/main/src/com/google/refine/model/recon/StandardReconConfig.java @@ -110,6 +110,8 @@ public class StandardReconConfig extends ReconConfig { JSONObject t = obj.has("type") && !obj.isNull("type") ? obj.getJSONObject("type") : null; + int limit = obj.has("limit") ? obj.getInt("limit") : 0; + return new StandardReconConfig( obj.getString("service"), obj.has("identifierSpace") ? obj.getString("identifierSpace") : null, @@ -117,7 +119,8 @@ public class StandardReconConfig extends ReconConfig { t == null ? null : t.getString("id"), t == null ? null : (t.has("name") ? t.getString("name") : null), obj.getBoolean("autoMatch"), - columnDetails + columnDetails, + limit ); } @@ -139,16 +142,41 @@ public class StandardReconConfig extends ReconConfig { final public String typeName; final public boolean autoMatch; final public List columnDetails; + final private int limit; + + public StandardReconConfig( + String service, + String identifierSpace, + String schemaSpace, + + String typeID, + String typeName, + boolean autoMatch, + List columnDetails + ) { + this(service, identifierSpace, schemaSpace, typeID, typeName, autoMatch, columnDetails, 0); + } + + /** + * @param service + * @param identifierSpace + * @param schemaSpace + * @param typeID + * @param typeName + * @param autoMatch + * @param columnDetails + * @param limit maximum number of results to return (0 = default) + */ public StandardReconConfig( String service, String identifierSpace, String schemaSpace, - String typeID, String typeName, boolean autoMatch, - List columnDetails + List columnDetails, + int limit ) { this.service = service; this.identifierSpace = identifierSpace; @@ -158,6 +186,7 @@ public class StandardReconConfig extends ReconConfig { this.typeName = typeName; this.autoMatch = autoMatch; this.columnDetails = columnDetails; + this.limit = limit; } @Override @@ -189,6 +218,7 @@ public class StandardReconConfig extends ReconConfig { writer.endObject(); } writer.endArray(); + writer.key("limit"); writer.value(limit); writer.endObject(); } @@ -265,6 +295,13 @@ public class StandardReconConfig extends ReconConfig { jsonWriter.endArray(); } + + // Only send limit if it's non-default to preserve backward compatibility with + // services which might choke on this + if (limit != 0) { + jsonWriter.key("limit"); jsonWriter.value(limit); + } + jsonWriter.endObject(); job.text = cell.value.toString(); @@ -382,7 +419,7 @@ public class StandardReconConfig extends ReconConfig { try { int length = results.length(); int count = 0; - for (int i = 0; i < length && count < 3; i++) { + for (int i = 0; i < length; i++) { JSONObject result = results.getJSONObject(i); if (!result.has("name")) { continue; diff --git a/main/webapp/modules/core/langs/translation-default.json b/main/webapp/modules/core/langs/translation-default.json index 5142e4fc5..42af77fa2 100644 --- a/main/webapp/modules/core/langs/translation-default.json +++ b/main/webapp/modules/core/langs/translation-default.json @@ -362,7 +362,8 @@ "fb-guid": "a Freebase GUID, e.g., #9202a8c04000641f80000000000354ae", "fb-key": "a Freebase key in", "fb-en-ns": "the Wikipedia English namespace", - "this-ns": "this namespace:" + "this-ns": "this namespace:", + "max-candidates" : "Maximum number of candidates to return" }, "core-util-enc": { "select-enc": "Select Encoding", diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index 5142e4fc5..1fa8b5607 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -362,7 +362,9 @@ "fb-guid": "a Freebase GUID, e.g., #9202a8c04000641f80000000000354ae", "fb-key": "a Freebase key in", "fb-en-ns": "the Wikipedia English namespace", - "this-ns": "this namespace:" + "this-ns": "this namespace:", + "max-candidates" : "Maximum number of candidates to return" + }, "core-util-enc": { "select-enc": "Select Encoding", diff --git a/main/webapp/modules/core/langs/translation-it.json b/main/webapp/modules/core/langs/translation-it.json index e716228b9..9bf650c8b 100644 --- a/main/webapp/modules/core/langs/translation-it.json +++ b/main/webapp/modules/core/langs/translation-it.json @@ -362,7 +362,9 @@ "fb-guid": "un Freebase GUID, es: #9202a8c04000641f80000000000354ae", "fb-key": "Una chiave Freebase nel", "fb-en-ns": "namespace di Wikipedia inglese", - "this-ns": "questo namespace:" + "this-ns": "questo namespace:", + // TODO: Translation required +// "max-candidates" : "Maximum number of candidates to return" }, "core-util-enc": { "select-enc": "Seleziona la codifica", diff --git a/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.html b/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.html index ee64cfe6c..58bea1585 100644 --- a/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.html +++ b/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.html @@ -29,5 +29,9 @@ + + + + diff --git a/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js b/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js index 4784d9dc0..60c4ff704 100644 --- a/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js +++ b/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js @@ -90,6 +90,7 @@ ReconStandardServicePanel.prototype._constructUI = function() { this._elmts.or_proc_againsType.html($.i18n._('core-recon')["against-type"]+":"); this._elmts.or_proc_noType.html($.i18n._('core-recon')["no-type"]); this._elmts.or_proc_autoMatch.html($.i18n._('core-recon')["auto-match"]); + this._elmts.or_proc_max_candidates.html($.i18n._('core-recon')["max-candidates"]); this._elmts.rawServiceLink.attr("href", this._service.url); @@ -328,8 +329,9 @@ ReconStandardServicePanel.prototype.start = function() { identifierSpace: this._service.identifierSpace, schemaSpace: this._service.schemaSpace, type: (type) ? { id: type.id, name: type.name } : null, - autoMatch: this._elmts.automatchCheck[0].checked, - columnDetails: columnDetails + autoMatch: this._elmts.automatchCheck[0].checked, + columnDetails: columnDetails, + limit: this._elmts.maxCandidates[0].value }) }, { cellsChanged: true, columnStatsChanged: true }