Search in sources :

Example 31 with StringColumn

use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.

the class StringMapFunctions method tokenizeAndSort.

default StringColumn tokenizeAndSort(String separator) {
    StringColumn newColumn = StringColumn.create(name() + "[sorted]", this.size());
    for (int r = 0; r < size(); r++) {
        String value = getString(r);
        Splitter splitter = Splitter.on(separator);
        splitter = splitter.trimResults();
        splitter = splitter.omitEmptyStrings();
        List<String> tokens = new ArrayList<>(splitter.splitToList(value));
        Collections.sort(tokens);
        value = String.join(separator, tokens);
        newColumn.set(r, value);
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn) Splitter(com.google.common.base.Splitter) ArrayList(java.util.ArrayList)

Example 32 with StringColumn

use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.

the class StringMapFunctions method tokens.

/**
 * Returns a column of arbitrary size containing each token in this column, where a token is
 * defined using the given separator.
 *
 * <p>NOTE: Unlike other map functions, this method produces a column whose size may be different
 * from the source, so they cannot safely be combined in a table.
 *
 * @param separator the delimiter used in the tokenizing operation
 * @return a new column
 */
default StringColumn tokens(String separator) {
    StringColumn newColumn = StringColumn.create(name() + "[token count]");
    for (int r = 0; r < size(); r++) {
        String value = getString(r);
        Splitter splitter = Splitter.on(separator);
        splitter = splitter.trimResults();
        splitter = splitter.omitEmptyStrings();
        List<String> tokens = new ArrayList<>(splitter.splitToList(value));
        for (String token : tokens) {
            newColumn.append(token);
        }
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn) Splitter(com.google.common.base.Splitter) ArrayList(java.util.ArrayList)

Example 33 with StringColumn

use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.

the class StringMapFunctions method commonSuffix.

default StringColumn commonSuffix(Column<String> column2) {
    StringColumn newColumn = StringColumn.create(name() + column2.name() + "[suffix]");
    for (int r = 0; r < size(); r++) {
        String value1 = getString(r);
        String value2 = column2.getString(r);
        newColumn.append(Strings.commonSuffix(value1, value2));
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Example 34 with StringColumn

use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.

the class StringMapFunctions method concatenate.

/**
 * Return a copy of this column with the corresponding value of each column argument appended to
 * each element. getString is used to ensure the value returned by the args are strings
 *
 * @param stringColumns the string columns to append
 * @return the new column
 */
default StringColumn concatenate(Column<?>... stringColumns) {
    StringColumn newColumn = StringColumn.create(name() + "[append]", this.size());
    for (int r = 0; r < size(); r++) {
        StringBuilder s = new StringBuilder(getString(r));
        for (Column<?> stringColumn : stringColumns) s.append(stringColumn.getString(r));
        newColumn.set(r, s.toString());
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Example 35 with StringColumn

use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.

the class Stats method asTableComplete.

public Table asTableComplete() {
    Table t = asTable();
    StringColumn measure = t.stringColumn("Measure");
    DoubleColumn value = t.doubleColumn("Value");
    measure.append("Sum of Squares");
    value.append(sumOfSquares());
    measure.append("Sum of Logs");
    value.append(sumOfLogs());
    measure.append("Population Variance");
    value.append(populationVariance());
    measure.append("Geometric Mean");
    value.append(geometricMean());
    measure.append("Quadratic Mean");
    value.append(quadraticMean());
    measure.append("Second Moment");
    value.append(secondMoment());
    return t;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) DoubleColumn(tech.tablesaw.api.DoubleColumn)

Aggregations

StringColumn (tech.tablesaw.api.StringColumn)39 Table (tech.tablesaw.api.Table)10 DoubleColumn (tech.tablesaw.api.DoubleColumn)5 Splitter (com.google.common.base.Splitter)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 IntColumn (tech.tablesaw.api.IntColumn)4 TreeBasedTable (com.google.common.collect.TreeBasedTable)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Byte2IntMap (it.unimi.dsi.fastutil.bytes.Byte2IntMap)1 Byte2IntOpenHashMap (it.unimi.dsi.fastutil.bytes.Byte2IntOpenHashMap)1 Byte2ObjectMap (it.unimi.dsi.fastutil.bytes.Byte2ObjectMap)1 Byte2ObjectOpenHashMap (it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap)1 Int2IntMap (it.unimi.dsi.fastutil.ints.Int2IntMap)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 Object2ByteOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap)1 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)1 Object2ShortOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ShortOpenHashMap)1