Search in sources :

Example 1 with ExpressionNominalValueGrouper

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

the class FacetCount method call.

@Override
public Object call(Properties bindings, Object[] args) {
    if (args.length == 3 && args[1] instanceof String && args[2] instanceof String) {
        // choice value to look up
        Object choiceValue = args[0];
        String facetExpression = (String) args[1];
        String columnName = (String) args[2];
        Project project = (Project) bindings.get("project");
        Column column = project.columnModel.getColumnByName(columnName);
        if (column == null) {
            return new EvalError("No such column named " + columnName);
        }
        String key = "nominal-bin:" + facetExpression;
        ExpressionNominalValueGrouper grouper = (ExpressionNominalValueGrouper) column.getPrecompute(key);
        if (grouper == null) {
            try {
                Evaluable eval = MetaParser.parse(facetExpression);
                Engine engine = new Engine(project);
                grouper = new ExpressionNominalValueGrouper(eval, columnName, column.getCellIndex());
                engine.getAllRows().accept(project, grouper);
                column.setPrecompute(key, grouper);
            } catch (ParsingException e) {
                return new EvalError("Error parsing facet expression " + facetExpression);
            }
        }
        return grouper.getChoiceValueCountMultiple(choiceValue);
    }
    return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a choice value, an expression as a string, and a column name");
}
Also used : Project(com.google.refine.model.Project) Evaluable(com.google.refine.expr.Evaluable) Column(com.google.refine.model.Column) ParsingException(com.google.refine.expr.ParsingException) EvalError(com.google.refine.expr.EvalError) Engine(com.google.refine.browsing.Engine) ExpressionNominalValueGrouper(com.google.refine.browsing.util.ExpressionNominalValueGrouper)

Example 2 with ExpressionNominalValueGrouper

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

the class ListFacet method computeChoices.

@Override
public void computeChoices(Project project, FilteredRows filteredRows) {
    if (_eval != null && _errorMessage == null) {
        ExpressionNominalValueGrouper grouper = new ExpressionNominalValueGrouper(_eval, _columnName, _cellIndex);
        filteredRows.accept(project, grouper);
        postProcessGrouper(grouper);
    }
}
Also used : ExpressionNominalValueGrouper(com.google.refine.browsing.util.ExpressionNominalValueGrouper)

Example 3 with ExpressionNominalValueGrouper

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

the class ListFacet method computeChoices.

@Override
public void computeChoices(Project project, FilteredRecords filteredRecords) {
    if (_eval != null && _errorMessage == null) {
        ExpressionNominalValueGrouper grouper = new ExpressionNominalValueGrouper(_eval, _columnName, _cellIndex);
        filteredRecords.accept(project, grouper);
        postProcessGrouper(grouper);
    }
}
Also used : ExpressionNominalValueGrouper(com.google.refine.browsing.util.ExpressionNominalValueGrouper)

Aggregations

ExpressionNominalValueGrouper (com.google.refine.browsing.util.ExpressionNominalValueGrouper)3 Engine (com.google.refine.browsing.Engine)1 EvalError (com.google.refine.expr.EvalError)1 Evaluable (com.google.refine.expr.Evaluable)1 ParsingException (com.google.refine.expr.ParsingException)1 Column (com.google.refine.model.Column)1 Project (com.google.refine.model.Project)1