use of com.google.refine.model.Column in project OpenRefine by OpenRefine.
the class ColumnSplitChange method load.
public static Change load(LineNumberReader reader, Pool pool) throws Exception {
String columnName = null;
List<String> columnNames = null;
List<Integer> rowIndices = null;
List<List<Serializable>> tuples = null;
boolean removeOriginalColumn = false;
Column column = null;
int columnIndex = -1;
int firstNewCellIndex = -1;
List<Row> oldRows = null;
List<Row> newRows = null;
List<ColumnGroup> oldColumnGroups = null;
String line;
while ((line = reader.readLine()) != null && !"/ec/".equals(line)) {
int equal = line.indexOf('=');
CharSequence field = line.subSequence(0, equal);
String value = line.substring(equal + 1);
if ("columnName".equals(field)) {
columnName = value;
} else if ("columnNameCount".equals(field)) {
int count = Integer.parseInt(value);
columnNames = new ArrayList<String>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
if (line != null) {
columnNames.add(line);
}
}
} else if ("rowIndexCount".equals(field)) {
int count = Integer.parseInt(value);
rowIndices = new ArrayList<Integer>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
if (line != null) {
rowIndices.add(Integer.parseInt(line));
}
}
} else if ("tupleCount".equals(field)) {
int count = Integer.parseInt(value);
tuples = new ArrayList<List<Serializable>>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
if (line == null) {
continue;
}
int valueCount = Integer.parseInt(line);
List<Serializable> tuple = new ArrayList<Serializable>(valueCount);
for (int r = 0; r < valueCount; r++) {
line = reader.readLine();
JSONTokener t = new JSONTokener(line);
Object o = t.nextValue();
tuple.add((o != JSONObject.NULL) ? (Serializable) o : null);
}
tuples.add(tuple);
}
} else if ("removeOriginalColumn".equals(field)) {
removeOriginalColumn = Boolean.parseBoolean(value);
} else if ("column".equals(field)) {
column = Column.load(value);
} else if ("columnIndex".equals(field)) {
columnIndex = Integer.parseInt(value);
} else if ("firstNewCellIndex".equals(field)) {
firstNewCellIndex = Integer.parseInt(value);
} else if ("oldRowCount".equals(field)) {
int count = Integer.parseInt(value);
oldRows = new ArrayList<Row>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
if (line != null) {
oldRows.add(Row.load(line, pool));
}
}
} else if ("newRowCount".equals(field)) {
int count = Integer.parseInt(value);
newRows = new ArrayList<Row>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
if (line != null) {
newRows.add(Row.load(line, pool));
}
}
} else if ("oldColumnGroupCount".equals(field)) {
int oldColumnGroupCount = Integer.parseInt(line.substring(equal + 1));
oldColumnGroups = ColumnChange.readOldColumnGroups(reader, oldColumnGroupCount);
}
}
ColumnSplitChange change = new ColumnSplitChange(columnName, columnNames, rowIndices, tuples, removeOriginalColumn, column, columnIndex, firstNewCellIndex, oldRows, newRows);
change._oldColumnGroups = oldColumnGroups != null ? oldColumnGroups : new LinkedList<ColumnGroup>();
return change;
}
use of com.google.refine.model.Column in project OpenRefine by OpenRefine.
the class MassCellChange method apply.
@Override
public void apply(Project project) {
synchronized (project) {
List<Row> rows = project.rows;
for (CellChange cellChange : _cellChanges) {
rows.get(cellChange.row).setCell(cellChange.cellIndex, cellChange.newCell);
}
if (_commonColumnName != null) {
Column column = project.columnModel.getColumnByName(_commonColumnName);
column.clearPrecomputes();
ProjectManager.singleton.getInterProjectModel().flushJoinsInvolvingProjectColumn(project.id, _commonColumnName);
}
if (_updateRowContextDependencies) {
project.update();
}
}
}
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");
}
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.
}
}
}
}
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());
}
Aggregations