2010-02-19 01:28:34 +01:00
|
|
|
function ReconDialog(column, types) {
|
2010-02-17 01:26:38 +01:00
|
|
|
this._column = column;
|
2010-03-01 22:38:50 +01:00
|
|
|
this._types = types.slice(0, 10);
|
|
|
|
|
|
|
|
var defaultTypes = {
|
|
|
|
"/people/person" : {
|
|
|
|
name: "Person"
|
|
|
|
},
|
|
|
|
"/location/location" : {
|
|
|
|
name: "Location"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$.each(this._types, function() {
|
|
|
|
delete defaultTypes[this.id];
|
|
|
|
});
|
|
|
|
for (var id in defaultTypes) {
|
2010-04-09 03:48:50 +02:00
|
|
|
if (defaultTypes.hasOwnProperty(id)) {
|
|
|
|
this._types.push({
|
|
|
|
id: id,
|
|
|
|
name: defaultTypes[id].name
|
|
|
|
});
|
|
|
|
}
|
2010-03-01 22:38:50 +01:00
|
|
|
}
|
|
|
|
|
2010-02-01 09:31:50 +01:00
|
|
|
this._createDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
ReconDialog.prototype._createDialog = function() {
|
|
|
|
var self = this;
|
|
|
|
var frame = DialogSystem.createDialog();
|
2010-03-01 22:38:50 +01:00
|
|
|
frame.width("800px");
|
2010-02-01 09:31:50 +01:00
|
|
|
|
2010-03-06 08:43:45 +01:00
|
|
|
var header = $('<div></div>').addClass("dialog-header").text("Reconcile column " + this._column.name).appendTo(frame);
|
2010-02-01 09:31:50 +01:00
|
|
|
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
|
|
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
var html = $(
|
2010-04-26 02:10:36 +02:00
|
|
|
'<div id="recon-dialog-tabs" class="gridworks-tabs">' +
|
2010-03-01 22:38:50 +01:00
|
|
|
'<ul>' +
|
|
|
|
'<li><a href="#recon-dialog-tabs-heuristic">Heuristic</a></li>' +
|
|
|
|
'<li><a href="#recon-dialog-tabs-strict">Strict</a></li>' +
|
|
|
|
'</ul>' +
|
|
|
|
'<div id="recon-dialog-tabs-heuristic">' +
|
2010-03-13 08:13:18 +01:00
|
|
|
'<div class="grid-layout layout-normal layout-full"><table>' +
|
2010-03-01 22:38:50 +01:00
|
|
|
'<tr>' +
|
|
|
|
'<td>Reconcile each cell to a Freebase topic of type:</td>' +
|
|
|
|
'<td>Also use relevant details from other columns:</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td>' +
|
|
|
|
'<div class="recon-dialog-heuristic-types-container" bind="heuristicTypeContainer">' +
|
|
|
|
'</div>' +
|
|
|
|
'<table class="recon-dialog-heuristic-other-type-container recon-dialog-inner-layout">' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td width="1"><input type="radio" name="recon-dialog-type-choice" value=""></td>' +
|
|
|
|
'<td>Search for type: <input size="20" bind="heuristicTypeInput" /></td>' +
|
|
|
|
'<tr>' +
|
|
|
|
'</table>' +
|
|
|
|
'</td>' +
|
|
|
|
'<td width="50%">' +
|
|
|
|
'<div class="recon-dialog-heuristic-details-container" bind="heuristicDetailContainer"></div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
2010-03-02 00:33:23 +01:00
|
|
|
'<tr>' +
|
|
|
|
'<td>' +
|
2010-03-02 01:33:32 +01:00
|
|
|
'<input type="checkbox" checked bind="heuristicAutomatchCheck" /> Auto-match candidates with high confidence' +
|
2010-03-02 00:33:23 +01:00
|
|
|
'</td>' +
|
|
|
|
'<td>' +
|
|
|
|
'Use ' +
|
2010-03-31 03:07:17 +02:00
|
|
|
'<input type="radio" name="recon-dialog-heuristic-service" value="relevance" checked="" /> relevance service ' +
|
|
|
|
'<input type="radio" name="recon-dialog-heuristic-service" value="recon" /> recon service ' +
|
2010-03-02 00:33:23 +01:00
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
2010-03-13 08:13:18 +01:00
|
|
|
'</table></div>' +
|
2010-03-01 22:38:50 +01:00
|
|
|
'</div>' +
|
|
|
|
'<div id="recon-dialog-tabs-strict" style="display: none;">' +
|
|
|
|
'<p>Each cell contains:</p>' +
|
2010-03-13 08:13:18 +01:00
|
|
|
'<div class="grid-layout layout-normal layout-full"><table>' +
|
2010-03-01 22:38:50 +01:00
|
|
|
'<tr><td width="1%"><input type="radio" name="recon-dialog-strict-choice" value="id" checked /></td><td>a Freebase ID, e.g., /en/solar_system</td></tr>' +
|
|
|
|
'<tr><td><input type="radio" name="recon-dialog-strict-choice" value="guid" /></td><td>a Freebase GUID, e.g., #9202a8c04000641f80000000000354ae</td></tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td width="1%"><input type="radio" name="recon-dialog-strict-choice" value="key" /></td>' +
|
|
|
|
'<td>' +
|
2010-03-13 08:13:18 +01:00
|
|
|
'<div class="grid-layout layout-tighter layout-full"><table>' +
|
2010-03-01 22:38:50 +01:00
|
|
|
'<tr><td colspan="2">a Freebase key in</td></tr>' +
|
|
|
|
'<tr>' +
|
2010-03-02 19:19:20 +01:00
|
|
|
'<td width="1%"><input type="radio" name="recon-dialog-strict-namespace-choice" value="/wikipedia/en" nsName="Wikipedia EN" checked /></td>' +
|
2010-03-01 22:38:50 +01:00
|
|
|
'<td>the Wikipedia English namespace</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td width="1%"><input type="radio" name="recon-dialog-strict-namespace-choice" value="other" /></td>' +
|
|
|
|
'<td>this namespace: <input bind="strictNamespaceInput" /></td>' +
|
|
|
|
'</tr>' +
|
2010-03-13 08:13:18 +01:00
|
|
|
'</table></div>' +
|
2010-03-01 22:38:50 +01:00
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
2010-03-13 08:13:18 +01:00
|
|
|
'</table></div>' +
|
2010-03-01 22:38:50 +01:00
|
|
|
'</div>' +
|
|
|
|
'</div>'
|
|
|
|
).appendTo(body);
|
2010-02-01 09:31:50 +01:00
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
this._elmts = DOM.bind(html);
|
|
|
|
this._populateDialog();
|
2010-02-19 01:28:34 +01:00
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
$('<button></button>').text("Start Reconciling").click(function() { self._onOK(); }).appendTo(footer);
|
|
|
|
$('<button></button>').text("Cancel").click(function() { self._dismiss(); }).appendTo(footer);
|
2010-02-01 09:31:50 +01:00
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
this._level = DialogSystem.showDialog(frame);
|
2010-02-21 08:32:16 +01:00
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
$("#recon-dialog-tabs").tabs();
|
|
|
|
$("#recon-dialog-tabs-strict").css("display", "");
|
2010-03-03 00:48:21 +01:00
|
|
|
|
|
|
|
this._wireEvents();
|
2010-03-01 22:38:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
ReconDialog.prototype._populateDialog = function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Populate types in heuristic tab
|
|
|
|
*/
|
2010-03-13 08:13:18 +01:00
|
|
|
var typeTableContainer = $('<div>').addClass("grid-layout layout-tighter").appendTo(this._elmts.heuristicTypeContainer);
|
|
|
|
var typeTable = $('<table></table>').appendTo(typeTableContainer)[0];
|
2010-03-01 22:38:50 +01:00
|
|
|
var createTypeChoice = function(type, check) {
|
|
|
|
var tr = typeTable.insertRow(typeTable.rows.length);
|
|
|
|
var td0 = tr.insertCell(0);
|
|
|
|
var td1 = tr.insertCell(1);
|
2010-02-19 01:28:34 +01:00
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
td0.width = "1%";
|
2010-03-03 00:48:21 +01:00
|
|
|
var radio = $('<input type="radio" name="recon-dialog-type-choice">')
|
2010-03-01 22:38:50 +01:00
|
|
|
.attr("value", type.id)
|
|
|
|
.attr("typeName", type.name)
|
2010-03-03 00:48:21 +01:00
|
|
|
.appendTo(td0)
|
|
|
|
.click(function() {
|
|
|
|
self._rewirePropertySuggests(this.value);
|
|
|
|
});
|
2010-02-26 22:56:41 +01:00
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
if (check) {
|
2010-03-03 00:48:21 +01:00
|
|
|
radio.attr("checked", "true");
|
2010-02-19 01:28:34 +01:00
|
|
|
}
|
2010-03-01 22:38:50 +01:00
|
|
|
|
|
|
|
$(td1).html(type.name + '<br/><span class="recon-dialog-type-id">' + type.id + '</span>');
|
|
|
|
};
|
|
|
|
for (var i = 0; i < this._types.length; i++) {
|
2010-04-08 22:18:38 +02:00
|
|
|
createTypeChoice(this._types[i], i === 0);
|
2010-03-01 22:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Populate properties in heuristic tab
|
|
|
|
*/
|
2010-03-13 08:13:18 +01:00
|
|
|
var heuristicDetailTableContainer = $('<div>')
|
|
|
|
.addClass("grid-layout layout-tighter")
|
|
|
|
.appendTo(this._elmts.heuristicDetailContainer);
|
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
var heuristicDetailTable = $(
|
|
|
|
'<table>' +
|
|
|
|
'<tr><th>Column</th><th>Freebase property</th></tr>' +
|
|
|
|
'</table>'
|
2010-03-13 08:13:18 +01:00
|
|
|
).appendTo(heuristicDetailTableContainer)[0];
|
2010-02-01 09:31:50 +01:00
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
function renderDetailColumn(column) {
|
|
|
|
var tr = heuristicDetailTable.insertRow(heuristicDetailTable.rows.length);
|
|
|
|
var td0 = tr.insertCell(0);
|
|
|
|
var td1 = tr.insertCell(1);
|
|
|
|
|
2010-03-06 08:43:45 +01:00
|
|
|
$(td0).html(column.name);
|
2010-03-02 01:33:32 +01:00
|
|
|
$('<input size="15" name="recon-dialog-heuristic-property" />')
|
2010-03-06 08:43:45 +01:00
|
|
|
.attr("columnName", column.name)
|
2010-03-03 00:48:21 +01:00
|
|
|
.appendTo(td1);
|
2010-03-01 22:38:50 +01:00
|
|
|
}
|
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
var column = columns[i];
|
|
|
|
if (column !== this._column) {
|
|
|
|
renderDetailColumn(column);
|
|
|
|
}
|
|
|
|
}
|
2010-03-03 00:48:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
ReconDialog.prototype._wireEvents = function() {
|
2010-03-05 20:28:35 +01:00
|
|
|
var self = this;
|
|
|
|
|
2010-03-03 00:48:21 +01:00
|
|
|
this._elmts.heuristicTypeInput
|
2010-04-27 22:34:36 +02:00
|
|
|
.suggestT({ type : '/type/type' })
|
2010-03-03 00:48:21 +01:00
|
|
|
.bind("fb-select", function(e, data) {
|
|
|
|
$('input[name="recon-dialog-type-choice"][value=""]').attr("checked", "true");
|
|
|
|
|
|
|
|
self._rewirePropertySuggests(data.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
this._rewirePropertySuggests(this._types[0].id);
|
2010-02-01 09:31:50 +01:00
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
this._elmts.strictNamespaceInput
|
|
|
|
.suggest({ type: '/type/namespace' })
|
|
|
|
.bind("fb-select", function(e, data) {
|
|
|
|
$('input[name="recon-dialog-strict-choice"][value="key"]').attr("checked", "true");
|
|
|
|
$('input[name="recon-dialog-strict-namespace-choice"][value="other"]').attr("checked", "true");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2010-03-03 00:48:21 +01:00
|
|
|
ReconDialog.prototype._rewirePropertySuggests = function(schema) {
|
|
|
|
var inputs = $('input[name="recon-dialog-heuristic-property"]');
|
|
|
|
|
2010-04-27 22:34:36 +02:00
|
|
|
inputs.unbind().suggestP({
|
2010-03-31 03:07:17 +02:00
|
|
|
type: '/type/property',
|
|
|
|
schema: schema || "/common/topic"
|
|
|
|
}).bind("fb-select", function(e, data) {
|
|
|
|
$('input[name="recon-dialog-heuristic-service"][value="recon"]').attr("checked", "true");
|
|
|
|
});
|
2010-03-03 00:48:21 +01:00
|
|
|
};
|
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
ReconDialog.prototype._onOK = function() {
|
|
|
|
var tab = $("#recon-dialog-tabs").tabs('option', 'selected');
|
2010-04-08 22:18:38 +02:00
|
|
|
if (tab === 0) {
|
2010-03-01 22:38:50 +01:00
|
|
|
this._onDoHeuristic();
|
|
|
|
} else {
|
|
|
|
this._onDoStrict();
|
|
|
|
}
|
2010-02-01 09:31:50 +01:00
|
|
|
};
|
2010-02-19 01:28:34 +01:00
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
ReconDialog.prototype._dismiss = function() {
|
|
|
|
DialogSystem.dismissUntil(this._level - 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
ReconDialog.prototype._onDoHeuristic = function() {
|
|
|
|
var type = this._elmts.heuristicTypeInput.data("data.suggest");
|
|
|
|
|
|
|
|
var choices = $('input[name="recon-dialog-type-choice"]:checked');
|
2010-04-09 03:00:44 +02:00
|
|
|
if (choices !== null && choices.length > 0 && choices[0].value != "") {
|
2010-03-01 22:38:50 +01:00
|
|
|
type = {
|
|
|
|
id: choices[0].value,
|
|
|
|
name: choices.attr("typeName")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-04-08 22:16:08 +02:00
|
|
|
if (!type) {
|
2010-03-01 22:38:50 +01:00
|
|
|
alert("Please specify a type.");
|
|
|
|
} else {
|
2010-03-02 01:33:32 +01:00
|
|
|
var columnDetails = [];
|
|
|
|
var propertyInputs = $('input[name="recon-dialog-heuristic-property"]');
|
|
|
|
$.each(propertyInputs, function() {
|
|
|
|
var property = $(this).data("data.suggest");
|
2010-04-10 18:58:00 +02:00
|
|
|
if (property && property.id) {
|
2010-03-02 01:33:32 +01:00
|
|
|
columnDetails.push({
|
|
|
|
column: this.getAttribute("columnName"),
|
|
|
|
property: {
|
|
|
|
id: property.id,
|
|
|
|
name: property.name
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-03-01 22:38:50 +01:00
|
|
|
Gridworks.postProcess(
|
|
|
|
"reconcile",
|
2010-03-02 00:33:23 +01:00
|
|
|
{},
|
2010-03-01 22:38:50 +01:00
|
|
|
{
|
2010-03-06 08:43:45 +01:00
|
|
|
columnName: this._column.name,
|
2010-03-02 00:33:23 +01:00
|
|
|
config: JSON.stringify({
|
|
|
|
mode: "heuristic",
|
|
|
|
service: $('input[name="recon-dialog-heuristic-service"]:checked')[0].value,
|
|
|
|
type: {
|
|
|
|
id: type.id,
|
|
|
|
name: type.name
|
|
|
|
},
|
2010-03-02 01:33:32 +01:00
|
|
|
autoMatch: this._elmts.heuristicAutomatchCheck[0].checked,
|
|
|
|
columnDetails: columnDetails
|
2010-03-02 00:33:23 +01:00
|
|
|
})
|
|
|
|
},
|
2010-03-01 22:38:50 +01:00
|
|
|
{ cellsChanged: true, columnStatsChanged: true }
|
|
|
|
);
|
2010-03-02 00:33:23 +01:00
|
|
|
|
|
|
|
this._dismiss();
|
2010-03-01 22:38:50 +01:00
|
|
|
}
|
2010-03-02 19:19:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
ReconDialog.prototype._onDoStrict = function() {
|
|
|
|
var bodyParams;
|
|
|
|
|
|
|
|
var match = $('input[name="recon-dialog-strict-choice"]:checked')[0].value;
|
|
|
|
if (match == "key") {
|
|
|
|
var namespaceChoice = $('input[name="recon-dialog-strict-namespace-choice"]:checked')[0];
|
|
|
|
var namespace;
|
|
|
|
|
|
|
|
if (namespaceChoice.value == "other") {
|
|
|
|
var suggest = this._elmts.strictNamespaceInput.data("data.suggest");
|
2010-04-08 22:16:08 +02:00
|
|
|
if (!suggest) {
|
2010-03-02 19:19:20 +01:00
|
|
|
alert("Please specify a namespace.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
namespace = {
|
|
|
|
id: suggest.id,
|
|
|
|
name: suggest.name
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
namespace = {
|
|
|
|
id: namespaceChoice.value,
|
|
|
|
name: namespaceChoice.getAttribute("nsName")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
bodyParams = {
|
2010-03-06 08:43:45 +01:00
|
|
|
columnName: this._column.name,
|
2010-03-02 19:19:20 +01:00
|
|
|
config: JSON.stringify({
|
|
|
|
mode: "strict",
|
|
|
|
match: "key",
|
|
|
|
namespace: namespace
|
|
|
|
})
|
|
|
|
};
|
|
|
|
} else if (match == "id") {
|
|
|
|
bodyParams = {
|
2010-03-06 08:43:45 +01:00
|
|
|
columnName: this._column.name,
|
2010-03-02 19:19:20 +01:00
|
|
|
config: JSON.stringify({
|
|
|
|
mode: "strict",
|
|
|
|
match: "id"
|
|
|
|
})
|
|
|
|
};
|
|
|
|
} else if (match == "guid") {
|
|
|
|
bodyParams = {
|
2010-03-06 08:43:45 +01:00
|
|
|
columnName: this._column.name,
|
2010-03-02 19:19:20 +01:00
|
|
|
config: JSON.stringify({
|
|
|
|
mode: "strict",
|
|
|
|
match: "guid"
|
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
Gridworks.postProcess(
|
|
|
|
"reconcile",
|
|
|
|
{},
|
|
|
|
bodyParams,
|
|
|
|
{ cellsChanged: true, columnStatsChanged: true }
|
|
|
|
);
|
|
|
|
|
|
|
|
this._dismiss();
|
2010-03-01 22:38:50 +01:00
|
|
|
};
|