Package com.google.refine.model

Examples of com.google.refine.model.Row


    }

    static protected void addImportRecordToProject(ImportRecord record, Project project) {
        if (record.rows.size() > 0) {
            for (List<Cell> row : record.rows) {
                Row realRow = new Row(row.size());
                int cellCount = 0;

                for (int c = 0; c < row.size(); c++) {
                    Cell cell = row.get(c);
                    if (cell != null) {
                        realRow.setCell(c, cell);
                        cellCount++;
                    }
                }

                if (cellCount > 0) {
View Full Code Here


            Set<String> ids = new HashSet<String>();
           
            int end;
            for (end = from; end < limit && ids.size() < 10; end++) {
                int index = rowIndices.get(end);
                Row row = _project.rows.get(index);
                Cell cell = row.getCell(_cellIndex);
               
                ids.add(cell.recon.match.id);
            }
           
            Map<String, DataExtension> map = null;
            try {
                map = _job.extend(ids, reconCandidateMap);
            } catch (Exception e) {
                map = new HashMap<String, DataExtension>();
            }
           
            for (int i = from; i < end; i++) {
                int index = rowIndices.get(i);
                Row row = _project.rows.get(index);
                Cell cell = row.getCell(_cellIndex);
                String guid = cell.recon.match.id;
               
                if (map.containsKey(guid)) {
                    dataExtensions.add(map.get(guid));
                } else {
View Full Code Here

                index++;
               
                Map<String, Recon> reconMap = new HashMap<String, Recon>();
               
                for (int r = 0; r < _oldRows.size(); r++) {
                    Row oldRow = _oldRows.get(r);
                    if (r < rowIndex) {
                        _newRows.add(oldRow.dup());
                        continue;
                    }
                   
                    if (dataExtension == null || dataExtension.data.length == 0) {
                        _newRows.add(oldRow);
                    } else {
                        Row firstNewRow = oldRow.dup();
                        extendRow(firstNewRow, dataExtension, 0, reconMap);
                        _newRows.add(firstNewRow);
                       
                        int r2 = r + 1;
                        for (int subR = 1; subR < dataExtension.data.length; subR++) {
                            if (r2 < project.rows.size()) {
                                Row oldRow2 = project.rows.get(r2);
                                if (oldRow2.isCellBlank(cellIndex) &&
                                    oldRow2.isCellBlank(keyCellIndex)) {
                                   
                                    Row newRow = oldRow2.dup();
                                    extendRow(newRow, dataExtension, subR, reconMap);
                                   
                                    _newRows.add(newRow);
                                    r2++;
                                   
                                    continue;
                                }
                            }
                           
                            Row newRow = new Row(cellIndex + _columnNames.size());
                            extendRow(newRow, dataExtension, subR, reconMap);
                           
                            _newRows.add(newRow);
                        }
                       
View Full Code Here

       
        Map<Long, Recon> oldRecons = new HashMap<Long, Recon>();
        Map<Long, Recon> newRecons = new HashMap<Long, Recon>();
       
        for (int r = 0; r < project.rows.size(); r++) {
            Row row = project.rows.get(r);
           
            for (int c = 0; c < row.cells.size(); c++) {
                Cell cell = row.cells.get(c);
                if (cell != null && cell.recon != null) {
                    Recon oldRecon = cell.recon;
View Full Code Here

        protected boolean internalVisit(Project project, Record record) {
            bindings.put("recordIndex", record.recordIndex);

            for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
                Row row = project.rows.get(r);

                bindings.put("rowIndex", r);

                internalVisit(project, r, row);
View Full Code Here

            }
        }
       
        int count = toProject.rows.size();
        for (int r = 0; r < count; r++) {
            Row toRow = toProject.rows.get(r);
           
            Object value = toRow.getCellValue(toColumn.getCellIndex());
            if (ExpressionUtils.isNonBlankData(value) && join.valueToRowIndices.containsKey(value)) {
                join.valueToRowIndices.get(value).add(r);
            }
        }
    }
View Full Code Here

            if (ExpressionUtils.isNonBlankData(value) && valueToRowIndices.containsKey(value)) {
                Project toProject = ProjectManager.singleton.getProject(toProjectID);
                if (toProject != null) {
                    HasFieldsListImpl rows = new HasFieldsListImpl();
                    for (Integer r : valueToRowIndices.get(value)) {
                        Row row = toProject.rows.get(r);
                        rows.add(new WrappedRow(toProject, r, row));
                    }
                   
                    return rows;
                }
View Full Code Here

        Map<String, Column> keyValueToNoteColumn = new HashMap<String, Column>();
        Map<String, Row> groupByCellValuesToRow = new HashMap<String, Row>();
       
        List<Row> newRows = new ArrayList<Row>();
        List<Row> oldRows = project.rows;
        Row reusableRow = null;
        List<Row> currentRows = new ArrayList<Row>();
        String recordKey = null; // key which indicates the start of a record
        if (unchangedColumns.isEmpty()) {
            reusableRow = new Row(1);
            newRows.add(reusableRow);
            currentRows.clear();
            currentRows.add(reusableRow);
        }

        for (int r = 0; r < oldRows.size(); r++) {
            Row oldRow = oldRows.get(r);
           
            Object key = oldRow.getCellValue(keyColumn.getCellIndex());
            if (!ExpressionUtils.isNonBlankData(key)) {
                if (unchangedColumns.isEmpty()) {
                    // For degenerate 2 column case (plus optional note column),
                    // start a new row when we hit a blank line
                    reusableRow = new Row(newColumns.size());
                    newRows.add(reusableRow);
                    currentRows.clear();
                    currentRows.add(reusableRow);
                } else {
                    // Copy rows with no key
                    newRows.add(buildNewRow(unchangedColumns, oldRow, unchangedColumns.size()));
                }
                continue;
            }
           
            String keyString = key.toString();
            // Start a new row on our beginning of record key
            if (keyString.equals(recordKey)) {
                reusableRow = new Row(newColumns.size());
                newRows.add(reusableRow);
                currentRows.clear();
                currentRows.add(reusableRow);
            }
            Column newColumn = keyValueToColumn.get(keyString);
            if (newColumn == null) {
                // Allocate new column
                newColumn = new Column(
                    project.columnModel.allocateNewCellIndex(),
                    project.columnModel.getUnduplicatedColumnName(keyString));
                keyValueToColumn.put(keyString, newColumn);
                newColumns.add(newColumn);

                // We assume first key encountered is the beginning of record key
                // TODO: make customizable?
                if (recordKey == null) {
                    recordKey = keyString;
                }
            }
           
            /*
             * NOTE: If we have additional columns, we currently merge all rows that
             * have identical values in those columns and then add our new columns.
             */
            if (unchangedColumns.size() > 0) {
                StringBuffer sb = new StringBuffer();
                for (int c = 0; c < unchangedColumns.size(); c++) {
                    Column unchangedColumn = unchangedColumns.get(c);
                    Object cellValue = oldRow.getCellValue(unchangedColumn.getCellIndex());
                    if (c > 0) {
                        sb.append('\0');
                    }
                    if (cellValue != null) {
                        sb.append(cellValue.toString());
                    }
                }
                String unchangedCellValues = sb.toString();

                reusableRow = groupByCellValuesToRow.get(unchangedCellValues);
                if (reusableRow == null ||
                        reusableRow.getCellValue(valueColumn.getCellIndex()) != null) {
                    reusableRow = buildNewRow(unchangedColumns, oldRow, newColumn.getCellIndex() + 1);
                    groupByCellValuesToRow.put(unchangedCellValues, reusableRow);
                    newRows.add(reusableRow);
                }
            }
           
            Cell cell = oldRow.getCell(valueColumn.getCellIndex());
            if (unchangedColumns.size() == 0) {
                int index = newColumn.getCellIndex();
                Row row = getAvailableRow(currentRows, newRows, index);
                row.setCell(index, cell);
            } else {
                // TODO: support repeating keys in this mode too
                reusableRow.setCell(newColumn.getCellIndex(), cell);
            }
           
View Full Code Here

            if (row.getCell(index) == null) {
                return row;
            }
        }
        // If we couldn't find a row with an empty spot, we'll need a new row
        Row row = new Row(index);
        newRows.add(row);
        currentRows.add(row);
        return row;
    }
View Full Code Here

        currentRows.add(row);
        return row;
    }

    private Row buildNewRow(List<Column> unchangedColumns, Row oldRow, int size) {
        Row reusableRow = new Row(size);
        for (int c = 0; c < unchangedColumns.size(); c++) {
            Column unchangedColumn = unchangedColumns.get(c);
            int cellIndex = unchangedColumn.getCellIndex();
            reusableRow.setCell(cellIndex, oldRow.getCell(cellIndex));
        }
        return reusableRow;
    }
View Full Code Here

TOP

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

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.