From 846e540ff69b8276f614862eba214340e56b8be9 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Fri, 19 Feb 2010 18:32:48 +0000 Subject: [PATCH] Keep track of type names of reconciled columns so we can display them later in the schema alignment dialog. Automatically create properties linking to all columns when starting with an empty protograph. git-svn-id: http://google-refine.googlecode.com/svn/trunk@110 7d457c2a-affb-35e4-300a-418c747d4874 --- .../commands/edit/ApplyOperationsCommand.java | 3 +- .../commands/recon/ReconcileCommand.java | 5 +- .../metaweb/gridworks/model/ReconConfig.java | 10 +- .../model/operations/ReconOperation.java | 7 +- .../webapp/scripts/project/recon-dialog.js | 13 +- .../project/schema-alignment-ui-node.js | 125 +++++++++--------- .../scripts/project/schema-alignment.js | 40 +++++- 7 files changed, 122 insertions(+), 81 deletions(-) diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/ApplyOperationsCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/ApplyOperationsCommand.java index fc43836e6..905aa7d14 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/ApplyOperationsCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/ApplyOperationsCommand.java @@ -91,7 +91,8 @@ public class ApplyOperationsCommand extends Command { operation = new ReconOperation( engineConfig, columnName, - obj.getString("typeID") + obj.getString("typeID"), + obj.getString("typeName") ); } else if ("save-protograph".equals(op)) { operation = new SaveProtographOperation( diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/ReconcileCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/ReconcileCommand.java index c573d990c..86c390128 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/ReconcileCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/ReconcileCommand.java @@ -15,8 +15,9 @@ public class ReconcileCommand extends EngineDependentCommand { JSONObject engineConfig) throws Exception { String columnName = request.getParameter("columnName"); - String typeID = request.getParameter("type"); + String typeID = request.getParameter("typeID"); + String typeName = request.getParameter("typeName"); - return new ReconOperation(engineConfig, columnName, typeID); + return new ReconOperation(engineConfig, columnName, typeID, typeName); } } diff --git a/src/main/java/com/metaweb/gridworks/model/ReconConfig.java b/src/main/java/com/metaweb/gridworks/model/ReconConfig.java index 33a0d6d84..e7792fb20 100644 --- a/src/main/java/com/metaweb/gridworks/model/ReconConfig.java +++ b/src/main/java/com/metaweb/gridworks/model/ReconConfig.java @@ -12,16 +12,22 @@ public class ReconConfig implements Serializable, Jsonizable { private static final long serialVersionUID = -4831409797104437854L; final public String typeID; + final public String typeName; - public ReconConfig(String typeID) { + public ReconConfig(String typeID, String typeName) { this.typeID = typeID; + this.typeName = typeName; } public void write(JSONWriter writer, Properties options) throws JSONException { writer.object(); - writer.key("type"); writer.value(typeID); + writer.key("type"); + writer.object(); + writer.key("id"); writer.value(typeID); + writer.key("name"); writer.value(typeName); + writer.endObject(); writer.endObject(); } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java index 50a4031c2..f816db991 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java @@ -43,11 +43,13 @@ public class ReconOperation extends EngineDependentOperation { final protected String _columnName; final protected String _typeID; + final protected String _typeName; - public ReconOperation(JSONObject engineConfig, String columnName, String typeID) { + public ReconOperation(JSONObject engineConfig, String columnName, String typeID, String typeName) { super(engineConfig); _columnName = columnName; _typeID = typeID; + _typeName = typeName; } public Process createProcess(Project project, Properties options) throws Exception { @@ -75,6 +77,7 @@ public class ReconOperation extends EngineDependentOperation { writer.key("description"); writer.value("Reconcile cells in column " + _columnName + " to type " + _typeID); writer.key("columnName"); writer.value(_columnName); writer.key("typeID"); writer.value(_typeID); + writer.key("typeName"); writer.value(_typeName); writer.key("engineConfig"); writer.value(getEngineConfig()); writer.endObject(); } @@ -214,7 +217,7 @@ public class ReconOperation extends EngineDependentOperation { } } - ReconConfig reconConfig = new ReconConfig(_typeID); + ReconConfig reconConfig = new ReconConfig(_typeID, _typeName); Change reconChange = new ReconChange(cellChanges, _columnName, reconConfig); diff --git a/src/main/webapp/scripts/project/recon-dialog.js b/src/main/webapp/scripts/project/recon-dialog.js index d102aee4c..976dbb648 100644 --- a/src/main/webapp/scripts/project/recon-dialog.js +++ b/src/main/webapp/scripts/project/recon-dialog.js @@ -20,6 +20,7 @@ ReconDialog.prototype._createDialog = function() { var div = $('
').appendTo(body); $('') .attr("value", type.id) + .attr("typeName", type.name) .appendTo(div); $('').text(" " + type.name).appendTo(div); @@ -40,14 +41,20 @@ ReconDialog.prototype._createDialog = function() { var type = null; var input = $('').appendTo($('

