Migrate ComputeClustersCommand to use new architecture
This commit is contained in:
parent
c9436f563d
commit
9f964af7d4
35
main/src/com/google/refine/clustering/ClustererConfig.java
Normal file
35
main/src/com/google/refine/clustering/ClustererConfig.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package com.google.refine.clustering;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.google.refine.Jsonizable;
|
||||||
|
import com.google.refine.model.Project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the configuration data for a clusterer.
|
||||||
|
* @author Antonin Delpeuch
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class ClustererConfig implements Jsonizable {
|
||||||
|
|
||||||
|
protected String columnName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the configuration from a JSON payload (TODO: delete)
|
||||||
|
* @param o
|
||||||
|
*/
|
||||||
|
public void initializeFromJSON(JSONObject o) {
|
||||||
|
columnName = o.getString("column");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColumnName() {
|
||||||
|
return columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate the configuration on a particular project.
|
||||||
|
* @param project
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract Clusterer apply(Project project);
|
||||||
|
}
|
@ -238,13 +238,6 @@ public class BinningClusterer extends Clusterer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
|
|
||||||
BinningClustererConfig config = new BinningClustererConfig();
|
|
||||||
config.initializeFromJSON(o);
|
|
||||||
initializeFromConfig(project, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initializeFromConfig(Project project, BinningClustererConfig config) {
|
public void initializeFromConfig(Project project, BinningClustererConfig config) {
|
||||||
super.initializeFromConfig(project, config);
|
super.initializeFromConfig(project, config);
|
||||||
_keyer = config.getKeyer();
|
_keyer = config.getKeyer();
|
||||||
|
@ -254,13 +254,6 @@ public class kNNClusterer extends Clusterer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
|
|
||||||
kNNClustererConfig config = new kNNClustererConfig();
|
|
||||||
config.initializeFromJSON(o);
|
|
||||||
initializeFromConfig(project, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initializeFromConfig(Project project, kNNClustererConfig config) {
|
public void initializeFromConfig(Project project, kNNClustererConfig config) {
|
||||||
super.initializeFromConfig(project, config);
|
super.initializeFromConfig(project, config);
|
||||||
_distance = config.getDistance();
|
_distance = config.getDistance();
|
||||||
|
@ -45,8 +45,9 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import com.google.refine.browsing.Engine;
|
import com.google.refine.browsing.Engine;
|
||||||
import com.google.refine.clustering.Clusterer;
|
import com.google.refine.clustering.Clusterer;
|
||||||
import com.google.refine.clustering.binning.BinningClusterer;
|
import com.google.refine.clustering.ClustererConfig;
|
||||||
import com.google.refine.clustering.knn.kNNClusterer;
|
import com.google.refine.clustering.binning.BinningClusterer.BinningClustererConfig;
|
||||||
|
import com.google.refine.clustering.knn.kNNClusterer.kNNClustererConfig;
|
||||||
import com.google.refine.commands.Command;
|
import com.google.refine.commands.Command;
|
||||||
import com.google.refine.model.Project;
|
import com.google.refine.model.Project;
|
||||||
|
|
||||||
@ -64,16 +65,17 @@ public class ComputeClustersCommand extends Command {
|
|||||||
Engine engine = getEngine(request, project);
|
Engine engine = getEngine(request, project);
|
||||||
JSONObject clusterer_conf = getJsonParameter(request,"clusterer");
|
JSONObject clusterer_conf = getJsonParameter(request,"clusterer");
|
||||||
|
|
||||||
Clusterer clusterer = null;
|
|
||||||
String type = clusterer_conf.has("type") ? clusterer_conf.getString("type") : "binning";
|
String type = clusterer_conf.has("type") ? clusterer_conf.getString("type") : "binning";
|
||||||
|
|
||||||
|
ClustererConfig clustererConfig = null;
|
||||||
if ("knn".equals(type)) {
|
if ("knn".equals(type)) {
|
||||||
clusterer = new kNNClusterer();
|
clustererConfig = new kNNClustererConfig();
|
||||||
} else {
|
} else {
|
||||||
clusterer = new BinningClusterer();
|
clustererConfig = new BinningClustererConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
clusterer.initializeFromJSON(project, clusterer_conf);
|
clustererConfig.initializeFromJSON(clusterer_conf);
|
||||||
|
Clusterer clusterer = clustererConfig.apply(project);
|
||||||
|
|
||||||
clusterer.computeClusters(engine);
|
clusterer.computeClusters(engine);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user