Actual work in operations must be delayed until their changes are applied.

Column addition change must track the new cell index that it allocates when it is first applied.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@103 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-02-18 23:27:40 +00:00
parent 8831703a2c
commit 4b2e48614b
29 changed files with 294 additions and 200 deletions

View File

@ -60,7 +60,7 @@ public class Engine implements Jsonizable {
}
if (facet != null) {
facet.initializeFromJSON(fo);
facet.initializeFromJSON(_project, fo);
_facets.add(facet);
}
}

View File

@ -12,5 +12,5 @@ public interface Facet extends Jsonizable {
public void computeChoices(Project project, FilteredRows filteredRows);
public void initializeFromJSON(JSONObject o) throws Exception;
public void initializeFromJSON(Project project, JSONObject o) throws Exception;
}

View File

@ -23,6 +23,7 @@ public class ListFacet implements Facet {
protected String _name;
protected String _expression;
protected String _columnName;
protected int _cellIndex;
protected Evaluable _eval;
@ -35,7 +36,7 @@ public class ListFacet implements Facet {
writer.object();
writer.key("name"); writer.value(_name);
writer.key("expression"); writer.value(_expression);
writer.key("cellIndex"); writer.value(_cellIndex);
writer.key("columnName"); writer.value(_columnName);
writer.key("choices"); writer.array();
for (NominalFacetChoice choice : _choices) {
@ -45,10 +46,11 @@ public class ListFacet implements Facet {
writer.endObject();
}
public void initializeFromJSON(JSONObject o) throws Exception {
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
_name = o.getString("name");
_expression = o.getString("expression");
_cellIndex = o.getInt("cellIndex");
_columnName = o.getString("columnName");
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
_eval = new Parser(_expression).getExpression();
_selection.clear();
@ -64,9 +66,7 @@ public class ListFacet implements Facet {
ocv.get("v"), ocv.getString("l"));
NominalFacetChoice nominalFacetChoice = new NominalFacetChoice(decoratedValue);
nominalFacetChoice.count = oc.getInt("c");
nominalFacetChoice.selected = oc.getBoolean("s");
nominalFacetChoice.selected = true;
_selection.add(nominalFacetChoice);
}

View File

@ -17,6 +17,7 @@ import com.metaweb.gridworks.model.Project;
public class RangeFacet implements Facet {
protected String _name;
protected String _expression;
protected String _columnName;
protected int _cellIndex;
protected Evaluable _eval;
@ -40,7 +41,7 @@ public class RangeFacet implements Facet {
writer.object();
writer.key("name"); writer.value(_name);
writer.key("expression"); writer.value(_expression);
writer.key("cellIndex"); writer.value(_cellIndex);
writer.key("columnName"); writer.value(_columnName);
writer.key("min"); writer.value(_min);
writer.key("max"); writer.value(_max);
writer.key("step"); writer.value(_step);
@ -69,10 +70,11 @@ public class RangeFacet implements Facet {
writer.endObject();
}
public void initializeFromJSON(JSONObject o) throws Exception {
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
_name = o.getString("name");
_expression = o.getString("expression");
_cellIndex = o.getInt("cellIndex");
_columnName = o.getString("columnName");
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
_eval = new Parser(_expression).getExpression();

View File

@ -15,6 +15,7 @@ import com.metaweb.gridworks.model.Project;
public class TextSearchFacet implements Facet {
protected String _name;
protected String _columnName;
protected int _cellIndex;
protected String _query;
@ -29,16 +30,17 @@ public class TextSearchFacet implements Facet {
writer.object();
writer.key("name"); writer.value(_name);
writer.key("cellIndex"); writer.value(_cellIndex);
writer.key("columnName"); writer.value(_columnName);
writer.key("query"); writer.value(_query);
writer.key("mode"); writer.value(_mode);
writer.key("caseSensitive"); writer.value(_caseSensitive);
writer.endObject();
}
public void initializeFromJSON(JSONObject o) throws Exception {
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
_name = o.getString("name");
_cellIndex = o.getInt("cellIndex");
_columnName = o.getString("columnName");
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
_query = o.getString("query");
_mode = o.getString("mode");
_caseSensitive = o.getBoolean("caseSensitive");

View File

@ -18,7 +18,6 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Recon;
import com.metaweb.gridworks.model.ReconCandidate;
import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.process.Process;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class JudgeOneCellCommand extends Command {
@ -31,19 +30,61 @@ public class JudgeOneCellCommand extends Command {
int rowIndex = Integer.parseInt(request.getParameter("row"));
int cellIndex = Integer.parseInt(request.getParameter("cell"));
Cell cell = project.rows.get(rowIndex).getCell(cellIndex);
String judgment = request.getParameter("judgment");
String candidateID = request.getParameter("candidate");
JudgeOneCellProcess process = new JudgeOneCellProcess(
project,
"Judge one cell's recon result",
rowIndex,
cellIndex,
judgment,
candidateID
);
boolean done = project.processManager.queueProcess(process);
if (done) {
JSONWriter writer = new JSONWriter(response.getWriter());
writer.object();
writer.key("code"); writer.value("ok");
writer.key("cell"); process.newCell.write(writer, new Properties());
writer.endObject();
} else {
respond(response, "{ \"code\" : \"pending\" }");
}
} catch (Exception e) {
respondException(response, e);
}
}
protected class JudgeOneCellProcess extends QuickHistoryEntryProcess {
final int rowIndex;
final int cellIndex;
final String judgment;
final String candidateID;
Cell newCell;
JudgeOneCellProcess(Project project, String briefDescription, int rowIndex, int cellIndex, String judgment, String candidateID) {
super(project, briefDescription);
this.rowIndex = rowIndex;
this.cellIndex = cellIndex;
this.judgment = judgment;
this.candidateID = candidateID;
}
protected HistoryEntry createHistoryEntry() throws Exception {
Cell cell = _project.rows.get(rowIndex).getCell(cellIndex);
if (cell == null || cell.value == null) {
respond(response, "{ \"code\" : \"error\", \"message\" : \"Cell is blank\" }");
return;
throw new Exception("Cell is blank");
}
Column column = project.columnModel.getColumnByCellIndex(cellIndex);
Column column = _project.columnModel.getColumnByCellIndex(cellIndex);
if (column == null) {
respond(response, "{ \"code\" : \"error\", \"message\" : \"No such column\" }");
return;
throw new Exception("No such column");
}
Cell newCell = new Cell(
newCell = new Cell(
cell.value,
cell.recon == null ? new Recon() : cell.recon.dup()
);
@ -55,13 +96,10 @@ public class JudgeOneCellCommand extends Command {
String description = null;
String judgment = request.getParameter("judgment");
if ("match".equals(judgment)) {
ReconCandidate match = null;
if (cell.recon != null) {
String candidateID = request.getParameter("candidate");
for (ReconCandidate c : cell.recon.candidates) {
if (candidateID.equals(c.topicID)) {
match = c;
@ -70,8 +108,7 @@ public class JudgeOneCellCommand extends Command {
}
}
if (match == null) {
respond(response, "{ \"code\" : \"error\", \"message\" : \"No such recon candidate\" }");
return;
throw new Exception("No such recon candidate");
}
newCell.recon.judgment = Recon.Judgment.Matched;
@ -88,29 +125,12 @@ public class JudgeOneCellCommand extends Command {
newCell.recon.judgment = Recon.Judgment.None;
newCell.recon.match = null;
description = "Discard recon judgment for " + cellDescription;
} else {
respond(response, "{ \"code\" : \"error\", \"message\" : \"bad judgment\" }");
return;
}
Change change = new CellChange(rowIndex, cellIndex, cell, newCell);
HistoryEntry historyEntry = new HistoryEntry(
project, description, null, change);
Process process = new QuickHistoryEntryProcess(project, historyEntry);
boolean done = project.processManager.queueProcess(process);
if (done) {
JSONWriter writer = new JSONWriter(response.getWriter());
writer.object();
writer.key("code"); writer.value("ok");
writer.key("cell"); newCell.write(writer, new Properties());
writer.endObject();
} else {
respond(response, "{ \"code\" : \"pending\" }");
}
} catch (Exception e) {
respondException(response, e);
return new HistoryEntry(
_project, description, null, change);
}
}
}

View File

@ -3,13 +3,32 @@ package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.util.Properties;
import org.apache.commons.lang.NotImplementedException;
import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.process.Process;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
/*
* An abstract operation can be applied to different but similar
* projects.
*/
public interface AbstractOperation extends Serializable, Jsonizable {
public Process createProcess(Project project, Properties options) throws Exception;
abstract public class AbstractOperation implements Serializable, Jsonizable {
public Process createProcess(Project project, Properties options) throws Exception {
return new QuickHistoryEntryProcess(project, getBriefDescription()) {
@Override
protected HistoryEntry createHistoryEntry() throws Exception {
return AbstractOperation.this.createHistoryEntry(_project);
}
};
}
protected HistoryEntry createHistoryEntry(Project project) throws Exception {
throw new NotImplementedException();
}
protected String getBriefDescription() {
throw new NotImplementedException();
}
}

View File

@ -12,7 +12,7 @@ public class ColumnAdditionChange extends ColumnChange {
final protected String _headerLabel;
final protected int _columnIndex;
final protected CellAtRow[] _newCells;
protected int _newCellIndex;
protected int _newCellIndex = -1;
public ColumnAdditionChange(String headerLabel, int columnIndex, List<CellAtRow> newCells) {
_headerLabel = headerLabel;
@ -23,8 +23,10 @@ public class ColumnAdditionChange extends ColumnChange {
public void apply(Project project) {
synchronized (project) {
_newCellIndex = project.columnModel.allocateNewCellIndex();
if (_newCellIndex < 0) {
_newCellIndex = project.columnModel.allocateNewCellIndex();
}
Column column = new Column(_newCellIndex, _headerLabel);
project.columnModel.columns.add(_columnIndex, column);

View File

@ -3,6 +3,7 @@ package com.metaweb.gridworks.model.changes;
import java.util.List;
import com.metaweb.gridworks.history.Change;
import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;
@ -10,12 +11,12 @@ public class MassCellChange implements Change {
private static final long serialVersionUID = -933571199802688027L;
final protected CellChange[] _cellChanges;
final protected int _commonCellIndex;
final protected String _commonColumnName;
final protected boolean _updateRowContextDependencies;
public MassCellChange(List<CellChange> cellChanges, int commonCellIndex, boolean updateRowContextDependencies) {
public MassCellChange(List<CellChange> cellChanges, String commonColumnName, boolean updateRowContextDependencies) {
_cellChanges = new CellChange[cellChanges.size()];
_commonCellIndex = commonCellIndex;
_commonColumnName = commonColumnName;
cellChanges.toArray(_cellChanges);
_updateRowContextDependencies = updateRowContextDependencies;
@ -29,8 +30,9 @@ public class MassCellChange implements Change {
rows.get(cellChange.row).setCell(cellChange.cellIndex, cellChange.newCell);
}
if (_commonCellIndex >= 0) {
project.columnModel.getColumnByCellIndex(_commonCellIndex).clearPrecomputes();
if (_commonColumnName != null) {
Column column = project.columnModel.getColumnByName(_commonColumnName);
column.clearPrecomputes();
}
if (_updateRowContextDependencies) {
@ -47,8 +49,9 @@ public class MassCellChange implements Change {
rows.get(cellChange.row).setCell(cellChange.cellIndex, cellChange.oldCell);
}
if (_commonCellIndex >= 0) {
project.columnModel.getColumnByCellIndex(_commonCellIndex).clearPrecomputes();
if (_commonColumnName != null) {
Column column = project.columnModel.getColumnByName(_commonColumnName);
column.clearPrecomputes();
}
if (_updateRowContextDependencies) {

View File

@ -33,6 +33,10 @@ public class ApproveNewReconOperation extends EngineDependentMassCellOperation {
writer.key("columnName"); writer.value(_columnName);
writer.endObject();
}
protected String getBriefDescription() {
return "Approve new topics for cells in column " + _columnName;
}
protected String createDescription(Column column,
List<CellChange> cellChanges) {

View File

@ -33,6 +33,10 @@ public class ApproveReconOperation extends EngineDependentMassCellOperation {
writer.endObject();
}
protected String getBriefDescription() {
return "Approve best recon candidates for cells in column " + _columnName;
}
protected String createDescription(Column column,
List<CellChange> cellChanges) {

View File

@ -22,8 +22,6 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.CellAtRow;
import com.metaweb.gridworks.model.changes.ColumnAdditionChange;
import com.metaweb.gridworks.process.Process;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class ColumnAdditionOperation extends EngineDependentOperation {
private static final long serialVersionUID = -5672677479629932356L;
@ -50,9 +48,7 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
_columnInsertIndex = columnInsertIndex;
}
public Process createProcess(Project project, Properties options)
throws Exception {
protected HistoryEntry createHistoryEntry(Project project) throws Exception {
Engine engine = createEngine(project);
Column column = project.columnModel.getColumnByName(_baseColumnName);
@ -68,10 +64,9 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
String description = createDescription(column, cellsAtRows);
Change change = new ColumnAdditionChange(_headerLabel, _columnInsertIndex, cellsAtRows);
HistoryEntry historyEntry = new HistoryEntry(
return new HistoryEntry(
project, description, this, change);
return new QuickHistoryEntryProcess(project, historyEntry);
}
public void write(JSONWriter writer, Properties options)
@ -93,6 +88,10 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
writer.endObject();
}
protected String getBriefDescription() {
return "Add in column " + _headerLabel + " based on column " + _baseColumnName;
}
protected String createDescription(Column column, List<CellAtRow> cellsAtRows) {
return "Create new column " + _headerLabel +
" based on column " + column.getHeaderLabel() +

View File

@ -11,10 +11,8 @@ import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.changes.ColumnRemovalChange;
import com.metaweb.gridworks.process.Process;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class ColumnRemovalOperation implements AbstractOperation {
public class ColumnRemovalOperation extends AbstractOperation {
private static final long serialVersionUID = 8422079695048733734L;
final protected String _columnName;
@ -25,9 +23,11 @@ public class ColumnRemovalOperation implements AbstractOperation {
_columnName = columnName;
}
public Process createProcess(Project project, Properties options)
throws Exception {
protected String getBriefDescription() {
return "Remove column " + _columnName;
}
protected HistoryEntry createHistoryEntry(Project project) throws Exception {
Column column = project.columnModel.getColumnByName(_columnName);
if (column == null) {
throw new Exception("No column named " + _columnName);
@ -36,10 +36,8 @@ public class ColumnRemovalOperation implements AbstractOperation {
String description = "Remove column " + column.getHeaderLabel();
Change change = new ColumnRemovalChange(project.columnModel.columns.indexOf(column));
HistoryEntry historyEntry = new HistoryEntry(
project, description, this, change);
return new QuickHistoryEntryProcess(project, historyEntry);
return new HistoryEntry(project, description, ColumnRemovalOperation.this, change);
}
public void write(JSONWriter writer, Properties options)

View File

@ -32,6 +32,10 @@ public class DiscardReconOperation extends EngineDependentMassCellOperation {
writer.endObject();
}
protected String getBriefDescription() {
return "Discard recon results for cells in column " + _columnName;
}
protected String createDescription(Column column,
List<CellChange> cellChanges) {

View File

@ -2,7 +2,6 @@ package com.metaweb.gridworks.model.operations;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.json.JSONObject;
@ -14,8 +13,6 @@ import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.MassCellChange;
import com.metaweb.gridworks.process.Process;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
abstract public class EngineDependentMassCellOperation extends EngineDependentOperation {
private static final long serialVersionUID = -8962461328087299452L;
@ -30,7 +27,7 @@ abstract public class EngineDependentMassCellOperation extends EngineDependentOp
_updateRowContextDependencies = updateRowContextDependencies;
}
public Process createProcess(Project project, Properties options) throws Exception {
protected HistoryEntry createHistoryEntry(Project project) throws Exception {
Engine engine = createEngine(project);
Column column = project.columnModel.getColumnByName(_columnName);
@ -45,11 +42,10 @@ abstract public class EngineDependentMassCellOperation extends EngineDependentOp
String description = createDescription(column, cellChanges);
MassCellChange massCellChange = new MassCellChange(cellChanges, column.getCellIndex(), _updateRowContextDependencies);
HistoryEntry historyEntry = new HistoryEntry(
MassCellChange massCellChange = new MassCellChange(cellChanges, column.getHeaderLabel(), _updateRowContextDependencies);
return new HistoryEntry(
project, description, this, massCellChange);
return new QuickHistoryEntryProcess(project, historyEntry);
}
abstract protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges) throws Exception;

View File

@ -8,7 +8,7 @@ import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.util.ParsingUtilities;
abstract public class EngineDependentOperation implements AbstractOperation {
abstract public class EngineDependentOperation extends AbstractOperation {
private static final long serialVersionUID = -2800091595856881731L;
final private String _engineConfigString;

View File

@ -16,10 +16,8 @@ import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.MassRowChange;
import com.metaweb.gridworks.process.Process;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class MultiValueCellJoinOperation implements AbstractOperation {
public class MultiValueCellJoinOperation extends AbstractOperation {
private static final long serialVersionUID = 3134524625206033285L;
final protected String _columnName;
@ -36,9 +34,11 @@ public class MultiValueCellJoinOperation implements AbstractOperation {
_separator = separator;
}
public Process createProcess(Project project, Properties options)
throws Exception {
protected String getBriefDescription() {
return "Join multi-valued cells in column " + _columnName;
}
protected HistoryEntry createHistoryEntry(Project project) throws Exception {
Column column = project.columnModel.getColumnByName(_columnName);
if (column == null) {
throw new Exception("No column named " + _columnName);
@ -102,10 +102,8 @@ public class MultiValueCellJoinOperation implements AbstractOperation {
String description = "Join multi-valued cells in column " + column.getHeaderLabel();
Change change = new MassRowChange(newRows);
HistoryEntry historyEntry = new HistoryEntry(
project, description, this, change);
return new QuickHistoryEntryProcess(project, historyEntry);
return new HistoryEntry(project, description, this, change);
}
public void write(JSONWriter writer, Properties options)

View File

@ -16,10 +16,8 @@ import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.MassRowChange;
import com.metaweb.gridworks.process.Process;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class MultiValueCellSplitOperation implements AbstractOperation {
public class MultiValueCellSplitOperation extends AbstractOperation {
private static final long serialVersionUID = 8217930220439070322L;
final protected String _columnName;
@ -39,9 +37,12 @@ public class MultiValueCellSplitOperation implements AbstractOperation {
_mode = mode;
}
public Process createProcess(Project project, Properties options)
throws Exception {
protected String getBriefDescription() {
return "Split multi-valued cells in column " + _columnName;
}
@Override
protected HistoryEntry createHistoryEntry(Project project) throws Exception {
Column column = project.columnModel.getColumnByName(_columnName);
if (column == null) {
throw new Exception("No column named " + _columnName);
@ -117,10 +118,8 @@ public class MultiValueCellSplitOperation implements AbstractOperation {
String description = "Split multi-valued cells in column " + column.getHeaderLabel();
Change change = new MassRowChange(newRows);
HistoryEntry historyEntry = new HistoryEntry(
project, description, this, change);
return new QuickHistoryEntryProcess(project, historyEntry);
return new HistoryEntry(project, description, this, change);
}
public void write(JSONWriter writer, Properties options)

View File

@ -53,43 +53,20 @@ public class ReconOperation extends EngineDependentOperation {
}
public Process createProcess(Project project, Properties options) throws Exception {
Engine engine = createEngine(project);
Column column = project.columnModel.getColumnByName(_columnName);
if (column == null) {
throw new Exception("No column named " + _columnName);
}
List<ReconEntry> entries = new ArrayList<ReconEntry>(project.rows.size());
FilteredRows filteredRows = engine.getAllFilteredRows(false);
filteredRows.accept(project, new RowVisitor() {
int cellIndex;
List<ReconEntry> entries;
public RowVisitor init(int cellIndex, List<ReconEntry> entries) {
this.cellIndex = cellIndex;
this.entries = entries;
return this;
}
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
if (cellIndex < row.cells.size()) {
Cell cell = row.cells.get(cellIndex);
if (cell != null && !ExpressionUtils.isBlank(cell.value)) {
entries.add(new ReconEntry(rowIndex, cell));
}
}
return false;
}
}.init(column.getCellIndex(), entries));
String description =
"Reconcile " + entries.size() +
" cells in column " + column.getHeaderLabel() +
" to type " + _typeID;
"Reconcile cells in column " + column.getHeaderLabel() + " to type " + _typeID;
return new ReconProcess(project, description, entries, column.getCellIndex());
return new ReconProcess(
project,
getEngineConfig(),
description,
_columnName
);
}
public void write(JSONWriter writer, Properties options)
@ -121,11 +98,11 @@ public class ReconOperation extends EngineDependentOperation {
protected ReconConfig _oldReconConfig;
public ReconChange(
List<CellChange> cellChanges,
int commonCellIndex,
List<CellChange> cellChanges,
String commonColumnName,
ReconConfig newReconConfig
) {
super(cellChanges, commonCellIndex, false);
super(cellChanges, commonColumnName, false);
_newReconConfig = newReconConfig;
}
@Override
@ -133,7 +110,7 @@ public class ReconOperation extends EngineDependentOperation {
synchronized (project) {
super.apply(project);
Column column = project.columnModel.getColumnByCellIndex(_commonCellIndex);
Column column = project.columnModel.getColumnByName(_commonColumnName);
_oldReconConfig = column.getReconConfig();
column.setReconConfig(_newReconConfig);
}
@ -144,28 +121,69 @@ public class ReconOperation extends EngineDependentOperation {
synchronized (project) {
super.revert(project);
project.columnModel.getColumnByCellIndex(_commonCellIndex).setReconConfig(_oldReconConfig);
project.columnModel.getColumnByName(_commonColumnName)
.setReconConfig(_oldReconConfig);
}
}
}
public class ReconProcess extends LongRunningProcess implements Runnable {
final protected Project _project;
final protected List<ReconEntry> _entries;
final protected int _cellIndex;
final protected Project _project;
final protected JSONObject _engineConfig;
final protected String _columnName;
protected List<ReconEntry> _entries;
protected int _cellIndex;
public ReconProcess(Project project, String description, List<ReconEntry> entries, int cellIndex) {
public ReconProcess(
Project project,
JSONObject engineConfig,
String description,
String columnName
) {
super(description);
_project = project;
_entries = entries;
_cellIndex = cellIndex;
_engineConfig = engineConfig;
_columnName = columnName;
}
protected Runnable getRunnable() {
return this;
}
protected void populateEntries() throws Exception {
Engine engine = new Engine(_project);
engine.initializeFromJSON(_engineConfig);
Column column = _project.columnModel.getColumnByName(_columnName);
if (column == null) {
throw new Exception("No column named " + _columnName);
}
_entries = new ArrayList<ReconEntry>(_project.rows.size());
_cellIndex = column.getCellIndex();
FilteredRows filteredRows = engine.getAllFilteredRows(false);
filteredRows.accept(_project, new RowVisitor() {
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
if (_cellIndex < row.cells.size()) {
Cell cell = row.cells.get(_cellIndex);
if (cell != null && !ExpressionUtils.isBlank(cell.value)) {
_entries.add(new ReconEntry(rowIndex, cell));
}
}
return false;
}
});
}
public void run() {
try {
populateEntries();
} catch (Exception e2) {
// TODO : Not sure what to do here?
e2.printStackTrace();
}
Map<String, List<ReconEntry>> valueToEntries = new HashMap<String, List<ReconEntry>>();
for (ReconEntry entry : _entries) {
@ -203,7 +221,7 @@ public class ReconOperation extends EngineDependentOperation {
ReconConfig reconConfig = new ReconConfig(_typeID);
Change reconChange = new ReconChange(cellChanges, _cellIndex, reconConfig);
Change reconChange = new ReconChange(cellChanges, _columnName, reconConfig);
HistoryEntry historyEntry = new HistoryEntry(
_project,

View File

@ -9,11 +9,9 @@ import com.metaweb.gridworks.history.Change;
import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.process.Process;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
import com.metaweb.gridworks.protograph.Protograph;
public class SaveProtographOperation implements AbstractOperation {
public class SaveProtographOperation extends AbstractOperation {
private static final long serialVersionUID = 3134524625206033285L;
final protected Protograph _protograph;
@ -24,16 +22,17 @@ public class SaveProtographOperation implements AbstractOperation {
_protograph = protograph;
}
public Process createProcess(Project project, Properties options)
throws Exception {
protected String getBriefDescription() {
return "Save schema skeleton";
}
@Override
protected HistoryEntry createHistoryEntry(Project project) throws Exception {
String description = "Save schema-alignment protograph";
Change change = new ProtographChange(_protograph);
HistoryEntry historyEntry = new HistoryEntry(
project, description, this, change);
return new QuickHistoryEntryProcess(project, historyEntry);
return new HistoryEntry(project, description, SaveProtographOperation.this, change);
}
public void write(JSONWriter writer, Properties options)

View File

@ -39,6 +39,10 @@ public class TextTransformOperation extends EngineDependentMassCellOperation {
writer.endObject();
}
protected String getBriefDescription() {
return "Text transform on cells in column " + _columnName + " using " + _expression;
}
protected String createDescription(Column column,
List<CellChange> cellChanges) {

View File

@ -8,7 +8,7 @@ public abstract class Process implements Jsonizable {
abstract public boolean isRunning();
abstract public boolean isDone();
abstract public void performImmediate();
abstract public void performImmediate() throws Exception;
abstract public void startPerforming(ProcessManager manager);
abstract public void cancel();

View File

@ -31,7 +31,12 @@ public class ProcessManager implements Jsonizable {
public boolean queueProcess(Process process) {
if (process.isImmediate() && _processes.size() == 0) {
process.performImmediate();
try {
process.performImmediate();
} catch (Exception e) {
// TODO: Not sure what to do yet
e.printStackTrace();
}
return true;
} else {
_processes.add(process);
@ -51,7 +56,12 @@ public class ProcessManager implements Jsonizable {
while (_processes.size() > 0) {
Process p = _processes.get(0);
if (p.isImmediate()) {
p.performImmediate();
try {
p.performImmediate();
} catch (Exception e) {
// TODO: Not sure what to do yet
e.printStackTrace();
}
_processes.remove(0);
} else if (p.isDone()) {
_processes.remove(0);

View File

@ -8,14 +8,15 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.model.Project;
public class QuickHistoryEntryProcess extends Process {
abstract public class QuickHistoryEntryProcess extends Process {
final protected Project _project;
final protected HistoryEntry _historyEntry;
final protected String _briefDescription;
protected HistoryEntry _historyEntry;
boolean _done = false;
public QuickHistoryEntryProcess(Project project, HistoryEntry historyEntry) {
public QuickHistoryEntryProcess(Project project, String briefDescription) {
_project = project;
_historyEntry = historyEntry;
_briefDescription = briefDescription;
}
public void cancel() {
@ -30,7 +31,10 @@ public class QuickHistoryEntryProcess extends Process {
throw new RuntimeException("Not a long-running process");
}
public void performImmediate() {
public void performImmediate() throws Exception {
if (_historyEntry == null) {
_historyEntry = createHistoryEntry();
}
_project.history.addEntry(_historyEntry);
_done = true;
}
@ -43,7 +47,7 @@ public class QuickHistoryEntryProcess extends Process {
throws JSONException {
writer.object();
writer.key("description"); writer.value(_historyEntry.description);
writer.key("description"); writer.value(_historyEntry != null ? _historyEntry.description : _briefDescription);
writer.key("immediate"); writer.value(true);
writer.key("status"); writer.value(_done ? "done" : "pending");
writer.endObject();
@ -54,4 +58,6 @@ public class QuickHistoryEntryProcess extends Process {
public boolean isDone() {
return _done;
}
abstract protected HistoryEntry createHistoryEntry() throws Exception;
}

View File

@ -61,4 +61,4 @@ function reinitializeProjectData(f) {
},
f
);
}
}

View File

@ -81,7 +81,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"list",
{
"name" : self._column.headerLabel,
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"expression" : "value"
}
);
@ -99,7 +99,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"range",
{
"name" : self._column.headerLabel,
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"expression" : "value",
"mode" : "range",
"min" : 0,
@ -122,7 +122,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"text",
{
"name" : self._column.headerLabel,
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"mode" : "text",
"caseSensitive" : false
}
@ -136,7 +136,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"text",
{
"name" : self._column.headerLabel + " (regex)",
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"mode" : "regex",
"caseSensitive" : true
}
@ -225,7 +225,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"list",
{
"name" : self._column.headerLabel + ": judgment",
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"expression" : "cell.recon.judgment"
},
{
@ -242,11 +242,9 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"range",
{
"name" : self._column.headerLabel + ": best candidate's relevance score",
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"expression" : "cell.recon.best.score",
"mode" : "range",
"min" : 0,
"max" : 200
"mode" : "range"
},
{
}
@ -260,7 +258,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"list",
{
"name" : self._column.headerLabel + ": best candidate's type match",
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"expression" : "cell.recon.features.typeMatch"
},
{
@ -276,7 +274,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"list",
{
"name" : self._column.headerLabel + ": best candidate's name match",
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"expression" : "cell.recon.features.nameMatch"
},
{
@ -293,12 +291,9 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"range",
{
"name" : self._column.headerLabel + ": best candidate's name edit distance",
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"expression" : "cell.recon.features.nameLevenshtein",
"mode" : "range",
"min" : 0,
"max" : 1,
"step" : 0.1
"mode" : "range"
},
{
}
@ -312,12 +307,9 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"range",
{
"name" : self._column.headerLabel + ": best candidate's name word similarity",
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"expression" : "cell.recon.features.nameWordDistance",
"mode" : "range",
"min" : 0,
"max" : 1,
"step" : 0.1
"mode" : "range"
},
{
}
@ -332,7 +324,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
"list",
{
"name" : self._column.headerLabel + ": best candidate's types",
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"expression" : "cell.recon.best.type"
}
);
@ -352,7 +344,7 @@ DataTableColumnHeaderUI.prototype._doFilterByExpressionPrompt = function(express
function(expression) {
var config = {
"name" : self._column.headerLabel + ": " + expression,
"cellIndex" : self._column.cellIndex,
"columnName" : self._column.headerLabel,
"expression" : expression
};
if (type == "range") {

View File

@ -14,12 +14,17 @@ function ListFacet(div, config, options) {
}
ListFacet.prototype.getJSON = function() {
var o = cloneDeep(this._config);
o.type = "list";
o.selection = [];
var o = {
type: "list",
name: this._config.name,
columnName: this._config.columnName,
expression: this._config.expression,
selection: []
}
for (var i = 0; i < this._selection.length; i++) {
var choice = cloneDeep(this._selection[i]);
choice.s = true;
var choice = {
v: cloneDeep(this._selection[i].v)
};
o.selection.push(choice);
}
return o;

View File

@ -26,8 +26,13 @@ RangeFacet.prototype._setDefaults = function() {
};
RangeFacet.prototype.getJSON = function() {
var o = cloneDeep(this._config);
o.type = "range";
var o = {
type: "range",
name: this._config.name,
mode: this._config.mode,
expression: this._config.expression,
columnName: this._config.columnName
};
if (this._config.mode == "min" || this._config.mode == "range") {
if (this._from != null) {

View File

@ -14,9 +14,14 @@ TextSearchFacet.prototype._setDefaults = function() {
};
TextSearchFacet.prototype.getJSON = function() {
var o = cloneDeep(this._config);
o.type = "text";
o.query = this._query;
var o = {
type: "text",
name: this._config.name,
columnName: this._config.columnName,
mode: this._config.mode,
caseSensitive: this._config.caseSensitive,
query: this._query
};
return o;
};