Search in sources :

Example 6 with ReconCandidate

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

the class ExcelImporter method extractCell.

protected static Cell extractCell(org.apache.poi.ss.usermodel.Cell cell, Map<String, Recon> reconMap) {
    Serializable value = extractCell(cell);
    if (value != null) {
        Recon recon = null;
        Hyperlink hyperlink = cell.getHyperlink();
        if (hyperlink != null) {
            String url = hyperlink.getAddress();
            if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) {
                final String sig = "freebase.com/view";
                int i = url.indexOf(sig);
                if (i > 0) {
                    String id = url.substring(i + sig.length());
                    int q = id.indexOf('?');
                    if (q > 0) {
                        id = id.substring(0, q);
                    }
                    int h = id.indexOf('#');
                    if (h > 0) {
                        id = id.substring(0, h);
                    }
                    if (reconMap.containsKey(id)) {
                        recon = reconMap.get(id);
                        recon.judgmentBatchSize++;
                    } else {
                        recon = new Recon(0, null, null);
                        recon.service = "import";
                        recon.match = new ReconCandidate(id, value.toString(), new String[0], 100);
                        recon.matchRank = 0;
                        recon.judgment = Judgment.Matched;
                        recon.judgmentAction = "auto";
                        recon.judgmentBatchSize = 1;
                        recon.addCandidate(recon.match);
                        reconMap.put(id, recon);
                    }
                }
            }
        }
        return new Cell(value, recon);
    } else {
        return null;
    }
}
Also used : Serializable(java.io.Serializable) Recon(com.google.refine.model.Recon) Cell(com.google.refine.model.Cell) ReconCandidate(com.google.refine.model.ReconCandidate) Hyperlink(org.apache.poi.common.usermodel.Hyperlink)

Example 7 with ReconCandidate

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

the class ReconJudgeSimilarCellsCommand method createOperation.

@Override
protected AbstractOperation createOperation(Project project, HttpServletRequest request, JSONObject engineConfig) throws Exception {
    String columnName = request.getParameter("columnName");
    String similarValue = request.getParameter("similarValue");
    Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
    ReconCandidate match = null;
    String id = request.getParameter("id");
    if (id != null) {
        String scoreString = request.getParameter("score");
        match = new ReconCandidate(id, request.getParameter("name"), request.getParameter("types").split(","), scoreString != null ? Double.parseDouble(scoreString) : 100);
    }
    String shareNewTopics = request.getParameter("shareNewTopics");
    return new ReconJudgeSimilarCellsOperation(engineConfig, columnName, similarValue, judgment, match, "true".equals(shareNewTopics));
}
Also used : ReconJudgeSimilarCellsOperation(com.google.refine.operations.recon.ReconJudgeSimilarCellsOperation) ReconCandidate(com.google.refine.model.ReconCandidate) Judgment(com.google.refine.model.Recon.Judgment)

Example 8 with ReconCandidate

use of com.google.refine.model.ReconCandidate 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 9 with ReconCandidate

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

the class ReconMatchSpecificTopicOperation method reconstruct.

public static AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
    JSONObject engineConfig = obj.getJSONObject("engineConfig");
    JSONObject match = obj.getJSONObject("match");
    JSONArray types = obj.getJSONArray("types");
    String[] typeIDs = new String[types.length()];
    for (int i = 0; i < typeIDs.length; i++) {
        typeIDs[i] = types.getString(i);
    }
    return new ReconMatchSpecificTopicOperation(engineConfig, obj.getString("columnName"), new ReconCandidate(match.getString("id"), match.getString("name"), typeIDs, 100), obj.getString("identifierSpace"), obj.getString("schemaSpace"));
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ReconCandidate(com.google.refine.model.ReconCandidate)

Aggregations

ReconCandidate (com.google.refine.model.ReconCandidate)9 Recon (com.google.refine.model.Recon)4 Judgment (com.google.refine.model.Recon.Judgment)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 Cell (com.google.refine.model.Cell)2 Serializable (java.io.Serializable)2 HistoryEntry (com.google.refine.history.HistoryEntry)1 Project (com.google.refine.model.Project)1 ReconJudgeSimilarCellsOperation (com.google.refine.operations.recon.ReconJudgeSimilarCellsOperation)1 ReconMatchSpecificTopicOperation (com.google.refine.operations.recon.ReconMatchSpecificTopicOperation)1 Pool (com.google.refine.util.Pool)1 IOException (java.io.IOException)1 LineNumberReader (java.io.LineNumberReader)1 Properties (java.util.Properties)1 ServletException (javax.servlet.ServletException)1 Hyperlink (org.apache.poi.common.usermodel.Hyperlink)1 JSONException (org.json.JSONException)1 JSONWriter (org.json.JSONWriter)1 OdfTableCell (org.odftoolkit.odfdom.doc.table.OdfTableCell)1