Namespaced operations' names by their modules' names.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1215 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-08-24 04:02:36 +00:00
parent d61522eb64
commit e4af19f8a6
2 changed files with 48 additions and 67 deletions

View File

@ -1,6 +1,6 @@
package com.google.gridworks.operations;
import java.lang.reflect.Method;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@ -8,84 +8,27 @@ import org.json.JSONObject;
import com.google.gridworks.model.AbstractOperation;
import com.google.gridworks.model.Project;
import com.google.gridworks.operations.cell.BlankDownOperation;
import com.google.gridworks.operations.cell.FillDownOperation;
import com.google.gridworks.operations.cell.MassEditOperation;
import com.google.gridworks.operations.cell.MultiValuedCellJoinOperation;
import com.google.gridworks.operations.cell.MultiValuedCellSplitOperation;
import com.google.gridworks.operations.cell.TextTransformOperation;
import com.google.gridworks.operations.cell.TransposeColumnsIntoRowsOperation;
import com.google.gridworks.operations.cell.TransposeRowsIntoColumnsOperation;
import com.google.gridworks.operations.column.ColumnAdditionByFetchingURLsOperation;
import com.google.gridworks.operations.column.ColumnAdditionOperation;
import com.google.gridworks.operations.column.ColumnMoveOperation;
import com.google.gridworks.operations.column.ColumnRemovalOperation;
import com.google.gridworks.operations.column.ColumnRenameOperation;
import com.google.gridworks.operations.column.ColumnSplitOperation;
import com.google.gridworks.operations.column.ExtendDataOperation;
import com.google.gridworks.operations.recon.ImportQADataOperation;
import com.google.gridworks.operations.recon.ReconDiscardJudgmentsOperation;
import com.google.gridworks.operations.recon.ReconJudgeSimilarCellsOperation;
import com.google.gridworks.operations.recon.ReconMarkNewTopicsOperation;
import com.google.gridworks.operations.recon.ReconMatchBestCandidatesOperation;
import com.google.gridworks.operations.recon.ReconMatchSpecificTopicOperation;
import com.google.gridworks.operations.recon.ReconOperation;
import com.google.gridworks.operations.row.DenormalizeOperation;
import com.google.gridworks.operations.row.RowFlagOperation;
import com.google.gridworks.operations.row.RowRemovalOperation;
import com.google.gridworks.operations.row.RowReorderOperation;
import com.google.gridworks.operations.row.RowStarOperation;
import edu.mit.simile.butterfly.ButterflyModule;
public abstract class OperationRegistry {
static final public Map<String, Class<? extends AbstractOperation>> s_opNameToClass = new HashMap<String, Class<? extends AbstractOperation>>();
static final public Map<Class<? extends AbstractOperation>, String> s_opClassToName = new HashMap<Class<? extends AbstractOperation>, String>();
static public void register(String name, Class<? extends AbstractOperation> klass) {
s_opNameToClass.put(name, klass);
s_opClassToName.put(klass, name);
}
static {
register("recon", ReconOperation.class);
register("recon-mark-new-topics", ReconMarkNewTopicsOperation.class);
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);
static public void registerOperation(ButterflyModule module, String name, Class<? extends AbstractOperation> klass) {
String key = module.getName() + "/" + name;
register("multivalued-cell-join", MultiValuedCellJoinOperation.class);
register("multivalued-cell-split", MultiValuedCellSplitOperation.class);
register("fill-down", FillDownOperation.class);
register("blank-down", BlankDownOperation.class);
register("transpose-columns-into-rows", TransposeColumnsIntoRowsOperation.class);
register("transpose-rows-into-columns", TransposeRowsIntoColumnsOperation.class);
register("column-addition", ColumnAdditionOperation.class);
register("column-removal", ColumnRemovalOperation.class);
register("column-rename", ColumnRenameOperation.class);
register("column-move", ColumnMoveOperation.class);
register("column-split", ColumnSplitOperation.class);
register("extend-data", ExtendDataOperation.class);
register("column-addition-by-fetching-urls", ColumnAdditionByFetchingURLsOperation.class);
register("row-removal", RowRemovalOperation.class);
register("row-star", RowStarOperation.class);
register("row-flag", RowFlagOperation.class);
register("row-reorder", RowReorderOperation.class);
register("save-protograph", SaveProtographOperation.class);
register("text-transform", TextTransformOperation.class);
register("mass-edit", MassEditOperation.class);
register("import-qa-data", ImportQADataOperation.class);
register("denormalize", DenormalizeOperation.class);
s_opNameToClass.put(key, klass);
s_opClassToName.put(klass, key);
}
static public AbstractOperation reconstruct(Project project, JSONObject obj) {
try {
String op = obj.getString("op");
if (!op.contains("/")) {
op = "core/" + op; // backward compatible
}
Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op);
if (klass != null) {

View File

@ -100,6 +100,43 @@ function registerCommands() {
GS.registerCommand(module, "set-preference", new Packages.com.google.gridworks.commands.SetPreferenceCommand());
}
function registerOperations() {
var OR = Packages.com.google.gridworks.operations.OperationRegistry;
OR.registerOperation(module, "text-transform", Packages.com.google.gridworks.operations.cell.TextTransformOperation);
OR.registerOperation(module, "mass-edit", Packages.com.google.gridworks.operations.cell.MassEditOperation);
OR.registerOperation(module, "multivalued-cell-join", Packages.com.google.gridworks.operations.cell.MultiValuedCellJoinOperation);
OR.registerOperation(module, "multivalued-cell-split", Packages.com.google.gridworks.operations.cell.MultiValuedCellSplitOperation);
OR.registerOperation(module, "fill-down", Packages.com.google.gridworks.operations.cell.FillDownOperation);
OR.registerOperation(module, "blank-down", Packages.com.google.gridworks.operations.cell.BlankDownOperation);
OR.registerOperation(module, "transpose-columns-into-rows", Packages.com.google.gridworks.operations.cell.TransposeColumnsIntoRowsOperation);
OR.registerOperation(module, "transpose-rows-into-columns", Packages.com.google.gridworks.operations.cell.TransposeRowsIntoColumnsOperation);
OR.registerOperation(module, "column-addition", Packages.com.google.gridworks.operations.column.ColumnAdditionOperation);
OR.registerOperation(module, "column-removal", Packages.com.google.gridworks.operations.column.ColumnRemovalOperation);
OR.registerOperation(module, "column-rename", Packages.com.google.gridworks.operations.column.ColumnRenameOperation);
OR.registerOperation(module, "column-move", Packages.com.google.gridworks.operations.column.ColumnMoveOperation);
OR.registerOperation(module, "column-split", Packages.com.google.gridworks.operations.column.ColumnSplitOperation);
OR.registerOperation(module, "extend-data", Packages.com.google.gridworks.operations.column.ExtendDataOperation);
OR.registerOperation(module, "column-addition-by-fetching-urls", Packages.com.google.gridworks.operations.column.ColumnAdditionByFetchingURLsOperation);
OR.registerOperation(module, "row-removal", Packages.com.google.gridworks.operations.row.RowRemovalOperation);
OR.registerOperation(module, "row-star", Packages.com.google.gridworks.operations.row.RowStarOperation);
OR.registerOperation(module, "row-flag", Packages.com.google.gridworks.operations.row.RowFlagOperation);
OR.registerOperation(module, "row-reorder", Packages.com.google.gridworks.operations.row.RowReorderOperation);
OR.registerOperation(module, "recon", Packages.com.google.gridworks.operations.recon.ReconOperation);
OR.registerOperation(module, "recon-mark-new-topics", Packages.com.google.gridworks.operations.recon.ReconMarkNewTopicsOperation);
OR.registerOperation(module, "recon-match-best-candidates", Packages.com.google.gridworks.operations.recon.ReconMatchBestCandidatesOperation);
OR.registerOperation(module, "recon-discard-judgments", Packages.com.google.gridworks.operations.recon.ReconDiscardJudgmentsOperation);
OR.registerOperation(module, "recon-match-specific-topic-to-cells", Packages.com.google.gridworks.operations.recon.ReconMatchSpecificTopicOperation);
OR.registerOperation(module, "recon-judge-similar-cells", Packages.com.google.gridworks.operations.recon.ReconJudgeSimilarCellsOperation);
OR.registerOperation(module, "import-qa-data", Packages.com.google.gridworks.operations.recon.ImportQADataOperation);
OR.registerOperation(module, "save-protograph", Packages.com.google.gridworks.operations.SaveProtographOperation);
}
/*
* This optional function is invoked from the module's init() Java function.
*/
@ -107,6 +144,7 @@ function init() {
// Packages.java.lang.System.err.println("Initializing by script " + module);
registerCommands();
registerOperations();
ClientSideResourceManager.addPaths(
"index/scripts",