Made extend data from freebase command available on columns not officially reconciled, since some columns might contain reconciled data copied from other columns.

More error checking in the extend data utility.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@583 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-05-02 22:27:17 +00:00
parent d303adc48e
commit 9641f28fe0
4 changed files with 54 additions and 40 deletions

View File

@ -61,6 +61,10 @@ public class PreviewExtendDataCommand extends Command {
topicNames.add(cell.recon.match.topicName); topicNames.add(cell.recon.match.topicName);
topicGuids.add(cell.recon.match.topicGUID); topicGuids.add(cell.recon.match.topicGUID);
guids.add(cell.recon.match.topicGUID); guids.add(cell.recon.match.topicGUID);
} else {
topicNames.add(null);
topicGuids.add(null);
guids.add(null);
} }
} }
} }
@ -101,7 +105,7 @@ public class PreviewExtendDataCommand extends Command {
String guid = topicGuids.get(r); String guid = topicGuids.get(r);
String topicName = topicNames.get(r); String topicName = topicNames.get(r);
if (map.containsKey(guid)) { if (guid != null && map.containsKey(guid)) {
DataExtension ext = map.get(guid); DataExtension ext = map.get(guid);
boolean first = true; boolean first = true;
@ -134,7 +138,14 @@ public class PreviewExtendDataCommand extends Command {
} }
writer.array(); writer.array();
writer.value(topicName); if (guid != null) {
writer.object();
writer.key("id"); writer.value("/guid/" + guid.substring(1));
writer.key("name"); writer.value(topicName);
writer.endObject();
} else {
writer.value("<not reconciled>");
}
writer.endArray(); writer.endArray();
} }
writer.endArray(); writer.endArray();

View File

@ -70,16 +70,18 @@ public class FreebaseDataExtensionJob {
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
Map<String, FreebaseDataExtensionJob.DataExtension> map = new HashMap<String, FreebaseDataExtensionJob.DataExtension>(); Map<String, FreebaseDataExtensionJob.DataExtension> map = new HashMap<String, FreebaseDataExtensionJob.DataExtension>();
JSONArray a = o.getJSONArray("result"); if (o.has("result")) {
int l = a.length(); JSONArray a = o.getJSONArray("result");
int l = a.length();
for (int i = 0; i < l; i++) {
JSONObject o2 = a.getJSONObject(i);
String guid = o2.getString("guid");
FreebaseDataExtensionJob.DataExtension ext = collectResult(o2, reconCandidateMap);
if (ext != null) { for (int i = 0; i < l; i++) {
map.put(guid, ext); JSONObject o2 = a.getJSONObject(i);
String guid = o2.getString("guid");
FreebaseDataExtensionJob.DataExtension ext = collectResult(o2, reconCandidateMap);
if (ext != null) {
map.put(guid, ext);
}
} }
} }
@ -284,7 +286,9 @@ public class FreebaseDataExtensionJob {
jsonWriter.key("guid|="); jsonWriter.key("guid|=");
jsonWriter.array(); jsonWriter.array();
for (String guid : guids) { for (String guid : guids) {
jsonWriter.value(guid); if (guid != null) {
jsonWriter.value(guid);
}
} }
jsonWriter.endArray(); jsonWriter.endArray();

View File

@ -53,8 +53,9 @@ function ExtendDataPreviewDialog(column, columnIndex, rowIndices, onDone) {
}).appendTo(footer); }).appendTo(footer);
var dismissBusy = DialogSystem.showBusy(); var dismissBusy = DialogSystem.showBusy();
var type = "reconConfig" in column && "type" in column.reconConfig ? column.reconConfig.type.id : "/common/topic";
ExtendDataPreviewDialog.getAllProperties(column.reconConfig.type.id, function(properties) { ExtendDataPreviewDialog.getAllProperties(type, function(properties) {
dismissBusy(); dismissBusy();
self._show(properties); self._show(properties);
}); });
@ -131,12 +132,14 @@ ExtendDataPreviewDialog.prototype._show = function(properties) {
} }
var suggestConfig = { var suggestConfig = {
type: '/type/property', type: '/type/property'
schema: this._column.reconConfig.type.id
}; };
if ("reconConfig" in this._column && "type" in this._column.reconConfig) {
suggestConfig.schema = this._column.reconConfig.type.id
}
this._elmts.addPropertyInput.suggestP(suggestConfig).bind("fb-select", function(evt, data) { this._elmts.addPropertyInput.suggestP(suggestConfig).bind("fb-select", function(evt, data) {
var expected = data["/type/property/expected_type"]; var expected = data["expected_type"];
self._addProperty({ self._addProperty({
id : data.id, id : data.id,
name: data.name, name: data.name,

View File

@ -866,30 +866,26 @@ DataTableColumnHeaderUI.prototype._doAddColumn = function(initialExpression) {
}; };
DataTableColumnHeaderUI.prototype._doAddColumnFromFreebase = function() { DataTableColumnHeaderUI.prototype._doAddColumnFromFreebase = function() {
if ("reconConfig" in this._column && "type" in this._column.reconConfig) { var o = DataTableView.sampleVisibleRows(this._column);
var o = DataTableView.sampleVisibleRows(this._column); var self = this;
var self = this; new ExtendDataPreviewDialog(
new ExtendDataPreviewDialog( this._column,
this._column, this._columnIndex,
this._columnIndex, o.rowIndices,
o.rowIndices, function(extension) {
function(extension) { Gridworks.postProcess(
Gridworks.postProcess( "extend-data",
"extend-data", {
{ baseColumnName: self._column.name,
baseColumnName: self._column.name, columnInsertIndex: self._columnIndex + 1
columnInsertIndex: self._columnIndex + 1 },
}, {
{ extension: JSON.stringify(extension)
extension: JSON.stringify(extension) },
}, { rowsChanged: true, modelsChanged: true }
{ rowsChanged: true, modelsChanged: true } );
); }
} );
);
} else {
alert("This column has not been reconciled yet.");
}
}; };
DataTableColumnHeaderUI.prototype._doRemoveColumn = function() { DataTableColumnHeaderUI.prototype._doRemoveColumn = function() {