Search in sources :

Example 1 with Change

use of com.google.refine.history.Change in project OpenRefine by OpenRefine.

the class MassChange method save.

@Override
public void save(Writer writer, Properties options) throws IOException {
    writer.write("updateRowContextDependencies=");
    writer.write(Boolean.toString(_updateRowContextDependencies));
    writer.write('\n');
    writer.write("changeCount=");
    writer.write(Integer.toString(_changes.size()));
    writer.write('\n');
    for (Change c : _changes) {
        History.writeOneChange(writer, c, options);
    }
    // end of change marker
    writer.write("/ec/\n");
}
Also used : Change(com.google.refine.history.Change)

Example 2 with Change

use of com.google.refine.history.Change in project OpenRefine by OpenRefine.

the class ColumnAdditionOperation method createHistoryEntry.

@Override
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
    Engine engine = createEngine(project);
    Column column = project.columnModel.getColumnByName(_baseColumnName);
    if (column == null) {
        throw new Exception("No column named " + _baseColumnName);
    }
    if (project.columnModel.getColumnByName(_newColumnName) != null) {
        throw new Exception("Another column already named " + _newColumnName);
    }
    List<CellAtRow> cellsAtRows = new ArrayList<CellAtRow>(project.rows.size());
    FilteredRows filteredRows = engine.getAllFilteredRows();
    filteredRows.accept(project, createRowVisitor(project, cellsAtRows));
    String description = createDescription(column, cellsAtRows);
    Change change = new ColumnAdditionChange(_newColumnName, _columnInsertIndex, cellsAtRows);
    return new HistoryEntry(historyEntryID, project, description, this, change);
}
Also used : CellAtRow(com.google.refine.model.changes.CellAtRow) ColumnAdditionChange(com.google.refine.model.changes.ColumnAdditionChange) Column(com.google.refine.model.Column) ArrayList(java.util.ArrayList) HistoryEntry(com.google.refine.history.HistoryEntry) Change(com.google.refine.history.Change) ColumnAdditionChange(com.google.refine.model.changes.ColumnAdditionChange) FilteredRows(com.google.refine.browsing.FilteredRows) Engine(com.google.refine.browsing.Engine) JSONException(org.json.JSONException)

Example 3 with Change

use of com.google.refine.history.Change in project OpenRefine by OpenRefine.

the class ColumnSplitOperation method createHistoryEntry.

@Override
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
    Engine engine = createEngine(project);
    Column column = project.columnModel.getColumnByName(_columnName);
    if (column == null) {
        throw new Exception("No column named " + _columnName);
    }
    List<String> columnNames = new ArrayList<String>();
    List<Integer> rowIndices = new ArrayList<Integer>(project.rows.size());
    List<List<Serializable>> tuples = new ArrayList<List<Serializable>>(project.rows.size());
    FilteredRows filteredRows = engine.getAllFilteredRows();
    RowVisitor rowVisitor;
    if ("lengths".equals(_mode)) {
        rowVisitor = new ColumnSplitRowVisitor(column.getCellIndex(), columnNames, rowIndices, tuples) {

            @Override
            protected java.util.List<Serializable> split(String s) {
                List<Serializable> results = new ArrayList<Serializable>(_fieldLengths.length + 1);
                int lastIndex = 0;
                for (int length : _fieldLengths) {
                    int from = lastIndex;
                    int to = Math.min(from + length, s.length());
                    results.add(stringToValue(s.substring(from, to)));
                    lastIndex = to;
                }
                return results;
            }

            ;
        };
    } else if (_regex) {
        Pattern pattern = Pattern.compile(_separator);
        rowVisitor = new ColumnSplitRowVisitor(column.getCellIndex(), columnNames, rowIndices, tuples) {

            Pattern _pattern;

            @Override
            protected java.util.List<Serializable> split(String s) {
                return stringArrayToValueList(_pattern.split(s, _maxColumns));
            }

            ;

            public RowVisitor init(Pattern pattern) {
                _pattern = pattern;
                return this;
            }
        }.init(pattern);
    } else {
        rowVisitor = new ColumnSplitRowVisitor(column.getCellIndex(), columnNames, rowIndices, tuples) {

            @Override
            protected java.util.List<Serializable> split(String s) {
                return stringArrayToValueList(StringUtils.splitByWholeSeparatorPreserveAllTokens(s, _separator, _maxColumns));
            }

            ;
        };
    }
    filteredRows.accept(project, rowVisitor);
    String description = "Split " + rowIndices.size() + " cell(s) in column " + _columnName + " into several columns" + ("separator".equals(_mode) ? " by separator" : " by field lengths");
    Change change = new ColumnSplitChange(_columnName, columnNames, rowIndices, tuples, _removeOriginalColumn);
    return new HistoryEntry(historyEntryID, project, description, this, change);
}
Also used : Pattern(java.util.regex.Pattern) Serializable(java.io.Serializable) ColumnSplitChange(com.google.refine.model.changes.ColumnSplitChange) ArrayList(java.util.ArrayList) Change(com.google.refine.history.Change) ColumnSplitChange(com.google.refine.model.changes.ColumnSplitChange) FilteredRows(com.google.refine.browsing.FilteredRows) JSONException(org.json.JSONException) Column(com.google.refine.model.Column) HistoryEntry(com.google.refine.history.HistoryEntry) ArrayList(java.util.ArrayList) List(java.util.List) RowVisitor(com.google.refine.browsing.RowVisitor) Engine(com.google.refine.browsing.Engine)

