Package com.google.refine.model

Examples of com.google.refine.model.Column


            return this;
        }
       
        @Override
        public void run() {
            Column column = _project.columnModel.getColumnByName(_baseColumnName);
            if (column == null) {
                _project.processManager.onFailedProcess(this, new Exception("No column named " + _baseColumnName));
                return;
            }
            if (_project.columnModel.getColumnByName(_newColumnName) != null) {
View Full Code Here


                int              cellIndex;
                Properties       bindings;
                List<CellAtRow>  cellsAtRows;
               
                public RowVisitor init(List<CellAtRow> cellsAtRows) {
                    Column column = _project.columnModel.getColumnByName(_baseColumnName);
                   
                    this.cellIndex = column.getCellIndex();
                    this.bindings = ExpressionUtils.createBindings(_project);
                    this.cellsAtRows = cellsAtRows;
                    return this;
                }
               
View Full Code Here

   
    @Override
    protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
        Engine engine = createEngine(project);
       
        Column column = project.columnModel.getColumnByName(_baseColumnName);
        if (column == null) {
            throw new Exception("No column named " + _baseColumnName);
        }
        if (project.columnModel.getColumnByName(_newColumnName) != null) {
            throw new Exception("Another column already named " + _newColumnName);
View Full Code Here

            " cells to its best candidate in column " + column.getName();
    }

    @Override
    protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges, long historyEntryID) throws Exception {
        Column column = project.columnModel.getColumnByName(_columnName);
       
        return new RowVisitor() {
            int                 cellIndex;
            List<CellChange>    cellChanges;
            Map<Long, Recon>    dupReconMap = new HashMap<Long, Recon>();
            long                historyEntryID;
           
            public RowVisitor init(int cellIndex, List<CellChange> cellChanges, long historyEntryID) {
                this.cellIndex = cellIndex;
                this.cellChanges = cellChanges;
                this.historyEntryID = historyEntryID;
                return this;
            }
           
            @Override
            public void start(Project project) {
                // nothing to do
            }

            @Override
            public void end(Project project) {
                // nothing to do
            }

            @Override
            public boolean visit(Project project, int rowIndex, Row row) {
                if (cellIndex < row.cells.size()) {
                    Cell cell = row.cells.get(cellIndex);
                    if (cell != null && cell.recon != null) {
                        ReconCandidate candidate = cell.recon.getBestCandidate();
                        if (candidate != null) {
                            Recon newRecon;
                            if (dupReconMap.containsKey(cell.recon.id)) {
                                newRecon = dupReconMap.get(cell.recon.id);
                                newRecon.judgmentBatchSize++;
                            } else {
                                newRecon = cell.recon.dup(historyEntryID);
                                newRecon.judgmentBatchSize = 1;
                                newRecon.match = candidate;
                                newRecon.matchRank = 0;
                                newRecon.judgment = Judgment.Matched;
                                newRecon.judgmentAction = "mass";
                               
                                dupReconMap.put(cell.recon.id, newRecon);
                            }
                            Cell newCell = new Cell(
                                cell.value,
                                newRecon
                            );
                           
                            CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell);
                            cellChanges.add(cellChange);
                        }
                    }
                }
                return false;
            }
        }.init(column.getCellIndex(), cellChanges, historyEntryID);
    }
