Delegated a lot of schema fetching to an acre app so our .js code can be less asynchronous.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@502 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-04-19 20:18:43 +00:00
parent 10e723cee4
commit b9bbff325e

View File

@ -104,50 +104,25 @@ SchemaAlignmentDialog.UILink.prototype._startEditProperty = function(elmt) {
var outgoing = []; var outgoing = [];
var incoming = []; var incoming = [];
function onDone() { function onDone(properties) {
dismissBusy(); dismissBusy();
var suggestions = SchemaAlignmentDialog.UILink._rankProperties(outgoing, incoming, sourceTypeID, targetTypeID, targetTypeName); self._showPropertySuggestPopup(
self._showPropertySuggestPopup(elmt, suggestions); elmt,
} SchemaAlignmentDialog.UILink._rankProperties(properties, sourceTypeID, targetTypeID, targetTypeName)
);
var cotypes = [];
function doCoTypes() {
if (cotypes.length === 0) {
onDone();
} else {
var cotype = cotypes.pop();
SchemaAlignmentDialog.UILink._getPropertiesOfType(
cotype.t,
outgoing,
incoming,
cotype.c / instanceCount,
doCoTypes
);
}
} }
SchemaAlignmentDialog.UILink._getPropertiesOfType( SchemaAlignmentDialog.UILink._getPropertiesOfType(
sourceTypeID, sourceTypeID,
outgoing, onDone
incoming,
1,
function(data) {
if ("result" in data) {
instanceCount = data.result.count;
if ("cotypes" in data.result) {
cotypes = data.result.cotypes.slice(0, 3);
}
}
doCoTypes();
}
); );
} else { } else {
this._showPropertySuggestPopup(elmt, []); this._showPropertySuggestPopup(elmt, []);
} }
}; };
SchemaAlignmentDialog.UILink._rankProperties = function(outgoing, incoming, sourceTypeID, targetTypeID, targetTypeName) { SchemaAlignmentDialog.UILink._rankProperties = function(properties, sourceTypeID, targetTypeID, targetTypeName) {
var nameScorer; var nameScorer;
if (targetTypeName === null) { if (targetTypeName === null) {
nameScorer = function() { return 1; }; nameScorer = function() { return 1; };
@ -173,15 +148,18 @@ SchemaAlignmentDialog.UILink._rankProperties = function(outgoing, incoming, sour
var score = nameScoreString(0, p.name); var score = nameScoreString(0, p.name);
score = nameScoreStrings(score, p.alias); score = nameScoreStrings(score, p.alias);
if ("name2" in p) {
score = nameScoreString(score, p.name2);
score = nameScoreStrings(score, p.alias2);
}
if ("expects" in p && p.expects !== null) { if ("expects" in p && p.expects !== null) {
score = nameScoreString(score, p.expects.name); score = nameScoreString(score, p.expects.name);
score = nameScoreStrings(score, p.expects.alias); score = nameScoreStrings(score, p.expects.alias);
if ("plural_names" in p.expects) { }
score = nameScoreStrings(score, p.expects.plural_names); if ("expects2" in p && p.expects2 !== null) {
} score = nameScoreString(score, p.expects2.name);
if ("plural_aliases" in p.expects) { score = nameScoreStrings(score, p.expects2.alias);
score = nameScoreStrings(score, p.expects.plural_aliases);
}
} }
return score; return score;
@ -198,12 +176,11 @@ SchemaAlignmentDialog.UILink._rankProperties = function(outgoing, incoming, sour
} }
var suggestions = []; var suggestions = [];
for (var i = 0; i < outgoing.length; i++) { for (var i = 0; i < properties.length; i++) {
var p = outgoing[i]; var p = properties[i];
p.score = p.weight * (0.5 * nameScorer(p) + 0.5 * typeScorer(p)); p.score = p.weight * (0.5 * nameScorer(p) + 0.5 * typeScorer(p));
if (p.score > 0) {
suggestions.push(p); suggestions.push(p);
}
} }
suggestions.sort(function(a, b) { return b.score - a.score; }); suggestions.sort(function(a, b) { return b.score - a.score; });
@ -212,32 +189,25 @@ SchemaAlignmentDialog.UILink._rankProperties = function(outgoing, incoming, sour
return suggestions; return suggestions;
}; };
SchemaAlignmentDialog.UILink._getPropertiesOfType = function(typeID, outgoing, incoming, weight, onDone) { SchemaAlignmentDialog.UILink._getPropertiesOfType = function(typeID, onDone) {
var done = false;
$.getJSON( $.getJSON(
"http://api.sandbox-freebase.com/api/trans/schema_index/-" + typeID + "?callback=?", "http://gridworks-helper.freebaseapps.com/get_properties_of_type?type=" + typeID + "&callback=?",
null, null,
function(data) { function(data) {
if ("result" in data) { if (done) return;
var result = data.result;
if ("outgoing" in result) { onDone(data.properties || []);
for (var i = 0; i < result.outgoing.length; i++) { }
var p = result.outgoing[i];
p.weight = weight;
outgoing.push(p);
}
}
if ("incoming" in result) {
for (var i = 0; i < result.incoming.length; i++) {
var p = result.incoming[i];
p.weight = weight;
incoming.push(p);
}
}
}
onDone(data);
},
"jsonp"
); );
window.setTimeout(function() {
if (done) return;
done = true;
onDone([]);
}, 7000); // time to give up?
}; };
SchemaAlignmentDialog.UILink.prototype._showPropertySuggestPopup = function(elmt, suggestions) { SchemaAlignmentDialog.UILink.prototype._showPropertySuggestPopup = function(elmt, suggestions) {
@ -248,17 +218,17 @@ SchemaAlignmentDialog.UILink.prototype._showPropertySuggestPopup = function(elmt
var commitProperty = function(p) { var commitProperty = function(p) {
window.setTimeout(function() { MenuSystem.dismissAll(); }, 100); window.setTimeout(function() { MenuSystem.dismissAll(); }, 100);
if ("plies" in p && p.plies.length > 1) { if ("id2" in p) {
// self._targetUI.dispose(); // self._targetUI.dispose();
self._link.property = { self._link.property = {
id: p.plies[0], id: p.id,
name: p.name name: p.name
}; };
self._link.target = { self._link.target = {
nodeType: "anonymous", nodeType: "anonymous",
links: [{ links: [{
property: { property: {
id: p.plies[1], id: p.id2,
name: p.name2 name: p.name2
}, },
target: self._link.target target: self._link.target