Example 4 with Change

use of com.google.refine.history.Change in project OpenRefine by OpenRefine.

the class RowFlagOperation method createHistoryEntry.

@Override
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
    Engine engine = createEngine(project);
    List<Change> changes = new ArrayList<Change>(project.rows.size());
    FilteredRows filteredRows = engine.getAllFilteredRows();
    filteredRows.accept(project, createRowVisitor(project, changes));
    return new HistoryEntry(historyEntryID, project, (_flagged ? "Flag" : "Unflag") + " " + changes.size() + " rows", this, new MassChange(changes, false));
}
Also used : MassChange(com.google.refine.model.changes.MassChange) ArrayList(java.util.ArrayList) HistoryEntry(com.google.refine.history.HistoryEntry) RowFlagChange(com.google.refine.model.changes.RowFlagChange) Change(com.google.refine.history.Change) MassChange(com.google.refine.model.changes.MassChange) FilteredRows(com.google.refine.browsing.FilteredRows) Engine(com.google.refine.browsing.Engine)

Example 5 with Change

use of com.google.refine.history.Change in project OpenRefine by OpenRefine.

the class ColumnRemovalOperation method createHistoryEntry.

@Override
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
    Column column = project.columnModel.getColumnByName(_columnName);
    if (column == null) {
        throw new Exception("No column named " + _columnName);
    }
    String description = "Remove column " + column.getName();
    Change change = new ColumnRemovalChange(project.columnModel.columns.indexOf(column));
    return new HistoryEntry(historyEntryID, project, description, ColumnRemovalOperation.this, change);
}
Also used : ColumnRemovalChange(com.google.refine.model.changes.ColumnRemovalChange) Column(com.google.refine.model.Column) HistoryEntry(com.google.refine.history.HistoryEntry) Change(com.google.refine.history.Change) ColumnRemovalChange(com.google.refine.model.changes.ColumnRemovalChange) JSONException(org.json.JSONException)

Aggregations

Change (com.google.refine.history.Change)7 HistoryEntry (com.google.refine.history.HistoryEntry)5 ArrayList (java.util.ArrayList)5 Engine (com.google.refine.browsing.Engine)4 FilteredRows (com.google.refine.browsing.FilteredRows)4 Column (com.google.refine.model.Column)3 MassChange (com.google.refine.model.changes.MassChange)3 JSONException (org.json.JSONException)3 ColumnAdditionChange (com.google.refine.model.changes.ColumnAdditionChange)2 RowVisitor (com.google.refine.browsing.RowVisitor)1 CellAtRow (com.google.refine.model.changes.CellAtRow)1 ColumnRemovalChange (com.google.refine.model.changes.ColumnRemovalChange)1 ColumnSplitChange (com.google.refine.model.changes.ColumnSplitChange)1 RowFlagChange (com.google.refine.model.changes.RowFlagChange)1 RowStarChange (com.google.refine.model.changes.RowStarChange)1 RefineTest (com.google.refine.tests.RefineTest)1 Serializable (java.io.Serializable)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 BeforeTest (org.testng.annotations.BeforeTest)1