Package com.google.refine.model

Examples of com.google.refine.model.Column


    protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
        int keyColumnIndex = project.columnModel.getColumnIndexByName(_keyColumnName);
        int valueColumnIndex = project.columnModel.getColumnIndexByName(_valueColumnName);
        int noteColumnIndex = _noteColumnName == null ? -1 :
            project.columnModel.getColumnIndexByName(_noteColumnName);
        Column keyColumn = project.columnModel.getColumnByName(_keyColumnName);
        Column valueColumn = project.columnModel.getColumnByName(_valueColumnName);
        Column noteColumn = _noteColumnName == null ? null :
            project.columnModel.getColumnByName(_noteColumnName);
       
        List<Column> unchangedColumns = new ArrayList<Column>();
        List<Column> oldColumns = project.columnModel.columns;
        for (int i = 0; i < oldColumns.size(); i++) {
            if (i != keyColumnIndex &&
                i != valueColumnIndex &&
                i != noteColumnIndex) {
                unchangedColumns.add(oldColumns.get(i));
            }
        }
       
        List<Column> newColumns = new ArrayList<Column>();
        List<Column> newNoteColumns = new ArrayList<Column>();
        Map<String, Column> keyValueToColumn = new HashMap<String, Column>();
        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);
            }
           
            if (noteColumn != null) {
                Object noteValue = oldRow.getCellValue(noteColumn.getCellIndex());
                if (ExpressionUtils.isNonBlankData(noteValue)) {
                    Column newNoteColumn = keyValueToNoteColumn.get(keyString);
                    if (newNoteColumn == null) {
                        // Allocate new column
                        newNoteColumn = new Column(
                            project.columnModel.allocateNewCellIndex(),
                            project.columnModel.getUnduplicatedColumnName(
                                noteColumn.getName() + " : " + keyString));
                        keyValueToNoteColumn.put(keyString, newNoteColumn);
                        newNoteColumns.add(newNoteColumn);
                    }
                   
                    int newNoteCellIndex = newNoteColumn.getCellIndex();
                    Object existingNewNoteValue = reusableRow.getCellValue(newNoteCellIndex);
                    if (ExpressionUtils.isNonBlankData(existingNewNoteValue)) {
                        Cell concatenatedNoteCell = new Cell(
                            existingNewNoteValue.toString() + ";" + noteValue.toString(), null);
                        reusableRow.setCell(newNoteCellIndex, concatenatedNoteCell);
View Full Code Here


    }

    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

    private static boolean descendCellNode(Project project, TransposedNodeFactory nodeFactory, int rowIndex, Row row,
            Node node, Context context, List<TransposedNode> tnodes, Link link) {
        CellNode node2 = (CellNode) node;
        for (String columnName : node2.columnNames) {
            Column column = project.columnModel.getColumnByName(columnName);
            if (column != null) {
                int cellIndex = column.getCellIndex();
               
                Cell cell = row.getCell(cellIndex);
                if (cell != null && ExpressionUtils.isNonBlankData(cell.value)) {
                    if (node2 instanceof CellTopicNode &&
                        (cell.recon == null || cell.recon.judgment == Judgment.None)) {
View Full Code Here

        contextRefCount++;
       
        if (!serializedRecons.contains(recon.id)) {
            serializedRecons.add(recon.id);
           
            Column column = project.columnModel.getColumnByCellIndex(cellIndex);
           
            // qa:sample_group
            {
                StringBuffer sb2 = new StringBuffer();
               
                sb2.append("{ \"s\" : \"rec");
                sb2.append(Long.toString(recon.id));
                sb2.append("\", \"p\" : \"qa:sample_group\", \"o\" : ");
                sb2.append(JSONObject.quote(column.getName()));
                sb2.append(", \"ignore\" : true }");
               
                writeLine(sb2.toString());
            }
           
            // qa:recon_data
            {
                StringBuffer sb2 = new StringBuffer();
               
                String s = cell.value instanceof String ? (String) cell.value : cell.value.toString();
                   
                sb2.append("{ \"s\" : \"rec");
                sb2.append(Long.toString(recon.id));
                sb2.append("\", \"p\" : \"qa:recon_data\", \"ignore\" : true, \"o\" : { ");
               
                sb2.append(" \"history_entry\" : "); sb2.append(Long.toString(recon.judgmentHistoryEntry));
                sb2.append(", \"text\" : "); sb2.append(JSONObject.quote(s));
                sb2.append(", \"column\" : "); sb2.append(JSONObject.quote(column.getName()));
                sb2.append(", \"service\" : "); sb2.append(JSONObject.quote(recon.service));
                sb2.append(", \"action\" : "); sb2.append(JSONObject.quote(recon.judgmentAction));
                sb2.append(", \"batch\" : "); sb2.append(Integer.toString(recon.judgmentBatchSize));
               
                if (recon.judgment == Judgment.Matched) {
                    sb2.append(", \"matchRank\" : "); sb2.append(Integer.toString(recon.matchRank));
                    sb2.append(", \"id\" : "); sb2.append(JSONObject.quote(recon.match.id));
                }
               
                ReconConfig reconConfig = column.getReconConfig();
                if (reconConfig != null && reconConfig instanceof StandardReconConfig) {
                    StandardReconConfig standardReconConfig = (StandardReconConfig) reconConfig;
                    sb2.append(", \"type\" : "); sb2.append(JSONObject.quote(standardReconConfig.typeID));
                }
               
View Full Code Here

                int objectCellIndex = cellIndex;
                Cell objectCell = cell;
               
                String typeID = node.type.id;
               
                Column column = project.columnModel.getColumnByCellIndex(cellIndex);
                ReconConfig reconConfig = column.getReconConfig();
                if (reconConfig instanceof StandardReconConfig) {
                    typeID = ((StandardReconConfig) reconConfig).typeID;
                }
               
                if (cell.recon.judgment == Recon.Judgment.Matched) {
                    id = cell.recon.match.id;
                   
                } else if (cell.recon.judgment == Judgment.New) {
                    if (newTopicVars.containsKey(cell.recon.id)) {
                        id = newTopicVars.get(cell.recon.id);
                    } else {
                        String columnName = column.getName();
                       
                        long var = 0;
                        if (varPool.containsKey(columnName)) {
                            var = varPool.get(columnName);
                        }
View Full Code Here

        this.columnName = columnName;
    }
   
    @Override
    public boolean test(Project project, int rowIndex, Row row) {
        Column column = project.columnModel.getColumnByName(columnName);
        if (column != null) {
            Object o = row.getCellValue(column.getCellIndex());
            if (o != null) {
                if (o instanceof Boolean) {
                    return ((Boolean) o).booleanValue();
                } else {
                    return Boolean.parseBoolean(o.toString());
View Full Code Here

      response.setHeader("Content-Type", "application/json");

      JSONWriter writer = new JSONWriter(response.getWriter());
      writer.object();

      Column column = project.columnModel.getColumnByName(columnName);
      if (column == null) {
        writer.key("code");
        writer.value("error");
        writer.key("message");
        writer.value("No such column");
View Full Code Here

      con.close();
    }
  }

  static void buildColumnModel(Project project)throws Exception{
    project.columnModel.addColumn(0, new Column(0,"Name"), true);
    project.columnModel.addColumn(1, new Column(1,"Email"), true);
    project.columnModel.addColumn(2, new Column(2,"Office"), true);
    project.columnModel.addColumn(3, new Column(3,"Faculty"), true);
    project.columnModel.addColumn(4, new Column(4,"Coffee Due"), true);
    project.columnModel.addColumn(5, new Column(5,"Advisor"), true);
  }
View Full Code Here

    assertTrue(RepositoryUtil.equals(expected, model));
  }
  //helper methods
 
  void buildColumnModel()throws Exception{
    project.columnModel.addColumn(0, new Column(0,"Post unique reference"), true);
    project.columnModel.addColumn(1, new Column(1,"Name"), true);
    project.columnModel.addColumn(2, new Column(2,"Grade"), true);
    project.columnModel.addColumn(3, new Column(3,"Job Title"), true);
    project.columnModel.addColumn(4, new Column(4,"Job/Team Function"), true);
    project.columnModel.addColumn(5, new Column(5,"Parent Department"), true);
    project.columnModel.addColumn(6, new Column(6,"Organisation"), true);
    project.columnModel.addColumn(7, new Column(7,"Unit"), true);
    project.columnModel.addColumn(8, new Column(8,"Contact Phone"), true);
    project.columnModel.addColumn(9, new Column(9,"Contact e-mail"), true);
    project.columnModel.addColumn(10, new Column(10,"Reports To"), true);
    project.columnModel.addColumn(11, new Column(11,"Reports To (Name)"), true);
    project.columnModel.addColumn(12, new Column(12,"HRO-Grade"), true);
    project.columnModel.addColumn(13, new Column(13,"HRO-AssignmentStatus"), true);
    project.columnModel.addColumn(14, new Column(14, "removed"), true);
    project.columnModel.addColumn(15, new Column(15,"Post unique reference OK"), true);
    project.columnModel.addColumn(16, new Column(16,"Is Department"), true);
    project.columnModel.addColumn(17, new Column(17,"Grade OK"), true);
  }
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.