use of tech.tablesaw.columns.Column in project symja_android_library by axkr.
the class ASTDataset method newAssociationOfAssociations.
/**
* Create a <code>Dataset</code> object from a (head-)association <code><|...|></code> of
* (sub-)associations. Each key in the (head-)association is used in the first column the
* (sub-)association represents the other columns of a row in the <code>Dataset</code>. The
* left-hand-side of each singular rule in a (sub-)association was assumed to be the name of the
* resulting <code>Dataset</code> columns. Identical names maps the right-hand-side values of the
* rule to the same columns in the resulting dataset.
*
* @param assocOfAssociations
* @return {@link F#NIL} if the <code>Dataset</code> cannot be created
*/
public static IExpr newAssociationOfAssociations(IAssociation assocOfAssociations) {
// 1. phase: build up column names; reserve 1 column for header assoc
List<String> colNames = new ArrayList<String>();
Set<String> colNamesSet = new HashSet<String>();
colNamesSet.add("");
colNames.add("");
for (int i = 1; i < assocOfAssociations.size(); i++) {
IAssociation assoc = (IAssociation) assocOfAssociations.get(i);
for (int j = 1; j < assoc.size(); j++) {
IAST rule = assoc.getRule(j);
String columnName = rule.first().toString();
if (!colNamesSet.contains(columnName)) {
colNamesSet.add(columnName);
colNames.add(columnName);
}
}
}
if (colNames.size() > 0) {
// 2. phase: define the columns
Table table = Table.create();
Column<?>[] cols = new Column<?>[colNames.size()];
for (int i = 0; i < colNames.size(); i++) {
cols[i] = ExprColumn.create(colNames.get(i));
}
table.addColumns(cols);
// 3. phase: add the values
for (int i = 1; i < assocOfAssociations.size(); i++) {
IExpr rule = assocOfAssociations.getRule(i);
IAssociation assoc = (IAssociation) rule.second();
Row row = table.appendRow();
row.setExpr("", rule.first());
for (int j = 1; j < assoc.size(); j++) {
rule = assoc.getRule(j);
String columnName = rule.first().toString();
IExpr value = rule.second();
row.setExpr(columnName, value);
}
}
return newTablesawTable(table);
}
return F.NIL;
}
use of tech.tablesaw.columns.Column in project symja_android_library by axkr.
the class ArgumentList method createEmptyDestinationColumns.
/**
* @return an ordered list of new columns this analytic query will generate.
*/
List<Column<?>> createEmptyDestinationColumns(int rowCount) {
List<Column<?>> newColumns = new ArrayList<>();
for (String toColumn : newColumnNames) {
FunctionCall<? extends FunctionMetaData> functionCall = Stream.of(aggregateFunctions.get(toColumn), numberingFunctions.get(toColumn)).filter(java.util.Objects::nonNull).findFirst().get();
ColumnType type = functionCall.function.returnType();
Column<?> resultColumn = type.create(toColumn);
newColumns.add(resultColumn);
for (int i = 0; i < rowCount; i++) {
resultColumn.appendMissing();
}
}
return newColumns;
}
use of tech.tablesaw.columns.Column in project symja_android_library by axkr.
the class Table method append.
@SuppressWarnings({ "rawtypes", "unchecked" })
public Table append(Table tableToAppend) {
for (final Column column : columnList) {
final Column columnToAppend = tableToAppend.column(column.name());
column.append(columnToAppend);
}
return this;
}
use of tech.tablesaw.columns.Column in project symja_android_library by axkr.
the class Rows method copyRowsToTable.
/**
* Copies the rows indicated by the row index values in the given array from oldTable to newTable
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void copyRowsToTable(int[] rows, Table oldTable, Table newTable) {
for (int columnIndex = 0; columnIndex < oldTable.columnCount(); columnIndex++) {
Column oldColumn = oldTable.column(columnIndex);
int r = 0;
for (int i : rows) {
newTable.column(columnIndex).set(r, oldColumn, i);
r++;
}
}
}
use of tech.tablesaw.columns.Column in project symja_android_library by axkr.
the class Rows method copyRowsToTable.
/**
* Copies the rows indicated by the row index values in the given selection from oldTable to
* newTable
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void copyRowsToTable(Selection rows, Table oldTable, Table newTable) {
for (int columnIndex = 0; columnIndex < oldTable.columnCount(); columnIndex++) {
Column oldColumn = oldTable.column(columnIndex);
int r = 0;
for (int i : rows) {
newTable.column(columnIndex).set(r, oldColumn, i);
r++;
}
}
}
Aggregations