View Full Code Here

        return new HistoryEntry(
            historyEntryID, project, description, this, change);
    }

    protected RowVisitor createRowVisitor(Project project, List<CellAtRow> cellsAtRows) throws Exception {
        Column column = project.columnModel.getColumnByName(_baseColumnName);
       
        Evaluable eval = MetaParser.parse(_expression);
        Properties bindings = ExpressionUtils.createBindings(project);
       
        return new RowVisitor() {
            int              cellIndex;
            Properties       bindings;
            List<CellAtRow>  cellsAtRows;
            Evaluable        eval;
           
            public RowVisitor init(int cellIndex, Properties bindings, List<CellAtRow> cellsAtRows, Evaluable eval) {
                this.cellIndex = cellIndex;
                this.bindings = bindings;
                this.cellsAtRows = cellsAtRows;
                this.eval = eval;
                return this;
            }
           
            @Override
            public void start(Project project) {
                // nothing to do
            }

            @Override
            public void end(Project project) {
                // nothing to do
            }
           
            @Override
            public boolean visit(Project project, int rowIndex, Row row) {
                Cell cell = row.getCell(cellIndex);
                Cell newCell = null;

                ExpressionUtils.bind(bindings, row, rowIndex, _baseColumnName, cell);
               
                Object o = eval.evaluate(bindings);
                if (o != null) {
                    if (o instanceof Cell) {
                        newCell = (Cell) o;
                    } else if (o instanceof WrappedCell) {
                        newCell = ((WrappedCell) o).cell;
                    } else {
                        Serializable v = ExpressionUtils.wrapStorable(o);
                        if (ExpressionUtils.isError(v)) {
                            if (_onError == OnError.SetToBlank) {
                                return false;
                            } else if (_onError == OnError.KeepOriginal) {
                                v = cell != null ? cell.value : null;
                            }
                        }
                       
                        if (v != null) {
                            newCell = new Cell(v, null);
                        }
                    }
                }
               
                if (newCell != null) {
                    cellsAtRows.add(new CellAtRow(rowIndex, newCell));
                }
               
                return false;
            }
        }.init(column.getCellIndex(), bindings, cellsAtRows, eval);
    }
View Full Code Here

            " cells in column " + column.getName();
    }

    @Override
    protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges, long historyEntryID) throws Exception {
        Column column = project.columnModel.getColumnByName(_columnName);
       
        Evaluable eval = MetaParser.parse(_expression);
        Properties bindings = ExpressionUtils.createBindings(project);
       
        Map<String, Serializable> fromTo = new HashMap<String, Serializable>();
        Serializable fromBlankTo = null;
        Serializable fromErrorTo = null;
       
        for (Edit edit : _edits) {
            for (String s : edit.from) {
                fromTo.put(s, edit.to);
            }
           
            // the last edit wins
            if (edit.fromBlank) {
                fromBlankTo = edit.to;
            }
            if (edit.fromError) {
                fromErrorTo = edit.to;
            }
        }
       
        return new RowVisitor() {
            int                         cellIndex;
            Properties                  bindings;
            List<CellChange>            cellChanges;
            Evaluable                   eval;
           
            Map<String, Serializable>   fromTo;
            Serializable                fromBlankTo;
            Serializable                fromErrorTo;
           
            public RowVisitor init(
                int cellIndex,
                Properties bindings,
                List<CellChange> cellChanges,
                Evaluable eval,
                Map<String, Serializable> fromTo,
                Serializable fromBlankTo,
                Serializable fromErrorTo
            ) {
                this.cellIndex = cellIndex;
                this.bindings = bindings;
                this.cellChanges = cellChanges;
                this.eval = eval;
                this.fromTo = fromTo;
                this.fromBlankTo = fromBlankTo;
                this.fromErrorTo = fromErrorTo;
                return this;
            }
           
            @Override
            public void start(Project project) {
                // nothing to do
            }

            @Override
            public void end(Project project) {
                // nothing to do
            }
           
            @Override
            public boolean visit(Project project, int rowIndex, Row row) {
                Cell cell = row.getCell(cellIndex);
                Cell newCell = null;
               
                ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell);
               
                Object v = eval.evaluate(bindings);
                if (ExpressionUtils.isError(v)) {
                    if (fromErrorTo != null) {
                        newCell = new Cell(fromErrorTo, (cell != null) ? cell.recon : null);
                    }
                } else if (ExpressionUtils.isNonBlankData(v)) {
                    String from = v.toString();
                    Serializable to = fromTo.get(from);
                    if (to != null) {
                        newCell = new Cell(to, (cell != null) ? cell.recon : null);
                    }
                } else {
                    if (fromBlankTo != null) {
                        newCell = new Cell(fromBlankTo, (cell != null) ? cell.recon : null);
                    }
                }
               
                if (newCell != null) {
                    CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell);
                    cellChanges.add(cellChange);
                }
                return false;
            }
        }.init(column.getCellIndex(), bindings, cellChanges, eval, fromTo, fromBlankTo, fromErrorTo);
    }
