Added mqlwrite exporter.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@854 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
d7f7d50e16
commit
638eb4ac24
@ -23,6 +23,7 @@ Fixes:
|
|||||||
Features:
|
Features:
|
||||||
- Row/record sorting (Issue 32)
|
- Row/record sorting (Issue 32)
|
||||||
- CSV exporting (Issue 59)
|
- CSV exporting (Issue 59)
|
||||||
|
- Mqlwrite exporting
|
||||||
|
|
||||||
Changes:
|
Changes:
|
||||||
- Moved unit tests from JUnit to TestNG
|
- Moved unit tests from JUnit to TestNG
|
||||||
|
@ -7,7 +7,6 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
@ -15,7 +14,7 @@ import com.metaweb.gridworks.browsing.FilteredRows;
|
|||||||
import com.metaweb.gridworks.commands.Command;
|
import com.metaweb.gridworks.commands.Command;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
import com.metaweb.gridworks.protograph.Protograph;
|
import com.metaweb.gridworks.protograph.Protograph;
|
||||||
import com.metaweb.gridworks.protograph.transpose.MqlreadLikeTransposedNodeFactory;
|
import com.metaweb.gridworks.protograph.transpose.MqlwriteLikeTransposedNodeFactory;
|
||||||
import com.metaweb.gridworks.protograph.transpose.Transposer;
|
import com.metaweb.gridworks.protograph.transpose.Transposer;
|
||||||
import com.metaweb.gridworks.protograph.transpose.TripleLoaderTransposedNodeFactory;
|
import com.metaweb.gridworks.protograph.transpose.TripleLoaderTransposedNodeFactory;
|
||||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||||
@ -52,14 +51,14 @@ public class PreviewProtographCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
MqlreadLikeTransposedNodeFactory nodeFactory = new MqlreadLikeTransposedNodeFactory();
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
MqlwriteLikeTransposedNodeFactory nodeFactory = new MqlwriteLikeTransposedNodeFactory(stringWriter);
|
||||||
|
|
||||||
Transposer.transpose(project, filteredRows, protograph, protograph.getRootNode(0), nodeFactory);
|
Transposer.transpose(project, filteredRows, protograph, protograph.getRootNode(0), nodeFactory);
|
||||||
|
nodeFactory.flush();
|
||||||
JSONArray results = nodeFactory.getJSON();
|
|
||||||
|
|
||||||
sb.append(", \"mqllike\" : ");
|
sb.append(", \"mqllike\" : ");
|
||||||
sb.append(results.toString());
|
sb.append(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(" }");
|
sb.append(" }");
|
||||||
|
@ -14,7 +14,7 @@ import org.json.JSONObject;
|
|||||||
import com.metaweb.gridworks.ProjectManager;
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.commands.Command;
|
import com.metaweb.gridworks.commands.Command;
|
||||||
import com.metaweb.gridworks.exporters.TripleloaderExporter;
|
import com.metaweb.gridworks.exporters.ProtographTransposeExporter.TripleLoaderExporter;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
import com.metaweb.gridworks.util.FreebaseUtils;
|
import com.metaweb.gridworks.util.FreebaseUtils;
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ public class UploadDataCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
Project project = getProject(request);
|
Project project = getProject(request);
|
||||||
Engine engine = getEngine(request, project);
|
Engine engine = getEngine(request, project);
|
||||||
TripleloaderExporter exporter = new TripleloaderExporter();
|
TripleLoaderExporter exporter = new TripleLoaderExporter();
|
||||||
StringWriter triples = new StringWriter(10 * 1024 * 1024);
|
StringWriter triples = new StringWriter(10 * 1024 * 1024);
|
||||||
exporter.export(project, new Properties(), engine, triples);
|
exporter.export(project, new Properties(), engine, triples);
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@ import com.metaweb.gridworks.commands.Command;
|
|||||||
import com.metaweb.gridworks.exporters.CsvExporter;
|
import com.metaweb.gridworks.exporters.CsvExporter;
|
||||||
import com.metaweb.gridworks.exporters.Exporter;
|
import com.metaweb.gridworks.exporters.Exporter;
|
||||||
import com.metaweb.gridworks.exporters.HtmlTableExporter;
|
import com.metaweb.gridworks.exporters.HtmlTableExporter;
|
||||||
import com.metaweb.gridworks.exporters.TripleloaderExporter;
|
import com.metaweb.gridworks.exporters.ProtographTransposeExporter.TripleLoaderExporter;
|
||||||
|
import com.metaweb.gridworks.exporters.ProtographTransposeExporter.MqlwriteLikeExporter;
|
||||||
import com.metaweb.gridworks.exporters.TsvExporter;
|
import com.metaweb.gridworks.exporters.TsvExporter;
|
||||||
import com.metaweb.gridworks.exporters.XlsExporter;
|
import com.metaweb.gridworks.exporters.XlsExporter;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
@ -26,10 +27,11 @@ public class ExportRowsCommand extends Command {
|
|||||||
static final protected Map<String, Exporter> s_formatToExporter = new HashMap<String, Exporter>();
|
static final protected Map<String, Exporter> s_formatToExporter = new HashMap<String, Exporter>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
s_formatToExporter.put("tripleloader", new TripleloaderExporter());
|
|
||||||
s_formatToExporter.put("html", new HtmlTableExporter());
|
s_formatToExporter.put("html", new HtmlTableExporter());
|
||||||
s_formatToExporter.put("xls", new XlsExporter());
|
s_formatToExporter.put("xls", new XlsExporter());
|
||||||
s_formatToExporter.put("csv", new CsvExporter());
|
s_formatToExporter.put("csv", new CsvExporter());
|
||||||
|
s_formatToExporter.put("tripleloader", new TripleLoaderExporter());
|
||||||
|
s_formatToExporter.put("mqlwrite", new MqlwriteLikeExporter());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
@ -8,10 +8,18 @@ import java.util.Properties;
|
|||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
import com.metaweb.gridworks.protograph.Protograph;
|
import com.metaweb.gridworks.protograph.Protograph;
|
||||||
|
import com.metaweb.gridworks.protograph.transpose.MqlwriteLikeTransposedNodeFactory;
|
||||||
|
import com.metaweb.gridworks.protograph.transpose.TransposedNodeFactory;
|
||||||
import com.metaweb.gridworks.protograph.transpose.Transposer;
|
import com.metaweb.gridworks.protograph.transpose.Transposer;
|
||||||
import com.metaweb.gridworks.protograph.transpose.TripleLoaderTransposedNodeFactory;
|
import com.metaweb.gridworks.protograph.transpose.TripleLoaderTransposedNodeFactory;
|
||||||
|
|
||||||
public class TripleloaderExporter implements Exporter {
|
abstract public class ProtographTransposeExporter implements Exporter {
|
||||||
|
final protected String _contentType;
|
||||||
|
|
||||||
|
public ProtographTransposeExporter(String contentType) {
|
||||||
|
_contentType = contentType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getContentType() {
|
public String getContentType() {
|
||||||
return "application/x-unknown";
|
return "application/x-unknown";
|
||||||
}
|
}
|
||||||
@ -31,11 +39,36 @@ public class TripleloaderExporter implements Exporter {
|
|||||||
if (project.protograph != null) {
|
if (project.protograph != null) {
|
||||||
Protograph protograph = project.protograph;
|
Protograph protograph = project.protograph;
|
||||||
|
|
||||||
TripleLoaderTransposedNodeFactory nodeFactory = new TripleLoaderTransposedNodeFactory(writer);
|
TransposedNodeFactory nodeFactory = createNodeFactory(writer);
|
||||||
|
|
||||||
Transposer.transpose(project, engine.getAllFilteredRows(), protograph, protograph.getRootNode(0), nodeFactory, -1);
|
Transposer.transpose(project, engine.getAllFilteredRows(), protograph, protograph.getRootNode(0), nodeFactory, -1);
|
||||||
|
|
||||||
nodeFactory.flush();
|
nodeFactory.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract protected TransposedNodeFactory createNodeFactory(Writer writer);
|
||||||
|
|
||||||
|
static public class TripleLoaderExporter extends ProtographTransposeExporter {
|
||||||
|
public TripleLoaderExporter() {
|
||||||
|
super("application/x-unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TransposedNodeFactory createNodeFactory(Writer writer) {
|
||||||
|
return new TripleLoaderTransposedNodeFactory(writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static public class MqlwriteLikeExporter extends ProtographTransposeExporter {
|
||||||
|
public MqlwriteLikeExporter() {
|
||||||
|
super("application/x-unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TransposedNodeFactory createNodeFactory(Writer writer) {
|
||||||
|
return new MqlwriteLikeTransposedNodeFactory(writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.metaweb.gridworks.protograph.transpose;
|
package com.metaweb.gridworks.protograph.transpose;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -19,7 +21,8 @@ import com.metaweb.gridworks.protograph.FreebaseTopicNode;
|
|||||||
import com.metaweb.gridworks.protograph.ValueNode;
|
import com.metaweb.gridworks.protograph.ValueNode;
|
||||||
import com.metaweb.gridworks.util.JSONUtilities;
|
import com.metaweb.gridworks.util.JSONUtilities;
|
||||||
|
|
||||||
public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
|
public class MqlwriteLikeTransposedNodeFactory implements TransposedNodeFactory {
|
||||||
|
protected Writer writer;
|
||||||
protected List<JSONObject> rootObjects = new LinkedList<JSONObject>();
|
protected List<JSONObject> rootObjects = new LinkedList<JSONObject>();
|
||||||
|
|
||||||
private static final String TYPE = "type";
|
private static final String TYPE = "type";
|
||||||
@ -30,10 +33,20 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
|
|||||||
private static final String CONNECT = "connect";
|
private static final String CONNECT = "connect";
|
||||||
private static final String LANG = "lang";
|
private static final String LANG = "lang";
|
||||||
|
|
||||||
public JSONArray getJSON() {
|
public MqlwriteLikeTransposedNodeFactory(Writer writer) {
|
||||||
|
this.writer = writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected JSONArray getJSON() {
|
||||||
return new JSONArray(rootObjects);
|
return new JSONArray(rootObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() throws IOException {
|
||||||
|
writer.write(getJSON().toString());
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
|
||||||
abstract protected class JsonTransposedNode implements TransposedNode {
|
abstract protected class JsonTransposedNode implements TransposedNode {
|
||||||
abstract public Object getJSON();
|
abstract public Object getJSON();
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.metaweb.gridworks.protograph.transpose;
|
package com.metaweb.gridworks.protograph.transpose;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.metaweb.gridworks.model.Cell;
|
import com.metaweb.gridworks.model.Cell;
|
||||||
import com.metaweb.gridworks.protograph.AnonymousNode;
|
import com.metaweb.gridworks.protograph.AnonymousNode;
|
||||||
import com.metaweb.gridworks.protograph.CellNode;
|
import com.metaweb.gridworks.protograph.CellNode;
|
||||||
@ -32,4 +34,6 @@ public interface TransposedNodeFactory {
|
|||||||
FreebaseProperty property,
|
FreebaseProperty property,
|
||||||
FreebaseTopicNode node
|
FreebaseTopicNode node
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public void flush() throws IOException;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
|
|||||||
this.writer = writer;
|
this.writer = writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush() {
|
@Override
|
||||||
|
public void flush() throws IOException {
|
||||||
if (lastRootNode != null) {
|
if (lastRootNode != null) {
|
||||||
lastRootNode.write(null, null, null);
|
lastRootNode.write(null, null, null);
|
||||||
lastRootNode = null;
|
lastRootNode = null;
|
||||||
|
@ -55,7 +55,11 @@ MenuBar.prototype._initializeUI = function() {
|
|||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
"label": "Tripleloader",
|
"label": "Tripleloader",
|
||||||
"click": function() { self._doExportTripleloader(); }
|
"click": function() { self._doExportTripleloader("tripleloader"); }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "MQLWrite",
|
||||||
|
"click": function() { self._doExportTripleloader("mqlwrite"); }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -178,14 +182,14 @@ MenuBar.prototype._doDenormalizeRecords = function() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
MenuBar.prototype._doExportTripleloader = function() {
|
MenuBar.prototype._doExportTripleloader = function(format) {
|
||||||
if (!theProject.protograph) {
|
if (!theProject.protograph) {
|
||||||
alert(
|
alert(
|
||||||
"You haven't done any schema alignment yet,\nso there is no triple to export.\n\n" +
|
"You haven't done any schema alignment yet,\nso there is no triple to export.\n\n" +
|
||||||
"Use the Schemas > Edit Schema Alignment Skeleton...\ncommand to align your data with Freebase schemas first."
|
"Use the Schemas > Edit Schema Alignment Skeleton...\ncommand to align your data with Freebase schemas first."
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this._doExportRows("tripleloader", "txt");
|
this._doExportRows(format, "txt");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user