Search in sources :

Example 1 with Table

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;
    }
}
Also used : Table(tech.tablesaw.api.Table) CsvReadOptions(tech.tablesaw.io.csv.CsvReadOptions) IStringX(org.matheclipse.core.interfaces.IStringX)

Example 2 with Table

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>&lt;|...|&gt;</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;
}
Also used : IAssociation(org.matheclipse.core.interfaces.IAssociation) Table(tech.tablesaw.api.Table) ArrayList(java.util.ArrayList) Column(tech.tablesaw.columns.Column) ExprColumn(tech.tablesaw.api.ExprColumn) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr) Row(tech.tablesaw.api.Row) HashSet(java.util.HashSet)

Example 3 with Table

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);
}
Also used : Table(tech.tablesaw.api.Table)

Example 4 with 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);
}
Also used : Table(tech.tablesaw.api.Table)

Example 5 with 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);
}
Also used : Table(tech.tablesaw.api.Table)

Aggregations

Table (tech.tablesaw.api.Table)42 StringColumn (tech.tablesaw.api.StringColumn)10 ArrayList (java.util.ArrayList)9 DoubleColumn (tech.tablesaw.api.DoubleColumn)8 IntColumn (tech.tablesaw.api.IntColumn)8 ColumnType (tech.tablesaw.api.ColumnType)7 Column (tech.tablesaw.columns.Column)7 TreeBasedTable (com.google.common.collect.TreeBasedTable)5 Map (java.util.Map)5 List (java.util.List)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IExpr (org.matheclipse.core.interfaces.IExpr)3 ExprColumn (tech.tablesaw.api.ExprColumn)3 Row (tech.tablesaw.api.Row)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 IAST (org.matheclipse.core.interfaces.IAST)2 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1