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;
}
}
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));
}
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);
}
}
}
}
}
}
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"));
}
Aggregations