Convert tabs to spaces. No functional changes.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@2172 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
123614539d
commit
7fd6e22af4
@ -89,11 +89,11 @@ public class AppEngineRefineBrokerImpl extends RefineBroker {
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
||||
protected void expire(HttpServletResponse response) throws Exception {
|
||||
// TODO: implement
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
protected void startProject(HttpServletResponse response, String pid, String uid, String lock, byte[] data, String metadata, List<String> transformations) throws Exception {
|
||||
// TODO: implement
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
protected void expireLocks(HttpServletResponse response) throws Exception {
|
||||
@ -133,7 +133,7 @@ public class AppEngineRefineBrokerImpl extends RefineBroker {
|
||||
PersistenceManager pm = pmfInstance.getPersistenceManager();
|
||||
|
||||
try {
|
||||
// TODO: implement
|
||||
// TODO: implement
|
||||
respond(response, lockToJSON(getLock(pm,pid)));
|
||||
} finally {
|
||||
pm.close();
|
||||
@ -143,7 +143,7 @@ public class AppEngineRefineBrokerImpl extends RefineBroker {
|
||||
protected void obtainLock(HttpServletResponse response, String pid, String uid, int locktype, String lockvalue) throws Exception {
|
||||
PersistenceManager pm = pmfInstance.getPersistenceManager();
|
||||
|
||||
// TODO: implement
|
||||
// TODO: implement
|
||||
|
||||
try {
|
||||
Lock lock = getLock(pm, pid);
|
||||
|
@ -48,12 +48,12 @@ import com.google.refine.freebase.protograph.transpose.Transposer;
|
||||
import com.google.refine.freebase.protograph.transpose.TripleLoaderTransposedNodeFactory;
|
||||
|
||||
abstract public class ProtographTransposeExporter implements WriterExporter {
|
||||
final protected String _contentType;
|
||||
|
||||
public ProtographTransposeExporter(String contentType) {
|
||||
_contentType = contentType;
|
||||
}
|
||||
|
||||
final protected String _contentType;
|
||||
|
||||
public ProtographTransposeExporter(String contentType) {
|
||||
_contentType = contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return "application/x-unknown";
|
||||
@ -86,25 +86,25 @@ abstract public class ProtographTransposeExporter implements WriterExporter {
|
||||
abstract protected TransposedNodeFactory createNodeFactory(Project project, Writer writer);
|
||||
|
||||
static public class TripleLoaderExporter extends ProtographTransposeExporter {
|
||||
public TripleLoaderExporter() {
|
||||
super("application/x-unknown");
|
||||
}
|
||||
public TripleLoaderExporter() {
|
||||
super("application/x-unknown");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) {
|
||||
return new TripleLoaderTransposedNodeFactory(project, writer);
|
||||
}
|
||||
@Override
|
||||
protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) {
|
||||
return new TripleLoaderTransposedNodeFactory(project, writer);
|
||||
}
|
||||
}
|
||||
|
||||
static public class MqlwriteLikeExporter extends ProtographTransposeExporter {
|
||||
public MqlwriteLikeExporter() {
|
||||
super("application/x-unknown");
|
||||
}
|
||||
public MqlwriteLikeExporter() {
|
||||
super("application/x-unknown");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) {
|
||||
return new MqlwriteLikeTransposedNodeFactory(writer);
|
||||
}
|
||||
@Override
|
||||
protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) {
|
||||
return new MqlwriteLikeTransposedNodeFactory(writer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -208,13 +208,13 @@ public class DataExtensionChange implements Change {
|
||||
column.setReconStats(ReconStats.create(project, cellIndex));
|
||||
|
||||
try {
|
||||
project.columnModel.addColumn(_columnInsertIndex + i, column, true);
|
||||
|
||||
// the column might have been renamed to avoid collision
|
||||
_columnNames.set(i, column.getName());
|
||||
} catch (ModelException e) {
|
||||
// won't get here since we set the avoid collision flag
|
||||
}
|
||||
project.columnModel.addColumn(_columnInsertIndex + i, column, true);
|
||||
|
||||
// the column might have been renamed to avoid collision
|
||||
_columnNames.set(i, column.getName());
|
||||
} catch (ModelException e) {
|
||||
// won't get here since we set the avoid collision flag
|
||||
}
|
||||
}
|
||||
|
||||
project.update();
|
||||
|
@ -137,7 +137,7 @@ public class GuidBasedReconConfig extends StrictReconConfig {
|
||||
jsonWriter.key("guid|=");
|
||||
jsonWriter.array();
|
||||
for (ReconJob job : jobs) {
|
||||
jsonWriter.value(((GuidBasedReconJob) job).guid);
|
||||
jsonWriter.value(((GuidBasedReconJob) job).guid);
|
||||
}
|
||||
jsonWriter.endArray();
|
||||
|
||||
@ -163,37 +163,37 @@ public class GuidBasedReconConfig extends StrictReconConfig {
|
||||
String s = ParsingUtilities.inputStreamToString(is);
|
||||
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
|
||||
if (o.has("result")) {
|
||||
JSONArray results = o.getJSONArray("result");
|
||||
int count = results.length();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
JSONObject result = results.getJSONObject(i);
|
||||
|
||||
String guid = result.getString("guid");
|
||||
|
||||
JSONArray types = result.getJSONArray("type");
|
||||
String[] typeIDs = new String[types.length()];
|
||||
for (int j = 0; j < typeIDs.length; j++) {
|
||||
typeIDs[j] = types.getString(j);
|
||||
}
|
||||
|
||||
ReconCandidate candidate = new ReconCandidate(
|
||||
result.getString("id"),
|
||||
result.getString("name"),
|
||||
typeIDs,
|
||||
100
|
||||
);
|
||||
|
||||
Recon recon = Recon.makeFreebaseRecon(historyEntryID);
|
||||
recon.addCandidate(candidate);
|
||||
recon.service = "mql";
|
||||
recon.judgment = Judgment.Matched;
|
||||
recon.judgmentAction = "auto";
|
||||
recon.match = candidate;
|
||||
recon.matchRank = 0;
|
||||
|
||||
guidToRecon.put(guid, recon);
|
||||
}
|
||||
JSONArray results = o.getJSONArray("result");
|
||||
int count = results.length();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
JSONObject result = results.getJSONObject(i);
|
||||
|
||||
String guid = result.getString("guid");
|
||||
|
||||
JSONArray types = result.getJSONArray("type");
|
||||
String[] typeIDs = new String[types.length()];
|
||||
for (int j = 0; j < typeIDs.length; j++) {
|
||||
typeIDs[j] = types.getString(j);
|
||||
}
|
||||
|
||||
ReconCandidate candidate = new ReconCandidate(
|
||||
result.getString("id"),
|
||||
result.getString("name"),
|
||||
typeIDs,
|
||||
100
|
||||
);
|
||||
|
||||
Recon recon = Recon.makeFreebaseRecon(historyEntryID);
|
||||
recon.addCandidate(candidate);
|
||||
recon.service = "mql";
|
||||
recon.judgment = Judgment.Matched;
|
||||
recon.judgmentAction = "auto";
|
||||
recon.match = candidate;
|
||||
recon.matchRank = 0;
|
||||
|
||||
guidToRecon.put(guid, recon);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
is.close();
|
||||
@ -206,7 +206,7 @@ public class GuidBasedReconConfig extends StrictReconConfig {
|
||||
String guid = ((GuidBasedReconJob) job).guid;
|
||||
Recon recon = guidToRecon.get(guid);
|
||||
if (recon == null) {
|
||||
recon = createNoMatchRecon(historyEntryID);
|
||||
recon = createNoMatchRecon(historyEntryID);
|
||||
}
|
||||
recons.add(recon);
|
||||
}
|
||||
|
@ -167,50 +167,50 @@ public class IdBasedReconConfig extends StrictReconConfig {
|
||||
String s = ParsingUtilities.inputStreamToString(is);
|
||||
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
|
||||
if (o.has("result")) {
|
||||
JSONArray results = o.getJSONArray("result");
|
||||
int count = results.length();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
JSONObject result = results.getJSONObject(i);
|
||||
|
||||
String id = result.getString("id");
|
||||
|
||||
JSONArray types = result.getJSONArray("type");
|
||||
String[] typeIDs = new String[types.length()];
|
||||
for (int j = 0; j < typeIDs.length; j++) {
|
||||
typeIDs[j] = types.getString(j);
|
||||
}
|
||||
|
||||
ReconCandidate candidate = new ReconCandidate(
|
||||
id,
|
||||
result.getString("name"),
|
||||
typeIDs,
|
||||
100
|
||||
);
|
||||
|
||||
Recon recon = Recon.makeFreebaseRecon(historyEntryID);
|
||||
recon.addCandidate(candidate);
|
||||
recon.service = "mql";
|
||||
recon.judgment = Judgment.Matched;
|
||||
recon.judgmentAction = "auto";
|
||||
recon.match = candidate;
|
||||
recon.matchRank = 0;
|
||||
|
||||
idToRecon.put(id, recon);
|
||||
}
|
||||
JSONArray results = o.getJSONArray("result");
|
||||
int count = results.length();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
JSONObject result = results.getJSONObject(i);
|
||||
|
||||
String id = result.getString("id");
|
||||
|
||||
JSONArray types = result.getJSONArray("type");
|
||||
String[] typeIDs = new String[types.length()];
|
||||
for (int j = 0; j < typeIDs.length; j++) {
|
||||
typeIDs[j] = types.getString(j);
|
||||
}
|
||||
|
||||
ReconCandidate candidate = new ReconCandidate(
|
||||
id,
|
||||
result.getString("name"),
|
||||
typeIDs,
|
||||
100
|
||||
);
|
||||
|
||||
Recon recon = Recon.makeFreebaseRecon(historyEntryID);
|
||||
recon.addCandidate(candidate);
|
||||
recon.service = "mql";
|
||||
recon.judgment = Judgment.Matched;
|
||||
recon.judgmentAction = "auto";
|
||||
recon.match = candidate;
|
||||
recon.matchRank = 0;
|
||||
|
||||
idToRecon.put(id, recon);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
is.close();
|
||||
is.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
for (ReconJob job : jobs) {
|
||||
String id = ((IdBasedReconJob) job).id;
|
||||
Recon recon = idToRecon.get(id);
|
||||
if (recon == null) {
|
||||
recon = createNoMatchRecon(historyEntryID);
|
||||
recon = createNoMatchRecon(historyEntryID);
|
||||
}
|
||||
recons.add(recon);
|
||||
}
|
||||
|
@ -181,37 +181,37 @@ public class KeyBasedReconConfig extends StrictReconConfig {
|
||||
String s = ParsingUtilities.inputStreamToString(is);
|
||||
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
|
||||
if (o.has("result")) {
|
||||
JSONArray results = o.getJSONArray("result");
|
||||
int count = results.length();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
JSONObject result = results.getJSONObject(i);
|
||||
|
||||
String key = result.getJSONArray("key").getJSONObject(0).getString("value");
|
||||
|
||||
JSONArray types = result.getJSONArray("type");
|
||||
String[] typeIDs = new String[types.length()];
|
||||
for (int j = 0; j < typeIDs.length; j++) {
|
||||
typeIDs[j] = types.getString(j);
|
||||
}
|
||||
|
||||
ReconCandidate candidate = new ReconCandidate(
|
||||
result.getString("id"),
|
||||
result.getString("name"),
|
||||
typeIDs,
|
||||
100
|
||||
);
|
||||
|
||||
Recon recon = Recon.makeFreebaseRecon(historyEntryID);
|
||||
recon.addCandidate(candidate);
|
||||
recon.service = "mql";
|
||||
recon.judgment = Judgment.Matched;
|
||||
recon.judgmentAction = "auto";
|
||||
recon.match = candidate;
|
||||
recon.matchRank = 0;
|
||||
|
||||
keyToRecon.put(key, recon);
|
||||
}
|
||||
JSONArray results = o.getJSONArray("result");
|
||||
int count = results.length();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
JSONObject result = results.getJSONObject(i);
|
||||
|
||||
String key = result.getJSONArray("key").getJSONObject(0).getString("value");
|
||||
|
||||
JSONArray types = result.getJSONArray("type");
|
||||
String[] typeIDs = new String[types.length()];
|
||||
for (int j = 0; j < typeIDs.length; j++) {
|
||||
typeIDs[j] = types.getString(j);
|
||||
}
|
||||
|
||||
ReconCandidate candidate = new ReconCandidate(
|
||||
result.getString("id"),
|
||||
result.getString("name"),
|
||||
typeIDs,
|
||||
100
|
||||
);
|
||||
|
||||
Recon recon = Recon.makeFreebaseRecon(historyEntryID);
|
||||
recon.addCandidate(candidate);
|
||||
recon.service = "mql";
|
||||
recon.judgment = Judgment.Matched;
|
||||
recon.judgmentAction = "auto";
|
||||
recon.match = candidate;
|
||||
recon.matchRank = 0;
|
||||
|
||||
keyToRecon.put(key, recon);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
is.close();
|
||||
@ -224,7 +224,7 @@ public class KeyBasedReconConfig extends StrictReconConfig {
|
||||
String key = ((KeyBasedReconJob) job).key;
|
||||
Recon recon = keyToRecon.get(key);
|
||||
if (recon == null) {
|
||||
recon = createNoMatchRecon(historyEntryID);
|
||||
recon = createNoMatchRecon(historyEntryID);
|
||||
}
|
||||
recons.add(recon);
|
||||
}
|
||||
|
@ -60,10 +60,10 @@ abstract public class StrictReconConfig extends ReconConfig {
|
||||
}
|
||||
|
||||
protected Recon createNoMatchRecon(long historyEntryID) {
|
||||
Recon recon = createNewRecon(historyEntryID);
|
||||
recon.service = "mql";
|
||||
recon.judgment = Judgment.None;
|
||||
recon.matchRank = -1;
|
||||
return recon;
|
||||
Recon recon = createNewRecon(historyEntryID);
|
||||
recon.service = "mql";
|
||||
recon.judgment = Judgment.None;
|
||||
recon.matchRank = -1;
|
||||
return recon;
|
||||
}
|
||||
}
|
||||
|
@ -188,15 +188,15 @@ public class ExtendDataOperation extends EngineDependentOperation {
|
||||
_rowIndices = rowIndices;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -266,7 +266,7 @@ public class FreebaseUtils {
|
||||
}
|
||||
|
||||
static public String getFreeQUrl() {
|
||||
String url = (String) ProjectManager.singleton.getPreferenceStore().get("freebase.freeq");
|
||||
return url != null ? url : FREEQ_URL;
|
||||
String url = (String) ProjectManager.singleton.getPreferenceStore().get("freebase.freeq");
|
||||
return url != null ? url : FREEQ_URL;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
|
||||
Copyright 2010, Google Inc.
|
||||
All rights reserved.
|
||||
@ -29,7 +29,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
package com.google.refine.browsing;
|
||||
|
||||
@ -59,104 +59,104 @@ import com.google.refine.model.Row;
|
||||
* Faceted browsing engine.
|
||||
*/
|
||||
public class Engine implements Jsonizable {
|
||||
static public enum Mode {
|
||||
RowBased,
|
||||
RecordBased
|
||||
}
|
||||
|
||||
static public enum Mode {
|
||||
RowBased,
|
||||
RecordBased
|
||||
}
|
||||
|
||||
public final static String INCLUDE_DEPENDENT = "includeDependent";
|
||||
public final static String MODE = "mode";
|
||||
public final static String MODE_ROW_BASED = "row-based";
|
||||
public final static String MODE_RECORD_BASED = "record-based";
|
||||
|
||||
protected Project _project;
|
||||
protected List<Facet> _facets = new LinkedList<Facet>();
|
||||
protected Mode _mode = Mode.RowBased;
|
||||
|
||||
|
||||
protected Project _project;
|
||||
protected List<Facet> _facets = new LinkedList<Facet>();
|
||||
protected Mode _mode = Mode.RowBased;
|
||||
|
||||
static public String modeToString(Mode mode) {
|
||||
return mode == Mode.RowBased ? MODE_ROW_BASED : MODE_RECORD_BASED;
|
||||
return mode == Mode.RowBased ? MODE_ROW_BASED : MODE_RECORD_BASED;
|
||||
}
|
||||
static public Mode stringToMode(String s) {
|
||||
return MODE_ROW_BASED.equals(s) ? Mode.RowBased : Mode.RecordBased;
|
||||
return MODE_ROW_BASED.equals(s) ? Mode.RowBased : Mode.RecordBased;
|
||||
}
|
||||
|
||||
|
||||
public Engine(Project project) {
|
||||
_project = project;
|
||||
}
|
||||
|
||||
|
||||
public Mode getMode() {
|
||||
return _mode;
|
||||
return _mode;
|
||||
}
|
||||
public void setMode(Mode mode) {
|
||||
_mode = mode;
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
|
||||
public FilteredRows getAllRows() {
|
||||
return new FilteredRows() {
|
||||
@Override
|
||||
public void accept(Project project, RowVisitor visitor) {
|
||||
try {
|
||||
visitor.start(project);
|
||||
|
||||
int c = project.rows.size();
|
||||
for (int rowIndex = 0; rowIndex < c; rowIndex++) {
|
||||
Row row = project.rows.get(rowIndex);
|
||||
visitor.visit(project, rowIndex, row);
|
||||
}
|
||||
} finally {
|
||||
visitor.end(project);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void accept(Project project, RowVisitor visitor) {
|
||||
try {
|
||||
visitor.start(project);
|
||||
|
||||
int c = project.rows.size();
|
||||
for (int rowIndex = 0; rowIndex < c; rowIndex++) {
|
||||
Row row = project.rows.get(rowIndex);
|
||||
visitor.visit(project, rowIndex, row);
|
||||
}
|
||||
} finally {
|
||||
visitor.end(project);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public FilteredRows getAllFilteredRows() {
|
||||
return getFilteredRows(null);
|
||||
}
|
||||
|
||||
public FilteredRows getFilteredRows(Facet except) {
|
||||
if (_mode == Mode.RecordBased) {
|
||||
return new FilteredRecordsAsFilteredRows(getFilteredRecords(except));
|
||||
} else if (_mode == Mode.RowBased) {
|
||||
ConjunctiveFilteredRows cfr = new ConjunctiveFilteredRows();
|
||||
for (Facet facet : _facets) {
|
||||
if (facet != except) {
|
||||
RowFilter rowFilter = facet.getRowFilter(_project);
|
||||
if (rowFilter != null) {
|
||||
cfr.add(rowFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cfr;
|
||||
}
|
||||
throw new InternalError("Unknown mode.");
|
||||
if (_mode == Mode.RecordBased) {
|
||||
return new FilteredRecordsAsFilteredRows(getFilteredRecords(except));
|
||||
} else if (_mode == Mode.RowBased) {
|
||||
ConjunctiveFilteredRows cfr = new ConjunctiveFilteredRows();
|
||||
for (Facet facet : _facets) {
|
||||
if (facet != except) {
|
||||
RowFilter rowFilter = facet.getRowFilter(_project);
|
||||
if (rowFilter != null) {
|
||||
cfr.add(rowFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cfr;
|
||||
}
|
||||
throw new InternalError("Unknown mode.");
|
||||
}
|
||||
|
||||
|
||||
public FilteredRecords getAllRecords() {
|
||||
return new FilteredRecords() {
|
||||
@Override
|
||||
public void accept(Project project, RecordVisitor visitor) {
|
||||
try {
|
||||
visitor.start(project);
|
||||
|
||||
int c = project.recordModel.getRecordCount();
|
||||
for (int r = 0; r < c; r++) {
|
||||
visitor.visit(project, project.recordModel.getRecord(r));
|
||||
}
|
||||
} finally {
|
||||
visitor.end(project);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void accept(Project project, RecordVisitor visitor) {
|
||||
try {
|
||||
visitor.start(project);
|
||||
|
||||
int c = project.recordModel.getRecordCount();
|
||||
for (int r = 0; r < c; r++) {
|
||||
visitor.visit(project, project.recordModel.getRecord(r));
|
||||
}
|
||||
} finally {
|
||||
visitor.end(project);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public FilteredRecords getFilteredRecords() {
|
||||
return getFilteredRecords(null);
|
||||
return getFilteredRecords(null);
|
||||
}
|
||||
|
||||
|
||||
public FilteredRecords getFilteredRecords(Facet except) {
|
||||
if (_mode == Mode.RecordBased) {
|
||||
ConjunctiveFilteredRecords cfr = new ConjunctiveFilteredRecords();
|
||||
if (_mode == Mode.RecordBased) {
|
||||
ConjunctiveFilteredRecords cfr = new ConjunctiveFilteredRecords();
|
||||
for (Facet facet : _facets) {
|
||||
if (facet != except) {
|
||||
RecordFilter recordFilter = facet.getRecordFilter(_project);
|
||||
@ -166,23 +166,23 @@ public class Engine implements Jsonizable {
|
||||
}
|
||||
}
|
||||
return cfr;
|
||||
}
|
||||
throw new InternalError("This method should not be called when the engine is not in record mode.");
|
||||
}
|
||||
throw new InternalError("This method should not be called when the engine is not in record mode.");
|
||||
}
|
||||
|
||||
|
||||
public void initializeFromJSON(JSONObject o) throws Exception {
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (o.has("facets") && !o.isNull("facets")) {
|
||||
JSONArray a = o.getJSONArray("facets");
|
||||
int length = a.length();
|
||||
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
JSONObject fo = a.getJSONObject(i);
|
||||
String type = fo.has("type") ? fo.getString("type") : "list";
|
||||
|
||||
|
||||
Facet facet = null;
|
||||
if ("list".equals(type)) {
|
||||
facet = new ListFacet();
|
||||
@ -195,53 +195,53 @@ public class Engine implements Jsonizable {
|
||||
} else if ("text".equals(type)) {
|
||||
facet = new TextSearchFacet();
|
||||
}
|
||||
|
||||
|
||||
if (facet != null) {
|
||||
facet.initializeFromJSON(_project, fo);
|
||||
_facets.add(facet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// for backward compatibility
|
||||
if (o.has(INCLUDE_DEPENDENT) && !o.isNull(INCLUDE_DEPENDENT)) {
|
||||
_mode = o.getBoolean(INCLUDE_DEPENDENT) ? Mode.RecordBased : Mode.RowBased;
|
||||
}
|
||||
|
||||
|
||||
if (o.has(MODE) && !o.isNull(MODE)) {
|
||||
_mode = MODE_ROW_BASED.equals(o.getString(MODE)) ? Mode.RowBased : Mode.RecordBased;
|
||||
_mode = MODE_ROW_BASED.equals(o.getString(MODE)) ? Mode.RowBased : Mode.RecordBased;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void computeFacets() throws JSONException {
|
||||
if (_mode == Mode.RowBased) {
|
||||
for (Facet facet : _facets) {
|
||||
FilteredRows filteredRows = getFilteredRows(facet);
|
||||
|
||||
facet.computeChoices(_project, filteredRows);
|
||||
}
|
||||
} else if (_mode == Mode.RecordBased) {
|
||||
for (Facet facet : _facets) {
|
||||
FilteredRecords filteredRecords = getFilteredRecords(facet);
|
||||
|
||||
facet.computeChoices(_project, filteredRecords);
|
||||
}
|
||||
} else {
|
||||
throw new InternalError("Unknown mode.");
|
||||
}
|
||||
if (_mode == Mode.RowBased) {
|
||||
for (Facet facet : _facets) {
|
||||
FilteredRows filteredRows = getFilteredRows(facet);
|
||||
|
||||
facet.computeChoices(_project, filteredRows);
|
||||
}
|
||||
} else if (_mode == Mode.RecordBased) {
|
||||
for (Facet facet : _facets) {
|
||||
FilteredRecords filteredRecords = getFilteredRecords(facet);
|
||||
|
||||
facet.computeChoices(_project, filteredRecords);
|
||||
}
|
||||
} else {
|
||||
throw new InternalError("Unknown mode.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("facets");
|
||||
writer.array();
|
||||
for (Facet facet : _facets) {
|
||||
facet.write(writer, options);
|
||||
}
|
||||
writer.endArray();
|
||||
writer.array();
|
||||
for (Facet facet : _facets) {
|
||||
facet.write(writer, options);
|
||||
}
|
||||
writer.endArray();
|
||||
writer.key(MODE); writer.value(_mode == Mode.RowBased ? MODE_ROW_BASED : MODE_RECORD_BASED);
|
||||
writer.endObject();
|
||||
}
|
||||
|
@ -41,12 +41,12 @@ import com.google.refine.model.Record;
|
||||
* particular criteria, such as facets' constraints.
|
||||
*/
|
||||
public interface RecordVisitor {
|
||||
public void start(Project project); // called before any visit() call
|
||||
|
||||
public void start(Project project); // called before any visit() call
|
||||
|
||||
public boolean visit(
|
||||
Project project,
|
||||
Record record
|
||||
Project project,
|
||||
Record record
|
||||
);
|
||||
|
||||
public void end(Project project); // called after all visit() calls
|
||||
|
||||
public void end(Project project); // called after all visit() calls
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ import com.google.refine.model.Row;
|
||||
* particular criteria, such as facets' constraints.
|
||||
*/
|
||||
public interface RowVisitor {
|
||||
public void start(Project project); // called before any visit() call
|
||||
|
||||
public void start(Project project); // called before any visit() call
|
||||
|
||||
public boolean visit(
|
||||
Project project,
|
||||
int rowIndex, // zero-based row index
|
||||
Row row
|
||||
Project project,
|
||||
int rowIndex, // zero-based row index
|
||||
Row row
|
||||
);
|
||||
|
||||
public void end(Project project); // called after all visit() calls
|
||||
|
||||
public void end(Project project); // called after all visit() calls
|
||||
}
|
||||
|
@ -218,11 +218,11 @@ public class ListFacet implements Facet {
|
||||
|
||||
@Override
|
||||
public RecordFilter getRecordFilter(Project project) {
|
||||
RowFilter rowFilter = getRowFilter(project);
|
||||
return rowFilter == null ? null :
|
||||
(_invert ?
|
||||
new AllRowsRecordFilter(rowFilter) :
|
||||
new AnyRowRecordFilter(rowFilter));
|
||||
RowFilter rowFilter = getRowFilter(project);
|
||||
return rowFilter == null ? null :
|
||||
(_invert ?
|
||||
new AllRowsRecordFilter(rowFilter) :
|
||||
new AnyRowRecordFilter(rowFilter));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -201,8 +201,8 @@ public class RangeFacet implements Facet {
|
||||
public RowFilter getRowFilter(Project project) {
|
||||
if (_eval != null && _errorMessage == null && _selected) {
|
||||
return new ExpressionNumberComparisonRowFilter(
|
||||
getRowEvaluable(project), _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) {
|
||||
|
||||
getRowEvaluable(project), _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) {
|
||||
|
||||
@Override
|
||||
protected boolean checkValue(double d) {
|
||||
return d >= _from && d < _to;
|
||||
@ -215,8 +215,8 @@ public class RangeFacet implements Facet {
|
||||
|
||||
@Override
|
||||
public RecordFilter getRecordFilter(Project project) {
|
||||
RowFilter rowFilter = getRowFilter(project);
|
||||
return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter);
|
||||
RowFilter rowFilter = getRowFilter(project);
|
||||
return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -267,7 +267,7 @@ public class RangeFacet implements Facet {
|
||||
}
|
||||
|
||||
protected RowEvaluable getRowEvaluable(Project project) {
|
||||
return new ExpressionBasedRowEvaluable(_columnName, _cellIndex, _eval);
|
||||
return new ExpressionBasedRowEvaluable(_columnName, _cellIndex, _eval);
|
||||
}
|
||||
|
||||
protected void retrieveDataFromBaseBinIndex(NumericBinIndex index) {
|
||||
|
@ -122,12 +122,12 @@ public class ScatterplotDrawingRowVisitor implements RowVisitor, RecordVisitor {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -153,10 +153,10 @@ public class ScatterplotDrawingRowVisitor implements RowVisitor, RecordVisitor {
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, Record record) {
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
visit(project, r, project.rows.get(r));
|
||||
}
|
||||
return false;
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
visit(project, r, project.rows.get(r));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public RenderedImage getImage() {
|
||||
|
@ -315,8 +315,8 @@ public class ScatterplotFacet implements Facet {
|
||||
|
||||
@Override
|
||||
public RecordFilter getRecordFilter(Project project) {
|
||||
RowFilter rowFilter = getRowFilter(project);
|
||||
return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter);
|
||||
RowFilter rowFilter = getRowFilter(project);
|
||||
return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -414,7 +414,7 @@ public class ScatterplotFacet implements Facet {
|
||||
}
|
||||
|
||||
public static NumericBinIndex getBinIndex(Project project, Column column, Evaluable eval, String expression) {
|
||||
return getBinIndex(project, column, eval, expression, "row-based");
|
||||
return getBinIndex(project, column, eval, expression, "row-based");
|
||||
}
|
||||
|
||||
public static NumericBinIndex getBinIndex(Project project, Column column, Evaluable eval, String expression, String mode) {
|
||||
@ -429,10 +429,10 @@ public class ScatterplotFacet implements Facet {
|
||||
NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key);
|
||||
if (index == null) {
|
||||
index = "row-based".equals(mode) ?
|
||||
new NumericBinRowIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval)) :
|
||||
new NumericBinRecordIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval));
|
||||
|
||||
column.setPrecompute(key, index);
|
||||
new NumericBinRowIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval)) :
|
||||
new NumericBinRecordIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval));
|
||||
|
||||
column.setPrecompute(key, index);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
@ -101,13 +101,13 @@ public class TextSearchFacet implements Facet {
|
||||
if ("regex".equals(_mode)) {
|
||||
try {
|
||||
_pattern = Pattern.compile(
|
||||
_query,
|
||||
_caseSensitive ? 0 : Pattern.CASE_INSENSITIVE);
|
||||
_query,
|
||||
_caseSensitive ? 0 : Pattern.CASE_INSENSITIVE);
|
||||
} catch (java.util.regex.PatternSyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (!_caseSensitive) {
|
||||
_query = _query.toLowerCase();
|
||||
_query = _query.toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -141,17 +141,17 @@ public class TextSearchFacet implements Facet {
|
||||
|
||||
@Override
|
||||
public RecordFilter getRecordFilter(Project project) {
|
||||
RowFilter rowFilter = getRowFilter(project);
|
||||
return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter);
|
||||
RowFilter rowFilter = getRowFilter(project);
|
||||
return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void computeChoices(Project project, FilteredRows filteredRows) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void computeChoices(Project project, FilteredRecords filteredRecords) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ import com.google.refine.model.Project;
|
||||
import com.google.refine.util.JSONUtilities;
|
||||
|
||||
public class TimeRangeFacet extends RangeFacet {
|
||||
|
||||
|
||||
protected boolean _selectTime; // whether the time selection applies, default true
|
||||
protected boolean _selectNonTime;
|
||||
|
||||
@ -153,7 +153,7 @@ public class TimeRangeFacet extends RangeFacet {
|
||||
public RowFilter getRowFilter(Project project) {
|
||||
if (_eval != null && _errorMessage == null && _selected) {
|
||||
return new ExpressionTimeComparisonRowFilter(
|
||||
getRowEvaluable(project), _selectTime, _selectNonTime, _selectBlank, _selectError) {
|
||||
getRowEvaluable(project), _selectTime, _selectNonTime, _selectBlank, _selectError) {
|
||||
|
||||
@Override
|
||||
protected boolean checkValue(long t) {
|
||||
|
@ -39,19 +39,19 @@ import com.google.refine.model.Project;
|
||||
import com.google.refine.model.Record;
|
||||
|
||||
public class AllRowsRecordFilter implements RecordFilter {
|
||||
final protected RowFilter _rowFilter;
|
||||
|
||||
public AllRowsRecordFilter(RowFilter rowFilter) {
|
||||
_rowFilter = rowFilter;
|
||||
}
|
||||
final protected RowFilter _rowFilter;
|
||||
|
||||
@Override
|
||||
public boolean filterRecord(Project project, Record record) {
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
if (!_rowFilter.filterRow(project, r, project.rows.get(r))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public AllRowsRecordFilter(RowFilter rowFilter) {
|
||||
_rowFilter = rowFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean filterRecord(Project project, Record record) {
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
if (!_rowFilter.filterRow(project, r, project.rows.get(r))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
@ -29,7 +29,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
package com.google.refine.browsing.filters;
|
||||
|
||||
@ -39,19 +39,19 @@ import com.google.refine.model.Project;
|
||||
import com.google.refine.model.Record;
|
||||
|
||||
public class AnyRowRecordFilter implements RecordFilter {
|
||||
final protected RowFilter _rowFilter;
|
||||
|
||||
public AnyRowRecordFilter(RowFilter rowFilter) {
|
||||
_rowFilter = rowFilter;
|
||||
}
|
||||
final protected RowFilter _rowFilter;
|
||||
|
||||
@Override
|
||||
public boolean filterRecord(Project project, Record record) {
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
if (_rowFilter.filterRow(project, r, project.rows.get(r))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public AnyRowRecordFilter(RowFilter rowFilter) {
|
||||
_rowFilter = rowFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean filterRecord(Project project, Record record) {
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
if (_rowFilter.filterRow(project, r, project.rows.get(r))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -52,20 +52,20 @@ import com.google.refine.model.Row;
|
||||
* values.
|
||||
*/
|
||||
abstract public class ExpressionNumberComparisonRowFilter implements RowFilter {
|
||||
final protected RowEvaluable _rowEvaluable;
|
||||
final protected boolean _selectNumeric;
|
||||
final protected boolean _selectNonNumeric;
|
||||
final protected boolean _selectBlank;
|
||||
final protected boolean _selectError;
|
||||
|
||||
final protected RowEvaluable _rowEvaluable;
|
||||
final protected boolean _selectNumeric;
|
||||
final protected boolean _selectNonNumeric;
|
||||
final protected boolean _selectBlank;
|
||||
final protected boolean _selectError;
|
||||
|
||||
public ExpressionNumberComparisonRowFilter(
|
||||
RowEvaluable rowEvaluable,
|
||||
boolean selectNumeric,
|
||||
boolean selectNonNumeric,
|
||||
boolean selectBlank,
|
||||
boolean selectError
|
||||
RowEvaluable rowEvaluable,
|
||||
boolean selectNumeric,
|
||||
boolean selectNonNumeric,
|
||||
boolean selectBlank,
|
||||
boolean selectError
|
||||
) {
|
||||
_rowEvaluable = rowEvaluable;
|
||||
_rowEvaluable = rowEvaluable;
|
||||
_selectNumeric = selectNumeric;
|
||||
_selectNonNumeric = selectNonNumeric;
|
||||
_selectBlank = selectBlank;
|
||||
|
@ -46,21 +46,21 @@ import com.google.refine.expr.ExpressionUtils;
|
||||
*/
|
||||
abstract public class ExpressionTimeComparisonRowFilter extends ExpressionNumberComparisonRowFilter {
|
||||
|
||||
final protected boolean _selectTime;
|
||||
final protected boolean _selectNonTime;
|
||||
final protected boolean _selectTime;
|
||||
final protected boolean _selectNonTime;
|
||||
|
||||
public ExpressionTimeComparisonRowFilter(
|
||||
RowEvaluable rowEvaluable,
|
||||
boolean selectTime,
|
||||
boolean selectNonTime,
|
||||
boolean selectBlank,
|
||||
boolean selectError
|
||||
RowEvaluable rowEvaluable,
|
||||
boolean selectTime,
|
||||
boolean selectNonTime,
|
||||
boolean selectBlank,
|
||||
boolean selectError
|
||||
) {
|
||||
super(rowEvaluable, selectTime, selectNonTime, selectBlank, selectError);
|
||||
_selectTime = selectTime;
|
||||
_selectNonTime = selectNonTime;
|
||||
super(rowEvaluable, selectTime, selectNonTime, selectBlank, selectError);
|
||||
_selectTime = selectTime;
|
||||
_selectNonTime = selectNonTime;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean checkValue(Object v) {
|
||||
if (ExpressionUtils.isError(v)) {
|
||||
@ -80,7 +80,7 @@ abstract public class ExpressionTimeComparisonRowFilter extends ExpressionNumber
|
||||
// not really needed for operation, just to make extending the abstract class possible
|
||||
@Override
|
||||
protected boolean checkValue(double d) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
abstract protected boolean checkValue(long d);
|
||||
|
@ -54,21 +54,21 @@ public class ConjunctiveFilteredRecords implements FilteredRecords {
|
||||
|
||||
@Override
|
||||
public void accept(Project project, RecordVisitor visitor) {
|
||||
try {
|
||||
visitor.start(project);
|
||||
|
||||
int c = project.recordModel.getRecordCount();
|
||||
for (int r = 0; r < c; r++) {
|
||||
Record record = project.recordModel.getRecord(r);
|
||||
if (matchRecord(project, record)) {
|
||||
if (visitor.visit(project, record)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
visitor.end(project);
|
||||
}
|
||||
try {
|
||||
visitor.start(project);
|
||||
|
||||
int c = project.recordModel.getRecordCount();
|
||||
for (int r = 0; r < c; r++) {
|
||||
Record record = project.recordModel.getRecord(r);
|
||||
if (matchRecord(project, record)) {
|
||||
if (visitor.visit(project, record)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
visitor.end(project);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean matchRecord(Project project, Record record) {
|
||||
|
@ -55,19 +55,19 @@ public class ConjunctiveFilteredRows implements FilteredRows {
|
||||
|
||||
@Override
|
||||
public void accept(Project project, RowVisitor visitor) {
|
||||
try {
|
||||
visitor.start(project);
|
||||
|
||||
int c = project.rows.size();
|
||||
for (int rowIndex = 0; rowIndex < c; rowIndex++) {
|
||||
Row row = project.rows.get(rowIndex);
|
||||
if (matchRow(project, rowIndex, row)) {
|
||||
visitRow(project, visitor, rowIndex, row);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
visitor.end(project);
|
||||
}
|
||||
try {
|
||||
visitor.start(project);
|
||||
|
||||
int c = project.rows.size();
|
||||
for (int rowIndex = 0; rowIndex < c; rowIndex++) {
|
||||
Row row = project.rows.get(rowIndex);
|
||||
if (matchRow(project, rowIndex, row)) {
|
||||
visitRow(project, visitor, rowIndex, row);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
visitor.end(project);
|
||||
}
|
||||
}
|
||||
|
||||
protected void visitRow(Project project, RowVisitor visitor, int rowIndex, Row row) {
|
||||
|
@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
@ -29,7 +29,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
package com.google.refine.browsing.util;
|
||||
|
||||
@ -56,94 +56,94 @@ import com.google.refine.model.Row;
|
||||
* from a given expression.
|
||||
*/
|
||||
public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor {
|
||||
static public class IndexedNominalFacetChoice extends NominalFacetChoice {
|
||||
int _latestIndex;
|
||||
|
||||
public IndexedNominalFacetChoice(DecoratedValue decoratedValue, int latestIndex) {
|
||||
super(decoratedValue);
|
||||
_latestIndex = latestIndex;
|
||||
}
|
||||
}
|
||||
|
||||
static public class IndexedNominalFacetChoice extends NominalFacetChoice {
|
||||
int _latestIndex;
|
||||
|
||||
public IndexedNominalFacetChoice(DecoratedValue decoratedValue, int latestIndex) {
|
||||
super(decoratedValue);
|
||||
_latestIndex = latestIndex;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Configuration
|
||||
*/
|
||||
final protected Evaluable _evaluable;
|
||||
final protected String _columnName;
|
||||
final protected int _cellIndex;
|
||||
|
||||
|
||||
/*
|
||||
* Computed results
|
||||
*/
|
||||
final public Map<Object, IndexedNominalFacetChoice> choices = new HashMap<Object, IndexedNominalFacetChoice>();
|
||||
public int blankCount = 0;
|
||||
public int errorCount = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Scratch pad variables
|
||||
*/
|
||||
protected boolean hasBlank;
|
||||
protected boolean hasError;
|
||||
|
||||
|
||||
public ExpressionNominalValueGrouper(Evaluable evaluable, String columnName, int cellIndex) {
|
||||
_evaluable = evaluable;
|
||||
_columnName = columnName;
|
||||
_cellIndex = cellIndex;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, int rowIndex, Row row) {
|
||||
hasError = false;
|
||||
hasBlank = false;
|
||||
|
||||
hasError = false;
|
||||
hasBlank = false;
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
|
||||
|
||||
visitRow(project, rowIndex, row, bindings, rowIndex);
|
||||
|
||||
|
||||
if (hasError) {
|
||||
errorCount++;
|
||||
errorCount++;
|
||||
}
|
||||
if (hasBlank) {
|
||||
blankCount++;
|
||||
blankCount++;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, Record record) {
|
||||
hasError = false;
|
||||
hasBlank = false;
|
||||
|
||||
hasError = false;
|
||||
hasBlank = false;
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
|
||||
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
Row row = project.rows.get(r);
|
||||
Row row = project.rows.get(r);
|
||||
visitRow(project, r, row, bindings, record.recordIndex);
|
||||
}
|
||||
|
||||
|
||||
if (hasError) {
|
||||
errorCount++;
|
||||
errorCount++;
|
||||
}
|
||||
if (hasBlank) {
|
||||
blankCount++;
|
||||
blankCount++;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected void visitRow(Project project, int rowIndex, Row row, Properties bindings, int index) {
|
||||
Object value = evalRow(project, rowIndex, row, bindings);
|
||||
Object value = evalRow(project, rowIndex, row, bindings);
|
||||
if (value != null) {
|
||||
if (value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
@ -155,83 +155,83 @@ public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor
|
||||
processValue(v, rowIndex);
|
||||
}
|
||||
} else {
|
||||
processValue(value, rowIndex);
|
||||
processValue(value, rowIndex);
|
||||
}
|
||||
} else {
|
||||
processValue(value, rowIndex);
|
||||
processValue(value, rowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Object evalRow(Project project, int rowIndex, Row row, Properties bindings) {
|
||||
Cell cell = _cellIndex < 0 ? null : row.getCell(_cellIndex);
|
||||
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell);
|
||||
|
||||
return _evaluable.evaluate(bindings);
|
||||
Cell cell = _cellIndex < 0 ? null : row.getCell(_cellIndex);
|
||||
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell);
|
||||
|
||||
return _evaluable.evaluate(bindings);
|
||||
}
|
||||
|
||||
|
||||
protected void processValue(Object value, int index) {
|
||||
if (ExpressionUtils.isError(value)) {
|
||||
hasError = true;
|
||||
} else if (ExpressionUtils.isNonBlankData(value)) {
|
||||
String valueString = value.toString();
|
||||
IndexedNominalFacetChoice facetChoice = choices.get(valueString);
|
||||
|
||||
|
||||
if (facetChoice != null) {
|
||||
if (facetChoice._latestIndex < index) {
|
||||
facetChoice._latestIndex = index;
|
||||
facetChoice.count++;
|
||||
}
|
||||
if (facetChoice._latestIndex < index) {
|
||||
facetChoice._latestIndex = index;
|
||||
facetChoice.count++;
|
||||
}
|
||||
} else {
|
||||
String label = value.toString();
|
||||
DecoratedValue dValue = new DecoratedValue(value, label);
|
||||
IndexedNominalFacetChoice choice =
|
||||
new IndexedNominalFacetChoice(dValue, index);
|
||||
|
||||
String label = value.toString();
|
||||
DecoratedValue dValue = new DecoratedValue(value, label);
|
||||
IndexedNominalFacetChoice choice =
|
||||
new IndexedNominalFacetChoice(dValue, index);
|
||||
|
||||
choice.count = 1;
|
||||
choices.put(valueString, choice);
|
||||
}
|
||||
} else {
|
||||
hasBlank = true;
|
||||
hasBlank = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RowEvaluable getChoiceCountRowEvaluable() {
|
||||
return new RowEvaluable() {
|
||||
@Override
|
||||
public Object eval(Project project, int rowIndex, Row row, Properties bindings) {
|
||||
Object value = evalRow(project, rowIndex, row, bindings);
|
||||
return getChoiceValueCountMultiple(value);
|
||||
}
|
||||
|
||||
};
|
||||
return new RowEvaluable() {
|
||||
@Override
|
||||
public Object eval(Project project, int rowIndex, Row row, Properties bindings) {
|
||||
Object value = evalRow(project, rowIndex, row, bindings);
|
||||
return getChoiceValueCountMultiple(value);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Object getChoiceValueCountMultiple(Object value) {
|
||||
if (value != null) {
|
||||
if (value.getClass().isArray()) {
|
||||
if (value.getClass().isArray()) {
|
||||
Object[] choiceValues = (Object[]) value;
|
||||
List<Integer> counts = new ArrayList<Integer>(choiceValues.length);
|
||||
|
||||
|
||||
for (int i = 0; i < choiceValues.length; i++) {
|
||||
counts.add(getChoiceValueCount(choiceValues[i]));
|
||||
counts.add(getChoiceValueCount(choiceValues[i]));
|
||||
}
|
||||
return counts;
|
||||
} else if (value instanceof Collection<?>) {
|
||||
List<Object> choiceValues = ExpressionUtils.toObjectList(value);
|
||||
List<Object> choiceValues = ExpressionUtils.toObjectList(value);
|
||||
List<Integer> counts = new ArrayList<Integer>(choiceValues.size());
|
||||
|
||||
int count = choiceValues.size();
|
||||
|
||||
int count = choiceValues.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
counts.add(getChoiceValueCount(choiceValues.get(i)));
|
||||
counts.add(getChoiceValueCount(choiceValues.get(i)));
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return getChoiceValueCount(value);
|
||||
}
|
||||
|
||||
|
||||
public Integer getChoiceValueCount(Object choiceValue) {
|
||||
if (ExpressionUtils.isError(choiceValue)) {
|
||||
return errorCount;
|
||||
|
@ -51,9 +51,9 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor {
|
||||
/*
|
||||
* Configuration
|
||||
*/
|
||||
final protected RowEvaluable _rowEvaluable;
|
||||
final protected NumericBinIndex _index; // base bins
|
||||
|
||||
final protected RowEvaluable _rowEvaluable;
|
||||
final protected NumericBinIndex _index; // base bins
|
||||
|
||||
/*
|
||||
* Computed results
|
||||
*/
|
||||
@ -72,19 +72,19 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor {
|
||||
protected boolean hasNonNumeric;
|
||||
|
||||
public ExpressionNumericValueBinner(RowEvaluable rowEvaluable, NumericBinIndex index) {
|
||||
_rowEvaluable = rowEvaluable;
|
||||
_rowEvaluable = rowEvaluable;
|
||||
_index = index;
|
||||
bins = new int[_index.getBins().length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -105,7 +105,7 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor {
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
processRow(project, r, project.rows.get(r), bindings);
|
||||
processRow(project, r, project.rows.get(r), bindings);
|
||||
}
|
||||
|
||||
updateCounts();
|
||||
|
@ -50,13 +50,13 @@ import com.google.refine.model.Row;
|
||||
* from a given expression.
|
||||
*/
|
||||
public class ExpressionTimeValueBinner implements RowVisitor, RecordVisitor {
|
||||
|
||||
|
||||
/*
|
||||
* Configuration
|
||||
*/
|
||||
final protected RowEvaluable _rowEvaluable;
|
||||
final protected TimeBinIndex _index; // base bins
|
||||
|
||||
final protected RowEvaluable _rowEvaluable;
|
||||
final protected TimeBinIndex _index; // base bins
|
||||
|
||||
/*
|
||||
* Computed results
|
||||
*/
|
||||
@ -75,19 +75,19 @@ public class ExpressionTimeValueBinner implements RowVisitor, RecordVisitor {
|
||||
protected boolean hasNonTime;
|
||||
|
||||
public ExpressionTimeValueBinner(RowEvaluable rowEvaluable, TimeBinIndex index) {
|
||||
_rowEvaluable = rowEvaluable;
|
||||
_rowEvaluable = rowEvaluable;
|
||||
_index = index;
|
||||
bins = new int[_index.getBins().length];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,7 +108,7 @@ public class ExpressionTimeValueBinner implements RowVisitor, RecordVisitor {
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
processRow(project, r, project.rows.get(r), bindings);
|
||||
processRow(project, r, project.rows.get(r), bindings);
|
||||
}
|
||||
|
||||
updateCounts();
|
||||
|
@ -74,17 +74,17 @@ abstract public class TimeBinIndex {
|
||||
protected boolean _hasBlank = false;
|
||||
|
||||
protected long[] steps = {
|
||||
1, // msec
|
||||
1000, // sec
|
||||
1000*60, // min
|
||||
1000*60*60, // hour
|
||||
1000*60*60*24, // day
|
||||
1000*60*60*24*7, // week
|
||||
1000l*2629746l, // month (average Gregorian year / 12)
|
||||
1000l*31556952l, // year (average Gregorian year)
|
||||
1000l*31556952l*10l, // decade
|
||||
1000l*31556952l*100l, // century
|
||||
1000l*31556952l*1000l, // millennium
|
||||
1, // msec
|
||||
1000, // sec
|
||||
1000*60, // min
|
||||
1000*60*60, // hour
|
||||
1000*60*60*24, // day
|
||||
1000*60*60*24*7, // week
|
||||
1000l*2629746l, // month (average Gregorian year / 12)
|
||||
1000l*31556952l, // year (average Gregorian year)
|
||||
1000l*31556952l*10l, // decade
|
||||
1000l*31556952l*100l, // century
|
||||
1000l*31556952l*1000l, // millennium
|
||||
};
|
||||
|
||||
abstract protected void iterate(Project project, RowEvaluable rowEvaluable, List<Long> allValues);
|
||||
@ -110,10 +110,10 @@ abstract public class TimeBinIndex {
|
||||
|
||||
long diff = _max - _min;
|
||||
|
||||
for (int i = 0; i < steps.length; i++) {
|
||||
_step = steps[i];
|
||||
if (diff / _step <= 100) break;
|
||||
}
|
||||
for (int i = 0; i < steps.length; i++) {
|
||||
_step = steps[i];
|
||||
if (diff / _step <= 100) break;
|
||||
}
|
||||
|
||||
_bins = new int[(int) (diff / _step) + 1];
|
||||
for (long d : allValues) {
|
||||
@ -180,7 +180,7 @@ abstract public class TimeBinIndex {
|
||||
_hasError = true;
|
||||
} else if (ExpressionUtils.isNonBlankData(v)) {
|
||||
if (v instanceof Calendar) {
|
||||
v = ((Calendar) v).getTime();
|
||||
v = ((Calendar) v).getTime();
|
||||
}
|
||||
|
||||
if (v instanceof Date) {
|
||||
@ -201,7 +201,7 @@ abstract public class TimeBinIndex {
|
||||
_hasError = true;
|
||||
} else if (ExpressionUtils.isNonBlankData(v)) {
|
||||
if (v instanceof Calendar) {
|
||||
v = ((Calendar) v).getTime();
|
||||
v = ((Calendar) v).getTime();
|
||||
}
|
||||
|
||||
if (v instanceof Date) {
|
||||
@ -218,7 +218,7 @@ abstract public class TimeBinIndex {
|
||||
_totalValueCount++;
|
||||
|
||||
if (value instanceof Calendar) {
|
||||
value = ((Calendar) value).getTime();
|
||||
value = ((Calendar) value).getTime();
|
||||
}
|
||||
|
||||
if (value instanceof Date) {
|
||||
|
@ -42,7 +42,7 @@ import com.google.refine.model.Record;
|
||||
import com.google.refine.model.Row;
|
||||
|
||||
public class TimeBinRecordIndex extends TimeBinIndex {
|
||||
|
||||
|
||||
public TimeBinRecordIndex(Project project, RowEvaluable rowEvaluable) {
|
||||
super(project, rowEvaluable);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ import com.google.refine.model.Row;
|
||||
|
||||
public class TimeBinRowIndex extends TimeBinIndex {
|
||||
|
||||
public TimeBinRowIndex(Project project, RowEvaluable rowEvaluable) {
|
||||
public TimeBinRowIndex(Project project, RowEvaluable rowEvaluable) {
|
||||
super(project, rowEvaluable);
|
||||
}
|
||||
|
||||
|
@ -103,12 +103,12 @@ public class BinningClusterer extends Clusterer {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -115,12 +115,12 @@ public class kNNClusterer extends Clusterer {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -167,12 +167,12 @@ public class kNNClusterer extends Clusterer {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,14 +57,14 @@ public class OpenWorkspaceDirCommand extends Command {
|
||||
File dir = ((FileProjectManager) ProjectManager.singleton).getWorkspaceDir();
|
||||
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
desktop.open(dir);
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
desktop.open(dir);
|
||||
} else /* if Mac */ {
|
||||
Runtime.getRuntime().exec(
|
||||
"open .",
|
||||
new String[] {},
|
||||
dir
|
||||
);
|
||||
Runtime.getRuntime().exec(
|
||||
"open .",
|
||||
new String[] {},
|
||||
dir
|
||||
);
|
||||
}
|
||||
|
||||
respond(response, "{ \"code\" : \"ok\" }");
|
||||
|
@ -51,10 +51,10 @@ import com.google.refine.model.Project;
|
||||
import com.google.refine.preference.TopList;
|
||||
|
||||
public class GetExpressionHistoryCommand extends Command {
|
||||
|
||||
static protected List<String> toExpressionList(Object o) {
|
||||
|
||||
static protected List<String> toExpressionList(Object o) {
|
||||
return o == null ? new ArrayList<String>() : ((TopList) o).getList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
|
@ -56,15 +56,15 @@ import com.google.refine.model.Project;
|
||||
public class ExportRowsCommand extends Command {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static public Properties getRequestParameters(HttpServletRequest request) {
|
||||
static public Properties getRequestParameters(HttpServletRequest request) {
|
||||
Properties options = new Properties();
|
||||
|
||||
|
||||
Enumeration<String> en = request.getParameterNames();
|
||||
while (en.hasMoreElements()) {
|
||||
String name = en.nextElement();
|
||||
options.put(name, request.getParameter(name));
|
||||
String name = en.nextElement();
|
||||
options.put(name, request.getParameter(name));
|
||||
}
|
||||
return options;
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,16 +50,16 @@ public class ReorderRowsCommand extends EngineDependentCommand {
|
||||
@Override
|
||||
protected AbstractOperation createOperation(Project project,
|
||||
HttpServletRequest request, JSONObject engineConfig) throws Exception {
|
||||
|
||||
String mode = request.getParameter("mode");
|
||||
JSONObject sorting = null;
|
||||
|
||||
|
||||
String mode = request.getParameter("mode");
|
||||
JSONObject sorting = null;
|
||||
|
||||
try{
|
||||
String json = request.getParameter("sorting");
|
||||
|
||||
|
||||
sorting = (json == null) ? null : ParsingUtilities.evaluateJsonStringToObject(json);
|
||||
} catch (JSONException e) {
|
||||
// ignore
|
||||
// ignore
|
||||
}
|
||||
|
||||
return new RowReorderOperation(Engine.stringToMode(mode), sorting);
|
||||
|
@ -48,7 +48,7 @@ import com.google.refine.model.Row;
|
||||
|
||||
public class HtmlTableExporter implements WriterExporter {
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return "text/html";
|
||||
}
|
||||
@ -84,12 +84,12 @@ public class HtmlTableExporter implements WriterExporter {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,12 +97,12 @@ public class XlsExporter implements StreamExporter {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,10 +77,10 @@ public class WrappedRow implements HasFields {
|
||||
}
|
||||
|
||||
protected class WrappedRecord implements HasFields {
|
||||
final Record _record;
|
||||
|
||||
final Record _record;
|
||||
|
||||
protected WrappedRecord(Record record) {
|
||||
_record = record;
|
||||
_record = record;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,36 +54,36 @@ public class FacetCount implements Function {
|
||||
@Override
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 3 && args[1] instanceof String && args[2] instanceof String) {
|
||||
Object choiceValue = args[0]; // choice value to look up
|
||||
String facetExpression = (String) args[1];
|
||||
String columnName = (String) args[2];
|
||||
|
||||
Project project = (Project) bindings.get("project");
|
||||
Object choiceValue = args[0]; // choice value to look up
|
||||
String facetExpression = (String) args[1];
|
||||
String columnName = (String) args[2];
|
||||
|
||||
Project project = (Project) bindings.get("project");
|
||||
Column column = project.columnModel.getColumnByName(columnName);
|
||||
if (column == null) {
|
||||
return new EvalError("No such column named " + columnName);
|
||||
}
|
||||
|
||||
|
||||
String key = "nominal-bin:" + facetExpression;
|
||||
ExpressionNominalValueGrouper grouper = (ExpressionNominalValueGrouper) column.getPrecompute(key);
|
||||
if (grouper == null) {
|
||||
try {
|
||||
Evaluable eval = MetaParser.parse(facetExpression);
|
||||
Engine engine = new Engine(project);
|
||||
|
||||
grouper = new ExpressionNominalValueGrouper(eval, columnName, column.getCellIndex());
|
||||
engine.getAllRows().accept(project, grouper);
|
||||
|
||||
column.setPrecompute(key, grouper);
|
||||
} catch (ParsingException e) {
|
||||
return new EvalError("Error parsing facet expression " + facetExpression);
|
||||
}
|
||||
try {
|
||||
Evaluable eval = MetaParser.parse(facetExpression);
|
||||
Engine engine = new Engine(project);
|
||||
|
||||
grouper = new ExpressionNominalValueGrouper(eval, columnName, column.getCellIndex());
|
||||
engine.getAllRows().accept(project, grouper);
|
||||
|
||||
column.setPrecompute(key, grouper);
|
||||
} catch (ParsingException e) {
|
||||
return new EvalError("Error parsing facet expression " + facetExpression);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return grouper.getChoiceValueCountMultiple(choiceValue);
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) +
|
||||
" expects a choice value, an expression as a string, and a column name");
|
||||
" expects a choice value, an expression as a string, and a column name");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,15 +49,15 @@ public class Jsonize implements Function {
|
||||
@Override
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length >= 1) {
|
||||
try {
|
||||
Object o1 = args[0];
|
||||
if (o1 == null) {
|
||||
return "null";
|
||||
} else if (o1 instanceof Number) {
|
||||
return JSONObject.numberToString((Number) o1);
|
||||
} else if (o1 instanceof Boolean) {
|
||||
return o1.toString();
|
||||
} else if (o1 instanceof JSONObject) {
|
||||
try {
|
||||
Object o1 = args[0];
|
||||
if (o1 == null) {
|
||||
return "null";
|
||||
} else if (o1 instanceof Number) {
|
||||
return JSONObject.numberToString((Number) o1);
|
||||
} else if (o1 instanceof Boolean) {
|
||||
return o1.toString();
|
||||
} else if (o1 instanceof JSONObject) {
|
||||
return ((JSONObject) o1).toString();
|
||||
} else if (o1 instanceof JSONArray) {
|
||||
return ((JSONArray) o1).toString();
|
||||
@ -67,12 +67,12 @@ public class Jsonize implements Function {
|
||||
return new JSONArray((Collection<?>) o1).toString();
|
||||
} else if (o1.getClass().isArray()) {
|
||||
return new JSONArray(o1).toString();
|
||||
} else {
|
||||
return JSONObject.quote(o1.toString());
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
return JSONObject.quote(o1.toString());
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class ArgsToArray implements Function {
|
||||
|
||||
@Override
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
return args;
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -232,7 +232,7 @@ public class ControlFunctionRegistry {
|
||||
registerFunction("htmlAttr", new HtmlAttr());
|
||||
registerFunction("htmlText", new HtmlText());
|
||||
registerFunction("innerHtml", new InnerHtml());
|
||||
registerFunction("ownText", new OwnText());
|
||||
registerFunction("ownText", new OwnText());
|
||||
|
||||
registerFunction("indexOf", new IndexOf());
|
||||
registerFunction("lastIndexOf", new LastIndexOf());
|
||||
|
@ -238,7 +238,7 @@ public class Parser {
|
||||
throw makeException("Missing )");
|
||||
}
|
||||
} else if (_token.type == TokenType.Delimiter && _token.text.equals("[")) { // [ ... ] array
|
||||
next(true); // swallow [
|
||||
next(true); // swallow [
|
||||
|
||||
List<Evaluable> args = parseExpressionList("]");
|
||||
|
||||
|
@ -117,7 +117,7 @@ public class Filter implements Control {
|
||||
|
||||
Object r = args[2].evaluate(bindings);
|
||||
if (r instanceof Boolean && ((Boolean) r).booleanValue()) {
|
||||
results.add(v);
|
||||
results.add(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,9 +120,9 @@ public class ForEachIndex implements Control {
|
||||
results = new ArrayList<Object>(list.size());
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Object v = list.get(i);
|
||||
|
||||
bindings.put(indexName, i);
|
||||
Object v = list.get(i);
|
||||
|
||||
bindings.put(indexName, i);
|
||||
bindings.put(elementName, v);
|
||||
|
||||
Object r = args[3].evaluate(bindings);
|
||||
|
@ -87,7 +87,7 @@ public class ForRange implements Control {
|
||||
double to = ((Number) toO).doubleValue();
|
||||
|
||||
while (from < to) {
|
||||
bindings.put(indexName, from);
|
||||
bindings.put(indexName, from);
|
||||
|
||||
Object r = args[4].evaluate(bindings);
|
||||
|
||||
@ -101,7 +101,7 @@ public class ForRange implements Control {
|
||||
double to = ((Number) toO).doubleValue();
|
||||
|
||||
while (from < to) {
|
||||
bindings.put(indexName, from);
|
||||
bindings.put(indexName, from);
|
||||
|
||||
Object r = args[4].evaluate(bindings);
|
||||
|
||||
@ -124,13 +124,13 @@ public class ForRange implements Control {
|
||||
}
|
||||
|
||||
static private boolean isIntegral(Number o) {
|
||||
if (o instanceof Integer || o instanceof Long) {
|
||||
return true;
|
||||
} else {
|
||||
return (o.doubleValue() - o.longValue()) == 0;
|
||||
}
|
||||
if (o instanceof Integer || o instanceof Long) {
|
||||
return true;
|
||||
} else {
|
||||
return (o.doubleValue() - o.longValue()) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
@ -34,25 +34,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
package com.google.refine.model;
|
||||
|
||||
public class ModelException extends Exception {
|
||||
private static final long serialVersionUID = -168448967638065467L;
|
||||
private static final long serialVersionUID = -168448967638065467L;
|
||||
|
||||
public ModelException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
public ModelException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ModelException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
public ModelException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ModelException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
public ModelException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ModelException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
public ModelException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,17 +34,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
package com.google.refine.model;
|
||||
|
||||
public class Record {
|
||||
final public int fromRowIndex;
|
||||
final public int toRowIndex;
|
||||
final public int recordIndex;
|
||||
|
||||
public Record(
|
||||
int fromRowIndex,
|
||||
int toRowIndex,
|
||||
int recordIndex
|
||||
) {
|
||||
this.fromRowIndex = fromRowIndex;
|
||||
this.toRowIndex = toRowIndex;
|
||||
this.recordIndex = recordIndex;
|
||||
}
|
||||
final public int fromRowIndex;
|
||||
final public int toRowIndex;
|
||||
final public int recordIndex;
|
||||
|
||||
public Record(
|
||||
int fromRowIndex,
|
||||
int toRowIndex,
|
||||
int recordIndex
|
||||
) {
|
||||
this.fromRowIndex = fromRowIndex;
|
||||
this.toRowIndex = toRowIndex;
|
||||
this.recordIndex = recordIndex;
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class RecordModel implements Jsonizable {
|
||||
this.cellIndex = cellIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final static public class RowDependency {
|
||||
public int recordIndex;
|
||||
public CellDependency[] cellDependencies;
|
||||
|
@ -161,12 +161,12 @@ public class Row implements HasFields, Jsonizable {
|
||||
|
||||
if (!"save".equals(options.getProperty("mode"))) {
|
||||
if (options.containsKey("rowIndex")) {
|
||||
int rowIndex = (Integer) options.get("rowIndex");
|
||||
int rowIndex = (Integer) options.get("rowIndex");
|
||||
writer.key("i"); writer.value(rowIndex);
|
||||
|
||||
|
||||
if (options.containsKey("recordIndex")) {
|
||||
int recordIndex = (Integer) options.get("recordIndex");
|
||||
|
||||
int recordIndex = (Integer) options.get("recordIndex");
|
||||
|
||||
writer.key("j"); writer.value(recordIndex);
|
||||
}
|
||||
}
|
||||
|
@ -55,15 +55,15 @@ public class RowReorderChange implements Change {
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
synchronized (project) {
|
||||
List<Row> oldRows = project.rows;
|
||||
List<Row> newRows = new ArrayList<Row>(oldRows.size());
|
||||
|
||||
for (Integer oldIndex : _rowIndices) {
|
||||
newRows.add(oldRows.get(oldIndex));
|
||||
}
|
||||
|
||||
project.rows.clear();
|
||||
project.rows.addAll(newRows);
|
||||
List<Row> oldRows = project.rows;
|
||||
List<Row> newRows = new ArrayList<Row>(oldRows.size());
|
||||
|
||||
for (Integer oldIndex : _rowIndices) {
|
||||
newRows.add(oldRows.get(oldIndex));
|
||||
}
|
||||
|
||||
project.rows.clear();
|
||||
project.rows.addAll(newRows);
|
||||
project.update();
|
||||
}
|
||||
}
|
||||
@ -71,23 +71,23 @@ public class RowReorderChange implements Change {
|
||||
@Override
|
||||
public void revert(Project project) {
|
||||
synchronized (project) {
|
||||
int count = project.rows.size();
|
||||
|
||||
List<Row> newRows = project.rows;
|
||||
List<Row> oldRows = new ArrayList<Row>(count);
|
||||
|
||||
for (int r = 0; r < count; r++) {
|
||||
oldRows.add(null);
|
||||
}
|
||||
|
||||
for (int newIndex = 0; newIndex < count; newIndex++) {
|
||||
int oldIndex = _rowIndices.get(newIndex);
|
||||
Row row = newRows.get(newIndex);
|
||||
oldRows.set(oldIndex, row);
|
||||
}
|
||||
|
||||
project.rows.clear();
|
||||
project.rows.addAll(oldRows);
|
||||
int count = project.rows.size();
|
||||
|
||||
List<Row> newRows = project.rows;
|
||||
List<Row> oldRows = new ArrayList<Row>(count);
|
||||
|
||||
for (int r = 0; r < count; r++) {
|
||||
oldRows.add(null);
|
||||
}
|
||||
|
||||
for (int newIndex = 0; newIndex < count; newIndex++) {
|
||||
int oldIndex = _rowIndices.get(newIndex);
|
||||
Row row = newRows.get(newIndex);
|
||||
oldRows.set(oldIndex, row);
|
||||
}
|
||||
|
||||
project.rows.clear();
|
||||
project.rows.addAll(oldRows);
|
||||
project.update();
|
||||
}
|
||||
}
|
||||
|
@ -108,15 +108,15 @@ public class BlankDownOperation extends EngineDependentMassCellOperation {
|
||||
this.cellChanges = cellChanges;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,12 +111,12 @@ public class FillDownOperation extends EngineDependentMassCellOperation {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -238,12 +238,12 @@ public class MassEditOperation extends EngineDependentMassCellOperation {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -161,29 +161,29 @@ public class TextTransformOperation extends EngineDependentMassCellOperation {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, int rowIndex, Row row) {
|
||||
Cell cell = row.getCell(cellIndex);
|
||||
Cell newCell = null;
|
||||
|
||||
|
||||
Object oldValue = cell != null ? cell.value : null;
|
||||
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell);
|
||||
|
||||
|
||||
Object o = eval.evaluate(bindings);
|
||||
if (o == null) {
|
||||
if (oldValue != null) {
|
||||
if (oldValue != null) {
|
||||
CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, null);
|
||||
cellChanges.add(cellChange);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (o instanceof Cell) {
|
||||
newCell = (Cell) o;
|
||||
|
@ -180,12 +180,12 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -277,12 +277,12 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,12 +122,12 @@ public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOpera
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -125,12 +125,12 @@ public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperatio
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -116,14 +116,14 @@ public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOp
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, int rowIndex, Row row) {
|
||||
if (cellIndex < row.cells.size()) {
|
||||
|
@ -161,14 +161,14 @@ public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOpe
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, int rowIndex, Row row) {
|
||||
Cell cell = row.getCell(cellIndex);
|
||||
|
@ -222,12 +222,12 @@ public class ReconOperation extends EngineDependentOperation {
|
||||
filteredRows.accept(_project, new RowVisitor() {
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,20 +87,20 @@ public void write(JSONWriter writer, Properties options)
|
||||
RowDependency rd = project.recordModel.getRowDependency(r);
|
||||
if (rd.cellDependencies != null) {
|
||||
newRow = oldRow.dup();
|
||||
|
||||
|
||||
for (int c = 0; c < rd.cellDependencies.length; c++) {
|
||||
CellDependency cd = rd.cellDependencies[c];
|
||||
if (cd != null) {
|
||||
int contextRowIndex = cd.rowIndex;
|
||||
int contextCellIndex = cd.cellIndex;
|
||||
|
||||
if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) {
|
||||
Row contextRow = oldRows.get(contextRowIndex);
|
||||
Cell contextCell = contextRow.getCell(contextCellIndex);
|
||||
|
||||
newRow.setCell(contextCellIndex, contextCell);
|
||||
}
|
||||
}
|
||||
CellDependency cd = rd.cellDependencies[c];
|
||||
if (cd != null) {
|
||||
int contextRowIndex = cd.rowIndex;
|
||||
int contextCellIndex = cd.cellIndex;
|
||||
|
||||
if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) {
|
||||
Row contextRow = oldRows.get(contextRowIndex);
|
||||
Cell contextCell = contextRow.getCell(contextCellIndex);
|
||||
|
||||
newRow.setCell(contextCellIndex, contextCell);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,12 +118,12 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID)
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,17 +107,17 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID)
|
||||
this.rowIndices = rowIndices;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, int rowIndex, Row row) {
|
||||
rowIndices.add(rowIndex);
|
||||
|
@ -57,18 +57,18 @@ import com.google.refine.sorting.SortingRowVisitor;
|
||||
|
||||
public class RowReorderOperation extends AbstractOperation {
|
||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||
String mode = obj.getString("mode");
|
||||
String mode = obj.getString("mode");
|
||||
JSONObject sorting = obj.has("sorting") && !obj.isNull("sorting") ?
|
||||
obj.getJSONObject("sorting") : null;
|
||||
|
||||
return new RowReorderOperation(Engine.stringToMode(mode), sorting);
|
||||
obj.getJSONObject("sorting") : null;
|
||||
|
||||
return new RowReorderOperation(Engine.stringToMode(mode), sorting);
|
||||
}
|
||||
|
||||
final protected Mode _mode;
|
||||
|
||||
final protected Mode _mode;
|
||||
final protected JSONObject _sorting;
|
||||
|
||||
|
||||
public RowReorderOperation(Mode mode, JSONObject sorting) {
|
||||
_mode = mode;
|
||||
_mode = mode;
|
||||
_sorting = sorting;
|
||||
}
|
||||
|
||||
@ -98,65 +98,65 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID)
|
||||
if (_mode == Mode.RowBased) {
|
||||
RowVisitor visitor = new IndexingVisitor(rowIndices);
|
||||
if (_sorting != null) {
|
||||
SortingRowVisitor srv = new SortingRowVisitor(visitor);
|
||||
|
||||
srv.initializeFromJSON(project, _sorting);
|
||||
if (srv.hasCriteria()) {
|
||||
visitor = srv;
|
||||
}
|
||||
SortingRowVisitor srv = new SortingRowVisitor(visitor);
|
||||
|
||||
srv.initializeFromJSON(project, _sorting);
|
||||
if (srv.hasCriteria()) {
|
||||
visitor = srv;
|
||||
}
|
||||
}
|
||||
|
||||
engine.getAllRows().accept(project, visitor);
|
||||
|
||||
engine.getAllRows().accept(project, visitor);
|
||||
} else {
|
||||
RecordVisitor visitor = new IndexingVisitor(rowIndices);
|
||||
if (_sorting != null) {
|
||||
SortingRecordVisitor srv = new SortingRecordVisitor(visitor);
|
||||
|
||||
srv.initializeFromJSON(project, _sorting);
|
||||
if (srv.hasCriteria()) {
|
||||
visitor = srv;
|
||||
}
|
||||
SortingRecordVisitor srv = new SortingRecordVisitor(visitor);
|
||||
|
||||
srv.initializeFromJSON(project, _sorting);
|
||||
if (srv.hasCriteria()) {
|
||||
visitor = srv;
|
||||
}
|
||||
}
|
||||
|
||||
engine.getAllRecords().accept(project, visitor);
|
||||
engine.getAllRecords().accept(project, visitor);
|
||||
}
|
||||
|
||||
return new HistoryEntry(
|
||||
historyEntryID,
|
||||
project,
|
||||
"Reorder rows",
|
||||
this,
|
||||
new RowReorderChange(rowIndices)
|
||||
historyEntryID,
|
||||
project,
|
||||
"Reorder rows",
|
||||
this,
|
||||
new RowReorderChange(rowIndices)
|
||||
);
|
||||
}
|
||||
|
||||
static protected class IndexingVisitor implements RowVisitor, RecordVisitor {
|
||||
List<Integer> _indices;
|
||||
|
||||
IndexingVisitor(List<Integer> indices) {
|
||||
_indices = indices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
}
|
||||
static protected class IndexingVisitor implements RowVisitor, RecordVisitor {
|
||||
List<Integer> _indices;
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, int rowIndex, Row row) {
|
||||
_indices.add(rowIndex);
|
||||
return false;
|
||||
}
|
||||
IndexingVisitor(List<Integer> indices) {
|
||||
_indices = indices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, Record record) {
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
_indices.add(r);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, int rowIndex, Row row) {
|
||||
_indices.add(rowIndex);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, Record record) {
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
_indices.add(r);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,12 +118,12 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID)
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,130 +44,130 @@ import com.google.refine.model.Project;
|
||||
import com.google.refine.sorting.Criterion.KeyMaker;
|
||||
|
||||
abstract public class BaseSorter {
|
||||
protected Criterion[] _criteria;
|
||||
protected KeyMaker[] _keyMakers;
|
||||
protected ComparatorWrapper[] _comparatorWrappers;
|
||||
protected List<Object[]> _keys;
|
||||
|
||||
public class ComparatorWrapper {
|
||||
final public int criterionIndex;
|
||||
final protected int multiplier;
|
||||
|
||||
public ComparatorWrapper(int criterionIndex) {
|
||||
this.criterionIndex = criterionIndex;
|
||||
this.multiplier = _criteria[criterionIndex].reverse ? -1 : 1;
|
||||
}
|
||||
|
||||
public Object getKey(Project project, Object o, int index) {
|
||||
while (index >= _keys.size()) {
|
||||
_keys.add(null);
|
||||
}
|
||||
|
||||
Object[] keys = _keys.get(index);
|
||||
if (keys == null) {
|
||||
keys = makeKeys(project, o, index);
|
||||
_keys.set(index, keys);
|
||||
}
|
||||
return keys[criterionIndex];
|
||||
}
|
||||
|
||||
public int compare(Project project, Object o1, int i1, Object o2, int i2) {
|
||||
Criterion c = _criteria[criterionIndex];
|
||||
Object key1 = getKey(project, o1, i1);
|
||||
Object key2 = getKey(project, o2, i2);
|
||||
|
||||
if (key1 == null) {
|
||||
if (key2 == null) {
|
||||
return 0;
|
||||
} else if (key2 instanceof EvalError) {
|
||||
return c.blankPosition - c.errorPosition;
|
||||
} else {
|
||||
return c.blankPosition;
|
||||
}
|
||||
} else if (key1 instanceof EvalError) {
|
||||
if (key2 == null) {
|
||||
return c.errorPosition - c.blankPosition;
|
||||
} else if (key2 instanceof EvalError) {
|
||||
return 0;
|
||||
} else {
|
||||
return c.errorPosition;
|
||||
}
|
||||
} else {
|
||||
if (key2 == null) {
|
||||
return -c.blankPosition;
|
||||
} else if (key2 instanceof EvalError) {
|
||||
return -c.errorPosition;
|
||||
} else {
|
||||
return _keyMakers[criterionIndex].compareKeys(key1, key2) * multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void initializeFromJSON(Project project, JSONObject obj) throws JSONException {
|
||||
if (obj.has("criteria") && !obj.isNull("criteria")) {
|
||||
JSONArray a = obj.getJSONArray("criteria");
|
||||
int count = a.length();
|
||||
|
||||
_criteria = new Criterion[count];
|
||||
_keyMakers = new KeyMaker[count];
|
||||
_comparatorWrappers = new ComparatorWrapper[count];
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
JSONObject obj2 = a.getJSONObject(i);
|
||||
|
||||
_criteria[i] = createCriterionFromJSON(project, obj2);
|
||||
_keyMakers[i] = _criteria[i].createKeyMaker();
|
||||
_comparatorWrappers[i] = new ComparatorWrapper(i);
|
||||
}
|
||||
} else {
|
||||
_criteria = new Criterion[0];
|
||||
_keyMakers = new KeyMaker[0];
|
||||
_comparatorWrappers = new ComparatorWrapper[0];
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCriteria() {
|
||||
return _criteria != null && _criteria.length > 0;
|
||||
}
|
||||
|
||||
protected Criterion createCriterionFromJSON(Project project, JSONObject obj) throws JSONException {
|
||||
String valueType = "string";
|
||||
if (obj.has("valueType") && !obj.isNull("valueType")) {
|
||||
valueType = obj.getString("valueType");
|
||||
}
|
||||
|
||||
Criterion c = null;
|
||||
if ("boolean".equals(valueType)) {
|
||||
c = new BooleanCriterion();
|
||||
} else if ("date".equals(valueType)) {
|
||||
c = new DateCriterion();
|
||||
} else if ("number".equals(valueType)) {
|
||||
c = new NumberCriterion();
|
||||
} else {
|
||||
c = new StringCriterion();
|
||||
}
|
||||
|
||||
c.initializeFromJSON(project, obj);
|
||||
return c;
|
||||
}
|
||||
|
||||
abstract protected Object makeKey(
|
||||
Project project, KeyMaker keyMaker, Criterion c, Object o, int index);
|
||||
|
||||
protected Object[] makeKeys(Project project, Object o, int index) {
|
||||
Object[] keys = new Object[_keyMakers.length];
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
keys[i] = makeKey(project, _keyMakers[i], _criteria[i], o, index);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
protected int compare(Project project, Object o1, int i1, Object o2, int i2) {
|
||||
int c = 0;
|
||||
for (int i = 0; c == 0 && i < _comparatorWrappers.length; i++) {
|
||||
c = _comparatorWrappers[i].compare(project, o1, i1, o2, i2);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
protected Criterion[] _criteria;
|
||||
protected KeyMaker[] _keyMakers;
|
||||
protected ComparatorWrapper[] _comparatorWrappers;
|
||||
protected List<Object[]> _keys;
|
||||
|
||||
public class ComparatorWrapper {
|
||||
final public int criterionIndex;
|
||||
final protected int multiplier;
|
||||
|
||||
public ComparatorWrapper(int criterionIndex) {
|
||||
this.criterionIndex = criterionIndex;
|
||||
this.multiplier = _criteria[criterionIndex].reverse ? -1 : 1;
|
||||
}
|
||||
|
||||
public Object getKey(Project project, Object o, int index) {
|
||||
while (index >= _keys.size()) {
|
||||
_keys.add(null);
|
||||
}
|
||||
|
||||
Object[] keys = _keys.get(index);
|
||||
if (keys == null) {
|
||||
keys = makeKeys(project, o, index);
|
||||
_keys.set(index, keys);
|
||||
}
|
||||
return keys[criterionIndex];
|
||||
}
|
||||
|
||||
public int compare(Project project, Object o1, int i1, Object o2, int i2) {
|
||||
Criterion c = _criteria[criterionIndex];
|
||||
Object key1 = getKey(project, o1, i1);
|
||||
Object key2 = getKey(project, o2, i2);
|
||||
|
||||
if (key1 == null) {
|
||||
if (key2 == null) {
|
||||
return 0;
|
||||
} else if (key2 instanceof EvalError) {
|
||||
return c.blankPosition - c.errorPosition;
|
||||
} else {
|
||||
return c.blankPosition;
|
||||
}
|
||||
} else if (key1 instanceof EvalError) {
|
||||
if (key2 == null) {
|
||||
return c.errorPosition - c.blankPosition;
|
||||
} else if (key2 instanceof EvalError) {
|
||||
return 0;
|
||||
} else {
|
||||
return c.errorPosition;
|
||||
}
|
||||
} else {
|
||||
if (key2 == null) {
|
||||
return -c.blankPosition;
|
||||
} else if (key2 instanceof EvalError) {
|
||||
return -c.errorPosition;
|
||||
} else {
|
||||
return _keyMakers[criterionIndex].compareKeys(key1, key2) * multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void initializeFromJSON(Project project, JSONObject obj) throws JSONException {
|
||||
if (obj.has("criteria") && !obj.isNull("criteria")) {
|
||||
JSONArray a = obj.getJSONArray("criteria");
|
||||
int count = a.length();
|
||||
|
||||
_criteria = new Criterion[count];
|
||||
_keyMakers = new KeyMaker[count];
|
||||
_comparatorWrappers = new ComparatorWrapper[count];
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
JSONObject obj2 = a.getJSONObject(i);
|
||||
|
||||
_criteria[i] = createCriterionFromJSON(project, obj2);
|
||||
_keyMakers[i] = _criteria[i].createKeyMaker();
|
||||
_comparatorWrappers[i] = new ComparatorWrapper(i);
|
||||
}
|
||||
} else {
|
||||
_criteria = new Criterion[0];
|
||||
_keyMakers = new KeyMaker[0];
|
||||
_comparatorWrappers = new ComparatorWrapper[0];
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCriteria() {
|
||||
return _criteria != null && _criteria.length > 0;
|
||||
}
|
||||
|
||||
protected Criterion createCriterionFromJSON(Project project, JSONObject obj) throws JSONException {
|
||||
String valueType = "string";
|
||||
if (obj.has("valueType") && !obj.isNull("valueType")) {
|
||||
valueType = obj.getString("valueType");
|
||||
}
|
||||
|
||||
Criterion c = null;
|
||||
if ("boolean".equals(valueType)) {
|
||||
c = new BooleanCriterion();
|
||||
} else if ("date".equals(valueType)) {
|
||||
c = new DateCriterion();
|
||||
} else if ("number".equals(valueType)) {
|
||||
c = new NumberCriterion();
|
||||
} else {
|
||||
c = new StringCriterion();
|
||||
}
|
||||
|
||||
c.initializeFromJSON(project, obj);
|
||||
return c;
|
||||
}
|
||||
|
||||
abstract protected Object makeKey(
|
||||
Project project, KeyMaker keyMaker, Criterion c, Object o, int index);
|
||||
|
||||
protected Object[] makeKeys(Project project, Object o, int index) {
|
||||
Object[] keys = new Object[_keyMakers.length];
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
keys[i] = makeKey(project, _keyMakers[i], _criteria[i], o, index);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
protected int compare(Project project, Object o1, int i1, Object o2, int i2) {
|
||||
int c = 0;
|
||||
for (int i = 0; c == 0 && i < _comparatorWrappers.length; i++) {
|
||||
c = _comparatorWrappers[i].compare(project, o1, i1, o2, i2);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
@ -44,55 +44,55 @@ import com.google.refine.model.Record;
|
||||
import com.google.refine.sorting.Criterion.KeyMaker;
|
||||
|
||||
public class SortingRecordVisitor extends BaseSorter implements RecordVisitor {
|
||||
final protected RecordVisitor _visitor;
|
||||
protected List<Record> _records;
|
||||
|
||||
public SortingRecordVisitor(RecordVisitor visitor) {
|
||||
_visitor = visitor;
|
||||
}
|
||||
final protected RecordVisitor _visitor;
|
||||
protected List<Record> _records;
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
int count = project.recordModel.getRecordCount();
|
||||
_records = new ArrayList<Record>(count);
|
||||
_keys = new ArrayList<Object[]>(count);
|
||||
}
|
||||
public SortingRecordVisitor(RecordVisitor visitor) {
|
||||
_visitor = visitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
_visitor.start(project);
|
||||
|
||||
Collections.sort(_records, new Comparator<Record>() {
|
||||
Project project;
|
||||
|
||||
Comparator<Record> init(Project project) {
|
||||
this.project = project;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Record o1, Record o2) {
|
||||
return SortingRecordVisitor.this.compare(project, o1, o1.recordIndex, o2, o2.recordIndex);
|
||||
}
|
||||
}.init(project));
|
||||
|
||||
for (Record record : _records) {
|
||||
_visitor.visit(project, record);
|
||||
}
|
||||
|
||||
_visitor.end(project);
|
||||
}
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
int count = project.recordModel.getRecordCount();
|
||||
_records = new ArrayList<Record>(count);
|
||||
_keys = new ArrayList<Object[]>(count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, Record record) {
|
||||
_records.add(record);
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
_visitor.start(project);
|
||||
|
||||
@Override
|
||||
protected Object makeKey(
|
||||
Project project, KeyMaker keyMaker, Criterion c, Object o, int index) {
|
||||
|
||||
return keyMaker.makeKey(project, (Record) o);
|
||||
}
|
||||
Collections.sort(_records, new Comparator<Record>() {
|
||||
Project project;
|
||||
|
||||
Comparator<Record> init(Project project) {
|
||||
this.project = project;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Record o1, Record o2) {
|
||||
return SortingRecordVisitor.this.compare(project, o1, o1.recordIndex, o2, o2.recordIndex);
|
||||
}
|
||||
}.init(project));
|
||||
|
||||
for (Record record : _records) {
|
||||
_visitor.visit(project, record);
|
||||
}
|
||||
|
||||
_visitor.end(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, Record record) {
|
||||
_records.add(record);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object makeKey(
|
||||
Project project, KeyMaker keyMaker, Criterion c, Object o, int index) {
|
||||
|
||||
return keyMaker.makeKey(project, (Record) o);
|
||||
}
|
||||
}
|
||||
|
@ -44,65 +44,65 @@ import com.google.refine.model.Row;
|
||||
import com.google.refine.sorting.Criterion.KeyMaker;
|
||||
|
||||
public class SortingRowVisitor extends BaseSorter implements RowVisitor {
|
||||
final protected RowVisitor _visitor;
|
||||
protected List<IndexedRow> _indexedRows;
|
||||
|
||||
static protected class IndexedRow {
|
||||
final int index;
|
||||
final Row row;
|
||||
|
||||
IndexedRow(int index, Row row) {
|
||||
this.index = index;
|
||||
this.row = row;
|
||||
}
|
||||
}
|
||||
|
||||
public SortingRowVisitor(RowVisitor visitor) {
|
||||
_visitor = visitor;
|
||||
}
|
||||
final protected RowVisitor _visitor;
|
||||
protected List<IndexedRow> _indexedRows;
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
int count = project.rows.size();
|
||||
_indexedRows = new ArrayList<IndexedRow>(count);
|
||||
_keys = new ArrayList<Object[]>(count);
|
||||
}
|
||||
static protected class IndexedRow {
|
||||
final int index;
|
||||
final Row row;
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
_visitor.start(project);
|
||||
|
||||
Collections.sort(_indexedRows, new Comparator<IndexedRow>() {
|
||||
Project project;
|
||||
|
||||
Comparator<IndexedRow> init(Project project) {
|
||||
this.project = project;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(IndexedRow o1, IndexedRow o2) {
|
||||
return SortingRowVisitor.this.compare(project, o1.row, o1.index, o2.row, o2.index);
|
||||
}
|
||||
}.init(project));
|
||||
|
||||
for (IndexedRow indexedRow : _indexedRows) {
|
||||
_visitor.visit(project, indexedRow.index, indexedRow.row);
|
||||
}
|
||||
|
||||
_visitor.end(project);
|
||||
}
|
||||
IndexedRow(int index, Row row) {
|
||||
this.index = index;
|
||||
this.row = row;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, int rowIndex, Row row) {
|
||||
_indexedRows.add(new IndexedRow(rowIndex, row));
|
||||
return false;
|
||||
}
|
||||
public SortingRowVisitor(RowVisitor visitor) {
|
||||
_visitor = visitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object makeKey(
|
||||
Project project, KeyMaker keyMaker, Criterion c, Object o, int index) {
|
||||
|
||||
return keyMaker.makeKey(project, (Row) o, index);
|
||||
}
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
int count = project.rows.size();
|
||||
_indexedRows = new ArrayList<IndexedRow>(count);
|
||||
_keys = new ArrayList<Object[]>(count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
_visitor.start(project);
|
||||
|
||||
Collections.sort(_indexedRows, new Comparator<IndexedRow>() {
|
||||
Project project;
|
||||
|
||||
Comparator<IndexedRow> init(Project project) {
|
||||
this.project = project;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(IndexedRow o1, IndexedRow o2) {
|
||||
return SortingRowVisitor.this.compare(project, o1.row, o1.index, o2.row, o2.index);
|
||||
}
|
||||
}.init(project));
|
||||
|
||||
for (IndexedRow indexedRow : _indexedRows) {
|
||||
_visitor.visit(project, indexedRow.index, indexedRow.row);
|
||||
}
|
||||
|
||||
_visitor.end(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, int rowIndex, Row row) {
|
||||
_indexedRows.add(new IndexedRow(rowIndex, row));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object makeKey(
|
||||
Project project, KeyMaker keyMaker, Criterion c, Object o, int index) {
|
||||
|
||||
return keyMaker.makeKey(project, (Row) o, index);
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ package com.google.refine.templating;
|
||||
import com.google.refine.expr.Evaluable;
|
||||
|
||||
class DynamicFragment extends Fragment {
|
||||
final public Evaluable eval;
|
||||
|
||||
public DynamicFragment(Evaluable eval) {
|
||||
this.eval = eval;
|
||||
}
|
||||
final public Evaluable eval;
|
||||
|
||||
public DynamicFragment(Evaluable eval) {
|
||||
this.eval = eval;
|
||||
}
|
||||
}
|
||||
|
@ -42,63 +42,63 @@ import com.google.refine.grel.ast.FieldAccessorExpr;
|
||||
import com.google.refine.grel.ast.VariableExpr;
|
||||
|
||||
public class Parser {
|
||||
static public Template parse(String s) throws ParsingException {
|
||||
List<Fragment> fragments = new ArrayList<Fragment>();
|
||||
|
||||
int start = 0, current = 0;
|
||||
while (current < s.length() - 1) {
|
||||
char c = s.charAt(current);
|
||||
if (c == '\\') {
|
||||
current += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
char c2 = s.charAt(current + 1);
|
||||
if (c == '$' && c2 == '{') {
|
||||
int closeBrace = s.indexOf('}', current + 2);
|
||||
if (closeBrace > current + 1) {
|
||||
String columnName = s.substring(current + 2, closeBrace);
|
||||
|
||||
if (current > start) {
|
||||
fragments.add(new StaticFragment(s.substring(start, current)));
|
||||
}
|
||||
start = current = closeBrace + 1;
|
||||
|
||||
fragments.add(
|
||||
new DynamicFragment(
|
||||
new FieldAccessorExpr(
|
||||
new FieldAccessorExpr(
|
||||
new VariableExpr("cells"),
|
||||
columnName),
|
||||
"value")));
|
||||
|
||||
continue;
|
||||
}
|
||||
} else if (c == '{' && c2 == '{') {
|
||||
int closeBrace = s.indexOf('}', current + 2);
|
||||
if (closeBrace > current + 1 && closeBrace < s.length() - 1 && s.charAt(closeBrace + 1) == '}') {
|
||||
String expression = s.substring(current + 2, closeBrace);
|
||||
|
||||
if (current > start) {
|
||||
fragments.add(new StaticFragment(s.substring(start, current)));
|
||||
}
|
||||
start = current = closeBrace + 2;
|
||||
|
||||
fragments.add(
|
||||
new DynamicFragment(
|
||||
MetaParser.parse(expression)));
|
||||
static public Template parse(String s) throws ParsingException {
|
||||
List<Fragment> fragments = new ArrayList<Fragment>();
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
current++;
|
||||
}
|
||||
|
||||
if (start < s.length()) {
|
||||
fragments.add(new StaticFragment(s.substring(start)));
|
||||
}
|
||||
|
||||
return new Template(fragments);
|
||||
}
|
||||
int start = 0, current = 0;
|
||||
while (current < s.length() - 1) {
|
||||
char c = s.charAt(current);
|
||||
if (c == '\\') {
|
||||
current += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
char c2 = s.charAt(current + 1);
|
||||
if (c == '$' && c2 == '{') {
|
||||
int closeBrace = s.indexOf('}', current + 2);
|
||||
if (closeBrace > current + 1) {
|
||||
String columnName = s.substring(current + 2, closeBrace);
|
||||
|
||||
if (current > start) {
|
||||
fragments.add(new StaticFragment(s.substring(start, current)));
|
||||
}
|
||||
start = current = closeBrace + 1;
|
||||
|
||||
fragments.add(
|
||||
new DynamicFragment(
|
||||
new FieldAccessorExpr(
|
||||
new FieldAccessorExpr(
|
||||
new VariableExpr("cells"),
|
||||
columnName),
|
||||
"value")));
|
||||
|
||||
continue;
|
||||
}
|
||||
} else if (c == '{' && c2 == '{') {
|
||||
int closeBrace = s.indexOf('}', current + 2);
|
||||
if (closeBrace > current + 1 && closeBrace < s.length() - 1 && s.charAt(closeBrace + 1) == '}') {
|
||||
String expression = s.substring(current + 2, closeBrace);
|
||||
|
||||
if (current > start) {
|
||||
fragments.add(new StaticFragment(s.substring(start, current)));
|
||||
}
|
||||
start = current = closeBrace + 2;
|
||||
|
||||
fragments.add(
|
||||
new DynamicFragment(
|
||||
MetaParser.parse(expression)));
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
current++;
|
||||
}
|
||||
|
||||
if (start < s.length()) {
|
||||
fragments.add(new StaticFragment(s.substring(start)));
|
||||
}
|
||||
|
||||
return new Template(fragments);
|
||||
}
|
||||
}
|
||||
|
@ -34,9 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
package com.google.refine.templating;
|
||||
|
||||
class StaticFragment extends Fragment {
|
||||
final public String text;
|
||||
|
||||
public StaticFragment(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
final public String text;
|
||||
|
||||
public StaticFragment(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
|
@ -47,160 +47,160 @@ import com.google.refine.model.Record;
|
||||
import com.google.refine.model.Row;
|
||||
|
||||
public class Template {
|
||||
protected String _prefix;
|
||||
protected String _suffix;
|
||||
protected String _separator;
|
||||
|
||||
protected List<Fragment> _fragments;
|
||||
|
||||
public Template(List<Fragment> fragments) {
|
||||
_fragments = fragments;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
_prefix = prefix;
|
||||
}
|
||||
|
||||
public void setSuffix(String suffix) {
|
||||
_suffix = suffix;
|
||||
}
|
||||
|
||||
public void setSeparator(String separator) {
|
||||
_separator = separator;
|
||||
}
|
||||
|
||||
public RowVisitor getRowVisitor(Writer writer, int limit) {
|
||||
return get(writer, limit);
|
||||
}
|
||||
|
||||
public RecordVisitor getRecordVisitor(Writer writer, int limit) {
|
||||
return get(writer, limit);
|
||||
}
|
||||
|
||||
protected RowWritingVisitor get(Writer writer, int limit) {
|
||||
return new RowWritingVisitor(writer, limit);
|
||||
}
|
||||
|
||||
protected String _prefix;
|
||||
protected String _suffix;
|
||||
protected String _separator;
|
||||
|
||||
protected List<Fragment> _fragments;
|
||||
|
||||
public Template(List<Fragment> fragments) {
|
||||
_fragments = fragments;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
_prefix = prefix;
|
||||
}
|
||||
|
||||
public void setSuffix(String suffix) {
|
||||
_suffix = suffix;
|
||||
}
|
||||
|
||||
public void setSeparator(String separator) {
|
||||
_separator = separator;
|
||||
}
|
||||
|
||||
public RowVisitor getRowVisitor(Writer writer, int limit) {
|
||||
return get(writer, limit);
|
||||
}
|
||||
|
||||
public RecordVisitor getRecordVisitor(Writer writer, int limit) {
|
||||
return get(writer, limit);
|
||||
}
|
||||
|
||||
protected RowWritingVisitor get(Writer writer, int limit) {
|
||||
return new RowWritingVisitor(writer, limit);
|
||||
}
|
||||
|
||||
protected class RowWritingVisitor implements RowVisitor, RecordVisitor {
|
||||
final protected int limit;
|
||||
final protected Writer writer;
|
||||
protected Properties bindings;
|
||||
|
||||
final protected int limit;
|
||||
final protected Writer writer;
|
||||
protected Properties bindings;
|
||||
|
||||
public int total;
|
||||
|
||||
|
||||
public RowWritingVisitor(Writer writer, int limit) {
|
||||
this.limit = limit;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
bindings = ExpressionUtils.createBindings(project);
|
||||
|
||||
try {
|
||||
if (_prefix != null) {
|
||||
writer.write(_prefix);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
bindings = ExpressionUtils.createBindings(project);
|
||||
|
||||
try {
|
||||
if (_prefix != null) {
|
||||
writer.write(_prefix);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end(Project project) {
|
||||
try {
|
||||
if (_suffix != null) {
|
||||
writer.write(_suffix);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
try {
|
||||
if (_suffix != null) {
|
||||
writer.write(_suffix);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, int rowIndex, Row row) {
|
||||
if (limit <= 0 || total < limit) {
|
||||
internalVisit(project, rowIndex, row);
|
||||
}
|
||||
total++;
|
||||
|
||||
total++;
|
||||
|
||||
return limit > 0 && total >= limit;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(Project project, Record record) {
|
||||
if (limit <= 0 || total < limit) {
|
||||
internalVisit(project, record);
|
||||
}
|
||||
total++;
|
||||
|
||||
total++;
|
||||
|
||||
return limit > 0 && total >= limit;
|
||||
}
|
||||
|
||||
|
||||
protected void writeValue(Object v) throws IOException {
|
||||
if (v == null) {
|
||||
writer.write("null");
|
||||
} else if (ExpressionUtils.isError(v)) {
|
||||
writer.write("null");
|
||||
//writer.write("[Error: " + ((EvalError) v).message);
|
||||
} else if (v instanceof String) {
|
||||
writer.write((String) v);
|
||||
} else {
|
||||
writer.write(v.toString());
|
||||
}
|
||||
if (v == null) {
|
||||
writer.write("null");
|
||||
} else if (ExpressionUtils.isError(v)) {
|
||||
writer.write("null");
|
||||
//writer.write("[Error: " + ((EvalError) v).message);
|
||||
} else if (v instanceof String) {
|
||||
writer.write((String) v);
|
||||
} else {
|
||||
writer.write(v.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean internalVisit(Project project, int rowIndex, Row row) {
|
||||
try {
|
||||
if (total > 0 && _separator != null) {
|
||||
writer.write(_separator);
|
||||
}
|
||||
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, null, null);
|
||||
for (Fragment f : _fragments) {
|
||||
if (f instanceof StaticFragment) {
|
||||
writer.write(((StaticFragment) f).text);
|
||||
} else {
|
||||
DynamicFragment df = (DynamicFragment) f;
|
||||
Object value = df.eval.evaluate(bindings);
|
||||
|
||||
if (value != null && ExpressionUtils.isArrayOrCollection(value)) {
|
||||
if (ExpressionUtils.isArray(value)) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
writeValue(v);
|
||||
}
|
||||
} else {
|
||||
Collection<Object> a = ExpressionUtils.toObjectCollection(value);
|
||||
for (Object v : a) {
|
||||
writeValue(v);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
writeValue(value);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
if (total > 0 && _separator != null) {
|
||||
writer.write(_separator);
|
||||
}
|
||||
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, null, null);
|
||||
for (Fragment f : _fragments) {
|
||||
if (f instanceof StaticFragment) {
|
||||
writer.write(((StaticFragment) f).text);
|
||||
} else {
|
||||
DynamicFragment df = (DynamicFragment) f;
|
||||
Object value = df.eval.evaluate(bindings);
|
||||
|
||||
if (value != null && ExpressionUtils.isArrayOrCollection(value)) {
|
||||
if (ExpressionUtils.isArray(value)) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
writeValue(v);
|
||||
}
|
||||
} else {
|
||||
Collection<Object> a = ExpressionUtils.toObjectCollection(value);
|
||||
for (Object v : a) {
|
||||
writeValue(v);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
writeValue(value);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected boolean internalVisit(Project project, Record record) {
|
||||
bindings.put("recordIndex", record.recordIndex);
|
||||
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
Row row = project.rows.get(r);
|
||||
|
||||
|
||||
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
|
||||
Row row = project.rows.get(r);
|
||||
|
||||
bindings.put("rowIndex", r);
|
||||
|
||||
|
||||
internalVisit(project, r, row);
|
||||
|
||||
|
||||
bindings.remove("recordIndex");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,16 +117,16 @@ public class HtmlExporterTests extends RefineTest {
|
||||
}
|
||||
|
||||
Assert.assertEquals(writer.toString(), "<html>\n" +
|
||||
"<head><title>" + TEST_PROJECT_NAME + "</title></head>\n" +
|
||||
"<body>\n" +
|
||||
"<table>\n" +
|
||||
"<tr><th>column0</th><th>column1</th></tr>\n" +
|
||||
"<tr><td>row0cell0</td><td>row0cell1</td></tr>\n" +
|
||||
"<tr><td>row1cell0</td><td>row1cell1</td></tr>\n" +
|
||||
"</table>\n" +
|
||||
"</body>\n" +
|
||||
"</html>\n");
|
||||
|
||||
"<head><title>" + TEST_PROJECT_NAME + "</title></head>\n" +
|
||||
"<body>\n" +
|
||||
"<table>\n" +
|
||||
"<tr><th>column0</th><th>column1</th></tr>\n" +
|
||||
"<tr><td>row0cell0</td><td>row0cell1</td></tr>\n" +
|
||||
"<tr><td>row1cell0</td><td>row1cell1</td></tr>\n" +
|
||||
"</table>\n" +
|
||||
"</body>\n" +
|
||||
"</html>\n");
|
||||
|
||||
}
|
||||
|
||||
// TODO: This test fails because the HTML table exporter
|
||||
|
@ -51,7 +51,7 @@ import com.google.refine.importers.tree.TreeReader.Token;
|
||||
import com.google.refine.model.Row;
|
||||
|
||||
public class JsonImporterTests extends ImporterTest {
|
||||
@Override
|
||||
@Override
|
||||
@BeforeTest
|
||||
public void init() {
|
||||
logger = LoggerFactory.getLogger(this.getClass());
|
||||
@ -270,8 +270,9 @@ public class JsonImporterTests extends ImporterTest {
|
||||
sb.append("[");
|
||||
for(int i = 1; i < 7; i++){
|
||||
sb.append(getTypicalElement(i));
|
||||
if(i < 6)
|
||||
sb.append(",");
|
||||
if(i < 6) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
@ -282,12 +283,12 @@ public class JsonImporterTests extends ImporterTest {
|
||||
sb.append("[");
|
||||
for(int i = 1; i < 7; i++){
|
||||
sb.append(getElementWithDuplicateSubElement(i));
|
||||
if(i < 6)
|
||||
sb.append(",");
|
||||
if(i < 6) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String getSampleWithLineBreak(){
|
||||
@ -336,8 +337,9 @@ public class JsonImporterTests extends ImporterTest {
|
||||
"\"title\" : \"Book title " + i + "\"," +
|
||||
"\"publish_date\" : \"2010-05-26\"" +
|
||||
"}");
|
||||
if(i < 6)
|
||||
sb.append(",");
|
||||
if(i < 6) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
|
Loading…
Reference in New Issue
Block a user