Search in sources :

Example 16 with Column

use of com.google.refine.model.Column in project OpenRefine by OpenRefine.

the class MassRowColumnChange method save.

@Override
public void save(Writer writer, Properties options) throws IOException {
    writer.write("newColumnCount=");
    writer.write(Integer.toString(_newColumns.size()));
    writer.write('\n');
    for (Column column : _newColumns) {
        column.save(writer);
        writer.write('\n');
    }
    writer.write("oldColumnCount=");
    writer.write(Integer.toString(_oldColumns.size()));
    writer.write('\n');
    for (Column column : _oldColumns) {
        column.save(writer);
        writer.write('\n');
    }
    writer.write("newRowCount=");
    writer.write(Integer.toString(_newRows.size()));
    writer.write('\n');
    for (Row row : _newRows) {
        row.save(writer, options);
        writer.write('\n');
    }
    writer.write("oldRowCount=");
    writer.write(Integer.toString(_oldRows.size()));
    writer.write('\n');
    for (Row row : _oldRows) {
        row.save(writer, options);
        writer.write('\n');
    }
    ColumnChange.writeOldColumnGroups(writer, options, _oldColumnGroups);
    // end of change marker
    writer.write("/ec/\n");
}
Also used : Column(com.google.refine.model.Column) Row(com.google.refine.model.Row)

Example 17 with Column

use of com.google.refine.model.Column in project OpenRefine by OpenRefine.

the class ImporterUtilities method setupColumns.

public static void setupColumns(Project project, List<String> columnNames) {
    Map<String, Integer> nameToIndex = new HashMap<String, Integer>();
    for (int c = 0; c < columnNames.size(); c++) {
        String cell = columnNames.get(c).trim();
        if (cell.isEmpty()) {
            cell = "Column";
        } else if (cell.startsWith("\"") && cell.endsWith("\"")) {
            // FIXME: is trimming quotation marks appropriate?
            cell = cell.substring(1, cell.length() - 1).trim();
        }
        if (nameToIndex.containsKey(cell)) {
            int index = nameToIndex.get(cell);
            nameToIndex.put(cell, index + 1);
            cell = cell.contains(" ") ? (cell + " " + index) : (cell + index);
        } else {
            nameToIndex.put(cell, 2);
        }
        columnNames.set(c, cell);
        if (project.columnModel.getColumnByName(cell) == null) {
            Column column = new Column(project.columnModel.allocateNewCellIndex(), cell);
            try {
                project.columnModel.addColumn(project.columnModel.columns.size(), column, false);
            } catch (ModelException e) {
            // Ignore: shouldn't get in here since we just checked for duplicate names.
            }
        }
    }
}
Also used : ModelException(com.google.refine.model.ModelException) HashMap(java.util.HashMap) Column(com.google.refine.model.Column)

Example 18 with Column

use of com.google.refine.model.Column in project OpenRefine by OpenRefine.

the class CellChange method apply.

@Override
public void apply(Project project) {
    project.rows.get(row).setCell(cellIndex, newCell);
    Column column = project.columnModel.getColumnByCellIndex(cellIndex);
    column.clearPrecomputes();
    ProjectManager.singleton.getInterProjectModel().flushJoinsInvolvingProjectColumn(project.id, column.getName());
}
Also used : Column(com.google.refine.model.Column)

Example 19 with Column

use of com.google.refine.model.Column in project OpenRefine by OpenRefine.

the class ColumnAdditionChange method apply.

@Override
public void apply(Project project) {
    synchronized (project) {
        if (_newCellIndex < 0) {
            _newCellIndex = project.columnModel.allocateNewCellIndex();
        }
        int columnGroupCount = project.columnModel.columnGroups.size();
        _oldColumnGroups = new ArrayList<ColumnGroup>(columnGroupCount);
        for (int i = columnGroupCount - 1; i >= 0; i--) {
            ColumnGroup columnGroup = project.columnModel.columnGroups.get(i);
            _oldColumnGroups.add(columnGroup);
            if (columnGroup.startColumnIndex <= _columnIndex) {
                if (columnGroup.startColumnIndex + columnGroup.columnSpan > _columnIndex) {
                    // the new column is inserted right in the middle of the group
                    project.columnModel.columnGroups.set(i, new ColumnGroup(columnGroup.startColumnIndex, columnGroup.columnSpan + 1, columnGroup.keyColumnIndex < _columnIndex ? columnGroup.keyColumnIndex : (columnGroup.keyColumnIndex + 1)));
                }
            } else {
                // the new column precedes this whole group
                project.columnModel.columnGroups.set(i, new ColumnGroup(columnGroup.startColumnIndex + 1, columnGroup.columnSpan, columnGroup.keyColumnIndex + 1));
            }
        }
        Column column = new Column(_newCellIndex, _columnName);
        project.columnModel.columns.add(_columnIndex, column);
        try {
            for (CellAtRow cell : _newCells) {
                project.rows.get(cell.row).setCell(_newCellIndex, cell.cell);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        project.update();
    }
}
Also used : Column(com.google.refine.model.Column) ColumnGroup(com.google.refine.model.ColumnGroup) IOException(java.io.IOException)

Example 20 with Column

use of com.google.refine.model.Column in project OpenRefine by OpenRefine.

the class ColumnReorderChange method save.

@Override
public void save(Writer writer, Properties options) throws IOException {
    writer.write("columnNameCount=");
    writer.write(Integer.toString(_columnNames.size()));
    writer.write('\n');
    for (String n : _columnNames) {
        writer.write(n);
        writer.write('\n');
    }
    writer.write("oldColumnCount=");
    writer.write(Integer.toString(_oldColumns.size()));
    writer.write('\n');
    for (Column c : _oldColumns) {
        c.save(writer);
        writer.write('\n');
    }
    writer.write("newColumnCount=");
    writer.write(Integer.toString(_newColumns.size()));
    writer.write('\n');
    for (Column c : _newColumns) {
        c.save(writer);
        writer.write('\n');
    }
    writeOldColumnGroups(writer, options, _oldColumnGroups);
    // end of change marker
    writer.write("/ec/\n");
}
Also used : Column(com.google.refine.model.Column)

Aggregations

Column (com.google.refine.model.Column)62 Row (com.google.refine.model.Row)25 Cell (com.google.refine.model.Cell)19 Project (com.google.refine.model.Project)16 ArrayList (java.util.ArrayList)14 JSONObject (org.json.JSONObject)14 JSONException (org.json.JSONException)11 HistoryEntry (com.google.refine.history.HistoryEntry)10 RowVisitor (com.google.refine.browsing.RowVisitor)9 Engine (com.google.refine.browsing.Engine)7 ParsingException (com.google.refine.expr.ParsingException)7 CellChange (com.google.refine.model.changes.CellChange)7 Serializable (java.io.Serializable)7 Properties (java.util.Properties)7 FilteredRows (com.google.refine.browsing.FilteredRows)6 NumericBinIndex (com.google.refine.browsing.util.NumericBinIndex)6 ColumnGroup (com.google.refine.model.ColumnGroup)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Evaluable (com.google.refine.expr.Evaluable)5