').appendTo(body)); input.suggest({ type : '/type/type' }).bind("fb-select", function(e, data) { - type = data.id; + type = { + id: data.id, + name: data.name + }; $('input[name="recon-dialog-type-choice"][value=""]').attr("checked", "true"); }); $('').text("Start Reconciling").click(function() { var choices = $('input[name="recon-dialog-type-choice"]:checked'); if (choices != null && choices.length > 0 && choices[0].value != "") { - type = choices[0].value; + type = { + id: choices[0].value, + name: choices.attr("typeName") + }; } if (type == null) { @@ -55,7 +62,7 @@ ReconDialog.prototype._createDialog = function() { } else { DialogSystem.dismissUntil(level - 1); $.post( - "/command/reconcile?" + $.param({ project: theProject.id, columnName: self._column.headerLabel, type: type }), + "/command/reconcile?" + $.param({ project: theProject.id, columnName: self._column.headerLabel, typeID: type.id, typeName: type.name }), { engine: JSON.stringify(ui.browsingEngine.getJSON()) }, function(data) { if (data.code != "error") { diff --git a/src/main/webapp/scripts/project/schema-alignment-ui-node.js b/src/main/webapp/scripts/project/schema-alignment-ui-node.js index c9750de0d..d3a6bc70c 100644 --- a/src/main/webapp/scripts/project/schema-alignment-ui-node.js +++ b/src/main/webapp/scripts/project/schema-alignment-ui-node.js @@ -263,59 +263,6 @@ SchemaAlignmentDialog.UINode.prototype._showNodeConfigDialog = function() { var html = $( '' + '' + - '' + - '' + + + '' + '' + '
' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '
' + - '
' + - ' Generate an anonymous graph node' + - '
' + - '
Assign a type to the node 
' + - '
' + - ' Use one existing Freebase topic' + - '
' + - '
Topic
' + - '
' + - ' Use a literal value' + - '
' + - '
Value
Value type
Language
' + - '
' + '' + '' + @@ -383,6 +330,59 @@ SchemaAlignmentDialog.UINode.prototype._showNodeConfigDialog = function() { '' + '
' + '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '
' + + ' Generate an anonymous graph node' + + '
' + + '
Assign a type to the node 
' + + '
' + + ' Use one existing Freebase topic' + + '
' + + '
Topic
' + + '
' + + ' Use a literal value' + + '
' + + '
Value
Value type
Language
' + + '
' ).appendTo(body); @@ -406,19 +406,12 @@ SchemaAlignmentDialog.UINode.prototype._showNodeConfigDialog = function() { elmts.radioNodeTypeCellAs[0].checked = true; if ("reconConfig" in column) { - var typeID = column.reconConfig.type; - $.getJSON( - "http://api.freebase.com/api/service/mqlread?query=" + JSON.stringify({ query: { "id" : typeID, "name" : null } }) + "&callback=?", - null, - function(o) { - if ("result" in o) { - elmts.cellAsTopicNodeTypeInput[0].value = o.result.name; - elmts.cellAsTopicNodeTypeInput.data("data.suggest", { "id" : typeID, "name" : o.result.name }); - elmts.radioNodeTypeCellAsTopicCreate[0].checked = true; - } - }, - "jsonp" - ); + var typeID = column.reconConfig.type.id; + var typeName = column.reconConfig.type.name; + + elmts.cellAsTopicNodeTypeInput[0].value = typeName; + elmts.cellAsTopicNodeTypeInput.data("data.suggest", { "id" : typeID, "name" : typeName }); + elmts.radioNodeTypeCellAsTopicCreate[0].checked = true; } }); diff --git a/src/main/webapp/scripts/project/schema-alignment.js b/src/main/webapp/scripts/project/schema-alignment.js index add28b91d..1e3cf29ce 100644 --- a/src/main/webapp/scripts/project/schema-alignment.js +++ b/src/main/webapp/scripts/project/schema-alignment.js @@ -90,17 +90,47 @@ SchemaAlignment._cleanName = function(s) { return s.replace(/\W/g, " ").replace(/\s+/g, " ").toLowerCase(); } +SchemaAlignment.createNewRootNode = function() { + var rootNode = null; + var links = []; + var columns = theProject.columnModel.columns; + for (var i = 0; i < columns.length; i++) { + var column = columns[i]; + var target = { + nodeType: "cell-as-topic", + columnName: column.headerLabel, + createForNoReconMatch: true + }; + if ("reconConfig" in column && column.reconConfig != null) { + target.type = { + id: column.reconConfig.type.id, + name: column.reconConfig.type.name + }; + } + + if (column.headerLabel == theProject.columnModel.keyColumnName) { + rootNode = target; + } else { + links.push({ + property: null, + target: target + }); + } + } + + rootNode = rootNode || { nodeType: "cell-as-topic" }; + rootNode.links = links; + + return rootNode; +}; + function SchemaAlignmentDialog(protograph, onDone) { this._onDone = onDone; this._originalProtograph = protograph || { rootNodes: [] }; this._protograph = cloneDeep(this._originalProtograph); // this is what can be munched on if (this._protograph.rootNodes.length == 0) { - this._protograph.rootNodes.push({ - nodeType: "cell-as-topic", - links: [ - ] - }); + this._protograph.rootNodes.push(SchemaAlignment.createNewRootNode()); } this._nodeUIs = [];