Search in sources :

Example 1 with Judgment

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

the class ReconJudgeSimilarCellsOperation method reconstruct.

public static AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
    JSONObject engineConfig = obj.getJSONObject("engineConfig");
    ReconCandidate match = null;
    if (obj.has("match")) {
        JSONObject matchObj = obj.getJSONObject("match");
        JSONArray types = matchObj.getJSONArray("types");
        String[] typeIDs = new String[types.length()];
        for (int i = 0; i < typeIDs.length; i++) {
            typeIDs[i] = types.getString(i);
        }
        match = new ReconCandidate(matchObj.getString("id"), matchObj.getString("name"), typeIDs, matchObj.getDouble("score"));
    }
    Judgment judgment = Judgment.None;
    if (obj.has("judgment")) {
        judgment = Recon.stringToJudgment(obj.getString("judgment"));
    }
    return new ReconJudgeSimilarCellsOperation(engineConfig, obj.getString("columnName"), obj.getString("similarValue"), judgment, match, obj.has("shareNewTopics") ? obj.getBoolean("shareNewTopics") : false);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ReconCandidate(com.google.refine.model.ReconCandidate) Judgment(com.google.refine.model.Recon.Judgment)

Example 2 with Judgment

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

the class ReconJudgeOneCellCommand method doPost.

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!hasValidCSRFToken(request)) {
        respondCSRFError(response);
        return;
    }
    try {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        Project project = getProject(request);
        int rowIndex = Integer.parseInt(request.getParameter("row"));
        int cellIndex = Integer.parseInt(request.getParameter("cell"));
        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);
        }
        JudgeOneCellProcess process = new JudgeOneCellProcess(project, "Judge one cell's recon result", judgment, rowIndex, cellIndex, match, request.getParameter("identifierSpace"), request.getParameter("schemaSpace"));
        HistoryEntry historyEntry = project.processManager.queueProcess(process);
        if (historyEntry != null) {
            /*
                 * If the process is done, write back the cell's data so that the
                 * client side can update its UI right away.
                 */
            Pool pool = new Pool();
            if (process.newCell != null && process.newCell.recon != null) {
                pool.pool(process.newCell.recon);
            }
            respondJSON(response, new ReconClearOneCellCommand.CellResponse(historyEntry, process.newCell, pool));
        } else {
            respond(response, "{ \"code\" : \"pending\" }");
        }
    } catch (Exception e) {
        respondException(response, e);
    }
}
Also used : Project(com.google.refine.model.Project) HistoryEntry(com.google.refine.history.HistoryEntry) Pool(com.google.refine.util.Pool) ReconCandidate(com.google.refine.model.ReconCandidate) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Judgment(com.google.refine.model.Recon.Judgment)

Example 3 with Judgment

use of com.google.refine.model.Recon.Judgment 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 4 with Judgment

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

the class ReconJudgeSimilarCellsCommand method createOperation.

@Override
protected AbstractOperation createOperation(Project project, HttpServletRequest request, EngineConfig 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)

Aggregations

Judgment (com.google.refine.model.Recon.Judgment)4 ReconCandidate (com.google.refine.model.ReconCandidate)4 ReconJudgeSimilarCellsOperation (com.google.refine.operations.recon.ReconJudgeSimilarCellsOperation)2 HistoryEntry (com.google.refine.history.HistoryEntry)1 Project (com.google.refine.model.Project)1 Pool (com.google.refine.util.Pool)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1