Add new command to expose known clustering functions and distances
This commit is contained in:
parent
d9af48a49a
commit
7ae71470ef
@ -1,23 +0,0 @@
|
||||
package com.google.refine.commands.browsing;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.refine.commands.Command;
|
||||
|
||||
public class GetClusteringFunctionsAndDistances extends Command {
|
||||
final static Logger logger = LoggerFactory.getLogger("get-clustering-functions-and-distances_command");
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.google.refine.commands.browsing;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.refine.clustering.binning.KeyerFactory;
|
||||
import com.google.refine.clustering.knn.DistanceFactory;
|
||||
import com.google.refine.commands.Command;
|
||||
|
||||
public class GetClusteringFunctionsAndDistancesCommand extends Command {
|
||||
final static Logger logger = LoggerFactory.getLogger("get-clustering-functions-and-distances_command");
|
||||
|
||||
private static class FunctionsAndDistancesResponse {
|
||||
@JsonProperty("distances")
|
||||
public Set<String> getDistances() {
|
||||
return DistanceFactory.getDistanceNames();
|
||||
}
|
||||
|
||||
@JsonProperty("keyers")
|
||||
public Set<String> getKeyers() {
|
||||
return KeyerFactory.getKeyerNames();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
respondJSON(response, new FunctionsAndDistancesResponse());
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.google.refine.tests.commands.browsing;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.google.refine.commands.Command;
|
||||
import com.google.refine.commands.browsing.GetClusteringFunctionsAndDistancesCommand;
|
||||
import com.google.refine.util.JSONUtilities;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
|
||||
public class GetClusteringFunctionsAndDistancesCommandTest {
|
||||
|
||||
protected HttpServletRequest request = null;
|
||||
protected HttpServletResponse response = null;
|
||||
protected StringWriter writer = null;
|
||||
protected Command command = null;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
request = mock(HttpServletRequest.class);
|
||||
response = mock(HttpServletResponse.class);
|
||||
command = new GetClusteringFunctionsAndDistancesCommand();
|
||||
writer = new StringWriter();
|
||||
try {
|
||||
when(response.getWriter()).thenReturn(new PrintWriter(writer));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFunctionsAndKeyers() throws ServletException, IOException {
|
||||
command.doGet(request, response);
|
||||
ObjectNode result = ParsingUtilities.mapper.readValue(writer.toString(), ObjectNode.class);
|
||||
assertTrue(Arrays.asList(JSONUtilities.getStringArray(result, "keyers")).contains("metaphone"));
|
||||
assertTrue(Arrays.asList(JSONUtilities.getStringArray(result, "distances")).contains("levenshtein"));
|
||||
}
|
||||
}
|
@ -90,6 +90,7 @@ function registerCommands() {
|
||||
|
||||
RS.registerCommand(module, "compute-facets", new Packages.com.google.refine.commands.browsing.ComputeFacetsCommand());
|
||||
RS.registerCommand(module, "compute-clusters", new Packages.com.google.refine.commands.browsing.ComputeClustersCommand());
|
||||
RS.registerCommand(module, "get-clustering-functions-and-distances", new Packages.com.google.refine.commands.browsing.GetClusteringFunctionsAndDistancesCommand());
|
||||
|
||||
RS.registerCommand(module, "edit-one-cell", new Packages.com.google.refine.commands.cell.EditOneCellCommand());
|
||||
RS.registerCommand(module, "text-transform", new Packages.com.google.refine.commands.cell.TextTransformCommand());
|
||||
|
Loading…
Reference in New Issue
Block a user