use of com.google.refine.model.ReconCandidate in project OpenRefine by OpenRefine.
the class ReconJudgeOneCellCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
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.
*/
JSONWriter writer = new JSONWriter(response.getWriter());
Pool pool = new Pool();
Properties options = new Properties();
options.put("pool", pool);
writer.object();
writer.key("code");
writer.value("ok");
writer.key("historyEntry");
historyEntry.write(writer, options);
writer.key("cell");
process.newCell.write(writer, options);
writer.key("pool");
pool.write(writer, options);
writer.endObject();
} else {
respond(response, "{ \"code\" : \"pending\" }");
}
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.refine.model.ReconCandidate in project OpenRefine by OpenRefine.
the class ReconMatchSpecificTopicCommand method createOperation.
@Override
protected AbstractOperation createOperation(Project project, HttpServletRequest request, JSONObject engineConfig) throws Exception {
String columnName = request.getParameter("columnName");
ReconCandidate match = new ReconCandidate(request.getParameter("topicID"), request.getParameter("topicName"), request.getParameter("types").split(","), 100);
return new ReconMatchSpecificTopicOperation(engineConfig, columnName, match, request.getParameter("identifierSpace"), request.getParameter("schemaSpace"));
}
use of com.google.refine.model.ReconCandidate in project OpenRefine by OpenRefine.
the class OdsImporter method extractCell.
protected static Cell extractCell(OdfTableCell cell, Map<String, Recon> reconMap) {
Serializable value = extractCell(cell);
if (value != null) {
Recon recon = null;
// TODO: cell.getHyperlink();
String hyperlink = "";
if (hyperlink != null) {
// TODO: hyperlink.getAddress();
String url = hyperlink;
if (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;
}
}
use of com.google.refine.model.ReconCandidate 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);
}
use of com.google.refine.model.ReconCandidate in project OpenRefine by OpenRefine.
the class StandardReconConfig method createReconServiceResults.
protected Recon createReconServiceResults(String text, JSONArray results, long historyEntryID) {
Recon recon = new Recon(historyEntryID, identifierSpace, schemaSpace);
try {
int length = results.length();
int count = 0;
for (int i = 0; i < length; i++) {
JSONObject result = results.getJSONObject(i);
if (!result.has("name")) {
continue;
}
JSONArray types = result.getJSONArray("type");
String[] typeIDs = new String[types.length()];
for (int j = 0; j < typeIDs.length; j++) {
Object type = types.get(j);
typeIDs[j] = type instanceof String ? (String) type : ((JSONObject) type).getString("id");
}
double score = result.getDouble("score");
ReconCandidate candidate = new ReconCandidate(result.getString("id"), result.getString("name"), typeIDs, score);
if (autoMatch && i == 0 && result.has("match") && result.getBoolean("match")) {
recon.match = candidate;
recon.matchRank = 0;
recon.judgment = Judgment.Matched;
recon.judgmentAction = "auto";
}
recon.addCandidate(candidate);
count++;
}
if (count > 0) {
ReconCandidate candidate = recon.candidates.get(0);
recon.setFeature(Recon.Feature_nameMatch, text.equalsIgnoreCase(candidate.name));
recon.setFeature(Recon.Feature_nameLevenshtein, StringUtils.getLevenshteinDistance(StringUtils.lowerCase(text), StringUtils.lowerCase(candidate.name)));
recon.setFeature(Recon.Feature_nameWordDistance, wordDistance(text, candidate.name));
recon.setFeature(Recon.Feature_typeMatch, false);
if (this.typeID != null) {
for (String typeID : candidate.types) {
if (this.typeID.equals(typeID)) {
recon.setFeature(Recon.Feature_typeMatch, true);
break;
}
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return recon;
}
Aggregations