Renamed "freebase-extension" to just "freebase".

Tried to validate literal values when generating freeq triples (e.g., so numeric years get converted into strings for /type/datetime properties).

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1562 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-10-15 07:33:34 +00:00
parent 6686a48804
commit e251a77077
6 changed files with 90 additions and 31 deletions

View File

@ -1,4 +1,4 @@
name = freebase-extension
name = freebase
description = Google Refine Freebase Extension
templating = false
requires = core

View File

@ -6,7 +6,7 @@ function ExtendDataPreviewDialog(column, columnIndex, rowIndices, onDone) {
this._extension = { properties: [] };
var self = this;
this._dialog = $(DOM.loadHTML("freebase-extension", "scripts/dialogs/extend-data-preview-dialog.html"));
this._dialog = $(DOM.loadHTML("freebase", "scripts/dialogs/extend-data-preview-dialog.html"));
this._elmts = DOM.bind(this._dialog);
this._elmts.dialogHeader.text("Add Columns from Freebase Based on Column " + column.name);
this._elmts.resetButton.click(function() {
@ -135,7 +135,7 @@ ExtendDataPreviewDialog.prototype._update = function() {
};
$.post(
"/command/freebase-extension/preview-extend-data?" + $.param(params),
"/command/freebase/preview-extend-data?" + $.param(params),
{
rowIndices: JSON.stringify(this._rowIndices),
extension: JSON.stringify(this._extension)

View File

@ -5,7 +5,7 @@ function FreebaseLoadingDialog() {
FreebaseLoadingDialog.prototype._createDialog = function() {
var self = this;
var dialog = $(DOM.loadHTML("freebase-extension", "scripts/dialogs/freebase-loading-dialog.html"));
var dialog = $(DOM.loadHTML("freebase", "scripts/dialogs/freebase-loading-dialog.html"));
this._elmts = DOM.bind(dialog);
this._elmts.cancelButton.click(function() { self._dismiss(); });
@ -14,7 +14,7 @@ FreebaseLoadingDialog.prototype._createDialog = function() {
var loadButton = this._elmts.loadButton;
var check_authorization = function(cont) {
$.get("/command/freebase-extension/check-authorization/" + provider, function(data) {
$.get("/command/freebase/check-authorization/" + provider, function(data) {
if ("status" in data && data.code == "/api/status/ok") {
authorization.html('Signed in as: <a target="_new" href="http://www.freebase.com/view/user/' + data.username + '">' + data.username + '</a> | <a href="javascript:{}" bind="signout">Sign Out</a>').show();
DOM.bind(authorization).signout.click(function() {
@ -50,7 +50,7 @@ FreebaseLoadingDialog.prototype._createDialog = function() {
"guid": null
}];
$.post("/command/freebase-extension/mqlwrite/" + provider,
$.post("/command/freebase/mqlwrite/" + provider,
{ "query" : JSON.stringify(mql_query) },
function(data) {
if ("status" in data && data.code == "/api/status/ok") {
@ -66,7 +66,7 @@ FreebaseLoadingDialog.prototype._createDialog = function() {
var show_triples = function(cont) {
$.post(
"/command/freebase-extension/preview-protograph?" + $.param({ project: theProject.id }),
"/command/freebase/preview-protograph?" + $.param({ project: theProject.id }),
{
protograph: JSON.stringify(theProject.overlayModels.freebaseProtograph || {}),
engine: JSON.stringify(ui.browsingEngine.getJSON())
@ -143,7 +143,7 @@ FreebaseLoadingDialog.prototype._load = function() {
var doLoad = function() {
var dismissBusy = DialogSystem.showBusy();
$.post("/command/freebase-extension/upload-data",
$.post("/command/freebase/upload-data",
{
project: theProject.id,
"qa" : qa,

View File

@ -170,7 +170,7 @@ SchemaAlignmentDialog.prototype._constructFooter = function(footer) {
var protograph = self.getJSON();
Refine.postProcess(
"freebase-extension",
"freebase",
"save-protograph",
{},
{ protograph: JSON.stringify(protograph) },
@ -264,7 +264,7 @@ SchemaAlignmentDialog.prototype.preview = function() {
var protograph = this.getJSON();
$.post(
"/command/freebase-extension/preview-protograph?" + $.param({ project: theProject.id }),
"/command/freebase/preview-protograph?" + $.param({ project: theProject.id }),
{ protograph: JSON.stringify(protograph), engine: JSON.stringify(ui.browsingEngine.getJSON()) },
function(data) {
if ("mqllike" in data) {

View File

@ -36,12 +36,12 @@ public class SaveProtographOperation extends AbstractOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription());
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("protograph"); _protograph.write(writer, options);
writer.endObject();
}
protected String getBriefDescription() {
protected String getBriefDescription(Project project) {
return "Save schema alignment skeleton";
}
@ -49,7 +49,7 @@ public class SaveProtographOperation extends AbstractOperation {
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
Change change = new ProtographChange(_protograph);
return new HistoryEntry(historyEntryID, project, getBriefDescription(), SaveProtographOperation.this, change);
return new HistoryEntry(historyEntryID, project, getBriefDescription(project), SaveProtographOperation.this, change);
}
static public class ProtographChange implements Change {

View File

@ -195,7 +195,7 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
sb.append("{ \"s\" : \""); sb.append(subject); sb.append('"');
sb.append(", \"p\" : \""); sb.append(predicate); sb.append('"');
sb.append(", \"o\" : "); sb.append(s);
sb.append(", \"lang\" : "); sb.append(lang);
sb.append(", \"lang\" : \""); sb.append(lang); sb.append('"');
if (subjectCell != null) {
sb.append(", \"meta\" : { ");
@ -409,18 +409,25 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
}
public Object internalWrite(String subject, String predicate, Project project, int subjectRowIndex, int subjectCellIndex, Cell subjectCell) {
Object value = cell.value;
if (value != null) {
if ("/type/text".equals(node.valueType)) {
value = value.toString();
if (subject != null) {
if ("/type/text".equals(node.lang)) {
writeLine(subject, predicate, cell.value, node.lang, project,
writeLine(subject, predicate, value, node.lang, project,
subjectRowIndex, subjectCellIndex, subjectCell, !load);
}
} else {
writeLine(subject, predicate, cell.value, project,
value = validateValue(value, node.valueType);
if (subject != null && value != null) {
writeLine(subject, predicate, value, project,
subjectRowIndex, subjectCellIndex, subjectCell,
-1, -1, null, !load);
}
}
}
return cell.value;
return value;
}
}
@ -472,16 +479,24 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
}
public Object internalWrite(String subject, String predicate, Project project, int subjectRowIndex, int subjectCellIndex, Cell subjectCell) {
if ("/type/text".equals(node.lang)) {
writeLine(subject, predicate, node.value, node.lang, project,
Object value = node.value;
if (value != null) {
if ("/type/text".equals(node.valueType)) {
value = value.toString();
if (subject != null) {
writeLine(subject, predicate, value, node.lang, project,
subjectRowIndex, subjectCellIndex, subjectCell, !load);
}
} else {
writeLine(subject, predicate, node.value, project,
value = validateValue(value, node.valueType);
if (subject != null && value != null) {
writeLine(subject, predicate, value, project,
subjectRowIndex, subjectCellIndex, subjectCell,
-1, -1, null, !load);
}
return node.value;
}
}
return value;
}
}
@ -722,4 +737,48 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
writeLine(sb.toString());
}
}
static protected Object validateValue(Object value, String valueType) {
if ("/type/datetime".equals(valueType)) {
if (!(value instanceof String)) {
value = value.toString();
}
} else if ("/type/boolean".equals(valueType)) {
if (!(value instanceof Boolean)) {
value = Boolean.parseBoolean(value.toString());
}
} else if ("/type/int".equals(valueType)) {
if (value instanceof Number) {
value = ((Number) value).longValue();
} else {
try {
value = Long.parseLong(value.toString());
} catch (NumberFormatException e) {
value = null;
}
}
} else if ("/type/float".equals(valueType)) {
if (value instanceof Number) {
value = ((Number) value).floatValue();
} else {
try {
value = Float.parseFloat(value.toString());
} catch (NumberFormatException e) {
value = null;
}
}
} else if ("/type/double".equals(valueType)) {
if (value instanceof Number) {
value = ((Number) value).doubleValue();
} else {
try {
value = Double.parseDouble(value.toString());
} catch (NumberFormatException e) {
value = null;
}
}
}
return value;
}
}