diff --git a/main/src/com/google/refine/clustering/ClustererConfig.java b/main/src/com/google/refine/clustering/ClustererConfig.java new file mode 100644 index 000000000..d7f5d4842 --- /dev/null +++ b/main/src/com/google/refine/clustering/ClustererConfig.java @@ -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); +} diff --git a/main/src/com/google/refine/clustering/binning/BinningClusterer.java b/main/src/com/google/refine/clustering/binning/BinningClusterer.java index 5d7e00ab9..1da042dbb 100644 --- a/main/src/com/google/refine/clustering/binning/BinningClusterer.java +++ b/main/src/com/google/refine/clustering/binning/BinningClusterer.java @@ -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) { super.initializeFromConfig(project, config); _keyer = config.getKeyer(); diff --git a/main/src/com/google/refine/clustering/knn/kNNClusterer.java b/main/src/com/google/refine/clustering/knn/kNNClusterer.java index 22ab1a3ff..d80f05f7c 100644 --- a/main/src/com/google/refine/clustering/knn/kNNClusterer.java +++ b/main/src/com/google/refine/clustering/knn/kNNClusterer.java @@ -253,13 +253,6 @@ public class kNNClusterer extends Clusterer { return _clusterer.getClusters(_radius); } } - - @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) { super.initializeFromConfig(project, config); diff --git a/main/src/com/google/refine/commands/browsing/ComputeClustersCommand.java b/main/src/com/google/refine/commands/browsing/ComputeClustersCommand.java index 0064db9a4..1c80c1863 100644 --- a/main/src/com/google/refine/commands/browsing/ComputeClustersCommand.java +++ b/main/src/com/google/refine/commands/browsing/ComputeClustersCommand.java @@ -45,8 +45,9 @@ import org.slf4j.LoggerFactory; import com.google.refine.browsing.Engine; import com.google.refine.clustering.Clusterer; -import com.google.refine.clustering.binning.BinningClusterer; -import com.google.refine.clustering.knn.kNNClusterer; +import com.google.refine.clustering.ClustererConfig; +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.model.Project; @@ -64,16 +65,17 @@ public class ComputeClustersCommand extends Command { Engine engine = getEngine(request, project); JSONObject clusterer_conf = getJsonParameter(request,"clusterer"); - Clusterer clusterer = null; String type = clusterer_conf.has("type") ? clusterer_conf.getString("type") : "binning"; + ClustererConfig clustererConfig = null; if ("knn".equals(type)) { - clusterer = new kNNClusterer(); + clustererConfig = new kNNClustererConfig(); } else { - clusterer = new BinningClusterer(); + clustererConfig = new BinningClustererConfig(); } - clusterer.initializeFromJSON(project, clusterer_conf); + clustererConfig.initializeFromJSON(clusterer_conf); + Clusterer clusterer = clustererConfig.apply(project); clusterer.computeClusters(engine);