Fixed Issue 14: Limiting Freebase load to starred records

git-svn-id: http://google-refine.googlecode.com/svn/trunk@853 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-05-24 23:01:34 +00:00
parent 3ac3feb01f
commit d7f7d50e16
6 changed files with 62 additions and 13 deletions

View File

@ -15,8 +15,10 @@ Fixes:
- Issue 46: "Array literals in GEL"
- Issue 55: "Use stable sorting for text facets sorted by count"
- Issue 53: "Moving the cursor inside the Text Filter box by clicking"
- Issue 58: "Meta facet"
- Issue 58: "Meta facet"
Supported by the function facetCount()
- Issue 14: "Limiting Freebase load to starred records"
We load whatever rows that are filtered through, not particularly starred rows.
Features:
- Row/record sorting (Issue 32)

View File

@ -10,6 +10,8 @@ import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray;
import org.json.JSONObject;
import com.metaweb.gridworks.browsing.Engine;
import com.metaweb.gridworks.browsing.FilteredRows;
import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.protograph.Protograph;
@ -25,6 +27,8 @@ public class PreviewProtographCommand extends Command {
try {
Project project = getProject(request);
Engine engine = getEngine(request, project);
FilteredRows filteredRows = engine.getAllFilteredRows();
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
@ -40,7 +44,7 @@ public class PreviewProtographCommand extends Command {
StringWriter stringWriter = new StringWriter();
TripleLoaderTransposedNodeFactory nodeFactory = new TripleLoaderTransposedNodeFactory(stringWriter);
Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory);
Transposer.transpose(project, filteredRows, protograph, protograph.getRootNode(0), nodeFactory);
nodeFactory.flush();
sb.append("\"tripleloader\" : ");
@ -50,7 +54,7 @@ public class PreviewProtographCommand extends Command {
{
MqlreadLikeTransposedNodeFactory nodeFactory = new MqlreadLikeTransposedNodeFactory();
Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory);
Transposer.transpose(project, filteredRows, protograph, protograph.getRootNode(0), nodeFactory);
JSONArray results = nodeFactory.getJSON();

View File

@ -33,7 +33,7 @@ public class TripleloaderExporter implements Exporter {
TripleLoaderTransposedNodeFactory nodeFactory = new TripleLoaderTransposedNodeFactory(writer);
Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory, -1);
Transposer.transpose(project, engine.getAllFilteredRows(), protograph, protograph.getRootNode(0), nodeFactory, -1);
nodeFactory.flush();
}
}

View File

@ -3,6 +3,8 @@ package com.metaweb.gridworks.protograph.transpose;
import java.util.LinkedList;
import java.util.List;
import com.metaweb.gridworks.browsing.FilteredRows;
import com.metaweb.gridworks.browsing.RowVisitor;
import com.metaweb.gridworks.expr.ExpressionUtils;
import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Column;
@ -23,15 +25,17 @@ import com.metaweb.gridworks.protograph.ValueNode;
public class Transposer {
static public void transpose(
Project project,
FilteredRows filteredRows,
Protograph protograph,
Node rootNode,
TransposedNodeFactory nodeFactory
) {
transpose(project, protograph, rootNode, nodeFactory, 20);
transpose(project, filteredRows, protograph, rootNode, nodeFactory, 20);
}
static public void transpose(
Project project,
FilteredRows filteredRows,
Protograph protograph,
Node rootNode,
TransposedNodeFactory nodeFactory,
@ -39,12 +43,50 @@ public class Transposer {
) {
Context rootContext = new Context(rootNode, null, null, limit);
for (Row row : project.rows) {
descend(project, protograph, nodeFactory, row, rootNode, rootContext);
if (rootContext.limit > 0 && rootContext.count > rootContext.limit) {
break;
}
}
filteredRows.accept(project, new RowVisitor() {
Context rootContext;
Protograph protograph;
Node rootNode;
TransposedNodeFactory nodeFactory;
@Override
public boolean visit(Project project, int rowIndex, Row row) {
if (rootContext.limit <= 0 || rootContext.count < rootContext.limit) {
descend(project, protograph, nodeFactory, row, rootNode, rootContext);
}
if (rootContext.limit > 0 && rootContext.count > rootContext.limit) {
return true;
}
return false;
}
@Override
public void start(Project project) {
// TODO Auto-generated method stub
}
@Override
public void end(Project project) {
// TODO Auto-generated method stub
}
public RowVisitor init(
Context rootContext,
Protograph protograph,
Node rootNode,
TransposedNodeFactory nodeFactory
) {
this.rootContext = rootContext;
this.protograph = protograph;
this.rootNode = rootNode;
this.nodeFactory = nodeFactory;
return this;
}
}.init(rootContext, protograph, rootNode, nodeFactory));
}
static protected void descend(

View File

@ -118,7 +118,7 @@ FreebaseLoadingDialog.prototype._createDialog = function() {
var show_triples = function(cont) {
$.post(
"/command/preview-protograph?" + $.param({ project: theProject.id }),
{ protograph: JSON.stringify(theProject.protograph) },
{ protograph: JSON.stringify(theProject.protograph), engine: JSON.stringify(ui.browsingEngine.getJSON()) },
function(data) {
if ("tripleloader" in data) {
body.html(
@ -192,6 +192,7 @@ FreebaseLoadingDialog.prototype._load = function() {
{
project: theProject.id,
"graph" : (freebase) ? "otg" : "sandbox",
"engine" : JSON.stringify(ui.browsingEngine.getJSON()),
"source_name" : self._elmts.source_name.val(),
"source_id" : self._elmts.source_id.val()
},

View File

@ -257,7 +257,7 @@ SchemaAlignmentDialog.prototype.preview = function() {
var protograph = this.getJSON();
$.post(
"/command/preview-protograph?" + $.param({ project: theProject.id }),
{ protograph: JSON.stringify(protograph) },
{ protograph: JSON.stringify(protograph), engine: JSON.stringify(ui.browsingEngine.getJSON()) },
function(data) {
if ("mqllike" in data) {
$(self._previewPanes[0]).text(JSON.stringify(data.mqllike, null, 2));