Added recon config to column model so we can use that to do automatic schema alignment.

Fixed bug in recon operation that also tried to reconcile blank cells.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@57 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-02-07 01:07:45 +00:00
parent 2eccab4c71
commit 51de415809
3 changed files with 85 additions and 3 deletions

View File

@ -16,6 +16,7 @@ public class Column implements Serializable, Jsonizable {
final private int _cellIndex;
final private String _originalHeaderLabel;
private String _headerLabel;
private ReconConfig _reconConfig;
transient protected Map<String, Object> _precomputes;
@ -40,6 +41,14 @@ public class Column implements Serializable, Jsonizable {
return _headerLabel;
}
public void setReconConfig(ReconConfig config) {
this._reconConfig = config;
}
public ReconConfig getReconConfig() {
return _reconConfig;
}
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
@ -47,6 +56,10 @@ public class Column implements Serializable, Jsonizable {
writer.object();
writer.key("cellIndex"); writer.value(getCellIndex());
writer.key("headerLabel"); writer.value(getHeaderLabel());
if (_reconConfig != null) {
writer.key("reconConfig");
_reconConfig.write(writer, options);
}
writer.endObject();
}

View File

@ -0,0 +1,28 @@
package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable;
public class ReconConfig implements Serializable, Jsonizable {
private static final long serialVersionUID = -4831409797104437854L;
final public String typeID;
public ReconConfig(String typeID) {
this.typeID = typeID;
}
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("type"); writer.value(typeID);
writer.endObject();
}
}

View File

@ -24,12 +24,15 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.browsing.Engine;
import com.metaweb.gridworks.browsing.FilteredRows;
import com.metaweb.gridworks.browsing.RowVisitor;
import com.metaweb.gridworks.expr.ExpressionUtils;
import com.metaweb.gridworks.history.Change;
import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Recon;
import com.metaweb.gridworks.model.ReconCandidate;
import com.metaweb.gridworks.model.ReconConfig;
import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.MassCellChange;
@ -75,7 +78,7 @@ public class ReconOperation extends EngineDependentOperation {
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
if (cellIndex < row.cells.size()) {
Cell cell = row.cells.get(cellIndex);
if (cell.value != null) {
if (cell != null && !ExpressionUtils.isBlank(cell.value)) {
entries.add(new ReconEntry(rowIndex, cell));
}
}
@ -108,6 +111,41 @@ public class ReconOperation extends EngineDependentOperation {
}
}
static protected class ReconChange extends MassCellChange {
private static final long serialVersionUID = 7048806528587330543L;
final protected ReconConfig _newReconConfig;
protected ReconConfig _oldReconConfig;
public ReconChange(
List<CellChange> cellChanges,
int commonCellIndex,
ReconConfig newReconConfig
) {
super(cellChanges, commonCellIndex, false);
_newReconConfig = newReconConfig;
}
@Override
public void apply(Project project) {
synchronized (project) {
super.apply(project);
Column column = project.columnModel.getColumnByCellIndex(_commonCellIndex);
_oldReconConfig = column.getReconConfig();
column.setReconConfig(_newReconConfig);
}
}
@Override
public void revert(Project project) {
synchronized (project) {
super.revert(project);
project.columnModel.getColumnByCellIndex(_commonCellIndex).setReconConfig(_oldReconConfig);
}
}
}
public class ReconProcess extends LongRunningProcess implements Runnable {
final protected Project _project;
final protected List<ReconEntry> _entries;
@ -160,12 +198,15 @@ public class ReconOperation extends EngineDependentOperation {
}
}
MassCellChange massCellChange = new MassCellChange(cellChanges, _cellIndex, false);
ReconConfig reconConfig = new ReconConfig(_typeID);
Change reconChange = new ReconChange(cellChanges, _cellIndex, reconConfig);
HistoryEntry historyEntry = new HistoryEntry(
_project,
_description,
ReconOperation.this,
massCellChange
reconChange
);
_project.history.addEntry(historyEntry);