Search in sources :

Example 1 with NumericBinRowIndex

use of com.google.refine.browsing.util.NumericBinRowIndex in project OpenRefine by OpenRefine.

the class GetColumnsInfoCommand method getBinIndex.

private NumericBinIndex getBinIndex(Project project, Column column) {
    String expression = "value";
    String key = "numeric-bin:" + expression;
    Evaluable eval = null;
    try {
        eval = MetaParser.parse(expression);
    } catch (ParsingException e) {
    // this should never happen
    }
    NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key);
    if (index == null) {
        index = new NumericBinRowIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval));
        column.setPrecompute(key, index);
    }
    return index;
}
Also used : Evaluable(com.google.refine.expr.Evaluable) ExpressionBasedRowEvaluable(com.google.refine.browsing.util.ExpressionBasedRowEvaluable) NumericBinRowIndex(com.google.refine.browsing.util.NumericBinRowIndex) NumericBinIndex(com.google.refine.browsing.util.NumericBinIndex) ParsingException(com.google.refine.expr.ParsingException) ExpressionBasedRowEvaluable(com.google.refine.browsing.util.ExpressionBasedRowEvaluable)

Example 2 with NumericBinRowIndex

use of com.google.refine.browsing.util.NumericBinRowIndex in project OpenRefine by OpenRefine.

the class RangeFacet method computeChoices.

@Override
public void computeChoices(Project project, FilteredRows filteredRows) {
    if (_eval != null && _errorMessage == null) {
        RowEvaluable rowEvaluable = getRowEvaluable(project);
        Column column = project.columnModel.getColumnByCellIndex(_cellIndex);
        String key = "numeric-bin:row-based:" + _config._expression;
        NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key);
        if (index == null) {
            index = new NumericBinRowIndex(project, rowEvaluable);
            column.setPrecompute(key, index);
        }
        retrieveDataFromBaseBinIndex(index);
        ExpressionNumericValueBinner binner = new ExpressionNumericValueBinner(rowEvaluable, index);
        filteredRows.accept(project, binner);
        retrieveDataFromBinner(binner);
    }
}
Also used : NumericBinRowIndex(com.google.refine.browsing.util.NumericBinRowIndex) Column(com.google.refine.model.Column) NumericBinIndex(com.google.refine.browsing.util.NumericBinIndex) ExpressionNumericValueBinner(com.google.refine.browsing.util.ExpressionNumericValueBinner) ExpressionBasedRowEvaluable(com.google.refine.browsing.util.ExpressionBasedRowEvaluable) RowEvaluable(com.google.refine.browsing.util.RowEvaluable)

Example 3 with NumericBinRowIndex

use of com.google.refine.browsing.util.NumericBinRowIndex in project OpenRefine by OpenRefine.

the class ScatterplotFacet method getBinIndex.

public static NumericBinIndex getBinIndex(Project project, Column column, Evaluable eval, String expression, String mode) {
    String key = "numeric-bin:" + mode + ":" + expression;
    if (eval == null) {
        try {
            eval = MetaParser.parse(expression);
        } catch (ParsingException e) {
            logger.warn("Error parsing expression", e);
        }
    }
    NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key);
    if (index == null) {
        index = "row-based".equals(mode) ? new NumericBinRowIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval)) : new NumericBinRecordIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval));
        column.setPrecompute(key, index);
    }
    return index;
}
Also used : NumericBinRecordIndex(com.google.refine.browsing.util.NumericBinRecordIndex) NumericBinRowIndex(com.google.refine.browsing.util.NumericBinRowIndex) NumericBinIndex(com.google.refine.browsing.util.NumericBinIndex) ParsingException(com.google.refine.expr.ParsingException) ExpressionBasedRowEvaluable(com.google.refine.browsing.util.ExpressionBasedRowEvaluable)

Aggregations

ExpressionBasedRowEvaluable (com.google.refine.browsing.util.ExpressionBasedRowEvaluable)3 NumericBinIndex (com.google.refine.browsing.util.NumericBinIndex)3 NumericBinRowIndex (com.google.refine.browsing.util.NumericBinRowIndex)3 ParsingException (com.google.refine.expr.ParsingException)2 ExpressionNumericValueBinner (com.google.refine.browsing.util.ExpressionNumericValueBinner)1 NumericBinRecordIndex (com.google.refine.browsing.util.NumericBinRecordIndex)1 RowEvaluable (com.google.refine.browsing.util.RowEvaluable)1 Evaluable (com.google.refine.expr.Evaluable)1 Column (com.google.refine.model.Column)1