View Full Code Here

    @Override
    protected HistoryEntry createHistoryEntry(final Project project, final long historyEntryID) throws Exception {
        Engine engine = createEngine(project);
       
        final Column fromColumn = project.columnModel.getColumnByName(_fromColumnName);
       
        final List<Column> toColumns = new ArrayList<Column>(_toColumnNames.length);
        for (String c : _toColumnNames) {
            Column toColumn = project.columnModel.getColumnByName(c);
            if (toColumn != null) {
                toColumns.add(toColumn);
            }
        }
       
View Full Code Here

            " cells in column " + column.getName();
    }

    @Override
    protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges, long historyEntryID) throws Exception {
        Column column = project.columnModel.getColumnByName(_columnName);
       
        return new RowVisitor() {
            int                 cellIndex;
            List<CellChange>    cellChanges;
            Cell                previousCell;
           
            public RowVisitor init(int cellIndex, List<CellChange> cellChanges) {
                this.cellIndex = cellIndex;
                this.cellChanges = cellChanges;
                return this;
            }

            @Override
            public void start(Project project) {
                // nothing to do
            }

            @Override
            public void end(Project project) {
                // nothing to do
            }
           
            @Override
            public boolean visit(Project project, int rowIndex, Row row) {
                Object value = row.getCellValue(cellIndex);
                if (ExpressionUtils.isNonBlankData(value)) {
                    Cell cell = row.getCell(cellIndex);
                    if (previousCell != null && cell.value.equals(previousCell.value)) {
                        CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, null);
                        cellChanges.add(cellChange);
                    }
                    previousCell = cell;
                } else {
                    previousCell = null;
                }
                return false;
            }
        }.init(column.getCellIndex(), cellChanges);
    }
View Full Code Here

    @Override
    protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
        Engine engine = createEngine(project);
       
        Column column = project.columnModel.getColumnByName(_columnName);
        if (column == null) {
            throw new Exception("No column named " + _columnName);
        }
       
        List<String> columnNames = new ArrayList<String>();
        List<Integer> rowIndices = new ArrayList<Integer>(project.rows.size());
        List<List<Serializable>> tuples = new ArrayList<List<Serializable>>(project.rows.size());
       
        FilteredRows filteredRows = engine.getAllFilteredRows();
        RowVisitor rowVisitor;
        if ("lengths".equals(_mode)) {
            rowVisitor = new ColumnSplitRowVisitor(column.getCellIndex(), columnNames, rowIndices, tuples) {
                @Override
                protected java.util.List<Serializable> split(String s) {
                    List<Serializable> results = new ArrayList<Serializable>(_fieldLengths.length + 1);
                   
                    int lastIndex = 0;
                    for (int length : _fieldLengths) {
                        int from = lastIndex;
                        int to = Math.min(from + length, s.length());
                       
                        results.add(stringToValue(s.substring(from, to)));
                       
                        lastIndex = to;
                    }
                   
                    return results;
                };
            };
        } else if (_regex) {
            Pattern pattern = Pattern.compile(_separator);
           
            rowVisitor = new ColumnSplitRowVisitor(column.getCellIndex(), columnNames, rowIndices, tuples) {
                Pattern _pattern;
               
                @Override
                protected java.util.List<Serializable> split(String s) {
                    return stringArrayToValueList(_pattern.split(s, _maxColumns));
                };
               
                public RowVisitor init(Pattern pattern) {
                    _pattern = pattern;
                    return this;
                }
            }.init(pattern);
        } else {
            rowVisitor = new ColumnSplitRowVisitor(column.getCellIndex(), columnNames, rowIndices, tuples) {
                @Override
                protected java.util.List<Serializable> split(String s) {
                    return stringArrayToValueList(
                            StringUtils.splitByWholeSeparatorPreserveAllTokens(s, _separator, _maxColumns));
                };
View Full Code Here

            _similarValue + "\" in column " + _columnName;
    }

    @Override
    protected RowVisitor createRowVisitor(final Project project, final List<CellChange> cellChanges, final long historyEntryID) throws Exception {
        Column column = project.columnModel.getColumnByName(_columnName);
        final int cellIndex = column != null ? column.getCellIndex() : -1;
       
        return new RowVisitor() {
            @Override
            public void start(Project project) {
                // nothing to do
View Full Code Here

TOP

Related Classes of com.google.refine.model.Column

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.