Make similar cell judgments an abstract operation.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@120 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
c98a8ad552
commit
e4b01cb36c
@ -18,6 +18,7 @@ import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.ReconCandidate;
|
||||
import com.metaweb.gridworks.model.Recon.Judgment;
|
||||
import com.metaweb.gridworks.model.changes.CellChange;
|
||||
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
|
||||
|
||||
@ -31,37 +32,31 @@ public class ReconJudgeOneCellCommand extends Command {
|
||||
|
||||
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
||||
int cellIndex = Integer.parseInt(request.getParameter("cell"));
|
||||
String judgment = request.getParameter("judgment");
|
||||
Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
|
||||
|
||||
JudgeOneCellProcess process = null;
|
||||
ReconCandidate match = null;
|
||||
String topicID = request.getParameter("topicID");
|
||||
if (topicID != null) {
|
||||
String scoreString = request.getParameter("score");
|
||||
|
||||
if (judgment != null) {
|
||||
process = new JudgeOneCellProcess(
|
||||
project,
|
||||
"Judge one cell's recon result",
|
||||
judgment,
|
||||
rowIndex,
|
||||
cellIndex,
|
||||
request.getParameter("candidate")
|
||||
);
|
||||
} else {
|
||||
ReconCandidate match = new ReconCandidate(
|
||||
request.getParameter("topicID"),
|
||||
match = new ReconCandidate(
|
||||
topicID,
|
||||
request.getParameter("topicGUID"),
|
||||
request.getParameter("topicName"),
|
||||
request.getParameter("types").split(","),
|
||||
100
|
||||
);
|
||||
|
||||
process = new JudgeOneCellProcess(
|
||||
project,
|
||||
"Judge one cell's recon result",
|
||||
rowIndex,
|
||||
cellIndex,
|
||||
match
|
||||
scoreString != null ? Double.parseDouble(scoreString) : 100
|
||||
);
|
||||
}
|
||||
|
||||
JudgeOneCellProcess process = new JudgeOneCellProcess(
|
||||
project,
|
||||
"Judge one cell's recon result",
|
||||
judgment,
|
||||
rowIndex,
|
||||
cellIndex,
|
||||
match
|
||||
);
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
if (done) {
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
@ -80,27 +75,24 @@ public class ReconJudgeOneCellCommand extends Command {
|
||||
protected class JudgeOneCellProcess extends QuickHistoryEntryProcess {
|
||||
final int rowIndex;
|
||||
final int cellIndex;
|
||||
final String judgment;
|
||||
final String candidateID;
|
||||
final Judgment judgment;
|
||||
final ReconCandidate match;
|
||||
Cell newCell;
|
||||
|
||||
|
||||
JudgeOneCellProcess(Project project, String briefDescription, String judgment, int rowIndex, int cellIndex, String candidateID) {
|
||||
JudgeOneCellProcess(
|
||||
Project project,
|
||||
String briefDescription,
|
||||
Judgment judgment,
|
||||
int rowIndex,
|
||||
int cellIndex,
|
||||
ReconCandidate match
|
||||
) {
|
||||
super(project, briefDescription);
|
||||
this.rowIndex = rowIndex;
|
||||
this.cellIndex = cellIndex;
|
||||
this.judgment = judgment;
|
||||
this.candidateID = candidateID;
|
||||
this.match = null;
|
||||
}
|
||||
|
||||
JudgeOneCellProcess(Project project, String briefDescription, int rowIndex, int cellIndex, ReconCandidate match) {
|
||||
super(project, briefDescription);
|
||||
this.judgment = judgment;
|
||||
this.rowIndex = rowIndex;
|
||||
this.cellIndex = cellIndex;
|
||||
this.judgment = null;
|
||||
this.candidateID = null;
|
||||
this.match = match;
|
||||
}
|
||||
|
||||
@ -126,45 +118,20 @@ public class ReconJudgeOneCellCommand extends Command {
|
||||
", containing \"" + cell.value + "\"";
|
||||
|
||||
String description = null;
|
||||
|
||||
if (match != null) {
|
||||
if (judgment == Judgment.None) {
|
||||
newCell.recon.judgment = Recon.Judgment.None;
|
||||
newCell.recon.match = null;
|
||||
description = "Discard recon judgment for " + cellDescription;
|
||||
} else if (judgment == Judgment.New) {
|
||||
newCell.recon.judgment = Recon.Judgment.New;
|
||||
description = "Mark to create new topic for " + cellDescription;
|
||||
} else {
|
||||
newCell.recon.judgment = Recon.Judgment.Matched;
|
||||
newCell.recon.match = this.match;
|
||||
|
||||
description = "Match " + this.match.topicName +
|
||||
" (" + match.topicID + ") to " +
|
||||
cellDescription;
|
||||
} else {
|
||||
if ("match".equals(judgment)) {
|
||||
ReconCandidate match = null;
|
||||
|
||||
if (cell.recon != null) {
|
||||
for (ReconCandidate c : cell.recon.candidates) {
|
||||
if (candidateID.equals(c.topicID)) {
|
||||
match = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match == null) {
|
||||
throw new Exception("No such recon candidate");
|
||||
}
|
||||
|
||||
newCell.recon.judgment = Recon.Judgment.Matched;
|
||||
newCell.recon.match = match;
|
||||
|
||||
description = "Match " + match.topicName +
|
||||
" (" + match.topicID + ") to " +
|
||||
cellDescription;
|
||||
|
||||
} else if ("new".equals(judgment)) {
|
||||
newCell.recon.judgment = Recon.Judgment.New;
|
||||
description = "Mark to create new topic for " + cellDescription;
|
||||
} else if ("discard".equals(judgment)) {
|
||||
newCell.recon.judgment = Recon.Judgment.None;
|
||||
newCell.recon.match = null;
|
||||
description = "Discard recon judgment for " + cellDescription;
|
||||
}
|
||||
}
|
||||
|
||||
Change change = new CellChange(rowIndex, cellIndex, cell, newCell);
|
||||
|
@ -1,220 +1,44 @@
|
||||
package com.metaweb.gridworks.commands.recon;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONWriter;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.metaweb.gridworks.browsing.Engine;
|
||||
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||
import com.metaweb.gridworks.commands.Command;
|
||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||
import com.metaweb.gridworks.history.HistoryEntry;
|
||||
import com.metaweb.gridworks.model.Cell;
|
||||
import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.commands.EngineDependentCommand;
|
||||
import com.metaweb.gridworks.model.AbstractOperation;
|
||||
import com.metaweb.gridworks.model.ReconCandidate;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.model.changes.CellChange;
|
||||
import com.metaweb.gridworks.model.changes.MassCellChange;
|
||||
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
|
||||
import com.metaweb.gridworks.operations.ReconJudgeSimilarCellsOperation;
|
||||
|
||||
public class ReconJudgeSimilarCellsCommand extends EngineDependentCommand {
|
||||
|
||||
public class ReconJudgeSimilarCellsCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
protected AbstractOperation createOperation(
|
||||
HttpServletRequest request, JSONObject engineConfig) throws Exception {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
Engine engine = getEngine(request, project);
|
||||
String columnName = request.getParameter("columnName");
|
||||
String similarValue = request.getParameter("similarValue");
|
||||
String judgment = request.getParameter("judgment");
|
||||
|
||||
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
||||
int cellIndex = Integer.parseInt(request.getParameter("cell"));
|
||||
String judgment = request.getParameter("judgment");
|
||||
ReconCandidate match = null;
|
||||
String topicID = request.getParameter("topicID");
|
||||
if (topicID != null) {
|
||||
String scoreString = request.getParameter("score");
|
||||
|
||||
JudgeSimilarCellsProcess process = null;
|
||||
|
||||
if (judgment != null) {
|
||||
process = new JudgeSimilarCellsProcess(
|
||||
project,
|
||||
engine,
|
||||
"Judge one cell's recon result",
|
||||
judgment,
|
||||
rowIndex,
|
||||
cellIndex,
|
||||
request.getParameter("candidate")
|
||||
);
|
||||
} else {
|
||||
ReconCandidate match = new ReconCandidate(
|
||||
request.getParameter("topicID"),
|
||||
request.getParameter("topicGUID"),
|
||||
request.getParameter("topicName"),
|
||||
request.getParameter("types").split(","),
|
||||
100
|
||||
);
|
||||
|
||||
process = new JudgeSimilarCellsProcess(
|
||||
project,
|
||||
engine,
|
||||
"Judge one cell's recon result",
|
||||
rowIndex,
|
||||
cellIndex,
|
||||
match
|
||||
);
|
||||
}
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
if (done) {
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
writer.object();
|
||||
writer.key("code"); writer.value("ok");
|
||||
writer.endObject();
|
||||
} else {
|
||||
respond(response, "{ \"code\" : \"pending\" }");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected class JudgeSimilarCellsProcess extends QuickHistoryEntryProcess {
|
||||
final Engine engine;
|
||||
final int rowIndex;
|
||||
final int cellIndex;
|
||||
final String judgment;
|
||||
final String candidateID;
|
||||
final ReconCandidate match;
|
||||
|
||||
JudgeSimilarCellsProcess(Project project, Engine engine, String briefDescription, String judgment, int rowIndex, int cellIndex, String candidateID) {
|
||||
super(project, briefDescription);
|
||||
this.engine = engine;
|
||||
this.rowIndex = rowIndex;
|
||||
this.cellIndex = cellIndex;
|
||||
this.judgment = judgment;
|
||||
this.candidateID = candidateID;
|
||||
this.match = null;
|
||||
match = new ReconCandidate(
|
||||
topicID,
|
||||
request.getParameter("topicGUID"),
|
||||
request.getParameter("topicName"),
|
||||
request.getParameter("types").split(","),
|
||||
scoreString != null ? Double.parseDouble(scoreString) : 100
|
||||
);
|
||||
}
|
||||
|
||||
JudgeSimilarCellsProcess(Project project, Engine engine, String briefDescription, int rowIndex, int cellIndex, ReconCandidate match) {
|
||||
super(project, briefDescription);
|
||||
this.engine = engine;
|
||||
this.rowIndex = rowIndex;
|
||||
this.cellIndex = cellIndex;
|
||||
this.judgment = null;
|
||||
this.candidateID = null;
|
||||
this.match = match;
|
||||
}
|
||||
|
||||
protected HistoryEntry createHistoryEntry() throws Exception {
|
||||
Cell cell = _project.rows.get(rowIndex).getCell(cellIndex);
|
||||
if (cell == null || ExpressionUtils.isBlank(cell.value)) {
|
||||
throw new Exception("Cell is blank");
|
||||
}
|
||||
|
||||
Column column = _project.columnModel.getColumnByCellIndex(cellIndex);
|
||||
if (column == null) {
|
||||
throw new Exception("No such column");
|
||||
}
|
||||
|
||||
List<CellChange> cellChanges = new ArrayList<CellChange>(_project.rows.size());
|
||||
String similarValue = cell.value.toString();
|
||||
|
||||
RowVisitor rowVisitor = new RowVisitor() {
|
||||
List<CellChange> cellChanges;
|
||||
String similarValue;
|
||||
|
||||
public RowVisitor init(List<CellChange> cellChanges, String similarValue) {
|
||||
this.cellChanges = cellChanges;
|
||||
this.similarValue = similarValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
Cell cell = row.getCell(cellIndex);
|
||||
if (cell != null && !ExpressionUtils.isBlank(cell.value) && similarValue.equals(cell.value)) {
|
||||
Cell newCell = new Cell(
|
||||
cell.value,
|
||||
cell.recon == null ? new Recon() : cell.recon.dup()
|
||||
);
|
||||
|
||||
if (match != null) {
|
||||
newCell.recon.judgment = Recon.Judgment.Matched;
|
||||
newCell.recon.match = match;
|
||||
} else {
|
||||
if ("match".equals(judgment)) {
|
||||
ReconCandidate match = null;
|
||||
|
||||
if (cell.recon != null) {
|
||||
for (ReconCandidate c : cell.recon.candidates) {
|
||||
if (candidateID.equals(c.topicID)) {
|
||||
match = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
newCell.recon.judgment = Recon.Judgment.Matched;
|
||||
newCell.recon.match = match;
|
||||
} else if ("new".equals(judgment)) {
|
||||
newCell.recon.judgment = Recon.Judgment.New;
|
||||
} else if ("discard".equals(judgment)) {
|
||||
newCell.recon.judgment = Recon.Judgment.None;
|
||||
newCell.recon.match = null;
|
||||
}
|
||||
}
|
||||
|
||||
CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell);
|
||||
cellChanges.add(cellChange);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}.init(cellChanges, similarValue);
|
||||
|
||||
FilteredRows filteredRows = engine.getAllFilteredRows(false);
|
||||
filteredRows.accept(_project, rowVisitor);
|
||||
|
||||
String description = null;
|
||||
if (match != null) {
|
||||
description = "Match " +
|
||||
cellChanges.size() + " cell(s) in column " +
|
||||
column.getHeaderLabel() + " containing " +
|
||||
similarValue + " to topic " +
|
||||
match.topicName + " (" +
|
||||
match.topicID + ")";
|
||||
} else {
|
||||
if ("match".equals(judgment)) {
|
||||
description = "Match " +
|
||||
cellChanges.size() + " cell(s) in column " +
|
||||
column.getHeaderLabel() + " containing " +
|
||||
similarValue + " to topic " +
|
||||
candidateID;
|
||||
} else if ("new".equals(judgment)) {
|
||||
description = "Mark to create new topic for " +
|
||||
cellChanges.size() + " cell(s) in column " +
|
||||
column.getHeaderLabel() + " containing " +
|
||||
similarValue;
|
||||
} else if ("discard".equals(judgment)) {
|
||||
description = "Discard recon judgments for " +
|
||||
cellChanges.size() + " cell(s) in column " +
|
||||
column.getHeaderLabel() + " containing " +
|
||||
similarValue;
|
||||
}
|
||||
}
|
||||
|
||||
MassCellChange massCellChange = new MassCellChange(
|
||||
cellChanges, column.getHeaderLabel(), false);
|
||||
|
||||
return new HistoryEntry(_project, description, null, massCellChange);
|
||||
}
|
||||
return new ReconJudgeSimilarCellsOperation(
|
||||
engineConfig,
|
||||
columnName,
|
||||
similarValue,
|
||||
judgment,
|
||||
match
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,27 @@ public class Recon implements Serializable, HasFields, Jsonizable {
|
||||
New
|
||||
}
|
||||
|
||||
static public String judgmentToString(Judgment judgment) {
|
||||
if (judgment == Judgment.Matched) {
|
||||
return "matched";
|
||||
} else if (judgment == Judgment.New) {
|
||||
return "new";
|
||||
} else {
|
||||
return "none";
|
||||
}
|
||||
}
|
||||
|
||||
static public Judgment stringToJudgment(String s) {
|
||||
if ("matched".equals(s)) {
|
||||
return Judgment.Matched;
|
||||
} else if ("new".equals(s)) {
|
||||
return Judgment.New;
|
||||
} else {
|
||||
return Judgment.None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public int Feature_typeMatch = 0;
|
||||
static public int Feature_nameMatch = 1;
|
||||
static public int Feature_nameLevenshtein = 2;
|
||||
@ -94,13 +115,7 @@ public class Recon implements Serializable, HasFields, Jsonizable {
|
||||
}
|
||||
|
||||
protected String judgmentToString() {
|
||||
if (judgment == Judgment.Matched) {
|
||||
return "matched";
|
||||
} else if (judgment == Judgment.New) {
|
||||
return "new";
|
||||
} else {
|
||||
return "none";
|
||||
}
|
||||
return judgmentToString(judgment);
|
||||
}
|
||||
|
||||
public class Features implements HasFields {
|
||||
|
@ -46,17 +46,14 @@ public class ReconCandidate implements Serializable, HasFields, Jsonizable {
|
||||
|
||||
writer.object();
|
||||
writer.key("id"); writer.value(topicID);
|
||||
//writer.key("guid"); writer.value(topicGUID);
|
||||
writer.key("guid"); writer.value(topicGUID);
|
||||
writer.key("name"); writer.value(topicName);
|
||||
writer.key("score"); writer.value(score);
|
||||
|
||||
/*
|
||||
writer.key("types"); writer.array();
|
||||
for (String typeID : typeIDs) {
|
||||
writer.value(typeID);
|
||||
}
|
||||
writer.endArray();
|
||||
*/
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ public abstract class OperationRegistry {
|
||||
register("recon-match-best-candidates", ReconMatchBestCandidatesOperation.class);
|
||||
register("recon-discard-judgments", ReconDiscardJudgmentsOperation.class);
|
||||
register("recon-match-specific-topic-to-cells", ReconMatchSpecificTopicOperation.class);
|
||||
register("recon-judge-similar-cells", ReconJudgeSimilarCellsOperation.class);
|
||||
|
||||
register("multivalued-cell-join", MultiValuedCellJoinOperation.class);
|
||||
register("multivalued-cell-split", MultiValuedCellSplitOperation.class);
|
||||
|
@ -0,0 +1,185 @@
|
||||
package com.metaweb.gridworks.operations;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||
import com.metaweb.gridworks.model.AbstractOperation;
|
||||
import com.metaweb.gridworks.model.Cell;
|
||||
import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.ReconCandidate;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.model.Recon.Judgment;
|
||||
import com.metaweb.gridworks.model.changes.CellChange;
|
||||
|
||||
public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOperation {
|
||||
private static final long serialVersionUID = -5205694623711144436L;
|
||||
|
||||
final protected String _similarValue;
|
||||
final protected Judgment _judgment;
|
||||
final protected ReconCandidate _match;
|
||||
|
||||
static public 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("guid"),
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
public ReconJudgeSimilarCellsOperation(
|
||||
JSONObject engineConfig,
|
||||
String columnName,
|
||||
String similarValue,
|
||||
Judgment judgment,
|
||||
ReconCandidate match
|
||||
) {
|
||||
super(engineConfig, columnName, false);
|
||||
this._similarValue = similarValue;
|
||||
this._judgment = judgment;
|
||||
this._match = match;
|
||||
}
|
||||
|
||||
public ReconJudgeSimilarCellsOperation(
|
||||
JSONObject engineConfig,
|
||||
String columnName,
|
||||
String similarValue,
|
||||
String judgmentString,
|
||||
ReconCandidate match
|
||||
) {
|
||||
super(engineConfig, columnName, false);
|
||||
this._similarValue = similarValue;
|
||||
this._judgment = Recon.stringToJudgment(judgmentString);
|
||||
this._match = match;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||
writer.key("description"); writer.value(getBriefDescription());
|
||||
writer.key("engineConfig"); writer.value(getEngineConfig());
|
||||
writer.key("columnName"); writer.value(_columnName);
|
||||
writer.key("similarValue"); writer.value(_similarValue);
|
||||
writer.key("judgment"); writer.value(Recon.judgmentToString(_judgment));
|
||||
if (_match != null) {
|
||||
writer.key("match"); _match.write(writer, options);
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
protected String getBriefDescription() {
|
||||
if (_judgment == Judgment.None) {
|
||||
return "Discard recon judgments for cells containing \"" +
|
||||
_similarValue + "\" in column " + _columnName;
|
||||
} else if (_judgment == Judgment.New) {
|
||||
return "Mark to create new topics for cells containing \"" +
|
||||
_similarValue + "\" in column " + _columnName;
|
||||
} else if (_judgment == Judgment.Matched) {
|
||||
return "Match topic " +
|
||||
_match.topicName + " (" +
|
||||
_match.topicID + ") for cells containing \"" +
|
||||
_similarValue + "\" in column " + _columnName;
|
||||
}
|
||||
throw new InternalError("Can't get here");
|
||||
}
|
||||
|
||||
protected String createDescription(Column column,
|
||||
List<CellChange> cellChanges) {
|
||||
|
||||
if (_judgment == Judgment.None) {
|
||||
return "Discard recon judgments for " + cellChanges.size() + " cells containing \"" +
|
||||
_similarValue + "\" in column " + _columnName;
|
||||
} else if (_judgment == Judgment.New) {
|
||||
return "Mark to create new topics for " + cellChanges.size() + " cells containing \"" +
|
||||
_similarValue + "\" in column " + _columnName;
|
||||
} else if (_judgment == Judgment.Matched) {
|
||||
return "Match topic " +
|
||||
_match.topicName + " (" +
|
||||
_match.topicID + ") for " +
|
||||
cellChanges.size() + " cells containing \"" +
|
||||
_similarValue + "\" in column " + _columnName;
|
||||
}
|
||||
throw new InternalError("Can't get here");
|
||||
}
|
||||
|
||||
protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges) throws Exception {
|
||||
Column column = project.columnModel.getColumnByName(_columnName);
|
||||
|
||||
return new RowVisitor() {
|
||||
int _cellIndex;
|
||||
List<CellChange> _cellChanges;
|
||||
|
||||
public RowVisitor init(int cellIndex, List<CellChange> cellChanges) {
|
||||
_cellIndex = cellIndex;
|
||||
_cellChanges = cellChanges;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
if (cell != null &&
|
||||
!ExpressionUtils.isBlank(cell.value) &&
|
||||
_similarValue.equals(cell.value)) {
|
||||
|
||||
Cell newCell = new Cell(
|
||||
cell.value,
|
||||
cell.recon == null ? new Recon() : cell.recon.dup()
|
||||
);
|
||||
|
||||
if (_judgment == Judgment.Matched) {
|
||||
newCell.recon.judgment = Recon.Judgment.Matched;
|
||||
newCell.recon.match = _match;
|
||||
} else if (_judgment == Judgment.New) {
|
||||
newCell.recon.judgment = Recon.Judgment.New;
|
||||
} else if (_judgment == Judgment.None) {
|
||||
newCell.recon.judgment = Recon.Judgment.None;
|
||||
newCell.recon.match = null;
|
||||
}
|
||||
|
||||
CellChange cellChange = new CellChange(rowIndex, _cellIndex, cell, newCell);
|
||||
_cellChanges.add(cellChange);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}.init(column.getCellIndex(), cellChanges);
|
||||
}
|
||||
}
|
@ -62,3 +62,14 @@ function reinitializeProjectData(f) {
|
||||
f
|
||||
);
|
||||
}
|
||||
|
||||
function cellIndexToColumn(index) {
|
||||
var columns = theProject.columnModel.columns;
|
||||
for (var i = 0; i < columns.length; i++) {
|
||||
var column = columns[i];
|
||||
if (column.cellIndex == index) {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
@ -10,10 +10,13 @@ BrowsingEngine.prototype._initializeUI = function() {
|
||||
var container = this._div.empty();
|
||||
};
|
||||
|
||||
BrowsingEngine.prototype.getJSON = function() {
|
||||
BrowsingEngine.prototype.getJSON = function(keepUnrestrictedFacets) {
|
||||
var a = { facets: [] };
|
||||
for (var i = 0; i < this._facets.length; i++) {
|
||||
a.facets.push(this._facets[i].facet.getJSON());
|
||||
var facet = this._facets[i];
|
||||
if (keepUnrestrictedFacets || facet.facet.hasSelection()) {
|
||||
a.facets.push(this._facets[i].facet.getJSON());
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
||||
@ -57,7 +60,7 @@ BrowsingEngine.prototype.update = function() {
|
||||
|
||||
$.post(
|
||||
"/command/compute-facets?" + $.param({ project: theProject.id }),
|
||||
{ engine: JSON.stringify(ui.browsingEngine.getJSON()) },
|
||||
{ engine: JSON.stringify(ui.browsingEngine.getJSON(true)) },
|
||||
function(data) {
|
||||
var facetData = data.facets;
|
||||
|
||||
|
@ -62,14 +62,14 @@ DataTableCellUI.prototype._render = function() {
|
||||
.addClass("data-table-recon-match-similar")
|
||||
.attr("title", "Match this topic to this cell and other cells with the same content")
|
||||
.appendTo(li).click(function(evt) {
|
||||
self._doMatchTopicToSimilarCells(candidate.id);
|
||||
self._doMatchTopicToSimilarCells(candidate);
|
||||
});
|
||||
|
||||
$('<a href="javascript:{}"> </a>')
|
||||
.addClass("data-table-recon-match")
|
||||
.attr("title", "Match this topic to this cell")
|
||||
.appendTo(li).click(function(evt) {
|
||||
self._doMatchTopicToOneCell(candidate.id);
|
||||
self._doMatchTopicToOneCell(candidate);
|
||||
});
|
||||
|
||||
$('<a></a>')
|
||||
@ -122,7 +122,7 @@ DataTableCellUI.prototype._render = function() {
|
||||
};
|
||||
|
||||
DataTableCellUI.prototype._doRematch = function() {
|
||||
this._doJudgment("discard");
|
||||
this._doJudgment("none");
|
||||
};
|
||||
|
||||
DataTableCellUI.prototype._doMatchNewTopicToOneCell = function() {
|
||||
@ -133,12 +133,24 @@ DataTableCellUI.prototype._doMatchNewTopicToSimilarCells = function() {
|
||||
this._doJudgmentForSimilarCells("new");
|
||||
};
|
||||
|
||||
DataTableCellUI.prototype._doMatchTopicToOneCell = function(candidateID) {
|
||||
this._doJudgment("match", { candidate : candidateID });
|
||||
DataTableCellUI.prototype._doMatchTopicToOneCell = function(candidate) {
|
||||
this._doJudgment("matched", {
|
||||
topicID : candidate.id,
|
||||
topicGUID: candidate.guid,
|
||||
topicName: candidate.name,
|
||||
score: candidate.score,
|
||||
types: candidate.types.join(",")
|
||||
});
|
||||
};
|
||||
|
||||
DataTableCellUI.prototype._doMatchTopicToSimilarCells = function(candidateID) {
|
||||
this._doJudgmentForSimilarCells("match", { candidate : candidateID });
|
||||
DataTableCellUI.prototype._doMatchTopicToSimilarCells = function(candidate) {
|
||||
this._doJudgmentForSimilarCells("matched", {
|
||||
topicID : candidate.id,
|
||||
topicGUID: candidate.guid,
|
||||
topicName: candidate.name,
|
||||
score: candidate.score,
|
||||
types: candidate.types.join(",")
|
||||
});
|
||||
};
|
||||
|
||||
DataTableCellUI.prototype._doJudgment = function(judgment, params) {
|
||||
@ -151,8 +163,8 @@ DataTableCellUI.prototype._doJudgment = function(judgment, params) {
|
||||
|
||||
DataTableCellUI.prototype._doJudgmentForSimilarCells = function(judgment, params) {
|
||||
params = params || {};
|
||||
params.row = this._rowIndex;
|
||||
params.cell = this._cellIndex;
|
||||
params.columnName = cellIndexToColumn(this._cellIndex).headerLabel;
|
||||
params.similarValue = this._cell.v;
|
||||
params.judgment = judgment;
|
||||
|
||||
ui.dataTableView.doPostThenUpdate("recon-judge-similar-cells", params);
|
||||
@ -182,16 +194,21 @@ DataTableCellUI.prototype._searchForMatch = function() {
|
||||
$('<button></button>').text("Match").click(function() {
|
||||
if (match != null) {
|
||||
var params = {
|
||||
row: self._rowIndex,
|
||||
cell: self._cellIndex,
|
||||
judgment: "matched",
|
||||
topicID: match.id,
|
||||
topicGUID: match.guid,
|
||||
topicName: match.name,
|
||||
types: $.map(match.type, function(elmt) { return elmt.id; }).join(",")
|
||||
};
|
||||
if (checkSimilar[0].checked) {
|
||||
params.similarValue = self._cell.v;
|
||||
params.columnName = cellIndexToColumn(self._cellIndex).headerLabel;
|
||||
|
||||
ui.dataTableView.doPostThenUpdate("recon-judge-similar-cells", params);
|
||||
} else {
|
||||
params.row = self._rowIndex;
|
||||
params.cell = self._cellIndex;
|
||||
|
||||
self.doPostThenUpdate("recon-judge-one-cell", params);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ ReconDialog.prototype._createDialog = function() {
|
||||
var optionDiv = $('<p>').appendTo(body);
|
||||
var autoMatchCheckbox = $('<input type="checkbox" checked />').appendTo(optionDiv);
|
||||
$('<span>').text(" Auto-match correctly-typed candidates scoring at least ").appendTo(optionDiv);
|
||||
var minScoreInput = $('<input/>').attr("value", "100").appendTo(optionDiv);
|
||||
var minScoreInput = $('<input/>').width("3em").attr("value", "100").appendTo(optionDiv);
|
||||
|
||||
$('<button></button>').text("Start Reconciling").click(function() {
|
||||
var choices = $('input[name="recon-dialog-type-choice"]:checked');
|
||||
|
Loading…
Reference in New Issue
Block a user