Search in sources :

Example 11 with Recon

use of com.google.refine.model.Recon in project OpenRefine by OpenRefine.

the class MassReconChange method writeRecons.

protected void writeRecons(Writer writer, Properties options, Map<Long, Recon> recons, String key) throws IOException {
    writer.write(key + "=");
    writer.write(Integer.toString(recons.size()));
    writer.write('\n');
    for (Recon recon : recons.values()) {
        Pool pool = (Pool) options.get("pool");
        pool.poolReconCandidates(recon);
        JSONWriter jsonWriter = new JSONWriter(writer);
        try {
            recon.write(jsonWriter, options);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        writer.write("\n");
    }
}
Also used : JSONWriter(org.json.JSONWriter) JSONException(org.json.JSONException) Pool(com.google.refine.util.Pool) Recon(com.google.refine.model.Recon)

Example 12 with Recon

use of com.google.refine.model.Recon in project OpenRefine by OpenRefine.

the class Pool method load.

public void load(Reader reader) throws Exception {
    LineNumberReader reader2 = new LineNumberReader(reader);
    /* String version = */
    reader2.readLine();
    String line;
    while ((line = reader2.readLine()) != null) {
        int equal = line.indexOf('=');
        CharSequence field = line.subSequence(0, equal);
        String value = line.substring(equal + 1);
        if ("reconCandidateCount".equals(field)) {
            int count = Integer.parseInt(value);
            for (int i = 0; i < count; i++) {
                line = reader2.readLine();
                if (line != null) {
                    ReconCandidate candidate = ReconCandidate.loadStreaming(line);
                    if (candidate != null) {
                        // pool for backward compatibility
                        pool(candidate);
                    }
                }
            }
        } else if ("reconCount".equals(field)) {
            int count = Integer.parseInt(value);
            for (int i = 0; i < count; i++) {
                line = reader2.readLine();
                if (line != null) {
                    Recon recon = Recon.loadStreaming(line, this);
                    if (recon != null) {
                        pool(recon);
                    }
                }
            }
        }
    }
}
Also used : Recon(com.google.refine.model.Recon) ReconCandidate(com.google.refine.model.ReconCandidate) LineNumberReader(java.io.LineNumberReader)

Example 13 with Recon

use of com.google.refine.model.Recon in project OpenRefine by OpenRefine.

the class ReconJudgeSimilarCellsOperation method createRowVisitor.

@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;

        Recon _sharedNewRecon = null;

        Map<Long, Recon> _dupReconMap = new HashMap<Long, Recon>();

        long _historyEntryID;

        public RowVisitor init(int cellIndex, List<CellChange> cellChanges, long historyEntryID) {
            _cellIndex = cellIndex;
            _cellChanges = cellChanges;
            _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) {
            Cell cell = row.getCell(_cellIndex);
            if (cell != null && ExpressionUtils.isNonBlankData(cell.value)) {
                String value = cell.value instanceof String ? ((String) cell.value) : cell.value.toString();
                if (_similarValue.equals(value)) {
                    Recon recon = null;
                    if (_judgment == Judgment.New && _shareNewTopics) {
                        if (_sharedNewRecon == null) {
                            _sharedNewRecon = new Recon(_historyEntryID, null, null);
                            _sharedNewRecon.judgment = Judgment.New;
                            _sharedNewRecon.judgmentBatchSize = 0;
                            _sharedNewRecon.judgmentAction = "similar";
                        }
                        _sharedNewRecon.judgmentBatchSize++;
                        recon = _sharedNewRecon;
                    } else {
                        if (_dupReconMap.containsKey(cell.recon.id)) {
                            recon = _dupReconMap.get(cell.recon.id);
                            recon.judgmentBatchSize++;
                        } else {
                            recon = cell.recon.dup(_historyEntryID);
                            recon.judgmentBatchSize = 1;
                            recon.matchRank = -1;
                            recon.judgmentAction = "similar";
                            if (_judgment == Judgment.Matched) {
                                recon.judgment = Recon.Judgment.Matched;
                                recon.match = _match;
                                if (recon.candidates != null) {
                                    for (int m = 0; m < recon.candidates.size(); m++) {
                                        if (recon.candidates.get(m).id.equals(_match.id)) {
                                            recon.matchRank = m;
                                            break;
                                        }
                                    }
                                }
                            } else if (_judgment == Judgment.New) {
                                recon.judgment = Recon.Judgment.New;
                                recon.match = null;
                            } else if (_judgment == Judgment.None) {
                                recon.judgment = Recon.Judgment.None;
                                recon.match = null;
                            }
                            _dupReconMap.put(cell.recon.id, recon);
                        }
                    }
                    Cell newCell = new Cell(cell.value, recon);
                    CellChange cellChange = new CellChange(rowIndex, _cellIndex, cell, newCell);
                    _cellChanges.add(cellChange);
                }
            }
            return false;
        }
    }.init(column.getCellIndex(), cellChanges, historyEntryID);
}
Also used : HashMap(java.util.HashMap) CellChange(com.google.refine.model.changes.CellChange) Project(com.google.refine.model.Project) Column(com.google.refine.model.Column) Row(com.google.refine.model.Row) RowVisitor(com.google.refine.browsing.RowVisitor) Recon(com.google.refine.model.Recon) Cell(com.google.refine.model.Cell)

Aggregations

Recon (com.google.refine.model.Recon)13 Cell (com.google.refine.model.Cell)6 JSONException (org.json.JSONException)5 JSONObject (org.json.JSONObject)5 ReconCandidate (com.google.refine.model.ReconCandidate)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 RowVisitor (com.google.refine.browsing.RowVisitor)2 Column (com.google.refine.model.Column)2 Project (com.google.refine.model.Project)2 Row (com.google.refine.model.Row)2 CellChange (com.google.refine.model.changes.CellChange)2 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 Map (java.util.Map)2 JSONArray (org.json.JSONArray)2 JSONWriter (org.json.JSONWriter)2 OdfTableCell (org.odftoolkit.odfdom.doc.table.OdfTableCell)2 Engine (com.google.refine.browsing.Engine)1 FilteredRows (com.google.refine.browsing.FilteredRows)1