use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class SemanticImportString method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
if (!(ast.arg1() instanceof IStringX)) {
return F.NIL;
}
IStringX arg1 = (IStringX) ast.arg1();
try {
String contents = arg1.toString();
char delimiter = determineDelimiter(contents);
CsvReadOptions.Builder builder = CsvReadOptions.builderFromString(contents).separator(delimiter);
CsvReadOptions options = builder.build();
Table table = Table.read().usingOptions(options);
return ASTDataset.newTablesawTable(table);
} catch (Exception rex) {
LOGGER.log(engine.getLogLevel(), "SemanticImportString ", rex);
return F.NIL;
}
}
use of tech.tablesaw.api.Table 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.api.Table in project symja_android_library by axkr.
the class ASTDataset method groupBy.
@Override
public IExpr groupBy(List<String> group) {
String[] strings = new String[group.size()];
for (int i = 0; i < strings.length; i++) {
strings[i] = group.get(i);
}
Table table = fTable.sortAscendingOn(strings);
return newTablesawTable(table);
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class ASTDataset method sortBy.
public IExpr sortBy(List<String> group) {
String[] strings = new String[group.size()];
for (int i = 0; i < strings.length; i++) {
strings[i] = group.get(i);
}
Table table = fTable.sortAscendingOn(strings);
return newTablesawTable(table);
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class ASTDataset method select.
private IExpr select(int row, int column) {
Table table = fTable;
Object obj = table.column(column - 1).get(row - 1);
return Object2Expr.convertString(obj);
}
Aggregations