We can now suggest CVT properties.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@300 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
c30a5126df
commit
2645c864ab
@ -48,36 +48,37 @@ function ExtendDataPreviewDialog(column, rowIndices, onDone) {
|
|||||||
|
|
||||||
ExtendDataPreviewDialog.getAllProperties = function(typeID, onDone) {
|
ExtendDataPreviewDialog.getAllProperties = function(typeID, onDone) {
|
||||||
var query = {
|
var query = {
|
||||||
id : typeID,
|
"id" : typeID,
|
||||||
type : "/type/type",
|
"type" : "/type/type",
|
||||||
"/freebase/type_hints/included_types" : [{
|
"/freebase/type_hints/included_types" : [{
|
||||||
optional: true,
|
"optional" : true,
|
||||||
properties : [{
|
"properties" : [{
|
||||||
id : null,
|
"id" : null,
|
||||||
name : null,
|
"name" : null,
|
||||||
"/type/property/expected_type" : {
|
"/type/property/expected_type" : {
|
||||||
id : null,
|
"id" : null,
|
||||||
"/freebase/type_hints/mediator" : []
|
"/freebase/type_hints/mediator" : []
|
||||||
},
|
},
|
||||||
sort : "name"
|
"sort" : "name"
|
||||||
}]
|
}]
|
||||||
}],
|
}],
|
||||||
properties : [{
|
"properties" : [{
|
||||||
id : null,
|
"id" : null,
|
||||||
name : null,
|
"name" : null,
|
||||||
"/type/property/expected_type" : {
|
"/type/property/expected_type" : {
|
||||||
id : null,
|
"id" : null,
|
||||||
"/freebase/type_hints/mediator" : []
|
"/freebase/type_hints/mediator" : []
|
||||||
},
|
},
|
||||||
sort : "name"
|
"sort" : "name"
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
var allProperties = [];
|
var allProperties = [];
|
||||||
var processProperty = function(property) {
|
var cvtProperties = [];
|
||||||
|
var processProperty = function(property, parent) {
|
||||||
var expectedType = property["/type/property/expected_type"];
|
var expectedType = property["/type/property/expected_type"];
|
||||||
if (expectedType["/freebase/type_hints/mediator"].length > 0 && expectedType["/freebase/type_hints/mediator"][0]) {
|
if (expectedType["/freebase/type_hints/mediator"].length > 0 && expectedType["/freebase/type_hints/mediator"][0]) {
|
||||||
|
cvtProperties.push(property);
|
||||||
} else {
|
} else {
|
||||||
allProperties.push({
|
allProperties.push({
|
||||||
id : property.id,
|
id : property.id,
|
||||||
@ -86,24 +87,88 @@ ExtendDataPreviewDialog.getAllProperties = function(typeID, onDone) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var processProperties = function(properties) {
|
var processProperties = function(properties, parent) {
|
||||||
$.each(properties, function() { processProperty(this); });
|
$.each(properties, function() { processProperty(this, parent); });
|
||||||
};
|
};
|
||||||
|
|
||||||
$.getJSON(
|
$.getJSON(
|
||||||
"http://api.freebase.com/api/service/mqlread?query=" + escape(JSON.stringify({ query : query })) + "&callback=?",
|
"http://api.freebase.com/api/service/mqlread?query=" + escape(JSON.stringify({ query : query })) + "&callback=?",
|
||||||
null,
|
null,
|
||||||
function(o) {
|
function(o) {
|
||||||
if ("result" in o) {
|
if (!("result" in o)) {
|
||||||
|
onDone([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
processProperties(o.result.properties);
|
processProperties(o.result.properties);
|
||||||
$.each(o.result["/freebase/type_hints/included_types"], function() {
|
$.each(o.result["/freebase/type_hints/included_types"], function() {
|
||||||
processProperties(this.properties);
|
processProperties(this.properties, null);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (cvtProperties.length == 0) {
|
||||||
onDone(allProperties);
|
onDone(allProperties);
|
||||||
} else {
|
return;
|
||||||
onDone([]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var expectedTypeToProperties = [];
|
||||||
|
var expectedTypeIDs = [];
|
||||||
|
$.each(cvtProperties, function() {
|
||||||
|
var expected = this["/type/property/expected_type"];
|
||||||
|
if (expected.id in expectedTypeToProperties) {
|
||||||
|
expectedTypeToProperties[expected.id].push(this);
|
||||||
|
} else {
|
||||||
|
expectedTypeToProperties[expected.id] = [ this ];
|
||||||
|
expectedTypeIDs.push(expected.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var query2 = [{
|
||||||
|
"id|=" : expectedTypeIDs,
|
||||||
|
"id" : null,
|
||||||
|
"type" : "/type/type",
|
||||||
|
"properties" : [{
|
||||||
|
"id" : null,
|
||||||
|
"name" : null,
|
||||||
|
"/type/property/expected_type" : {
|
||||||
|
id : null,
|
||||||
|
"/freebase/type_hints/mediator" : []
|
||||||
|
},
|
||||||
|
"sort" : "name"
|
||||||
|
}]
|
||||||
|
}];
|
||||||
|
|
||||||
|
$.getJSON(
|
||||||
|
"http://api.freebase.com/api/service/mqlread?query=" + escape(JSON.stringify({ query : query2 })) + "&callback=?",
|
||||||
|
null,
|
||||||
|
function(o2) {
|
||||||
|
if ("result" in o2) {
|
||||||
|
var processCVTProperty = function(parentProperty, properties) {
|
||||||
|
$.each(properties, function() {
|
||||||
|
allProperties.push({
|
||||||
|
id : parentProperty.id,
|
||||||
|
name : parentProperty.name,
|
||||||
|
expected : parentProperty["/type/property/expected_type"].id,
|
||||||
|
properties: [{
|
||||||
|
id : this.id,
|
||||||
|
name : this.name,
|
||||||
|
expected : this["/type/property/expected_type"].id
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var processCVTProperties = function(parentProperties, properties) {
|
||||||
|
$.each(parentProperties, function() { processCVTProperty(this, properties); });
|
||||||
|
};
|
||||||
|
|
||||||
|
$.each(o2.result, function() {
|
||||||
|
processCVTProperties(expectedTypeToProperties[this.id], this.properties);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onDone(allProperties);
|
||||||
|
},
|
||||||
|
"jsonp"
|
||||||
|
);
|
||||||
},
|
},
|
||||||
"jsonp"
|
"jsonp"
|
||||||
);
|
);
|
||||||
@ -115,8 +180,10 @@ ExtendDataPreviewDialog.prototype._show = function(properties) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var container = this._elmts.suggestedPropertyContainer;
|
var container = this._elmts.suggestedPropertyContainer;
|
||||||
var renderSuggestedProperty = function(property) {
|
var renderSuggestedProperty = function(property) {
|
||||||
|
var label = ("properties" in property) ? (property.name + " » " + property.properties[0].name) : property.name;
|
||||||
var div = $('<div>').addClass("suggested-property").appendTo(container);
|
var div = $('<div>').addClass("suggested-property").appendTo(container);
|
||||||
$('<a>').attr("href", "javascript:{}").text(property.name).appendTo(div).click(function() {
|
|
||||||
|
$('<a>').attr("href", "javascript:{}").html(label).appendTo(div).click(function() {
|
||||||
self._addProperty(property);
|
self._addProperty(property);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -236,8 +303,7 @@ ExtendDataPreviewDialog.prototype._renderPreview = function(data) {
|
|||||||
var trHead = table.insertRow(table.rows.length);
|
var trHead = table.insertRow(table.rows.length);
|
||||||
$('<th>').appendTo(trHead).text(this._column.name);
|
$('<th>').appendTo(trHead).text(this._column.name);
|
||||||
|
|
||||||
for (var c = 0; c < data.columns.length; c++) {
|
var renderColumnHeader = function(column) {
|
||||||
var column = data.columns[c];
|
|
||||||
var th = $('<th>').appendTo(trHead);
|
var th = $('<th>').appendTo(trHead);
|
||||||
|
|
||||||
$('<span>').html(column.names.join(" » ")).appendTo(th);
|
$('<span>').html(column.names.join(" » ")).appendTo(th);
|
||||||
@ -247,6 +313,9 @@ ExtendDataPreviewDialog.prototype._renderPreview = function(data) {
|
|||||||
.click(function() {
|
.click(function() {
|
||||||
self._removeProperty(column.path);
|
self._removeProperty(column.path);
|
||||||
}).appendTo(th);
|
}).appendTo(th);
|
||||||
|
};
|
||||||
|
for (var c = 0; c < data.columns.length; c++) {
|
||||||
|
renderColumnHeader(data.columns[c]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var r = 0; r < data.rows.length; r++) {
|
for (var r = 0; r < data.rows.length; r++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user