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);
});
$('<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);
};

View File

@ -1,6 +1,25 @@
var ReconciliationManager = {
"customServices" : [], // services registered by core and extensions
"standardServices" : [] // services registered by user
customServices : [], // services registered by core and extensions
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() {
@ -9,6 +28,7 @@ ReconciliationManager.getAllServices = function() {
ReconciliationManager.registerService = function(service) {
ReconciliationManager.customServices.push(service);
ReconciliationManager._rebuildMap();
return ReconciliationManager.customServices.length - 1;
};
@ -25,6 +45,8 @@ ReconciliationManager.registerStandardService = function(url, f) {
ReconciliationManager.standardServices.length;
ReconciliationManager.standardServices.push(data);
ReconciliationManager._rebuildMap();
ReconciliationManager.save();
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) {
$.ajax({
async: false,
@ -64,6 +102,7 @@ ReconciliationManager.save = function(f) {
success: function(data) {
if (data.value && data.value != "null") {
ReconciliationManager.standardServices = JSON.parse(data.value);
ReconciliationManager._rebuildMap();
} else {
ReconciliationManager.registerStandardService(
"http://standard-reconcile.dfhuynh.user.dev.freebaseapps.com/reconcile");

View File

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

View File

@ -49,6 +49,8 @@ DataTableCellUI.prototype._render = function() {
}
} else {
var r = cell.r;
var service = (r.service) ? ReconciliationManager.getServiceFromUrl(r.service) : null;
if (r.j == "new") {
$('<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) {
var match = cell.r.m;
$('<a></a>')
var a = $('<a></a>')
.text(match.name)
.attr("href", "http://www.freebase.com/view" + match.id)
.attr("target", "_blank")
.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);
$('<a href="javascript:{}"></a>')
.text("re\u2011match")
@ -98,19 +107,36 @@ DataTableCellUI.prototype._render = function() {
self._doMatchTopicToOneCell(candidate);
});
$('<a></a>')
var a = $('<a></a>')
.addClass("data-table-recon-topic")
.attr("href", "http://www.freebase.com/view" + candidate.id)
.attr("target", "_blank")
.text(candidate.name)
.appendTo(li)
.click(function(evt) {
if (!evt.metaKey && !evt.ctrlKey) {
self._previewCandidateTopic(candidate, this);
evt.preventDefault();
return false;
}
});
.appendTo(li);
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) {
self._previewCandidateTopic(candidate, this, preview);
evt.preventDefault();
return false;
}
});
}
}
var score;
if (candidate.score < 1) {
@ -322,77 +348,48 @@ DataTableCellUI.prototype._postProcessSeveralCells = function(command, params, c
);
};
DataTableCellUI.topicBlockParams = {
"mode" : "content",
"blocks" : JSON.stringify([
{
"block" : "full_info"
},
{
"block" : "article_props"
}
])
};
DataTableCellUI.topicBlockDimensions = {
DataTableCellUI.topicBlockPreview = {
url: 'http://www.freebase.com/widget/topic{{id}}?mode=content&blocks=[{"block":"full_info"},{"block":"article_props"}]',
width: 430,
height: 300
};
DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt) {
DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt, preview) {
var self = this;
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();
fakeMenu
.width(DataTableCellUI.topicBlockDimensions.width)
.css("background", "none")
.css("border", "none")
.html(
'<div class="data-table-topic-popup-header">' +
'<button title="Match topic to this cell" bind="matchButton">Match</button> ' +
'<button title="Match topic to all visible cells with same content" bind="matchSimilarButton">Match Similar</button>' +
'</div>'
);
var iframe = $('<iframe></iframe>')
.addClass("data-table-topic-popup-iframe")
.width(DataTableCellUI.topicBlockDimensions.width)
.height(DataTableCellUI.topicBlockDimensions.height)
.attr("src", url)
.appendTo(fakeMenu);
MenuSystem.showMenu(fakeMenu, function(){});
MenuSystem.positionMenuLeftRight(fakeMenu, $(elmt));
var elmts = DOM.bind(fakeMenu);
elmts.matchButton.click(function() {
self._doMatchTopicToOneCell(candidate);
MenuSystem.dismissAll();
});
elmts.matchSimilarButton.click(function() {
self._doMatchTopicToSimilarCells(candidate);
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);
}
var fakeMenu = MenuSystem.createMenu();
fakeMenu
.width(preview.width)
.css("background", "none")
.css("border", "none")
.html(
'<div class="data-table-topic-popup-header">' +
'<button title="Match topic to this cell" bind="matchButton">Match</button> ' +
'<button title="Match topic to all visible cells with same content" bind="matchSimilarButton">Match Similar</button>' +
'</div>'
);
}
var iframe = $('<iframe></iframe>')
.addClass("data-table-topic-popup-iframe")
.width(preview.width)
.height(preview.height)
.attr("src", url)
.appendTo(fakeMenu);
MenuSystem.showMenu(fakeMenu, function(){});
MenuSystem.positionMenuLeftRight(fakeMenu, $(elmt));
var elmts = DOM.bind(fakeMenu);
elmts.matchButton.click(function() {
self._doMatchTopicToOneCell(candidate);
MenuSystem.dismissAll();
});
elmts.matchSimilarButton.click(function() {
self._doMatchTopicToSimilarCells(candidate);
MenuSystem.dismissAll();
});
};
DataTableCellUI.prototype._startEdit = function(elmt) {

View File

@ -26,3 +26,19 @@ a.recon-dialog-service-selector.selected {
padding: 50px 0;
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;
}