More work on recon refactoring:

- services can now be unregistered.
- matched topics and candidates now have links formatted by the service that generated them.
- recon candidate previews are also based on the recon service.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1040 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-06-26 05:34:54 +00:00
parent ecfb893e98
commit 40c5fb8ff1
5 changed files with 142 additions and 82 deletions

View File

@ -77,6 +77,16 @@ ReconDialog.prototype._populateDialog = function() {
self._selectService(record); self._selectService(record);
}); });
$('<a>')
.html("&nbsp;")
.addClass("recon-dialog-service-selector-remove")
.prependTo(record.selector)
.click(function() {
ReconciliationManager.unregisterService(service, function() {
self._refresh(-1);
});
});
self._serviceRecords.push(record); self._serviceRecords.push(record);
}; };

View File

@ -1,6 +1,25 @@
var ReconciliationManager = { var ReconciliationManager = {
"customServices" : [], // services registered by core and extensions customServices : [], // services registered by core and extensions
"standardServices" : [] // services registered by user standardServices : [], // services registered by user
_urlMap : {}
};
ReconciliationManager.isFreebaseId = function(s) {
return s == "http://rdf.freebase.com/ns/type.object.id";
};
ReconciliationManager._rebuildMap = function() {
var map = {};
$.each(ReconciliationManager.getAllServices(), function(i, service) {
if ("url" in service) {
map[service.url] = service;
}
});
ReconciliationManager._urlMap = map;
};
ReconciliationManager.getServiceFromUrl = function(url) {
return ReconciliationManager._urlMap[url];
}; };
ReconciliationManager.getAllServices = function() { ReconciliationManager.getAllServices = function() {
@ -9,6 +28,7 @@ ReconciliationManager.getAllServices = function() {
ReconciliationManager.registerService = function(service) { ReconciliationManager.registerService = function(service) {
ReconciliationManager.customServices.push(service); ReconciliationManager.customServices.push(service);
ReconciliationManager._rebuildMap();
return ReconciliationManager.customServices.length - 1; return ReconciliationManager.customServices.length - 1;
}; };
@ -25,6 +45,8 @@ ReconciliationManager.registerStandardService = function(url, f) {
ReconciliationManager.standardServices.length; ReconciliationManager.standardServices.length;
ReconciliationManager.standardServices.push(data); ReconciliationManager.standardServices.push(data);
ReconciliationManager._rebuildMap();
ReconciliationManager.save(); ReconciliationManager.save();
if (f) { if (f) {
@ -35,6 +57,22 @@ ReconciliationManager.registerStandardService = function(url, f) {
}); });
}; };
ReconciliationManager.unregisterService = function(service, f) {
for (var i = 0; i < ReconciliationManager.customServices.length; i++) {
if (ReconciliationManager.customServices[i] === service) {
ReconciliationManager.customServices.splice(i, 1);
break;
}
}
for (var i = 0; i < ReconciliationManager.standardServices.length; i++) {
if (ReconciliationManager.standardServices[i] === service) {
ReconciliationManager.standardServices.splice(i, 1);
break;
}
}
ReconciliationManager.save(f);
};
ReconciliationManager.save = function(f) { ReconciliationManager.save = function(f) {
$.ajax({ $.ajax({
async: false, async: false,
@ -64,6 +102,7 @@ ReconciliationManager.save = function(f) {
success: function(data) { success: function(data) {
if (data.value && data.value != "null") { if (data.value && data.value != "null") {
ReconciliationManager.standardServices = JSON.parse(data.value); ReconciliationManager.standardServices = JSON.parse(data.value);
ReconciliationManager._rebuildMap();
} else { } else {
ReconciliationManager.registerStandardService( ReconciliationManager.registerStandardService(
"http://standard-reconcile.dfhuynh.user.dev.freebaseapps.com/reconcile"); "http://standard-reconcile.dfhuynh.user.dev.freebaseapps.com/reconcile");

View File

@ -212,13 +212,11 @@ ReconStandardServicePanel.prototype._rewirePropertySuggests = function(type) {
}; };
ReconStandardServicePanel.prototype._isInFreebaseIdentifierSpace = function() { ReconStandardServicePanel.prototype._isInFreebaseIdentifierSpace = function() {
return "identifierSpace" in this._service && return ReconciliationManager.isFreebaseId(this._service.identifierSpace);
this._service.identifierSpace == "http://rdf.freebase.com/ns/type.object.id";
}; };
ReconStandardServicePanel.prototype._isInFreebaseSchemaSpace = function() { ReconStandardServicePanel.prototype._isInFreebaseSchemaSpace = function() {
return "schemaSpace" in this._service && return ReconciliationManager.isFreebaseId(this._service.schemaSpace);
this._service.schemaSpace == "http://rdf.freebase.com/ns/type.object.id";
}; };
ReconStandardServicePanel.prototype.start = function() { ReconStandardServicePanel.prototype.start = function() {

View File

@ -49,6 +49,8 @@ DataTableCellUI.prototype._render = function() {
} }
} else { } else {
var r = cell.r; var r = cell.r;
var service = (r.service) ? ReconciliationManager.getServiceFromUrl(r.service) : null;
if (r.j == "new") { if (r.j == "new") {
$('<span>').text(cell.v + " (new topic) ").appendTo(divContent); $('<span>').text(cell.v + " (new topic) ").appendTo(divContent);
@ -60,12 +62,19 @@ DataTableCellUI.prototype._render = function() {
}); });
} else if (r.j == "matched" && "m" in r && r.m !== null) { } else if (r.j == "matched" && "m" in r && r.m !== null) {
var match = cell.r.m; var match = cell.r.m;
$('<a></a>') var a = $('<a></a>')
.text(match.name) .text(match.name)
.attr("href", "http://www.freebase.com/view" + match.id)
.attr("target", "_blank") .attr("target", "_blank")
.appendTo(divContent); .appendTo(divContent);
if (service) {
if ((service.view) && (service.view.url)) {
a.attr("href", service.view.url.replace("{{id}}", match.id));
} else if (ReconciliationManager.isFreebaseId(service.identifierSpace)) {
a.attr("href", "http://www.freebase.com/view" + match.id);
}
}
$('<span> </span>').appendTo(divContent); $('<span> </span>').appendTo(divContent);
$('<a href="javascript:{}"></a>') $('<a href="javascript:{}"></a>')
.text("re\u2011match") .text("re\u2011match")
@ -98,19 +107,36 @@ DataTableCellUI.prototype._render = function() {
self._doMatchTopicToOneCell(candidate); self._doMatchTopicToOneCell(candidate);
}); });
$('<a></a>') var a = $('<a></a>')
.addClass("data-table-recon-topic") .addClass("data-table-recon-topic")
.attr("href", "http://www.freebase.com/view" + candidate.id)
.attr("target", "_blank") .attr("target", "_blank")
.text(candidate.name) .text(candidate.name)
.appendTo(li) .appendTo(li);
.click(function(evt) {
if (service) {
if ((service.view) && (service.view.url)) {
a.attr("href", service.view.url.replace("{{id}}", candidate.id));
} else if (ReconciliationManager.isFreebaseId(service.identifierSpace)) {
a.attr("href", "http://www.freebase.com/view" + candidate.id);
}
var preview = null;
if (service.preview) {
preview = service.preview;
} else if (ReconciliationManager.isFreebaseId(service.identifierSpace)) {
preview = DataTableCellUI.topicBlockPreview;
}
if (preview) {
a.click(function(evt) {
if (!evt.metaKey && !evt.ctrlKey) { if (!evt.metaKey && !evt.ctrlKey) {
self._previewCandidateTopic(candidate, this); self._previewCandidateTopic(candidate, this, preview);
evt.preventDefault(); evt.preventDefault();
return false; return false;
} }
}); });
}
}
var score; var score;
if (candidate.score < 1) { if (candidate.score < 1) {
@ -322,33 +348,20 @@ DataTableCellUI.prototype._postProcessSeveralCells = function(command, params, c
); );
}; };
DataTableCellUI.topicBlockParams = { DataTableCellUI.topicBlockPreview = {
"mode" : "content", url: 'http://www.freebase.com/widget/topic{{id}}?mode=content&blocks=[{"block":"full_info"},{"block":"article_props"}]',
"blocks" : JSON.stringify([
{
"block" : "full_info"
},
{
"block" : "article_props"
}
])
};
DataTableCellUI.topicBlockDimensions = {
width: 430, width: 430,
height: 300 height: 300
}; };
DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt) { DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt, preview) {
var self = this; var self = this;
var id = candidate.id; var id = candidate.id;
var url = preview.url.replace("{{id}}", id);
var render = function(id2) {
var url = "http://www.freebase.com/widget/topic" + id2 + '?' + $.param(DataTableCellUI.topicBlockParams);
var fakeMenu = MenuSystem.createMenu(); var fakeMenu = MenuSystem.createMenu();
fakeMenu fakeMenu
.width(DataTableCellUI.topicBlockDimensions.width) .width(preview.width)
.css("background", "none") .css("background", "none")
.css("border", "none") .css("border", "none")
.html( .html(
@ -360,8 +373,8 @@ DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt) {
var iframe = $('<iframe></iframe>') var iframe = $('<iframe></iframe>')
.addClass("data-table-topic-popup-iframe") .addClass("data-table-topic-popup-iframe")
.width(DataTableCellUI.topicBlockDimensions.width) .width(preview.width)
.height(DataTableCellUI.topicBlockDimensions.height) .height(preview.height)
.attr("src", url) .attr("src", url)
.appendTo(fakeMenu); .appendTo(fakeMenu);
@ -377,22 +390,6 @@ DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt) {
self._doMatchTopicToSimilarCells(candidate); self._doMatchTopicToSimilarCells(candidate);
MenuSystem.dismissAll(); MenuSystem.dismissAll();
}); });
};
if (id.indexOf("/guid/") !== 0) {
render(id);
} else {
Freebase.mqlread(
{
"guid" : "#" + id.substring(6),
"id" : null
},
null,
function(o) {
render(o.result.id);
}
);
}
}; };
DataTableCellUI.prototype._startEdit = function(elmt) { DataTableCellUI.prototype._startEdit = function(elmt) {

View File

@ -26,3 +26,19 @@ a.recon-dialog-service-selector.selected {
padding: 50px 0; padding: 50px 0;
color: #aaa; color: #aaa;
} }
a.recon-dialog-service-selector-remove {
float: right;
position: relative;
top: -5px;
left: 5px;
width: 16px;
height: 16px;
text-decoration: none;
background-image: url(../../images/close-map.png);
background-repeat: no-repeat;
background-position: 0px 0px;
}
a.recon-dialog-service-selector-remove:hover {
background-position: -16px 0px;
}