03d997be8e
http://code.google.com/p/google-refine/issues/detail?id=576 git-svn-id: http://google-refine.googlecode.com/svn/trunk@2584 7d457c2a-affb-35e4-300a-418c747d4874
165 lines
5.2 KiB
JavaScript
165 lines
5.2 KiB
JavaScript
/*
|
|
|
|
Copyright 2010, Google Inc.
|
|
All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions are
|
|
met:
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
* Redistributions in binary form must reproduce the above
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
in the documentation and/or other materials provided with the
|
|
distribution.
|
|
* Neither the name of Google Inc. nor the names of its
|
|
contributors may be used to endorse or promote products derived from
|
|
this software without specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
var ReconciliationManager = {
|
|
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.isFreebaseMid = function(s) {
|
|
return s == "http://rdf.freebase.com/ns/type.object.mid";
|
|
};
|
|
|
|
ReconciliationManager.isFreebaseIdOrMid = function(s) {
|
|
return ReconciliationManager.isFreebaseMid(s) || ReconciliationManager.isFreebaseId(s);
|
|
};
|
|
|
|
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() {
|
|
return ReconciliationManager.customServices.concat(ReconciliationManager.standardServices);
|
|
};
|
|
|
|
ReconciliationManager.registerService = function(service) {
|
|
ReconciliationManager.customServices.push(service);
|
|
ReconciliationManager._rebuildMap();
|
|
|
|
return ReconciliationManager.customServices.length - 1;
|
|
};
|
|
|
|
ReconciliationManager.registerStandardService = function(url, f) {
|
|
var dismissBusy = DialogSystem.showBusy("Contacting reconciliation service...");
|
|
|
|
$.ajax(
|
|
url,
|
|
{ "dataType" : "jsonp",
|
|
"timeout":10000
|
|
}
|
|
)
|
|
.success(function(data, textStatus, jqXHR) {
|
|
data.url = url;
|
|
data.ui = { "handler" : "ReconStandardServicePanel" };
|
|
|
|
index = ReconciliationManager.customServices.length +
|
|
ReconciliationManager.standardServices.length;
|
|
|
|
ReconciliationManager.standardServices.push(data);
|
|
ReconciliationManager._rebuildMap();
|
|
|
|
ReconciliationManager.save();
|
|
|
|
dismissBusy();
|
|
|
|
if (f) {
|
|
f(index);
|
|
}
|
|
})
|
|
.error(function(jqXHR, textStatus, errorThrown) {
|
|
dismissBusy();
|
|
alert('Error contacting recon service: ' + textStatus + ' : ' + errorThrown + ' - ' + url);
|
|
});
|
|
};
|
|
|
|
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._rebuildMap();
|
|
ReconciliationManager.save(f);
|
|
};
|
|
|
|
ReconciliationManager.save = function(f) {
|
|
$.ajax({
|
|
async: false,
|
|
type: "POST",
|
|
url: "command/core/set-preference?" + $.param({
|
|
name: "reconciliation.standardServices"
|
|
}),
|
|
data: { "value" : JSON.stringify(ReconciliationManager.standardServices) },
|
|
success: function(data) {
|
|
if (f) { f(); }
|
|
},
|
|
dataType: "json"
|
|
});
|
|
};
|
|
|
|
(function() {
|
|
ReconciliationManager.customServices.push({
|
|
"name" : "Freebase Query-based Reconciliation",
|
|
"ui" : { "handler" : "ReconFreebaseQueryPanel" }
|
|
});
|
|
|
|
$.ajax({
|
|
async: false,
|
|
url: "command/core/get-preference?" + $.param({
|
|
name: "reconciliation.standardServices"
|
|
}),
|
|
success: function(data) {
|
|
if (data.value && data.value != "null") {
|
|
ReconciliationManager.standardServices = JSON.parse(data.value);
|
|
ReconciliationManager._rebuildMap();
|
|
} else {
|
|
ReconciliationManager.registerStandardService(
|
|
"http://4.standard-reconcile.dfhuynh.user.dev.freebaseapps.com/reconcile");
|
|
}
|
|
},
|
|
dataType: "json"
|
|
});
|
|
})();
|