Changed tabs to spaces. No functionality change.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@174 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
2691ee50d7
commit
b75f1faea8
@ -46,89 +46,89 @@ import com.metaweb.gridworks.commands.util.PreviewProtographCommand;
|
||||
|
||||
public class GridworksServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 2386057901503517403L;
|
||||
|
||||
static protected Map<String, Command> _commands = new HashMap<String, Command>();
|
||||
|
||||
static {
|
||||
_commands.put("create-project-from-upload", new CreateProjectCommand());
|
||||
_commands.put("export-rows", new ExportRowsCommand());
|
||||
|
||||
_commands.put("get-project-metadata", new GetProjectMetadataCommand());
|
||||
_commands.put("get-all-project-metadata", new GetAllProjectMetadataCommand());
|
||||
|
||||
_commands.put("get-models", new GetModelsCommand());
|
||||
_commands.put("get-rows", new GetRowsCommand());
|
||||
_commands.put("get-processes", new GetProcessesCommand());
|
||||
_commands.put("get-history", new GetHistoryCommand());
|
||||
_commands.put("get-operations", new GetOperationsCommand());
|
||||
|
||||
_commands.put("undo-redo", new UndoRedoCommand());
|
||||
_commands.put("apply-operations", new ApplyOperationsCommand());
|
||||
_commands.put("cancel-processes", new CancelProcessesCommand());
|
||||
|
||||
_commands.put("compute-facets", new ComputeFacetsCommand());
|
||||
_commands.put("do-text-transform", new DoTextTransformCommand());
|
||||
_commands.put("facet-based-edit", new FacetBasedEditCommand());
|
||||
|
||||
_commands.put("add-column", new AddColumnCommand());
|
||||
_commands.put("remove-column", new RemoveColumnCommand());
|
||||
private static final long serialVersionUID = 2386057901503517403L;
|
||||
|
||||
static protected Map<String, Command> _commands = new HashMap<String, Command>();
|
||||
|
||||
static {
|
||||
_commands.put("create-project-from-upload", new CreateProjectCommand());
|
||||
_commands.put("export-rows", new ExportRowsCommand());
|
||||
|
||||
_commands.put("get-project-metadata", new GetProjectMetadataCommand());
|
||||
_commands.put("get-all-project-metadata", new GetAllProjectMetadataCommand());
|
||||
|
||||
_commands.put("get-models", new GetModelsCommand());
|
||||
_commands.put("get-rows", new GetRowsCommand());
|
||||
_commands.put("get-processes", new GetProcessesCommand());
|
||||
_commands.put("get-history", new GetHistoryCommand());
|
||||
_commands.put("get-operations", new GetOperationsCommand());
|
||||
|
||||
_commands.put("undo-redo", new UndoRedoCommand());
|
||||
_commands.put("apply-operations", new ApplyOperationsCommand());
|
||||
_commands.put("cancel-processes", new CancelProcessesCommand());
|
||||
|
||||
_commands.put("compute-facets", new ComputeFacetsCommand());
|
||||
_commands.put("do-text-transform", new DoTextTransformCommand());
|
||||
_commands.put("facet-based-edit", new FacetBasedEditCommand());
|
||||
|
||||
_commands.put("add-column", new AddColumnCommand());
|
||||
_commands.put("remove-column", new RemoveColumnCommand());
|
||||
_commands.put("join-multi-value-cells", new JoinMultiValueCellsCommand());
|
||||
_commands.put("split-multi-value-cells", new SplitMultiValueCellsCommand());
|
||||
|
||||
_commands.put("reconcile", new ReconcileCommand());
|
||||
_commands.put("recon-match-best-candidates", new ReconMatchBestCandidatesCommand());
|
||||
_commands.put("recon-mark-new-topics", new ReconMarkNewTopicsCommand());
|
||||
_commands.put("recon-discard-judgments", new ReconDiscardJudgmentsCommand());
|
||||
_commands.put("recon-match-specific-topic-to-cells", new ReconMatchSpecificTopicCommand());
|
||||
_commands.put("recon-judge-one-cell", new ReconJudgeOneCellCommand());
|
||||
|
||||
_commands.put("reconcile", new ReconcileCommand());
|
||||
_commands.put("recon-match-best-candidates", new ReconMatchBestCandidatesCommand());
|
||||
_commands.put("recon-mark-new-topics", new ReconMarkNewTopicsCommand());
|
||||
_commands.put("recon-discard-judgments", new ReconDiscardJudgmentsCommand());
|
||||
_commands.put("recon-match-specific-topic-to-cells", new ReconMatchSpecificTopicCommand());
|
||||
_commands.put("recon-judge-one-cell", new ReconJudgeOneCellCommand());
|
||||
_commands.put("recon-judge-similar-cells", new ReconJudgeSimilarCellsCommand());
|
||||
|
||||
|
||||
_commands.put("annotate-one-row", new AnnotateOneRowCommand());
|
||||
_commands.put("annotate-rows", new AnnotateRowsCommand());
|
||||
|
||||
_commands.put("save-protograph", new SaveProtographCommand());
|
||||
|
||||
_commands.put("preview-expression", new PreviewExpressionCommand());
|
||||
_commands.put("save-protograph", new SaveProtographCommand());
|
||||
|
||||
_commands.put("preview-expression", new PreviewExpressionCommand());
|
||||
_commands.put("get-expression-language-info", new GetExpressionLanguageInfoCommand());
|
||||
_commands.put("preview-protograph", new PreviewProtographCommand());
|
||||
_commands.put("guess-types-of-column", new GuessTypesOfColumnCommand());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (ProjectManager.singleton != null) {
|
||||
ProjectManager.singleton.saveAllProjects();
|
||||
ProjectManager.singleton.save();
|
||||
ProjectManager.singleton = null;
|
||||
}
|
||||
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (ProjectManager.singleton != null) {
|
||||
ProjectManager.singleton.saveAllProjects();
|
||||
ProjectManager.singleton.save();
|
||||
ProjectManager.singleton = null;
|
||||
}
|
||||
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
ProjectManager.initialize();
|
||||
|
||||
String commandName = request.getPathInfo().substring(1);
|
||||
Command command = _commands.get(commandName);
|
||||
if (command != null) {
|
||||
command.doPost(request, response);
|
||||
}
|
||||
ProjectManager.initialize();
|
||||
|
||||
String commandName = request.getPathInfo().substring(1);
|
||||
Command command = _commands.get(commandName);
|
||||
if (command != null) {
|
||||
command.doPost(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
ProjectManager.initialize();
|
||||
|
||||
String commandName = request.getPathInfo().substring(1);
|
||||
Command command = _commands.get(commandName);
|
||||
if (command != null) {
|
||||
command.doGet(request, response);
|
||||
}
|
||||
ProjectManager.initialize();
|
||||
|
||||
String commandName = request.getPathInfo().substring(1);
|
||||
Command command = _commands.get(commandName);
|
||||
if (command != null) {
|
||||
command.doGet(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,5 +6,5 @@ import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
public interface Jsonizable {
|
||||
public void write(JSONWriter writer, Properties options) throws JSONException;
|
||||
public void write(JSONWriter writer, Properties options) throws JSONException;
|
||||
}
|
||||
|
@ -15,55 +15,55 @@ import com.codeberry.jdatapath.JDataPathSystem;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class ProjectManager implements Serializable {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -2967415873336723962L;
|
||||
|
||||
protected File _dir;
|
||||
protected Map<Long, ProjectMetadata> _projectsMetadata;
|
||||
|
||||
transient protected Map<Long, Project> _projects;
|
||||
|
||||
static public ProjectManager singleton;
|
||||
|
||||
static public void initialize() {
|
||||
if (singleton == null) {
|
||||
File dir = getProjectLocation();
|
||||
Gridworks.log("Using data directory: " + dir.getAbsolutePath());
|
||||
File file = new File(dir, "projects");
|
||||
if (file.exists()) {
|
||||
singleton = load(file);
|
||||
} else {
|
||||
singleton = new ProjectManager(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static protected File getProjectLocation() {
|
||||
String data_dir = Configurations.get("gridworks.data_dir");
|
||||
if (data_dir != null) {
|
||||
return new File(data_dir);
|
||||
}
|
||||
|
||||
String os = Configurations.get("os.name").toLowerCase();
|
||||
if (os.contains("windows")) {
|
||||
// NOTE(SM): finding the "local data app" in windows from java is actually a PITA
|
||||
// see http://stackoverflow.com/questions/1198911/how-to-get-local-application-data-folder-in-java
|
||||
// so we're using a library that uses JNI to ask directly the win32 APIs,
|
||||
// it's not elegant but it's the safest bet
|
||||
DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Gridworks");
|
||||
|
||||
protected File _dir;
|
||||
protected Map<Long, ProjectMetadata> _projectsMetadata;
|
||||
|
||||
transient protected Map<Long, Project> _projects;
|
||||
|
||||
static public ProjectManager singleton;
|
||||
|
||||
static public void initialize() {
|
||||
if (singleton == null) {
|
||||
File dir = getProjectLocation();
|
||||
Gridworks.log("Using data directory: " + dir.getAbsolutePath());
|
||||
File file = new File(dir, "projects");
|
||||
if (file.exists()) {
|
||||
singleton = load(file);
|
||||
} else {
|
||||
singleton = new ProjectManager(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static protected File getProjectLocation() {
|
||||
String data_dir = Configurations.get("gridworks.data_dir");
|
||||
if (data_dir != null) {
|
||||
return new File(data_dir);
|
||||
}
|
||||
|
||||
String os = Configurations.get("os.name").toLowerCase();
|
||||
if (os.contains("windows")) {
|
||||
// NOTE(SM): finding the "local data app" in windows from java is actually a PITA
|
||||
// see http://stackoverflow.com/questions/1198911/how-to-get-local-application-data-folder-in-java
|
||||
// so we're using a library that uses JNI to ask directly the win32 APIs,
|
||||
// it's not elegant but it's the safest bet
|
||||
DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Gridworks");
|
||||
File data = new File(localDataPath.getPath());
|
||||
data.mkdirs();
|
||||
return data;
|
||||
} else if (os.contains("mac os x")) {
|
||||
// on macosx, use "~/Library/Application Support"
|
||||
String home = System.getProperty("user.home");
|
||||
return data;
|
||||
} else if (os.contains("mac os x")) {
|
||||
// on macosx, use "~/Library/Application Support"
|
||||
String home = System.getProperty("user.home");
|
||||
String data_home = (home != null) ? home + "/Library/Application Support/Gridworks" : ".gridworks";
|
||||
File data = new File(data_home);
|
||||
data.mkdirs();
|
||||
return data;
|
||||
} else { // most likely a UNIX flavor
|
||||
// start with the XDG environment
|
||||
// see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
} else { // most likely a UNIX flavor
|
||||
// start with the XDG environment
|
||||
// see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
String data_home = System.getenv("XDG_DATA_HOME");
|
||||
if (data_home == null) { // if not found, default back to ~/.local/share
|
||||
String home = System.getProperty("user.home");
|
||||
@ -73,172 +73,172 @@ public class ProjectManager implements Serializable {
|
||||
File data = new File(data_home + "/gridworks");
|
||||
data.mkdirs();
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
static protected ProjectManager load(File file) {
|
||||
ProjectManager pm = null;
|
||||
FileInputStream fis = null;
|
||||
ObjectInputStream in = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
in = new ObjectInputStream(fis);
|
||||
|
||||
pm = (ProjectManager) in.readObject();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return pm;
|
||||
}
|
||||
|
||||
private ProjectManager(File dir) {
|
||||
_dir = dir;
|
||||
_dir.mkdirs();
|
||||
|
||||
_projectsMetadata = new HashMap<Long, ProjectMetadata>();
|
||||
|
||||
internalInitialize();
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
internalInitialize();
|
||||
}
|
||||
|
||||
private void internalInitialize() {
|
||||
_projects = new HashMap<Long, Project>();
|
||||
}
|
||||
|
||||
public File getDataDir() {
|
||||
return _dir;
|
||||
}
|
||||
|
||||
public void registerProject(Project project, ProjectMetadata projectMetadata) {
|
||||
_projects.put(project.id, project);
|
||||
_projectsMetadata.put(project.id, projectMetadata);
|
||||
}
|
||||
|
||||
public ProjectMetadata getProjectMetadata(long id) {
|
||||
return _projectsMetadata.get(id);
|
||||
}
|
||||
|
||||
public Map<Long, ProjectMetadata> getAllProjectMetadata() {
|
||||
return _projectsMetadata;
|
||||
}
|
||||
|
||||
public Project getProject(long id) {
|
||||
if (_projects.containsKey(id)) {
|
||||
return _projects.get(id);
|
||||
} else {
|
||||
File file = new File(_dir, id + ".project");
|
||||
|
||||
Project project = null;
|
||||
FileInputStream fis = null;
|
||||
ObjectInputStream in = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
in = new ObjectInputStream(fis);
|
||||
|
||||
project = (Project) in.readObject();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_projects.put(id, project);
|
||||
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
File file = new File(_dir, "projects");
|
||||
|
||||
FileOutputStream fos = null;
|
||||
ObjectOutputStream out = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
out = new ObjectOutputStream(fos);
|
||||
out.writeObject(this);
|
||||
out.flush();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAllProjects() {
|
||||
for (Project project : _projects.values()) {
|
||||
saveProject(project);
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveProject(Project project) {
|
||||
File file = new File(_dir, project.id + ".project");
|
||||
|
||||
FileOutputStream fos = null;
|
||||
ObjectOutputStream out = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
out = new ObjectOutputStream(fos);
|
||||
out.writeObject(project);
|
||||
out.flush();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static protected ProjectManager load(File file) {
|
||||
ProjectManager pm = null;
|
||||
FileInputStream fis = null;
|
||||
ObjectInputStream in = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
in = new ObjectInputStream(fis);
|
||||
|
||||
pm = (ProjectManager) in.readObject();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return pm;
|
||||
}
|
||||
|
||||
private ProjectManager(File dir) {
|
||||
_dir = dir;
|
||||
_dir.mkdirs();
|
||||
|
||||
_projectsMetadata = new HashMap<Long, ProjectMetadata>();
|
||||
|
||||
internalInitialize();
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
internalInitialize();
|
||||
}
|
||||
|
||||
private void internalInitialize() {
|
||||
_projects = new HashMap<Long, Project>();
|
||||
}
|
||||
|
||||
public File getDataDir() {
|
||||
return _dir;
|
||||
}
|
||||
|
||||
public void registerProject(Project project, ProjectMetadata projectMetadata) {
|
||||
_projects.put(project.id, project);
|
||||
_projectsMetadata.put(project.id, projectMetadata);
|
||||
}
|
||||
|
||||
public ProjectMetadata getProjectMetadata(long id) {
|
||||
return _projectsMetadata.get(id);
|
||||
}
|
||||
|
||||
public Map<Long, ProjectMetadata> getAllProjectMetadata() {
|
||||
return _projectsMetadata;
|
||||
}
|
||||
|
||||
public Project getProject(long id) {
|
||||
if (_projects.containsKey(id)) {
|
||||
return _projects.get(id);
|
||||
} else {
|
||||
File file = new File(_dir, id + ".project");
|
||||
|
||||
Project project = null;
|
||||
FileInputStream fis = null;
|
||||
ObjectInputStream in = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
in = new ObjectInputStream(fis);
|
||||
|
||||
project = (Project) in.readObject();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_projects.put(id, project);
|
||||
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
File file = new File(_dir, "projects");
|
||||
|
||||
FileOutputStream fos = null;
|
||||
ObjectOutputStream out = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
out = new ObjectOutputStream(fos);
|
||||
out.writeObject(this);
|
||||
out.flush();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAllProjects() {
|
||||
for (Project project : _projects.values()) {
|
||||
saveProject(project);
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveProject(Project project) {
|
||||
File file = new File(_dir, project.id + ".project");
|
||||
|
||||
FileOutputStream fos = null;
|
||||
ObjectOutputStream out = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
out = new ObjectOutputStream(fos);
|
||||
out.writeObject(project);
|
||||
out.flush();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,26 +9,26 @@ import org.json.JSONException;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
public class ProjectMetadata implements Serializable, Jsonizable {
|
||||
private static final long serialVersionUID = 7959027046468240844L;
|
||||
|
||||
private final Date _created = new Date();
|
||||
private String _name;
|
||||
private String _password;
|
||||
private String _encoding;
|
||||
private int _encodingConfidence;
|
||||
private Date _modified = new Date();
|
||||
|
||||
public Date getCreated() {
|
||||
return _created;
|
||||
}
|
||||
private static final long serialVersionUID = 7959027046468240844L;
|
||||
|
||||
private final Date _created = new Date();
|
||||
private String _name;
|
||||
private String _password;
|
||||
private String _encoding;
|
||||
private int _encodingConfidence;
|
||||
private Date _modified = new Date();
|
||||
|
||||
public Date getCreated() {
|
||||
return _created;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this._name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public void setEncoding(String encoding) {
|
||||
this._encoding = encoding;
|
||||
@ -50,31 +50,31 @@ public class ProjectMetadata implements Serializable, Jsonizable {
|
||||
return _encodingConfidence;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this._password = password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this._password = password;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return _password;
|
||||
}
|
||||
|
||||
public Date getModified() {
|
||||
return _modified;
|
||||
}
|
||||
|
||||
public void updateModified() {
|
||||
_modified = new Date();
|
||||
}
|
||||
public String getPassword() {
|
||||
return _password;
|
||||
}
|
||||
|
||||
public Date getModified() {
|
||||
return _modified;
|
||||
}
|
||||
|
||||
public void updateModified() {
|
||||
_modified = new Date();
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance();
|
||||
|
||||
writer.object();
|
||||
writer.key("name"); writer.value(getName());
|
||||
writer.key("created"); writer.value(sdf.format(getCreated()));
|
||||
writer.key("modified"); writer.value(sdf.format(_modified));
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance();
|
||||
|
||||
writer.object();
|
||||
writer.key("name"); writer.value(getName());
|
||||
writer.key("created"); writer.value(sdf.format(getCreated()));
|
||||
writer.key("modified"); writer.value(sdf.format(_modified));
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -8,75 +8,75 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
public class ConjunctiveFilteredRows implements FilteredRows {
|
||||
final protected List<RowFilter> _rowFilters = new LinkedList<RowFilter>();
|
||||
final protected boolean _contextual;
|
||||
|
||||
public ConjunctiveFilteredRows(boolean contextual) {
|
||||
_contextual = contextual;
|
||||
}
|
||||
|
||||
public void add(RowFilter rowFilter) {
|
||||
_rowFilters.add(rowFilter);
|
||||
}
|
||||
|
||||
public void accept(Project project, RowVisitor visitor) {
|
||||
if (_contextual) {
|
||||
contextualAccept(project, visitor);
|
||||
} else {
|
||||
simpleAccept(project, visitor);
|
||||
}
|
||||
}
|
||||
|
||||
protected void simpleAccept(Project project, RowVisitor visitor) {
|
||||
for (int i = 0; i < project.rows.size(); i++) {
|
||||
Row row = project.rows.get(i);
|
||||
|
||||
boolean ok = true;
|
||||
for (RowFilter rowFilter : _rowFilters) {
|
||||
if (!rowFilter.filterRow(project, i, row)) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
visitor.visit(project, i, row, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void contextualAccept(Project project, RowVisitor visitor) {
|
||||
int lastVisitedRow = -1;
|
||||
|
||||
for (int i = 0; i < project.rows.size(); i++) {
|
||||
Row row = project.rows.get(i);
|
||||
|
||||
boolean ok = true;
|
||||
for (RowFilter rowFilter : _rowFilters) {
|
||||
if (!rowFilter.filterRow(project, i, row)) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
if (row.contextRows != null && lastVisitedRow < i - 1) {
|
||||
for (int contextRowIndex : row.contextRows) {
|
||||
if (contextRowIndex > lastVisitedRow) {
|
||||
visitor.visit(
|
||||
project,
|
||||
contextRowIndex,
|
||||
project.rows.get(contextRowIndex),
|
||||
true
|
||||
);
|
||||
lastVisitedRow = contextRowIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visitor.visit(project, i, row, false);
|
||||
lastVisitedRow = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
final protected List<RowFilter> _rowFilters = new LinkedList<RowFilter>();
|
||||
final protected boolean _contextual;
|
||||
|
||||
public ConjunctiveFilteredRows(boolean contextual) {
|
||||
_contextual = contextual;
|
||||
}
|
||||
|
||||
public void add(RowFilter rowFilter) {
|
||||
_rowFilters.add(rowFilter);
|
||||
}
|
||||
|
||||
public void accept(Project project, RowVisitor visitor) {
|
||||
if (_contextual) {
|
||||
contextualAccept(project, visitor);
|
||||
} else {
|
||||
simpleAccept(project, visitor);
|
||||
}
|
||||
}
|
||||
|
||||
protected void simpleAccept(Project project, RowVisitor visitor) {
|
||||
for (int i = 0; i < project.rows.size(); i++) {
|
||||
Row row = project.rows.get(i);
|
||||
|
||||
boolean ok = true;
|
||||
for (RowFilter rowFilter : _rowFilters) {
|
||||
if (!rowFilter.filterRow(project, i, row)) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
visitor.visit(project, i, row, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void contextualAccept(Project project, RowVisitor visitor) {
|
||||
int lastVisitedRow = -1;
|
||||
|
||||
for (int i = 0; i < project.rows.size(); i++) {
|
||||
Row row = project.rows.get(i);
|
||||
|
||||
boolean ok = true;
|
||||
for (RowFilter rowFilter : _rowFilters) {
|
||||
if (!rowFilter.filterRow(project, i, row)) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
if (row.contextRows != null && lastVisitedRow < i - 1) {
|
||||
for (int contextRowIndex : row.contextRows) {
|
||||
if (contextRowIndex > lastVisitedRow) {
|
||||
visitor.visit(
|
||||
project,
|
||||
contextRowIndex,
|
||||
project.rows.get(contextRowIndex),
|
||||
true
|
||||
);
|
||||
lastVisitedRow = contextRowIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visitor.visit(project, i, row, false);
|
||||
lastVisitedRow = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,19 +8,19 @@ import org.json.JSONWriter;
|
||||
import com.metaweb.gridworks.Jsonizable;
|
||||
|
||||
public class DecoratedValue implements Jsonizable {
|
||||
final public Object value;
|
||||
final public String label;
|
||||
|
||||
public DecoratedValue(Object value, String label) {
|
||||
this.value = value;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
writer.object();
|
||||
writer.key("v"); writer.value(value);
|
||||
writer.key("l"); writer.value(label);
|
||||
writer.endObject();
|
||||
}
|
||||
final public Object value;
|
||||
final public String label;
|
||||
|
||||
public DecoratedValue(Object value, String label) {
|
||||
this.value = value;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
writer.object();
|
||||
writer.key("v"); writer.value(value);
|
||||
writer.key("l"); writer.value(label);
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -18,71 +18,71 @@ import com.metaweb.gridworks.browsing.filters.RowFilter;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class Engine implements Jsonizable {
|
||||
protected Project _project;
|
||||
protected List<Facet> _facets = new LinkedList<Facet>();
|
||||
|
||||
public Engine(Project project) {
|
||||
_project = project;
|
||||
}
|
||||
|
||||
public FilteredRows getAllFilteredRows(boolean contextual) {
|
||||
return getFilteredRows(null, contextual);
|
||||
}
|
||||
protected Project _project;
|
||||
protected List<Facet> _facets = new LinkedList<Facet>();
|
||||
|
||||
public Engine(Project project) {
|
||||
_project = project;
|
||||
}
|
||||
|
||||
public FilteredRows getAllFilteredRows(boolean contextual) {
|
||||
return getFilteredRows(null, contextual);
|
||||
}
|
||||
|
||||
public FilteredRows getFilteredRows(Facet except, boolean contextual) {
|
||||
ConjunctiveFilteredRows cfr = new ConjunctiveFilteredRows(contextual);
|
||||
for (Facet facet : _facets) {
|
||||
if (facet != except) {
|
||||
RowFilter rowFilter = facet.getRowFilter();
|
||||
if (rowFilter != null) {
|
||||
cfr.add(rowFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cfr;
|
||||
}
|
||||
|
||||
public void initializeFromJSON(JSONObject o) throws Exception {
|
||||
JSONArray a = o.getJSONArray("facets");
|
||||
int length = a.length();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
JSONObject fo = a.getJSONObject(i);
|
||||
String type = fo.has("type") ? fo.getString("type") : "list";
|
||||
|
||||
Facet facet = null;
|
||||
if ("list".equals(type)) {
|
||||
facet = new ListFacet();
|
||||
} else if ("range".equals(type)) {
|
||||
facet = new RangeFacet();
|
||||
} else if ("text".equals(type)) {
|
||||
facet = new TextSearchFacet();
|
||||
}
|
||||
|
||||
if (facet != null) {
|
||||
facet.initializeFromJSON(_project, fo);
|
||||
_facets.add(facet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void computeFacets() throws JSONException {
|
||||
for (Facet facet : _facets) {
|
||||
FilteredRows filteredRows = getFilteredRows(facet, false);
|
||||
|
||||
facet.computeChoices(_project, filteredRows);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("facets"); writer.array();
|
||||
for (Facet facet : _facets) {
|
||||
facet.write(writer, options);
|
||||
}
|
||||
writer.endArray();
|
||||
writer.endObject();
|
||||
}
|
||||
public FilteredRows getFilteredRows(Facet except, boolean contextual) {
|
||||
ConjunctiveFilteredRows cfr = new ConjunctiveFilteredRows(contextual);
|
||||
for (Facet facet : _facets) {
|
||||
if (facet != except) {
|
||||
RowFilter rowFilter = facet.getRowFilter();
|
||||
if (rowFilter != null) {
|
||||
cfr.add(rowFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cfr;
|
||||
}
|
||||
|
||||
public void initializeFromJSON(JSONObject o) throws Exception {
|
||||
JSONArray a = o.getJSONArray("facets");
|
||||
int length = a.length();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
JSONObject fo = a.getJSONObject(i);
|
||||
String type = fo.has("type") ? fo.getString("type") : "list";
|
||||
|
||||
Facet facet = null;
|
||||
if ("list".equals(type)) {
|
||||
facet = new ListFacet();
|
||||
} else if ("range".equals(type)) {
|
||||
facet = new RangeFacet();
|
||||
} else if ("text".equals(type)) {
|
||||
facet = new TextSearchFacet();
|
||||
}
|
||||
|
||||
if (facet != null) {
|
||||
facet.initializeFromJSON(_project, fo);
|
||||
_facets.add(facet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void computeFacets() throws JSONException {
|
||||
for (Facet facet : _facets) {
|
||||
FilteredRows filteredRows = getFilteredRows(facet, false);
|
||||
|
||||
facet.computeChoices(_project, filteredRows);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("facets"); writer.array();
|
||||
for (Facet facet : _facets) {
|
||||
facet.write(writer, options);
|
||||
}
|
||||
writer.endArray();
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ package com.metaweb.gridworks.browsing;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public interface FilteredRows {
|
||||
public void accept(Project project, RowVisitor visitor);
|
||||
public void accept(Project project, RowVisitor visitor);
|
||||
}
|
||||
|
@ -4,6 +4,6 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
public interface RowVisitor {
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual);
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual);
|
||||
|
||||
}
|
||||
|
@ -13,55 +13,55 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
public class ExpressionNominalRowGrouper implements RowVisitor {
|
||||
final protected Evaluable _evaluable;
|
||||
final protected int _cellIndex;
|
||||
|
||||
final public Map<Object, NominalFacetChoice> choices = new HashMap<Object, NominalFacetChoice>();
|
||||
public int blankCount = 0;
|
||||
public int errorCount = 0;
|
||||
|
||||
public ExpressionNominalRowGrouper(Evaluable evaluable, int cellIndex) {
|
||||
_evaluable = evaluable;
|
||||
_cellIndex = cellIndex;
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
final protected Evaluable _evaluable;
|
||||
final protected int _cellIndex;
|
||||
|
||||
final public Map<Object, NominalFacetChoice> choices = new HashMap<Object, NominalFacetChoice>();
|
||||
public int blankCount = 0;
|
||||
public int errorCount = 0;
|
||||
|
||||
public ExpressionNominalRowGrouper(Evaluable evaluable, int cellIndex) {
|
||||
_evaluable = evaluable;
|
||||
_cellIndex = cellIndex;
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
|
||||
Object value = _evaluable.evaluate(bindings);
|
||||
if (value != null && value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
processValue(v);
|
||||
}
|
||||
} else {
|
||||
processValue(value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void processValue(Object value) {
|
||||
|
||||
Object value = _evaluable.evaluate(bindings);
|
||||
if (value != null && value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
processValue(v);
|
||||
}
|
||||
} else {
|
||||
processValue(value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void processValue(Object value) {
|
||||
if (ExpressionUtils.isError(value)) {
|
||||
errorCount++;
|
||||
} else if (ExpressionUtils.isNonBlankData(value)) {
|
||||
String valueString = value.toString();
|
||||
String label = value.toString();
|
||||
|
||||
DecoratedValue dValue = new DecoratedValue(value, label);
|
||||
|
||||
if (choices.containsKey(valueString)) {
|
||||
choices.get(valueString).count++;
|
||||
} else {
|
||||
NominalFacetChoice choice = new NominalFacetChoice(dValue);
|
||||
choice.count = 1;
|
||||
|
||||
choices.put(valueString, choice);
|
||||
}
|
||||
String valueString = value.toString();
|
||||
String label = value.toString();
|
||||
|
||||
DecoratedValue dValue = new DecoratedValue(value, label);
|
||||
|
||||
if (choices.containsKey(valueString)) {
|
||||
choices.get(valueString).count++;
|
||||
} else {
|
||||
NominalFacetChoice choice = new NominalFacetChoice(dValue);
|
||||
choice.count = 1;
|
||||
|
||||
choices.put(valueString, choice);
|
||||
}
|
||||
} else {
|
||||
blankCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,46 +10,46 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
public class ExpressionNumericRowBinner implements RowVisitor {
|
||||
final protected Evaluable _evaluable;
|
||||
final protected int _cellIndex;
|
||||
final protected NumericBinIndex _index;
|
||||
|
||||
final public int[] bins;
|
||||
|
||||
public ExpressionNumericRowBinner(Evaluable evaluable, int cellIndex, NumericBinIndex index) {
|
||||
_evaluable = evaluable;
|
||||
_cellIndex = cellIndex;
|
||||
_index = index;
|
||||
bins = new int[_index.getBins().length];
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
final protected Evaluable _evaluable;
|
||||
final protected int _cellIndex;
|
||||
final protected NumericBinIndex _index;
|
||||
|
||||
final public int[] bins;
|
||||
|
||||
public ExpressionNumericRowBinner(Evaluable evaluable, int cellIndex, NumericBinIndex index) {
|
||||
_evaluable = evaluable;
|
||||
_cellIndex = cellIndex;
|
||||
_index = index;
|
||||
bins = new int[_index.getBins().length];
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
|
||||
Object value = _evaluable.evaluate(bindings);
|
||||
if (value != null) {
|
||||
if (value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
processValue(v);
|
||||
}
|
||||
} else {
|
||||
processValue(value);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void processValue(Object value) {
|
||||
if (value instanceof Number) {
|
||||
double d = ((Number) value).doubleValue();
|
||||
|
||||
int bin = (int) Math.round((d - _index.getMin()) / _index.getStep());
|
||||
|
||||
bins[bin]++;
|
||||
}
|
||||
}
|
||||
|
||||
Object value = _evaluable.evaluate(bindings);
|
||||
if (value != null) {
|
||||
if (value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
processValue(v);
|
||||
}
|
||||
} else {
|
||||
processValue(value);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void processValue(Object value) {
|
||||
if (value instanceof Number) {
|
||||
double d = ((Number) value).doubleValue();
|
||||
|
||||
int bin = (int) Math.round((d - _index.getMin()) / _index.getStep());
|
||||
|
||||
bins[bin]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ import com.metaweb.gridworks.browsing.filters.RowFilter;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public interface Facet extends Jsonizable {
|
||||
public RowFilter getRowFilter();
|
||||
|
||||
public void computeChoices(Project project, FilteredRows filteredRows);
|
||||
|
||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception;
|
||||
public RowFilter getRowFilter();
|
||||
|
||||
public void computeChoices(Project project, FilteredRows filteredRows);
|
||||
|
||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception;
|
||||
}
|
||||
|
@ -18,45 +18,45 @@ import com.metaweb.gridworks.expr.MetaParser;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class ListFacet implements Facet {
|
||||
protected List<NominalFacetChoice> _selection = new LinkedList<NominalFacetChoice>();
|
||||
protected boolean _selectBlank;
|
||||
protected boolean _selectError;
|
||||
|
||||
protected String _name;
|
||||
protected String _expression;
|
||||
protected String _columnName;
|
||||
protected int _cellIndex;
|
||||
protected Evaluable _eval;
|
||||
|
||||
// computed
|
||||
protected List<NominalFacetChoice> _selection = new LinkedList<NominalFacetChoice>();
|
||||
protected boolean _selectBlank;
|
||||
protected boolean _selectError;
|
||||
|
||||
protected String _name;
|
||||
protected String _expression;
|
||||
protected String _columnName;
|
||||
protected int _cellIndex;
|
||||
protected Evaluable _eval;
|
||||
|
||||
// computed
|
||||
protected List<NominalFacetChoice> _choices = new LinkedList<NominalFacetChoice>();
|
||||
protected int _blankCount;
|
||||
protected int _errorCount;
|
||||
|
||||
public ListFacet() {
|
||||
}
|
||||
public ListFacet() {
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("name"); writer.value(_name);
|
||||
writer.key("expression"); writer.value(_expression);
|
||||
writer.key("columnName"); writer.value(_columnName);
|
||||
|
||||
writer.key("choices"); writer.array();
|
||||
for (NominalFacetChoice choice : _choices) {
|
||||
choice.write(writer, options);
|
||||
}
|
||||
writer.endArray();
|
||||
|
||||
if (_selectBlank || _blankCount > 0) {
|
||||
writer.key("blankChoice");
|
||||
writer.object();
|
||||
writer.key("s"); writer.value(_selectBlank);
|
||||
writer.key("c"); writer.value(_blankCount);
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("name"); writer.value(_name);
|
||||
writer.key("expression"); writer.value(_expression);
|
||||
writer.key("columnName"); writer.value(_columnName);
|
||||
|
||||
writer.key("choices"); writer.array();
|
||||
for (NominalFacetChoice choice : _choices) {
|
||||
choice.write(writer, options);
|
||||
}
|
||||
writer.endArray();
|
||||
|
||||
if (_selectBlank || _blankCount > 0) {
|
||||
writer.key("blankChoice");
|
||||
writer.object();
|
||||
writer.key("s"); writer.value(_selectBlank);
|
||||
writer.key("c"); writer.value(_blankCount);
|
||||
writer.endObject();
|
||||
}
|
||||
if (_selectError || _errorCount > 0) {
|
||||
writer.key("errorChoice");
|
||||
writer.object();
|
||||
@ -64,76 +64,76 @@ public class ListFacet implements Facet {
|
||||
writer.key("c"); writer.value(_errorCount);
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
|
||||
_name = o.getString("name");
|
||||
_expression = o.getString("expression");
|
||||
_columnName = o.getString("columnName");
|
||||
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
|
||||
|
||||
_eval = MetaParser.parse(_expression);
|
||||
_selection.clear();
|
||||
|
||||
JSONArray a = o.getJSONArray("selection");
|
||||
int length = a.length();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
JSONObject oc = a.getJSONObject(i);
|
||||
JSONObject ocv = oc.getJSONObject("v");
|
||||
|
||||
DecoratedValue decoratedValue = new DecoratedValue(
|
||||
ocv.get("v"), ocv.getString("l"));
|
||||
|
||||
NominalFacetChoice nominalFacetChoice = new NominalFacetChoice(decoratedValue);
|
||||
nominalFacetChoice.selected = true;
|
||||
|
||||
_selection.add(nominalFacetChoice);
|
||||
}
|
||||
|
||||
if (o.has("selectBlank")) {
|
||||
_selectBlank = o.getBoolean("selectBlank");
|
||||
}
|
||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
|
||||
_name = o.getString("name");
|
||||
_expression = o.getString("expression");
|
||||
_columnName = o.getString("columnName");
|
||||
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
|
||||
|
||||
_eval = MetaParser.parse(_expression);
|
||||
_selection.clear();
|
||||
|
||||
JSONArray a = o.getJSONArray("selection");
|
||||
int length = a.length();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
JSONObject oc = a.getJSONObject(i);
|
||||
JSONObject ocv = oc.getJSONObject("v");
|
||||
|
||||
DecoratedValue decoratedValue = new DecoratedValue(
|
||||
ocv.get("v"), ocv.getString("l"));
|
||||
|
||||
NominalFacetChoice nominalFacetChoice = new NominalFacetChoice(decoratedValue);
|
||||
nominalFacetChoice.selected = true;
|
||||
|
||||
_selection.add(nominalFacetChoice);
|
||||
}
|
||||
|
||||
if (o.has("selectBlank")) {
|
||||
_selectBlank = o.getBoolean("selectBlank");
|
||||
}
|
||||
if (o.has("selectError")) {
|
||||
_selectError = o.getBoolean("selectError");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RowFilter getRowFilter() {
|
||||
return _selection.size() == 0 && !_selectBlank && !_selectError ? null :
|
||||
new ExpressionEqualRowFilter(_eval, _cellIndex, createMatches(), _selectBlank, _selectError);
|
||||
}
|
||||
public RowFilter getRowFilter() {
|
||||
return _selection.size() == 0 && !_selectBlank && !_selectError ? null :
|
||||
new ExpressionEqualRowFilter(_eval, _cellIndex, createMatches(), _selectBlank, _selectError);
|
||||
}
|
||||
|
||||
public void computeChoices(Project project, FilteredRows filteredRows) {
|
||||
ExpressionNominalRowGrouper grouper =
|
||||
new ExpressionNominalRowGrouper(_eval, _cellIndex);
|
||||
|
||||
filteredRows.accept(project, grouper);
|
||||
|
||||
_choices.clear();
|
||||
_choices.addAll(grouper.choices.values());
|
||||
|
||||
for (NominalFacetChoice choice : _selection) {
|
||||
String valueString = choice.decoratedValue.value.toString();
|
||||
if (grouper.choices.containsKey(valueString)) {
|
||||
grouper.choices.get(valueString).selected = true;
|
||||
} else {
|
||||
choice.count = 0;
|
||||
_choices.add(choice);
|
||||
}
|
||||
}
|
||||
|
||||
_blankCount = grouper.blankCount;
|
||||
_errorCount = grouper.errorCount;
|
||||
}
|
||||
|
||||
protected Object[] createMatches() {
|
||||
Object[] a = new Object[_selection.size()];
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
a[i] = _selection.get(i).decoratedValue.value;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
public void computeChoices(Project project, FilteredRows filteredRows) {
|
||||
ExpressionNominalRowGrouper grouper =
|
||||
new ExpressionNominalRowGrouper(_eval, _cellIndex);
|
||||
|
||||
filteredRows.accept(project, grouper);
|
||||
|
||||
_choices.clear();
|
||||
_choices.addAll(grouper.choices.values());
|
||||
|
||||
for (NominalFacetChoice choice : _selection) {
|
||||
String valueString = choice.decoratedValue.value.toString();
|
||||
if (grouper.choices.containsKey(valueString)) {
|
||||
grouper.choices.get(valueString).selected = true;
|
||||
} else {
|
||||
choice.count = 0;
|
||||
_choices.add(choice);
|
||||
}
|
||||
}
|
||||
|
||||
_blankCount = grouper.blankCount;
|
||||
_errorCount = grouper.errorCount;
|
||||
}
|
||||
|
||||
protected Object[] createMatches() {
|
||||
Object[] a = new Object[_selection.size()];
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
a[i] = _selection.get(i).decoratedValue.value;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
@ -9,20 +9,20 @@ import com.metaweb.gridworks.Jsonizable;
|
||||
import com.metaweb.gridworks.browsing.DecoratedValue;
|
||||
|
||||
public class NominalFacetChoice implements Jsonizable {
|
||||
final public DecoratedValue decoratedValue;
|
||||
public int count;
|
||||
public boolean selected;
|
||||
|
||||
public NominalFacetChoice(DecoratedValue decoratedValue) {
|
||||
this.decoratedValue = decoratedValue;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
writer.object();
|
||||
writer.key("v"); decoratedValue.write(writer, options);
|
||||
writer.key("c"); writer.value(count);
|
||||
writer.key("s"); writer.value(selected);
|
||||
writer.endObject();
|
||||
}
|
||||
final public DecoratedValue decoratedValue;
|
||||
public int count;
|
||||
public boolean selected;
|
||||
|
||||
public NominalFacetChoice(DecoratedValue decoratedValue) {
|
||||
this.decoratedValue = decoratedValue;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
writer.object();
|
||||
writer.key("v"); decoratedValue.write(writer, options);
|
||||
writer.key("c"); writer.value(count);
|
||||
writer.key("s"); writer.value(selected);
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,92 +11,92 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
public class NumericBinIndex {
|
||||
private double _min;
|
||||
private double _max;
|
||||
private double _step;
|
||||
private int[] _bins;
|
||||
|
||||
public NumericBinIndex(Project project, int cellIndex, Evaluable eval) {
|
||||
private double _min;
|
||||
private double _max;
|
||||
private double _step;
|
||||
private int[] _bins;
|
||||
|
||||
public NumericBinIndex(Project project, int cellIndex, Evaluable eval) {
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
|
||||
_min = Double.POSITIVE_INFINITY;
|
||||
_max = Double.NEGATIVE_INFINITY;
|
||||
|
||||
List<Double> allValues = new ArrayList<Double>();
|
||||
for (int i = 0; i < project.rows.size(); i++) {
|
||||
Row row = project.rows.get(i);
|
||||
Cell cell = row.getCell(cellIndex);
|
||||
|
||||
_min = Double.POSITIVE_INFINITY;
|
||||
_max = Double.NEGATIVE_INFINITY;
|
||||
|
||||
List<Double> allValues = new ArrayList<Double>();
|
||||
for (int i = 0; i < project.rows.size(); i++) {
|
||||
Row row = project.rows.get(i);
|
||||
Cell cell = row.getCell(cellIndex);
|
||||
|
||||
ExpressionUtils.bind(bindings, row, i, cell);
|
||||
|
||||
Object value = eval.evaluate(bindings);
|
||||
if (value != null) {
|
||||
if (value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
if (v instanceof Number) {
|
||||
processValue(((Number) v).doubleValue(), allValues);
|
||||
}
|
||||
}
|
||||
} else if (value instanceof Number) {
|
||||
processValue(((Number) value).doubleValue(), allValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_min >= _max) {
|
||||
_step = 0;
|
||||
_bins = new int[1];
|
||||
return;
|
||||
}
|
||||
|
||||
double diff = getMax() - getMin();
|
||||
_step = 1;
|
||||
if (diff > 10) {
|
||||
while (getStep() * 100 < diff) {
|
||||
_step *= 10;
|
||||
}
|
||||
} else {
|
||||
while (getStep() * 100 > diff) {
|
||||
_step /= 10;
|
||||
}
|
||||
}
|
||||
|
||||
_min = (Math.floor(_min / _step) * _step);
|
||||
_max = (Math.ceil(_max / _step) * _step);
|
||||
|
||||
int binCount = 1 + (int) Math.ceil((getMax() - getMin()) / getStep());
|
||||
if (binCount > 100) {
|
||||
_step *= 2;
|
||||
binCount = Math.round((1 + binCount) / 2);
|
||||
}
|
||||
|
||||
_bins = new int[binCount];
|
||||
for (double d : allValues) {
|
||||
int bin = (int) Math.round((d - _min) / _step);
|
||||
_bins[bin]++;
|
||||
}
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
return _min;
|
||||
}
|
||||
|
||||
Object value = eval.evaluate(bindings);
|
||||
if (value != null) {
|
||||
if (value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
if (v instanceof Number) {
|
||||
processValue(((Number) v).doubleValue(), allValues);
|
||||
}
|
||||
}
|
||||
} else if (value instanceof Number) {
|
||||
processValue(((Number) value).doubleValue(), allValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_min >= _max) {
|
||||
_step = 0;
|
||||
_bins = new int[1];
|
||||
return;
|
||||
}
|
||||
|
||||
double diff = getMax() - getMin();
|
||||
_step = 1;
|
||||
if (diff > 10) {
|
||||
while (getStep() * 100 < diff) {
|
||||
_step *= 10;
|
||||
}
|
||||
} else {
|
||||
while (getStep() * 100 > diff) {
|
||||
_step /= 10;
|
||||
}
|
||||
}
|
||||
|
||||
_min = (Math.floor(_min / _step) * _step);
|
||||
_max = (Math.ceil(_max / _step) * _step);
|
||||
|
||||
int binCount = 1 + (int) Math.ceil((getMax() - getMin()) / getStep());
|
||||
if (binCount > 100) {
|
||||
_step *= 2;
|
||||
binCount = Math.round((1 + binCount) / 2);
|
||||
}
|
||||
|
||||
_bins = new int[binCount];
|
||||
for (double d : allValues) {
|
||||
int bin = (int) Math.round((d - _min) / _step);
|
||||
_bins[bin]++;
|
||||
}
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
return _min;
|
||||
}
|
||||
|
||||
public double getMax() {
|
||||
return _max;
|
||||
}
|
||||
public double getMax() {
|
||||
return _max;
|
||||
}
|
||||
|
||||
public double getStep() {
|
||||
return _step;
|
||||
}
|
||||
public double getStep() {
|
||||
return _step;
|
||||
}
|
||||
|
||||
public int[] getBins() {
|
||||
return _bins;
|
||||
}
|
||||
public int[] getBins() {
|
||||
return _bins;
|
||||
}
|
||||
|
||||
protected void processValue(double v, List<Double> allValues) {
|
||||
_min = Math.min(getMin(), v);
|
||||
_max = Math.max(getMax(), v);
|
||||
allValues.add(v);
|
||||
}
|
||||
protected void processValue(double v, List<Double> allValues) {
|
||||
_min = Math.min(getMin(), v);
|
||||
_max = Math.max(getMax(), v);
|
||||
allValues.add(v);
|
||||
}
|
||||
}
|
||||
|
@ -15,147 +15,147 @@ import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class RangeFacet implements Facet {
|
||||
protected String _name;
|
||||
protected String _expression;
|
||||
protected String _columnName;
|
||||
protected int _cellIndex;
|
||||
protected Evaluable _eval;
|
||||
|
||||
protected String _mode;
|
||||
protected double _min;
|
||||
protected double _max;
|
||||
protected double _step;
|
||||
protected int[] _baseBins;
|
||||
protected int[] _bins;
|
||||
|
||||
protected double _from;
|
||||
protected double _to;
|
||||
protected boolean _selected;
|
||||
|
||||
public RangeFacet() {
|
||||
}
|
||||
protected String _name;
|
||||
protected String _expression;
|
||||
protected String _columnName;
|
||||
protected int _cellIndex;
|
||||
protected Evaluable _eval;
|
||||
|
||||
protected String _mode;
|
||||
protected double _min;
|
||||
protected double _max;
|
||||
protected double _step;
|
||||
protected int[] _baseBins;
|
||||
protected int[] _bins;
|
||||
|
||||
protected double _from;
|
||||
protected double _to;
|
||||
protected boolean _selected;
|
||||
|
||||
public RangeFacet() {
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("name"); writer.value(_name);
|
||||
writer.key("expression"); writer.value(_expression);
|
||||
writer.key("columnName"); writer.value(_columnName);
|
||||
writer.key("mode"); writer.value(_mode);
|
||||
|
||||
if (!Double.isInfinite(_min) && !Double.isInfinite(_max)) {
|
||||
writer.key("min"); writer.value(_min);
|
||||
writer.key("max"); writer.value(_max);
|
||||
writer.key("step"); writer.value(_step);
|
||||
|
||||
writer.key("bins"); writer.array();
|
||||
for (int b : _bins) {
|
||||
writer.value(b);
|
||||
}
|
||||
writer.endArray();
|
||||
|
||||
writer.key("baseBins"); writer.array();
|
||||
for (int b : _baseBins) {
|
||||
writer.value(b);
|
||||
}
|
||||
writer.endArray();
|
||||
|
||||
if ("min".equals(_mode)) {
|
||||
writer.key("from"); writer.value(_from);
|
||||
} else if ("max".equals(_mode)) {
|
||||
writer.key("to"); writer.value(_to);
|
||||
} else {
|
||||
writer.key("from"); writer.value(_from);
|
||||
writer.key("to"); writer.value(_to);
|
||||
}
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("name"); writer.value(_name);
|
||||
writer.key("expression"); writer.value(_expression);
|
||||
writer.key("columnName"); writer.value(_columnName);
|
||||
writer.key("mode"); writer.value(_mode);
|
||||
|
||||
if (!Double.isInfinite(_min) && !Double.isInfinite(_max)) {
|
||||
writer.key("min"); writer.value(_min);
|
||||
writer.key("max"); writer.value(_max);
|
||||
writer.key("step"); writer.value(_step);
|
||||
|
||||
writer.key("bins"); writer.array();
|
||||
for (int b : _bins) {
|
||||
writer.value(b);
|
||||
}
|
||||
writer.endArray();
|
||||
|
||||
writer.key("baseBins"); writer.array();
|
||||
for (int b : _baseBins) {
|
||||
writer.value(b);
|
||||
}
|
||||
writer.endArray();
|
||||
|
||||
if ("min".equals(_mode)) {
|
||||
writer.key("from"); writer.value(_from);
|
||||
} else if ("max".equals(_mode)) {
|
||||
writer.key("to"); writer.value(_to);
|
||||
} else {
|
||||
writer.key("from"); writer.value(_from);
|
||||
writer.key("to"); writer.value(_to);
|
||||
}
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
|
||||
_name = o.getString("name");
|
||||
_expression = o.getString("expression");
|
||||
_columnName = o.getString("columnName");
|
||||
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
|
||||
|
||||
_eval = MetaParser.parse(_expression);
|
||||
|
||||
_mode = o.getString("mode");
|
||||
if ("min".equals(_mode)) {
|
||||
if (o.has("from")) {
|
||||
_from = o.getDouble("from");
|
||||
_selected = true;
|
||||
}
|
||||
} else if ("max".equals(_mode)) {
|
||||
if (o.has("to")) {
|
||||
_to = o.getDouble("to");
|
||||
_selected = true;
|
||||
}
|
||||
} else {
|
||||
if (o.has("from") && o.has("to")) {
|
||||
_from = o.getDouble("from");
|
||||
_to = o.getDouble("to");
|
||||
_selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
|
||||
_name = o.getString("name");
|
||||
_expression = o.getString("expression");
|
||||
_columnName = o.getString("columnName");
|
||||
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
|
||||
|
||||
_eval = MetaParser.parse(_expression);
|
||||
|
||||
_mode = o.getString("mode");
|
||||
if ("min".equals(_mode)) {
|
||||
if (o.has("from")) {
|
||||
_from = o.getDouble("from");
|
||||
_selected = true;
|
||||
}
|
||||
} else if ("max".equals(_mode)) {
|
||||
if (o.has("to")) {
|
||||
_to = o.getDouble("to");
|
||||
_selected = true;
|
||||
}
|
||||
} else {
|
||||
if (o.has("from") && o.has("to")) {
|
||||
_from = o.getDouble("from");
|
||||
_to = o.getDouble("to");
|
||||
_selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RowFilter getRowFilter() {
|
||||
if (_selected) {
|
||||
if ("min".equals(_mode)) {
|
||||
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
|
||||
protected boolean checkValue(double d) {
|
||||
return d >= _from;
|
||||
};
|
||||
};
|
||||
} else if ("max".equals(_mode)) {
|
||||
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
|
||||
protected boolean checkValue(double d) {
|
||||
return d <= _to;
|
||||
};
|
||||
};
|
||||
} else {
|
||||
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
|
||||
protected boolean checkValue(double d) {
|
||||
return d >= _from && d <= _to;
|
||||
};
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public RowFilter getRowFilter() {
|
||||
if (_selected) {
|
||||
if ("min".equals(_mode)) {
|
||||
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
|
||||
protected boolean checkValue(double d) {
|
||||
return d >= _from;
|
||||
};
|
||||
};
|
||||
} else if ("max".equals(_mode)) {
|
||||
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
|
||||
protected boolean checkValue(double d) {
|
||||
return d <= _to;
|
||||
};
|
||||
};
|
||||
} else {
|
||||
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
|
||||
protected boolean checkValue(double d) {
|
||||
return d >= _from && d <= _to;
|
||||
};
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void computeChoices(Project project, FilteredRows filteredRows) {
|
||||
Column column = project.columnModel.getColumnByCellIndex(_cellIndex);
|
||||
|
||||
String key = "numeric-bin:" + _expression;
|
||||
NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key);
|
||||
if (index == null) {
|
||||
index = new NumericBinIndex(project, _cellIndex, _eval);
|
||||
column.setPrecompute(key, index);
|
||||
}
|
||||
|
||||
_min = index.getMin();
|
||||
_max = index.getMax();
|
||||
_step = index.getStep();
|
||||
_baseBins = index.getBins();
|
||||
|
||||
if (_selected) {
|
||||
_from = Math.max(_from, _min);
|
||||
_to = Math.min(_to, _max);
|
||||
} else {
|
||||
_from = _min;
|
||||
_to = _max;
|
||||
}
|
||||
|
||||
ExpressionNumericRowBinner binner =
|
||||
new ExpressionNumericRowBinner(_eval, _cellIndex, index);
|
||||
|
||||
filteredRows.accept(project, binner);
|
||||
|
||||
_bins = binner.bins;
|
||||
}
|
||||
public void computeChoices(Project project, FilteredRows filteredRows) {
|
||||
Column column = project.columnModel.getColumnByCellIndex(_cellIndex);
|
||||
|
||||
String key = "numeric-bin:" + _expression;
|
||||
NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key);
|
||||
if (index == null) {
|
||||
index = new NumericBinIndex(project, _cellIndex, _eval);
|
||||
column.setPrecompute(key, index);
|
||||
}
|
||||
|
||||
_min = index.getMin();
|
||||
_max = index.getMax();
|
||||
_step = index.getStep();
|
||||
_baseBins = index.getBins();
|
||||
|
||||
if (_selected) {
|
||||
_from = Math.max(_from, _min);
|
||||
_to = Math.min(_to, _max);
|
||||
} else {
|
||||
_from = _min;
|
||||
_to = _max;
|
||||
}
|
||||
|
||||
ExpressionNumericRowBinner binner =
|
||||
new ExpressionNumericRowBinner(_eval, _cellIndex, index);
|
||||
|
||||
filteredRows.accept(project, binner);
|
||||
|
||||
_bins = binner.bins;
|
||||
}
|
||||
}
|
||||
|
@ -14,71 +14,71 @@ import com.metaweb.gridworks.gel.ast.VariableExpr;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class TextSearchFacet implements Facet {
|
||||
protected String _name;
|
||||
protected String _columnName;
|
||||
protected int _cellIndex;
|
||||
protected String _query;
|
||||
|
||||
protected String _mode;
|
||||
protected boolean _caseSensitive;
|
||||
|
||||
public TextSearchFacet() {
|
||||
}
|
||||
protected String _name;
|
||||
protected String _columnName;
|
||||
protected int _cellIndex;
|
||||
protected String _query;
|
||||
|
||||
protected String _mode;
|
||||
protected boolean _caseSensitive;
|
||||
|
||||
public TextSearchFacet() {
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("name"); writer.value(_name);
|
||||
writer.key("columnName"); writer.value(_columnName);
|
||||
writer.key("query"); writer.value(_query);
|
||||
writer.key("mode"); writer.value(_mode);
|
||||
writer.key("caseSensitive"); writer.value(_caseSensitive);
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("name"); writer.value(_name);
|
||||
writer.key("columnName"); writer.value(_columnName);
|
||||
writer.key("query"); writer.value(_query);
|
||||
writer.key("mode"); writer.value(_mode);
|
||||
writer.key("caseSensitive"); writer.value(_caseSensitive);
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
|
||||
_name = o.getString("name");
|
||||
_columnName = o.getString("columnName");
|
||||
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
|
||||
|
||||
if (!o.isNull("query")) {
|
||||
_query = o.getString("query");
|
||||
}
|
||||
|
||||
_mode = o.getString("mode");
|
||||
_caseSensitive = o.getBoolean("caseSensitive");
|
||||
if (_query != null) {
|
||||
_query = _query.trim();
|
||||
if (!_caseSensitive) {
|
||||
_query = _query.toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
|
||||
_name = o.getString("name");
|
||||
_columnName = o.getString("columnName");
|
||||
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
|
||||
|
||||
if (!o.isNull("query")) {
|
||||
_query = o.getString("query");
|
||||
}
|
||||
|
||||
_mode = o.getString("mode");
|
||||
_caseSensitive = o.getBoolean("caseSensitive");
|
||||
if (_query != null) {
|
||||
_query = _query.trim();
|
||||
if (!_caseSensitive) {
|
||||
_query = _query.toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RowFilter getRowFilter() {
|
||||
if (_query == null || _query.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Evaluable eval = new VariableExpr("value");
|
||||
|
||||
if ("regex".equals(_mode)) {
|
||||
return new ExpressionStringComparisonRowFilter(eval, _cellIndex) {
|
||||
protected boolean checkValue(String s) {
|
||||
return s.matches(_query);
|
||||
};
|
||||
};
|
||||
} else {
|
||||
return new ExpressionStringComparisonRowFilter(eval, _cellIndex) {
|
||||
protected boolean checkValue(String s) {
|
||||
return (_caseSensitive ? s : s.toLowerCase()).contains(_query);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
public RowFilter getRowFilter() {
|
||||
if (_query == null || _query.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Evaluable eval = new VariableExpr("value");
|
||||
|
||||
if ("regex".equals(_mode)) {
|
||||
return new ExpressionStringComparisonRowFilter(eval, _cellIndex) {
|
||||
protected boolean checkValue(String s) {
|
||||
return s.matches(_query);
|
||||
};
|
||||
};
|
||||
} else {
|
||||
return new ExpressionStringComparisonRowFilter(eval, _cellIndex) {
|
||||
protected boolean checkValue(String s) {
|
||||
return (_caseSensitive ? s : s.toLowerCase()).contains(_query);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void computeChoices(Project project, FilteredRows filteredRows) {
|
||||
// nothing to do
|
||||
}
|
||||
public void computeChoices(Project project, FilteredRows filteredRows) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
|
@ -9,57 +9,57 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
public class ExpressionEqualRowFilter implements RowFilter {
|
||||
final protected Evaluable _evaluable;
|
||||
final protected int _cellIndex;
|
||||
final protected Object[] _matches;
|
||||
final protected boolean _selectBlank;
|
||||
final protected boolean _selectError;
|
||||
|
||||
public ExpressionEqualRowFilter(Evaluable evaluable, int cellIndex, Object[] matches, boolean selectBlank, boolean selectError) {
|
||||
_evaluable = evaluable;
|
||||
_cellIndex = cellIndex;
|
||||
_matches = matches;
|
||||
_selectBlank = selectBlank;
|
||||
_selectError = selectError;
|
||||
}
|
||||
final protected Evaluable _evaluable;
|
||||
final protected int _cellIndex;
|
||||
final protected Object[] _matches;
|
||||
final protected boolean _selectBlank;
|
||||
final protected boolean _selectError;
|
||||
|
||||
public ExpressionEqualRowFilter(Evaluable evaluable, int cellIndex, Object[] matches, boolean selectBlank, boolean selectError) {
|
||||
_evaluable = evaluable;
|
||||
_cellIndex = cellIndex;
|
||||
_matches = matches;
|
||||
_selectBlank = selectBlank;
|
||||
_selectError = selectError;
|
||||
}
|
||||
|
||||
public boolean filterRow(Project project, int rowIndex, Row row) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
public boolean filterRow(Project project, int rowIndex, Row row) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
|
||||
Object value = _evaluable.evaluate(bindings);
|
||||
if (value != null && value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
if (testValue(v)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return testValue(value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean testValue(Object v) {
|
||||
if (ExpressionUtils.isError(v)) {
|
||||
return _selectError;
|
||||
} else if (ExpressionUtils.isNonBlankData(v)) {
|
||||
|
||||
Object value = _evaluable.evaluate(bindings);
|
||||
if (value != null && value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
if (testValue(v)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return testValue(value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean testValue(Object v) {
|
||||
if (ExpressionUtils.isError(v)) {
|
||||
return _selectError;
|
||||
} else if (ExpressionUtils.isNonBlankData(v)) {
|
||||
for (Object match : _matches) {
|
||||
if (testValue(v, match)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return _selectBlank;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean testValue(Object v, Object match) {
|
||||
return (v instanceof Number && match instanceof Number) ?
|
||||
((Number) match).doubleValue() == ((Number) v).doubleValue() :
|
||||
match.equals(v);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return _selectBlank;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean testValue(Object v, Object match) {
|
||||
return (v instanceof Number && match instanceof Number) ?
|
||||
((Number) match).doubleValue() == ((Number) v).doubleValue() :
|
||||
match.equals(v);
|
||||
}
|
||||
}
|
||||
|
@ -9,37 +9,37 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
abstract public class ExpressionNumberComparisonRowFilter implements RowFilter {
|
||||
final protected Evaluable _evaluable;
|
||||
final protected int _cellIndex;
|
||||
|
||||
public ExpressionNumberComparisonRowFilter(Evaluable evaluable, int cellIndex) {
|
||||
_evaluable = evaluable;
|
||||
_cellIndex = cellIndex;
|
||||
}
|
||||
final protected Evaluable _evaluable;
|
||||
final protected int _cellIndex;
|
||||
|
||||
public ExpressionNumberComparisonRowFilter(Evaluable evaluable, int cellIndex) {
|
||||
_evaluable = evaluable;
|
||||
_cellIndex = cellIndex;
|
||||
}
|
||||
|
||||
public boolean filterRow(Project project, int rowIndex, Row row) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
public boolean filterRow(Project project, int rowIndex, Row row) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
|
||||
Object value = _evaluable.evaluate(bindings);
|
||||
if (value != null) {
|
||||
if (value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
if (v instanceof Number && checkValue(((Number) v).doubleValue())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (value instanceof Number && checkValue(((Number) value).doubleValue())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
abstract protected boolean checkValue(double d);
|
||||
|
||||
Object value = _evaluable.evaluate(bindings);
|
||||
if (value != null) {
|
||||
if (value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
if (v instanceof Number && checkValue(((Number) v).doubleValue())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (value instanceof Number && checkValue(((Number) value).doubleValue())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
abstract protected boolean checkValue(double d);
|
||||
}
|
||||
|
@ -9,36 +9,36 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
abstract public class ExpressionStringComparisonRowFilter implements RowFilter {
|
||||
final protected Evaluable _evaluable;
|
||||
final protected int _cellIndex;
|
||||
|
||||
public ExpressionStringComparisonRowFilter(Evaluable evaluable, int cellIndex) {
|
||||
_evaluable = evaluable;
|
||||
_cellIndex = cellIndex;
|
||||
}
|
||||
final protected Evaluable _evaluable;
|
||||
final protected int _cellIndex;
|
||||
|
||||
public ExpressionStringComparisonRowFilter(Evaluable evaluable, int cellIndex) {
|
||||
_evaluable = evaluable;
|
||||
_cellIndex = cellIndex;
|
||||
}
|
||||
|
||||
public boolean filterRow(Project project, int rowIndex, Row row) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
public boolean filterRow(Project project, int rowIndex, Row row) {
|
||||
Cell cell = row.getCell(_cellIndex);
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
|
||||
Object value = _evaluable.evaluate(bindings);
|
||||
if (value != null) {
|
||||
if (value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
if (checkValue(v instanceof String ? ((String) v) : v.toString())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (checkValue(value instanceof String ? ((String) value) : value.toString())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
abstract protected boolean checkValue(String s);
|
||||
|
||||
Object value = _evaluable.evaluate(bindings);
|
||||
if (value != null) {
|
||||
if (value.getClass().isArray()) {
|
||||
Object[] a = (Object[]) value;
|
||||
for (Object v : a) {
|
||||
if (checkValue(v instanceof String ? ((String) v) : v.toString())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (checkValue(value instanceof String ? ((String) value) : value.toString())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
abstract protected boolean checkValue(String s);
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
public interface RowFilter {
|
||||
public boolean filterRow(Project project, int rowIndex, Row row);
|
||||
public boolean filterRow(Project project, int rowIndex, Row row);
|
||||
}
|
||||
|
@ -32,160 +32,160 @@ import com.oreilly.servlet.multipart.Part;
|
||||
|
||||
public abstract class Command {
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
throw new NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
};
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
throw new NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
};
|
||||
|
||||
protected Project getProject(HttpServletRequest request) throws ServletException {
|
||||
try {
|
||||
Project p = ProjectManager.singleton.getProject(Long.parseLong(request.getParameter("project")));
|
||||
if (p != null) {
|
||||
return p;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
throw new ServletException("Missing or bad project URL parameter");
|
||||
try {
|
||||
Project p = ProjectManager.singleton.getProject(Long.parseLong(request.getParameter("project")));
|
||||
if (p != null) {
|
||||
return p;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
throw new ServletException("Missing or bad project URL parameter");
|
||||
}
|
||||
|
||||
protected int getIntegerParameter(HttpServletRequest request, String name, int def) throws ServletException {
|
||||
try {
|
||||
return Integer.parseInt(request.getParameter(name));
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return def;
|
||||
try {
|
||||
return Integer.parseInt(request.getParameter(name));
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
protected void respond(HttpServletResponse response, String content) throws IOException {
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
OutputStream os = response.getOutputStream();
|
||||
OutputStreamWriter osw = new OutputStreamWriter(os);
|
||||
try {
|
||||
osw.write(content);
|
||||
} finally {
|
||||
osw.flush();
|
||||
osw.close();
|
||||
}
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
OutputStream os = response.getOutputStream();
|
||||
OutputStreamWriter osw = new OutputStreamWriter(os);
|
||||
try {
|
||||
osw.write(content);
|
||||
} finally {
|
||||
osw.flush();
|
||||
osw.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void respondJSON(HttpServletResponse response, Jsonizable o) throws IOException, JSONException {
|
||||
respondJSON(response, o, new Properties());
|
||||
respondJSON(response, o, new Properties());
|
||||
}
|
||||
|
||||
protected void respondJSON(HttpServletResponse response, Jsonizable o, Properties options) throws IOException, JSONException {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
|
||||
o.write(writer, options);
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
|
||||
o.write(writer, options);
|
||||
}
|
||||
|
||||
protected void respondException(HttpServletResponse response, Exception e) throws IOException {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
JSONObject o = new JSONObject();
|
||||
o.put("code", "error");
|
||||
o.put("message", e.getMessage());
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
pw.flush();
|
||||
sw.flush();
|
||||
|
||||
o.put("stack", sw.toString());
|
||||
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
respond(response, o.toString());
|
||||
} catch (JSONException e1) {
|
||||
e.printStackTrace(response.getWriter());
|
||||
}
|
||||
try {
|
||||
JSONObject o = new JSONObject();
|
||||
o.put("code", "error");
|
||||
o.put("message", e.getMessage());
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
pw.flush();
|
||||
sw.flush();
|
||||
|
||||
o.put("stack", sw.toString());
|
||||
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
respond(response, o.toString());
|
||||
} catch (JSONException e1) {
|
||||
e.printStackTrace(response.getWriter());
|
||||
}
|
||||
}
|
||||
|
||||
protected void redirect(HttpServletResponse response, String url) throws IOException {
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
String content = "<html><head><meta http-equiv=\"refresh\" content=\"1;url=" + url + "\"></head><body></body></html>";
|
||||
response.getWriter().print(content);
|
||||
}
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
String content = "<html><head><meta http-equiv=\"refresh\" content=\"1;url=" + url + "\"></head><body></body></html>";
|
||||
response.getWriter().print(content);
|
||||
}
|
||||
|
||||
protected String readFileUpload(HttpServletRequest request, Properties properties) throws IOException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
try {
|
||||
MultipartParser parser = new MultipartParser(request, 20 * 1024 * 1024);
|
||||
Part part = null;
|
||||
while ((part = parser.readNextPart()) != null) {
|
||||
|
||||
if (part.isFile()) {
|
||||
Reader reader = new InputStreamReader(((FilePart) part).getInputStream());
|
||||
LineNumberReader lnr = new LineNumberReader(reader);
|
||||
try {
|
||||
String line = null;
|
||||
while ((line = lnr.readLine()) != null) {
|
||||
sb.append(line);
|
||||
sb.append('\n');
|
||||
}
|
||||
} finally {
|
||||
lnr.close();
|
||||
}
|
||||
} else if (part.isParam()) {
|
||||
ParamPart paramPart = (ParamPart) part;
|
||||
properties.put(part.getName(), paramPart.getStringValue());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
try {
|
||||
MultipartParser parser = new MultipartParser(request, 20 * 1024 * 1024);
|
||||
Part part = null;
|
||||
while ((part = parser.readNextPart()) != null) {
|
||||
|
||||
if (part.isFile()) {
|
||||
Reader reader = new InputStreamReader(((FilePart) part).getInputStream());
|
||||
LineNumberReader lnr = new LineNumberReader(reader);
|
||||
try {
|
||||
String line = null;
|
||||
while ((line = lnr.readLine()) != null) {
|
||||
sb.append(line);
|
||||
sb.append('\n');
|
||||
}
|
||||
} finally {
|
||||
lnr.close();
|
||||
}
|
||||
} else if (part.isParam()) {
|
||||
ParamPart paramPart = (ParamPart) part;
|
||||
properties.put(part.getName(), paramPart.getStringValue());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected JSONObject getJsonParameter(HttpServletRequest request, String name) {
|
||||
String value = request.getParameter(name);
|
||||
if (value != null) {
|
||||
try {
|
||||
JSONObject o = jsonStringToObject(value);
|
||||
|
||||
return o;
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
String value = request.getParameter(name);
|
||||
if (value != null) {
|
||||
try {
|
||||
JSONObject o = jsonStringToObject(value);
|
||||
|
||||
return o;
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected JSONObject jsonStringToObject(String s) throws JSONException {
|
||||
JSONTokener t = new JSONTokener(s);
|
||||
JSONObject o = (JSONObject) t.nextValue();
|
||||
return o;
|
||||
JSONTokener t = new JSONTokener(s);
|
||||
JSONObject o = (JSONObject) t.nextValue();
|
||||
return o;
|
||||
}
|
||||
|
||||
protected JSONArray jsonStringToArray(String s) throws JSONException {
|
||||
JSONTokener t = new JSONTokener(s);
|
||||
JSONArray a = (JSONArray) t.nextValue();
|
||||
return a;
|
||||
JSONTokener t = new JSONTokener(s);
|
||||
JSONArray a = (JSONArray) t.nextValue();
|
||||
return a;
|
||||
}
|
||||
|
||||
protected JSONObject getEngineConfig(HttpServletRequest request) throws Exception {
|
||||
String json = request.getParameter("engine");
|
||||
if (json != null) {
|
||||
return jsonStringToObject(json);
|
||||
}
|
||||
return null;
|
||||
String json = request.getParameter("engine");
|
||||
if (json != null) {
|
||||
return jsonStringToObject(json);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Engine getEngine(HttpServletRequest request, Project project) throws Exception {
|
||||
Engine engine = new Engine(project);
|
||||
String json = request.getParameter("engine");
|
||||
if (json != null) {
|
||||
JSONObject o = jsonStringToObject(json);
|
||||
engine.initializeFromJSON(o);
|
||||
}
|
||||
return engine;
|
||||
Engine engine = new Engine(project);
|
||||
String json = request.getParameter("engine");
|
||||
if (json != null) {
|
||||
JSONObject o = jsonStringToObject(json);
|
||||
engine.initializeFromJSON(o);
|
||||
}
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
|
@ -14,25 +14,25 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.process.Process;
|
||||
|
||||
abstract public class EngineDependentCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
AbstractOperation op = createOperation(request, getEngineConfig(request));
|
||||
Process process = op.createProcess(project, new Properties());
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected AbstractOperation createOperation(
|
||||
HttpServletRequest request, JSONObject engineConfig) throws Exception;
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
AbstractOperation op = createOperation(request, getEngineConfig(request));
|
||||
Process process = op.createProcess(project, new Properties());
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected AbstractOperation createOperation(
|
||||
HttpServletRequest request, JSONObject engineConfig) throws Exception;
|
||||
}
|
||||
|
@ -9,22 +9,22 @@ import com.metaweb.gridworks.model.AbstractOperation;
|
||||
import com.metaweb.gridworks.operations.ColumnAdditionOperation;
|
||||
|
||||
public class AddColumnCommand extends EngineDependentCommand {
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String baseColumnName = request.getParameter("baseColumnName");
|
||||
String expression = request.getParameter("expression");
|
||||
String headerLabel = request.getParameter("headerLabel");
|
||||
int columnInsertIndex = Integer.parseInt(request.getParameter("columnInsertIndex"));
|
||||
|
||||
return new ColumnAdditionOperation(
|
||||
engineConfig,
|
||||
baseColumnName,
|
||||
expression,
|
||||
headerLabel,
|
||||
columnInsertIndex
|
||||
);
|
||||
}
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String baseColumnName = request.getParameter("baseColumnName");
|
||||
String expression = request.getParameter("expression");
|
||||
String headerLabel = request.getParameter("headerLabel");
|
||||
int columnInsertIndex = Integer.parseInt(request.getParameter("columnInsertIndex"));
|
||||
|
||||
return new ColumnAdditionOperation(
|
||||
engineConfig,
|
||||
baseColumnName,
|
||||
expression,
|
||||
headerLabel,
|
||||
columnInsertIndex
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,71 +15,71 @@ import com.metaweb.gridworks.model.changes.RowStarChange;
|
||||
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
|
||||
|
||||
public class AnnotateOneRowCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
||||
|
||||
String starredString = request.getParameter("starred");
|
||||
if (starredString != null) {
|
||||
boolean starred = "true".endsWith(starredString);
|
||||
String description = starred ? "Star row " + rowIndex : "Unstar row " + rowIndex;
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
||||
|
||||
String starredString = request.getParameter("starred");
|
||||
if (starredString != null) {
|
||||
boolean starred = "true".endsWith(starredString);
|
||||
String description = starred ? "Star row " + rowIndex : "Unstar row " + rowIndex;
|
||||
|
||||
StarOneRowProcess process = new StarOneRowProcess(
|
||||
StarOneRowProcess process = new StarOneRowProcess(
|
||||
project,
|
||||
description,
|
||||
rowIndex,
|
||||
starred
|
||||
);
|
||||
|
||||
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\" }");
|
||||
}
|
||||
} else {
|
||||
|
||||
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\" }");
|
||||
}
|
||||
} else {
|
||||
respond(response, "{ \"code\" : \"error\", \"message\" : \"invalid command parameters\" }");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected class StarOneRowProcess extends QuickHistoryEntryProcess {
|
||||
final int rowIndex;
|
||||
final boolean starred;
|
||||
|
||||
StarOneRowProcess(
|
||||
Project project,
|
||||
String briefDescription,
|
||||
int rowIndex,
|
||||
boolean starred
|
||||
) {
|
||||
super(project, briefDescription);
|
||||
|
||||
this.rowIndex = rowIndex;
|
||||
this.starred = starred;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected class StarOneRowProcess extends QuickHistoryEntryProcess {
|
||||
final int rowIndex;
|
||||
final boolean starred;
|
||||
|
||||
StarOneRowProcess(
|
||||
Project project,
|
||||
String briefDescription,
|
||||
int rowIndex,
|
||||
boolean starred
|
||||
) {
|
||||
super(project, briefDescription);
|
||||
|
||||
this.rowIndex = rowIndex;
|
||||
this.starred = starred;
|
||||
}
|
||||
|
||||
protected HistoryEntry createHistoryEntry() throws Exception {
|
||||
return new HistoryEntry(
|
||||
_project,
|
||||
starred ? "Star row " + rowIndex : "Unstar row " + rowIndex,
|
||||
null,
|
||||
new RowStarChange(rowIndex, starred)
|
||||
);
|
||||
}
|
||||
}
|
||||
protected HistoryEntry createHistoryEntry() throws Exception {
|
||||
return new HistoryEntry(
|
||||
_project,
|
||||
starred ? "Star row " + rowIndex : "Unstar row " + rowIndex,
|
||||
null,
|
||||
new RowStarChange(rowIndex, starred)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,11 +9,11 @@ import com.metaweb.gridworks.model.AbstractOperation;
|
||||
import com.metaweb.gridworks.operations.RowStarOperation;
|
||||
|
||||
public class AnnotateRowsCommand extends EngineDependentCommand {
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String starredString = request.getParameter("starred");
|
||||
if (starredString != null) {
|
||||
boolean starred = "true".endsWith(starredString);
|
||||
@ -21,5 +21,5 @@ public class AnnotateRowsCommand extends EngineDependentCommand {
|
||||
return new RowStarOperation(engineConfig, starred);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,55 +19,55 @@ import com.metaweb.gridworks.operations.OperationRegistry;
|
||||
import com.metaweb.gridworks.process.Process;
|
||||
|
||||
public class ApplyOperationsCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
String jsonString = request.getParameter("operations");
|
||||
try {
|
||||
JSONArray a = jsonStringToArray(jsonString);
|
||||
int count = a.length();
|
||||
for (int i = 0; i < count; i++) {
|
||||
JSONObject obj = a.getJSONObject(i);
|
||||
|
||||
reconstructOperation(project, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
String jsonString = request.getParameter("operations");
|
||||
try {
|
||||
JSONArray a = jsonStringToArray(jsonString);
|
||||
int count = a.length();
|
||||
for (int i = 0; i < count; i++) {
|
||||
JSONObject obj = a.getJSONObject(i);
|
||||
|
||||
reconstructOperation(project, obj);
|
||||
}
|
||||
|
||||
if (project.processManager.hasPending()) {
|
||||
respond(response, "{ \"code\" : \"pending\" }");
|
||||
} else {
|
||||
respond(response, "{ \"code\" : \"ok\" }");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void reconstructOperation(Project project, JSONObject obj) {
|
||||
try {
|
||||
String op = obj.getString("op");
|
||||
|
||||
Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op);
|
||||
if (klass == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class);
|
||||
if (reconstruct == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractOperation operation = (AbstractOperation) reconstruct.invoke(null, project, obj);
|
||||
if (project.processManager.hasPending()) {
|
||||
respond(response, "{ \"code\" : \"pending\" }");
|
||||
} else {
|
||||
respond(response, "{ \"code\" : \"ok\" }");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void reconstructOperation(Project project, JSONObject obj) {
|
||||
try {
|
||||
String op = obj.getString("op");
|
||||
|
||||
Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op);
|
||||
if (klass == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class);
|
||||
if (reconstruct == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractOperation operation = (AbstractOperation) reconstruct.invoke(null, project, obj);
|
||||
if (operation != null) {
|
||||
Process process = operation.createProcess(project, new Properties());
|
||||
|
||||
project.processManager.queueProcess(process);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -34,79 +34,79 @@ import com.oreilly.servlet.multipart.Part;
|
||||
public class CreateProjectCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Properties options = parseUrlParameters(request);
|
||||
Project project = new Project();
|
||||
|
||||
internalImport(request, project, options);
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Properties options = parseUrlParameters(request);
|
||||
Project project = new Project();
|
||||
|
||||
internalImport(request, project, options);
|
||||
|
||||
ProjectMetadata pm = new ProjectMetadata();
|
||||
pm.setName(options.getProperty("project-name"));
|
||||
pm.setPassword(options.getProperty("project-password"));
|
||||
ProjectMetadata pm = new ProjectMetadata();
|
||||
pm.setName(options.getProperty("project-name"));
|
||||
pm.setPassword(options.getProperty("project-password"));
|
||||
pm.setEncoding(options.getProperty("encoding"));
|
||||
pm.setEncodingConfidence(options.getProperty("encoding_confidence"));
|
||||
ProjectManager.singleton.registerProject(project, pm);
|
||||
ProjectManager.singleton.registerProject(project, pm);
|
||||
|
||||
project.columnModel.update();
|
||||
project.columnModel.update();
|
||||
project.recomputeRowContextDependencies();
|
||||
|
||||
redirect(response, "/project.html?project=" + project.id);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected Properties parseUrlParameters(HttpServletRequest request) {
|
||||
Properties options = new Properties();
|
||||
|
||||
String query = request.getQueryString();
|
||||
if (query != null) {
|
||||
if (query.startsWith("?")) {
|
||||
query = query.substring(1);
|
||||
}
|
||||
|
||||
String[] pairs = query.split("&");
|
||||
for (String pairString : pairs) {
|
||||
int equal = pairString.indexOf('=');
|
||||
String name = equal >= 0 ? pairString.substring(0, equal) : "";
|
||||
String value = equal >= 0 ? ParsingUtilities.decode(pairString.substring(equal + 1)) : "";
|
||||
|
||||
options.put(name, value);
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
protected void internalImport(
|
||||
HttpServletRequest request,
|
||||
Project project,
|
||||
Properties options
|
||||
) throws Exception {
|
||||
MultipartParser parser = null;
|
||||
try {
|
||||
parser = new MultipartParser(request, 20 * 1024 * 1024);
|
||||
} catch (Exception e) {
|
||||
// silent
|
||||
}
|
||||
|
||||
if (parser != null) {
|
||||
Part part = null;
|
||||
String url = null;
|
||||
|
||||
int limit = -1;
|
||||
int skip = 0;
|
||||
|
||||
if (options.containsKey("limit")) {
|
||||
String s = options.getProperty("limit");
|
||||
try {
|
||||
limit = Integer.parseInt(s);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
redirect(response, "/project.html?project=" + project.id);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected Properties parseUrlParameters(HttpServletRequest request) {
|
||||
Properties options = new Properties();
|
||||
|
||||
String query = request.getQueryString();
|
||||
if (query != null) {
|
||||
if (query.startsWith("?")) {
|
||||
query = query.substring(1);
|
||||
}
|
||||
|
||||
String[] pairs = query.split("&");
|
||||
for (String pairString : pairs) {
|
||||
int equal = pairString.indexOf('=');
|
||||
String name = equal >= 0 ? pairString.substring(0, equal) : "";
|
||||
String value = equal >= 0 ? ParsingUtilities.decode(pairString.substring(equal + 1)) : "";
|
||||
|
||||
options.put(name, value);
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
protected void internalImport(
|
||||
HttpServletRequest request,
|
||||
Project project,
|
||||
Properties options
|
||||
) throws Exception {
|
||||
MultipartParser parser = null;
|
||||
try {
|
||||
parser = new MultipartParser(request, 20 * 1024 * 1024);
|
||||
} catch (Exception e) {
|
||||
// silent
|
||||
}
|
||||
|
||||
if (parser != null) {
|
||||
Part part = null;
|
||||
String url = null;
|
||||
|
||||
int limit = -1;
|
||||
int skip = 0;
|
||||
|
||||
if (options.containsKey("limit")) {
|
||||
String s = options.getProperty("limit");
|
||||
try {
|
||||
limit = Integer.parseInt(s);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (options.containsKey("skip")) {
|
||||
String s = options.getProperty("skip");
|
||||
try {
|
||||
@ -114,15 +114,15 @@ public class CreateProjectCommand extends Command {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
while ((part = parser.readNextPart()) != null) {
|
||||
|
||||
if (part.isFile()) {
|
||||
FilePart filePart = (FilePart) part;
|
||||
|
||||
Importer importer = guessImporter(options, null, filePart.getFileName());
|
||||
|
||||
if (importer.takesReader()) {
|
||||
|
||||
while ((part = parser.readNextPart()) != null) {
|
||||
|
||||
if (part.isFile()) {
|
||||
FilePart filePart = (FilePart) part;
|
||||
|
||||
Importer importer = guessImporter(options, null, filePart.getFileName());
|
||||
|
||||
if (importer.takesReader()) {
|
||||
CharsetDetector detector = new CharsetDetector();
|
||||
detector.setDeclaredEncoding("utf8"); // the content on the web is encoded in UTF-8 so assume that
|
||||
CharsetMatch charsetMatch = detector.setText(enforceMarking(filePart.getInputStream())).detect();
|
||||
@ -135,120 +135,120 @@ public class CreateProjectCommand extends Command {
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} else {
|
||||
InputStream inputStream = filePart.getInputStream();
|
||||
try {
|
||||
importer.read(inputStream, project, options, skip, limit);
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
} else if (part.isParam()) {
|
||||
ParamPart paramPart = (ParamPart) part;
|
||||
String paramName = paramPart.getName();
|
||||
if (paramName.equals("raw-text")) {
|
||||
StringReader reader = new StringReader(paramPart.getStringValue());
|
||||
try {
|
||||
new TsvCsvImporter().read(reader, project, options, skip, limit);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} else if (paramName.equals("url")) {
|
||||
url = paramPart.getStringValue();
|
||||
} else {
|
||||
options.put(paramName, paramPart.getStringValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (url != null && url.length() > 0) {
|
||||
internalImportURL(request, project, options, url, skip, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void internalImportURL(
|
||||
HttpServletRequest request,
|
||||
Project project,
|
||||
Properties options,
|
||||
String urlString,
|
||||
int skip,
|
||||
int limit
|
||||
) throws Exception {
|
||||
URL url = new URL(urlString);
|
||||
URLConnection connection = null;
|
||||
|
||||
try {
|
||||
connection = url.openConnection();
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.connect();
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Cannot connect to " + urlString, e);
|
||||
}
|
||||
|
||||
} else {
|
||||
InputStream inputStream = filePart.getInputStream();
|
||||
try {
|
||||
importer.read(inputStream, project, options, skip, limit);
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
} else if (part.isParam()) {
|
||||
ParamPart paramPart = (ParamPart) part;
|
||||
String paramName = paramPart.getName();
|
||||
if (paramName.equals("raw-text")) {
|
||||
StringReader reader = new StringReader(paramPart.getStringValue());
|
||||
try {
|
||||
new TsvCsvImporter().read(reader, project, options, skip, limit);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} else if (paramName.equals("url")) {
|
||||
url = paramPart.getStringValue();
|
||||
} else {
|
||||
options.put(paramName, paramPart.getStringValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (url != null && url.length() > 0) {
|
||||
internalImportURL(request, project, options, url, skip, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void internalImportURL(
|
||||
HttpServletRequest request,
|
||||
Project project,
|
||||
Properties options,
|
||||
String urlString,
|
||||
int skip,
|
||||
int limit
|
||||
) throws Exception {
|
||||
URL url = new URL(urlString);
|
||||
URLConnection connection = null;
|
||||
|
||||
try {
|
||||
connection = url.openConnection();
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.connect();
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Cannot connect to " + urlString, e);
|
||||
}
|
||||
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = connection.getInputStream();
|
||||
inputStream = connection.getInputStream();
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Cannot retrieve content from " + url, e);
|
||||
throw new Exception("Cannot retrieve content from " + url, e);
|
||||
}
|
||||
|
||||
try {
|
||||
Importer importer = guessImporter(
|
||||
options,
|
||||
connection.getContentType(),
|
||||
url.getPath()
|
||||
);
|
||||
Importer importer = guessImporter(
|
||||
options,
|
||||
connection.getContentType(),
|
||||
url.getPath()
|
||||
);
|
||||
|
||||
if (importer.takesReader()) {
|
||||
String encoding = connection.getContentEncoding();
|
||||
|
||||
Reader reader = new InputStreamReader(
|
||||
inputStream, (encoding == null) ? "ISO-8859-1" : encoding);
|
||||
|
||||
importer.read(reader, project, options, skip, limit);
|
||||
} else {
|
||||
importer.read(inputStream, project, options, skip, limit);
|
||||
}
|
||||
if (importer.takesReader()) {
|
||||
String encoding = connection.getContentEncoding();
|
||||
|
||||
Reader reader = new InputStreamReader(
|
||||
inputStream, (encoding == null) ? "ISO-8859-1" : encoding);
|
||||
|
||||
importer.read(reader, project, options, skip, limit);
|
||||
} else {
|
||||
importer.read(inputStream, project, options, skip, limit);
|
||||
}
|
||||
} finally {
|
||||
inputStream.close();
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected Importer guessImporter(
|
||||
Properties options, String contentType, String fileName) {
|
||||
|
||||
if (contentType != null) {
|
||||
contentType = contentType.toLowerCase().trim();
|
||||
|
||||
if ("application/msexcel".equals(contentType) ||
|
||||
"application/x-msexcel".equals(contentType) ||
|
||||
"application/x-ms-excel".equals(contentType) ||
|
||||
"application/vnd.ms-excel".equals(contentType) ||
|
||||
"application/x-excel".equals(contentType) ||
|
||||
"application/xls".equals(contentType)) {
|
||||
|
||||
return new ExcelImporter(false);
|
||||
} else if("application/x-xls".equals(contentType)) {
|
||||
return new ExcelImporter(true);
|
||||
}
|
||||
} else if (fileName != null) {
|
||||
fileName = fileName.toLowerCase();
|
||||
if (fileName.endsWith(".xls")) {
|
||||
return new ExcelImporter(false);
|
||||
} else if (fileName.endsWith(".xlsx")) {
|
||||
return new ExcelImporter(true);
|
||||
}
|
||||
}
|
||||
|
||||
return new TsvCsvImporter();
|
||||
}
|
||||
}
|
||||
|
||||
protected Importer guessImporter(
|
||||
Properties options, String contentType, String fileName) {
|
||||
|
||||
if (contentType != null) {
|
||||
contentType = contentType.toLowerCase().trim();
|
||||
|
||||
if ("application/msexcel".equals(contentType) ||
|
||||
"application/x-msexcel".equals(contentType) ||
|
||||
"application/x-ms-excel".equals(contentType) ||
|
||||
"application/vnd.ms-excel".equals(contentType) ||
|
||||
"application/x-excel".equals(contentType) ||
|
||||
"application/xls".equals(contentType)) {
|
||||
|
||||
return new ExcelImporter(false);
|
||||
} else if("application/x-xls".equals(contentType)) {
|
||||
return new ExcelImporter(true);
|
||||
}
|
||||
} else if (fileName != null) {
|
||||
fileName = fileName.toLowerCase();
|
||||
if (fileName.endsWith(".xls")) {
|
||||
return new ExcelImporter(false);
|
||||
} else if (fileName.endsWith(".xlsx")) {
|
||||
return new ExcelImporter(true);
|
||||
}
|
||||
}
|
||||
|
||||
return new TsvCsvImporter();
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE(SM): The ICU4J char detection code requires the input stream to support mark/reset. Unfortunately, not
|
||||
* all ServletInputStream implementations are marking, so we need do this memory-expensive wrapping to make
|
||||
* it work. It's far from ideal but I don't have a more efficient solution.
|
||||
*/
|
||||
/*
|
||||
* NOTE(SM): The ICU4J char detection code requires the input stream to support mark/reset. Unfortunately, not
|
||||
* all ServletInputStream implementations are marking, so we need do this memory-expensive wrapping to make
|
||||
* it work. It's far from ideal but I don't have a more efficient solution.
|
||||
*/
|
||||
private static InputStream enforceMarking(InputStream input) throws IOException {
|
||||
if (input.markSupported()) {
|
||||
return input;
|
||||
@ -267,5 +267,5 @@ public class CreateProjectCommand extends Command {
|
||||
return new ByteArrayInputStream(output.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ import com.metaweb.gridworks.model.AbstractOperation;
|
||||
import com.metaweb.gridworks.operations.TextTransformOperation;
|
||||
|
||||
public class DoTextTransformCommand extends EngineDependentCommand {
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String expression = request.getParameter("expression");
|
||||
|
||||
return new TextTransformOperation(engineConfig, columnName, expression);
|
||||
}
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String expression = request.getParameter("expression");
|
||||
|
||||
return new TextTransformOperation(engineConfig, columnName, expression);
|
||||
}
|
||||
}
|
||||
|
@ -10,19 +10,19 @@ import com.metaweb.gridworks.operations.FacetBasedEditOperation;
|
||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||
|
||||
public class FacetBasedEditCommand extends EngineDependentCommand {
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String expression = request.getParameter("expression");
|
||||
String editsString = request.getParameter("edits");
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String expression = request.getParameter("expression");
|
||||
String editsString = request.getParameter("edits");
|
||||
|
||||
return new FacetBasedEditOperation(
|
||||
engineConfig,
|
||||
columnName,
|
||||
expression,
|
||||
FacetBasedEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,26 +14,26 @@ import com.metaweb.gridworks.operations.MultiValuedCellJoinOperation;
|
||||
import com.metaweb.gridworks.process.Process;
|
||||
|
||||
public class JoinMultiValueCellsCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String keyColumnName = request.getParameter("keyColumnName");
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String keyColumnName = request.getParameter("keyColumnName");
|
||||
String separator = request.getParameter("separator");
|
||||
|
||||
AbstractOperation op = new MultiValuedCellJoinOperation(columnName, keyColumnName, separator);
|
||||
Process process = op.createProcess(project, new Properties());
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
AbstractOperation op = new MultiValuedCellJoinOperation(columnName, keyColumnName, separator);
|
||||
Process process = op.createProcess(project, new Properties());
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,24 +14,24 @@ import com.metaweb.gridworks.operations.ColumnRemovalOperation;
|
||||
import com.metaweb.gridworks.process.Process;
|
||||
|
||||
public class RemoveColumnCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
|
||||
AbstractOperation op = new ColumnRemovalOperation(columnName);
|
||||
Process process = op.createProcess(project, new Properties());
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
|
||||
AbstractOperation op = new ColumnRemovalOperation(columnName);
|
||||
Process process = op.createProcess(project, new Properties());
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,26 +17,26 @@ import com.metaweb.gridworks.process.Process;
|
||||
import com.metaweb.gridworks.protograph.Protograph;
|
||||
|
||||
public class SaveProtographCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
String jsonString = request.getParameter("protograph");
|
||||
JSONObject json = jsonStringToObject(jsonString);
|
||||
Protograph protograph = Protograph.reconstruct(json);
|
||||
|
||||
AbstractOperation op = new SaveProtographOperation(protograph);
|
||||
Process process = op.createProcess(project, new Properties());
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
String jsonString = request.getParameter("protograph");
|
||||
JSONObject json = jsonStringToObject(jsonString);
|
||||
Protograph protograph = Protograph.reconstruct(json);
|
||||
|
||||
AbstractOperation op = new SaveProtographOperation(protograph);
|
||||
Process process = op.createProcess(project, new Properties());
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,27 +14,27 @@ import com.metaweb.gridworks.operations.MultiValuedCellSplitOperation;
|
||||
import com.metaweb.gridworks.process.Process;
|
||||
|
||||
public class SplitMultiValueCellsCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String keyColumnName = request.getParameter("keyColumnName");
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String keyColumnName = request.getParameter("keyColumnName");
|
||||
String separator = request.getParameter("separator");
|
||||
String mode = request.getParameter("mode");
|
||||
|
||||
AbstractOperation op = new MultiValuedCellSplitOperation(columnName, keyColumnName, separator, mode);
|
||||
Process process = op.createProcess(project, new Properties());
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
AbstractOperation op = new MultiValuedCellSplitOperation(columnName, keyColumnName, separator, mode);
|
||||
Process process = op.createProcess(project, new Properties());
|
||||
|
||||
boolean done = project.processManager.queueProcess(process);
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,17 @@ import com.metaweb.gridworks.history.HistoryProcess;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class UndoRedoCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
long lastDoneID = Long.parseLong(request.getParameter("lastDoneID"));
|
||||
|
||||
boolean done = project.processManager.queueProcess(
|
||||
new HistoryProcess(project, lastDoneID));
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
long lastDoneID = Long.parseLong(request.getParameter("lastDoneID"));
|
||||
|
||||
boolean done = project.processManager.queueProcess(
|
||||
new HistoryProcess(project, lastDoneID));
|
||||
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
}
|
||||
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
|
||||
}
|
||||
}
|
||||
|
@ -11,19 +11,19 @@ import com.metaweb.gridworks.commands.Command;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class ComputeFacetsCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
Engine engine = getEngine(request, project);
|
||||
|
||||
engine.computeFacets();
|
||||
|
||||
respondJSON(response, engine);
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
Engine engine = getEngine(request, project);
|
||||
|
||||
engine.computeFacets();
|
||||
|
||||
respondJSON(response, engine);
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,91 +19,91 @@ import com.metaweb.gridworks.model.Row;
|
||||
public class ExportRowsCommand extends Command {
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
Engine engine = getEngine(request, project);
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "text/plain");
|
||||
|
||||
PrintWriter writer = response.getWriter();
|
||||
|
||||
boolean first = true;
|
||||
for (Column column : project.columnModel.columns) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
writer.print("\t");
|
||||
}
|
||||
writer.print(column.getHeaderLabel());
|
||||
}
|
||||
writer.print("\n");
|
||||
|
||||
{
|
||||
RowVisitor visitor = new RowVisitor() {
|
||||
PrintWriter writer;
|
||||
|
||||
public RowVisitor init(PrintWriter writer) {
|
||||
this.writer = writer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
boolean first = true;
|
||||
for (Column column : project.columnModel.columns) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
writer.print("\t");
|
||||
}
|
||||
|
||||
int cellIndex = column.getCellIndex();
|
||||
if (cellIndex < row.cells.size()) {
|
||||
Cell cell = row.cells.get(cellIndex);
|
||||
if (cell != null && cell.value != null) {
|
||||
writer.print(cell.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.print("\n");
|
||||
|
||||
return false;
|
||||
}
|
||||
}.init(writer);
|
||||
|
||||
FilteredRows filteredRows = engine.getAllFilteredRows(true);
|
||||
filteredRows.accept(project, visitor);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
static protected class RowAccumulator implements RowVisitor {
|
||||
final public int start;
|
||||
final public int limit;
|
||||
|
||||
public int total;
|
||||
|
||||
public RowAccumulator(int start, int limit) {
|
||||
this.start = start;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
boolean r = false;
|
||||
|
||||
if (total >= start && total < start + limit) {
|
||||
r = internalVisit(rowIndex, row);
|
||||
}
|
||||
total++;
|
||||
return r;
|
||||
}
|
||||
|
||||
protected boolean internalVisit(int rowIndex, Row row) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
Engine engine = getEngine(request, project);
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "text/plain");
|
||||
|
||||
PrintWriter writer = response.getWriter();
|
||||
|
||||
boolean first = true;
|
||||
for (Column column : project.columnModel.columns) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
writer.print("\t");
|
||||
}
|
||||
writer.print(column.getHeaderLabel());
|
||||
}
|
||||
writer.print("\n");
|
||||
|
||||
{
|
||||
RowVisitor visitor = new RowVisitor() {
|
||||
PrintWriter writer;
|
||||
|
||||
public RowVisitor init(PrintWriter writer) {
|
||||
this.writer = writer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
boolean first = true;
|
||||
for (Column column : project.columnModel.columns) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
writer.print("\t");
|
||||
}
|
||||
|
||||
int cellIndex = column.getCellIndex();
|
||||
if (cellIndex < row.cells.size()) {
|
||||
Cell cell = row.cells.get(cellIndex);
|
||||
if (cell != null && cell.value != null) {
|
||||
writer.print(cell.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.print("\n");
|
||||
|
||||
return false;
|
||||
}
|
||||
}.init(writer);
|
||||
|
||||
FilteredRows filteredRows = engine.getAllFilteredRows(true);
|
||||
filteredRows.accept(project, visitor);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
static protected class RowAccumulator implements RowVisitor {
|
||||
final public int start;
|
||||
final public int limit;
|
||||
|
||||
public int total;
|
||||
|
||||
public RowAccumulator(int start, int limit) {
|
||||
this.start = start;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
boolean r = false;
|
||||
|
||||
if (total >= start && total < start + limit) {
|
||||
r = internalVisit(rowIndex, row);
|
||||
}
|
||||
total++;
|
||||
return r;
|
||||
}
|
||||
|
||||
protected boolean internalVisit(int rowIndex, Row row) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,30 +16,30 @@ import com.metaweb.gridworks.ProjectMetadata;
|
||||
import com.metaweb.gridworks.commands.Command;
|
||||
|
||||
public class GetAllProjectMetadataCommand extends Command {
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
Properties options = new Properties();
|
||||
|
||||
writer.object();
|
||||
|
||||
writer.key("projects"); writer.object();
|
||||
|
||||
Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
|
||||
for (Long id : m.keySet()) {
|
||||
writer.key(id.toString());
|
||||
m.get(id).write(writer, options);
|
||||
}
|
||||
writer.endObject();
|
||||
writer.endObject();
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
Properties options = new Properties();
|
||||
|
||||
writer.object();
|
||||
|
||||
writer.key("projects"); writer.object();
|
||||
|
||||
Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
|
||||
for (Long id : m.keySet()) {
|
||||
writer.key(id.toString());
|
||||
m.get(id).write(writer, options);
|
||||
}
|
||||
writer.endObject();
|
||||
writer.endObject();
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,16 +12,16 @@ import com.metaweb.gridworks.commands.Command;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class GetHistoryCommand extends Command {
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
try {
|
||||
respondJSON(response, project.history);
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
try {
|
||||
respondJSON(response, project.history);
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,31 +14,31 @@ import com.metaweb.gridworks.commands.Command;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class GetModelsCommand extends Command {
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
Properties options = new Properties();
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
|
||||
writer.object();
|
||||
writer.key("columnModel"); project.columnModel.write(writer, options);
|
||||
writer.key("protograph");
|
||||
if (project.protograph == null) {
|
||||
writer.value(null);
|
||||
} else {
|
||||
project.protograph.write(writer, options);
|
||||
}
|
||||
writer.endObject();
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
Properties options = new Properties();
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
|
||||
writer.object();
|
||||
writer.key("columnModel"); project.columnModel.write(writer, options);
|
||||
writer.key("protograph");
|
||||
if (project.protograph == null) {
|
||||
writer.value(null);
|
||||
} else {
|
||||
project.protograph.write(writer, options);
|
||||
}
|
||||
writer.endObject();
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,36 +15,36 @@ import com.metaweb.gridworks.history.HistoryEntry;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class GetOperationsCommand extends Command {
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
Properties options = new Properties();
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
|
||||
writer.object();
|
||||
writer.key("entries"); writer.array();
|
||||
|
||||
for (HistoryEntry entry : project.history.getLastPastEntries(-1)) {
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(entry.description);
|
||||
if (entry.operation != null) {
|
||||
writer.key("operation");
|
||||
entry.operation.write(writer, options);
|
||||
}
|
||||
writer.endObject();
|
||||
}
|
||||
writer.endArray();
|
||||
writer.endObject();
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
Properties options = new Properties();
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
|
||||
writer.object();
|
||||
writer.key("entries"); writer.array();
|
||||
|
||||
for (HistoryEntry entry : project.history.getLastPastEntries(-1)) {
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(entry.description);
|
||||
if (entry.operation != null) {
|
||||
writer.key("operation");
|
||||
entry.operation.write(writer, options);
|
||||
}
|
||||
writer.endObject();
|
||||
}
|
||||
writer.endArray();
|
||||
writer.endObject();
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,16 +12,16 @@ import com.metaweb.gridworks.commands.Command;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class GetProcessesCommand extends Command {
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
|
||||
try {
|
||||
respondJSON(response, project.processManager);
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
|
||||
try {
|
||||
respondJSON(response, project.processManager);
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,16 +13,16 @@ import com.metaweb.gridworks.commands.Command;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class GetProjectMetadataCommand extends Command {
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
|
||||
try {
|
||||
respondJSON(response, ProjectManager.singleton.getProjectMetadata(project.id));
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = getProject(request);
|
||||
|
||||
try {
|
||||
respondJSON(response, ProjectManager.singleton.getProjectMetadata(project.id));
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,99 +20,99 @@ import com.metaweb.gridworks.model.Row;
|
||||
public class GetRowsCommand extends Command {
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
Engine engine = getEngine(request, project);
|
||||
|
||||
int start = Math.min(project.rows.size(), Math.max(0, getIntegerParameter(request, "start", 0)));
|
||||
int limit = Math.min(project.rows.size() - start, Math.max(0, getIntegerParameter(request, "limit", 20)));
|
||||
Properties options = new Properties();
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
writer.object();
|
||||
|
||||
{
|
||||
RowAccumulator acc = new RowAccumulator(start, limit) {
|
||||
JSONWriter writer;
|
||||
Properties options;
|
||||
Properties extra;
|
||||
|
||||
public RowAccumulator init(JSONWriter writer, Properties options) {
|
||||
this.writer = writer;
|
||||
this.options = options;
|
||||
|
||||
this.extra = new Properties();
|
||||
this.extra.put("contextual", true);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean internalVisit(int rowIndex, Row row, boolean contextual) {
|
||||
try {
|
||||
if (contextual) {
|
||||
options.put("extra", extra);
|
||||
} else {
|
||||
options.remove("extra");
|
||||
}
|
||||
options.put("rowIndex", rowIndex);
|
||||
|
||||
row.write(writer, options);
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}.init(writer, options);
|
||||
|
||||
FilteredRows filteredRows = engine.getAllFilteredRows(true);
|
||||
|
||||
writer.key("rows"); writer.array();
|
||||
filteredRows.accept(project, acc);
|
||||
writer.endArray();
|
||||
|
||||
writer.key("filtered"); writer.value(acc.total);
|
||||
}
|
||||
|
||||
writer.key("start"); writer.value(start);
|
||||
writer.key("limit"); writer.value(limit);
|
||||
writer.key("total"); writer.value(project.rows.size());
|
||||
|
||||
writer.endObject();
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
static protected class RowAccumulator implements RowVisitor {
|
||||
final public int start;
|
||||
final public int limit;
|
||||
|
||||
public int total;
|
||||
|
||||
public RowAccumulator(int start, int limit) {
|
||||
this.start = start;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
boolean r = false;
|
||||
|
||||
if (total >= start && total < start + limit) {
|
||||
r = internalVisit(rowIndex, row, contextual);
|
||||
}
|
||||
if (!contextual) {
|
||||
total++;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
protected boolean internalVisit(int rowIndex, Row row, boolean contextual) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
Engine engine = getEngine(request, project);
|
||||
|
||||
int start = Math.min(project.rows.size(), Math.max(0, getIntegerParameter(request, "start", 0)));
|
||||
int limit = Math.min(project.rows.size() - start, Math.max(0, getIntegerParameter(request, "limit", 20)));
|
||||
Properties options = new Properties();
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
writer.object();
|
||||
|
||||
{
|
||||
RowAccumulator acc = new RowAccumulator(start, limit) {
|
||||
JSONWriter writer;
|
||||
Properties options;
|
||||
Properties extra;
|
||||
|
||||
public RowAccumulator init(JSONWriter writer, Properties options) {
|
||||
this.writer = writer;
|
||||
this.options = options;
|
||||
|
||||
this.extra = new Properties();
|
||||
this.extra.put("contextual", true);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean internalVisit(int rowIndex, Row row, boolean contextual) {
|
||||
try {
|
||||
if (contextual) {
|
||||
options.put("extra", extra);
|
||||
} else {
|
||||
options.remove("extra");
|
||||
}
|
||||
options.put("rowIndex", rowIndex);
|
||||
|
||||
row.write(writer, options);
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}.init(writer, options);
|
||||
|
||||
FilteredRows filteredRows = engine.getAllFilteredRows(true);
|
||||
|
||||
writer.key("rows"); writer.array();
|
||||
filteredRows.accept(project, acc);
|
||||
writer.endArray();
|
||||
|
||||
writer.key("filtered"); writer.value(acc.total);
|
||||
}
|
||||
|
||||
writer.key("start"); writer.value(start);
|
||||
writer.key("limit"); writer.value(limit);
|
||||
writer.key("total"); writer.value(project.rows.size());
|
||||
|
||||
writer.endObject();
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
static protected class RowAccumulator implements RowVisitor {
|
||||
final public int start;
|
||||
final public int limit;
|
||||
|
||||
public int total;
|
||||
|
||||
public RowAccumulator(int start, int limit) {
|
||||
this.start = start;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
||||
boolean r = false;
|
||||
|
||||
if (total >= start && total < start + limit) {
|
||||
r = internalVisit(rowIndex, row, contextual);
|
||||
}
|
||||
if (!contextual) {
|
||||
total++;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
protected boolean internalVisit(int rowIndex, Row row, boolean contextual) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,12 @@ import com.metaweb.gridworks.model.AbstractOperation;
|
||||
import com.metaweb.gridworks.operations.ReconDiscardJudgmentsOperation;
|
||||
|
||||
public class ReconDiscardJudgmentsCommand extends EngineDependentCommand {
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
|
||||
return new ReconDiscardJudgmentsOperation(engineConfig, columnName);
|
||||
}
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
|
||||
return new ReconDiscardJudgmentsOperation(engineConfig, columnName);
|
||||
}
|
||||
}
|
||||
|
@ -25,154 +25,154 @@ import com.metaweb.gridworks.model.changes.ReconChange;
|
||||
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
|
||||
|
||||
public class ReconJudgeOneCellCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
||||
int cellIndex = Integer.parseInt(request.getParameter("cell"));
|
||||
Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
|
||||
|
||||
ReconCandidate match = null;
|
||||
String topicID = request.getParameter("topicID");
|
||||
if (topicID != null) {
|
||||
String scoreString = request.getParameter("score");
|
||||
|
||||
match = new ReconCandidate(
|
||||
topicID,
|
||||
request.getParameter("topicGUID"),
|
||||
request.getParameter("topicName"),
|
||||
request.getParameter("types").split(","),
|
||||
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());
|
||||
writer.object();
|
||||
writer.key("code"); writer.value("ok");
|
||||
writer.key("cell"); process.newCell.write(writer, new Properties());
|
||||
writer.endObject();
|
||||
} else {
|
||||
respond(response, "{ \"code\" : \"pending\" }");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected class JudgeOneCellProcess extends QuickHistoryEntryProcess {
|
||||
final int rowIndex;
|
||||
final int cellIndex;
|
||||
final Judgment judgment;
|
||||
final ReconCandidate match;
|
||||
Cell newCell;
|
||||
|
||||
|
||||
JudgeOneCellProcess(
|
||||
Project project,
|
||||
String briefDescription,
|
||||
Judgment judgment,
|
||||
int rowIndex,
|
||||
int cellIndex,
|
||||
ReconCandidate match
|
||||
) {
|
||||
super(project, briefDescription);
|
||||
|
||||
this.judgment = judgment;
|
||||
this.rowIndex = rowIndex;
|
||||
this.cellIndex = cellIndex;
|
||||
this.match = match;
|
||||
}
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
||||
int cellIndex = Integer.parseInt(request.getParameter("cell"));
|
||||
Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
|
||||
|
||||
ReconCandidate match = null;
|
||||
String topicID = request.getParameter("topicID");
|
||||
if (topicID != null) {
|
||||
String scoreString = request.getParameter("score");
|
||||
|
||||
match = new ReconCandidate(
|
||||
topicID,
|
||||
request.getParameter("topicGUID"),
|
||||
request.getParameter("topicName"),
|
||||
request.getParameter("types").split(","),
|
||||
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());
|
||||
writer.object();
|
||||
writer.key("code"); writer.value("ok");
|
||||
writer.key("cell"); process.newCell.write(writer, new Properties());
|
||||
writer.endObject();
|
||||
} else {
|
||||
respond(response, "{ \"code\" : \"pending\" }");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected class JudgeOneCellProcess extends QuickHistoryEntryProcess {
|
||||
final int rowIndex;
|
||||
final int cellIndex;
|
||||
final Judgment judgment;
|
||||
final ReconCandidate match;
|
||||
Cell newCell;
|
||||
|
||||
|
||||
JudgeOneCellProcess(
|
||||
Project project,
|
||||
String briefDescription,
|
||||
Judgment judgment,
|
||||
int rowIndex,
|
||||
int cellIndex,
|
||||
ReconCandidate match
|
||||
) {
|
||||
super(project, briefDescription);
|
||||
|
||||
this.judgment = judgment;
|
||||
this.rowIndex = rowIndex;
|
||||
this.cellIndex = cellIndex;
|
||||
this.match = match;
|
||||
}
|
||||
|
||||
protected HistoryEntry createHistoryEntry() throws Exception {
|
||||
Cell cell = _project.rows.get(rowIndex).getCell(cellIndex);
|
||||
protected HistoryEntry createHistoryEntry() throws Exception {
|
||||
Cell cell = _project.rows.get(rowIndex).getCell(cellIndex);
|
||||
if (cell == null || !ExpressionUtils.isNonBlankData(cell.value)) {
|
||||
throw new Exception("Cell is blank or error");
|
||||
}
|
||||
|
||||
Column column = _project.columnModel.getColumnByCellIndex(cellIndex);
|
||||
if (column == null) {
|
||||
throw new Exception("No such column");
|
||||
}
|
||||
|
||||
Judgment oldJudgment = cell.recon == null ? Judgment.None : cell.recon.judgment;
|
||||
|
||||
newCell = new Cell(
|
||||
cell.value,
|
||||
cell.recon == null ? new Recon() : cell.recon.dup()
|
||||
);
|
||||
|
||||
String cellDescription =
|
||||
"single cell on row " + (rowIndex + 1) +
|
||||
", column " + column.getHeaderLabel() +
|
||||
", containing \"" + cell.value + "\"";
|
||||
|
||||
String description = 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;
|
||||
}
|
||||
|
||||
ReconStats stats = column.getReconStats();
|
||||
if (stats == null) {
|
||||
stats = ReconStats.create(_project, cellIndex);
|
||||
} else {
|
||||
int newChange = 0;
|
||||
int matchChange = 0;
|
||||
|
||||
if (oldJudgment == Judgment.New) {
|
||||
newChange--;
|
||||
}
|
||||
if (oldJudgment == Judgment.Matched) {
|
||||
matchChange--;
|
||||
}
|
||||
if (newCell.recon.judgment == Judgment.New) {
|
||||
newChange++;
|
||||
}
|
||||
if (newCell.recon.judgment == Judgment.Matched) {
|
||||
matchChange++;
|
||||
}
|
||||
|
||||
stats = new ReconStats(
|
||||
stats.nonBlanks,
|
||||
stats.newTopics + newChange,
|
||||
stats.matchedTopics + matchChange);
|
||||
}
|
||||
|
||||
Change change = new ReconChange(
|
||||
new CellChange(rowIndex, cellIndex, cell, newCell),
|
||||
column.getHeaderLabel(),
|
||||
column.getReconConfig(),
|
||||
stats
|
||||
);
|
||||
|
||||
return new HistoryEntry(
|
||||
_project, description, null, change);
|
||||
}
|
||||
}
|
||||
throw new Exception("Cell is blank or error");
|
||||
}
|
||||
|
||||
Column column = _project.columnModel.getColumnByCellIndex(cellIndex);
|
||||
if (column == null) {
|
||||
throw new Exception("No such column");
|
||||
}
|
||||
|
||||
Judgment oldJudgment = cell.recon == null ? Judgment.None : cell.recon.judgment;
|
||||
|
||||
newCell = new Cell(
|
||||
cell.value,
|
||||
cell.recon == null ? new Recon() : cell.recon.dup()
|
||||
);
|
||||
|
||||
String cellDescription =
|
||||
"single cell on row " + (rowIndex + 1) +
|
||||
", column " + column.getHeaderLabel() +
|
||||
", containing \"" + cell.value + "\"";
|
||||
|
||||
String description = 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;
|
||||
}
|
||||
|
||||
ReconStats stats = column.getReconStats();
|
||||
if (stats == null) {
|
||||
stats = ReconStats.create(_project, cellIndex);
|
||||
} else {
|
||||
int newChange = 0;
|
||||
int matchChange = 0;
|
||||
|
||||
if (oldJudgment == Judgment.New) {
|
||||
newChange--;
|
||||
}
|
||||
if (oldJudgment == Judgment.Matched) {
|
||||
matchChange--;
|
||||
}
|
||||
if (newCell.recon.judgment == Judgment.New) {
|
||||
newChange++;
|
||||
}
|
||||
if (newCell.recon.judgment == Judgment.Matched) {
|
||||
matchChange++;
|
||||
}
|
||||
|
||||
stats = new ReconStats(
|
||||
stats.nonBlanks,
|
||||
stats.newTopics + newChange,
|
||||
stats.matchedTopics + matchChange);
|
||||
}
|
||||
|
||||
Change change = new ReconChange(
|
||||
new CellChange(rowIndex, cellIndex, cell, newCell),
|
||||
column.getHeaderLabel(),
|
||||
column.getReconConfig(),
|
||||
stats
|
||||
);
|
||||
|
||||
return new HistoryEntry(
|
||||
_project, description, null, change);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,37 +13,37 @@ import com.metaweb.gridworks.operations.ReconJudgeSimilarCellsOperation;
|
||||
|
||||
public class ReconJudgeSimilarCellsCommand extends EngineDependentCommand {
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(
|
||||
HttpServletRequest request, JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String similarValue = request.getParameter("similarValue");
|
||||
Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
|
||||
|
||||
ReconCandidate match = null;
|
||||
String topicID = request.getParameter("topicID");
|
||||
if (topicID != null) {
|
||||
String scoreString = request.getParameter("score");
|
||||
|
||||
match = new ReconCandidate(
|
||||
topicID,
|
||||
request.getParameter("topicGUID"),
|
||||
request.getParameter("topicName"),
|
||||
request.getParameter("types").split(","),
|
||||
scoreString != null ? Double.parseDouble(scoreString) : 100
|
||||
);
|
||||
}
|
||||
|
||||
String shareNewTopics = request.getParameter("shareNewTopics");
|
||||
|
||||
return new ReconJudgeSimilarCellsOperation(
|
||||
engineConfig,
|
||||
columnName,
|
||||
similarValue,
|
||||
judgment,
|
||||
match,
|
||||
"true".equals(shareNewTopics)
|
||||
);
|
||||
}
|
||||
@Override
|
||||
protected AbstractOperation createOperation(
|
||||
HttpServletRequest request, JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String similarValue = request.getParameter("similarValue");
|
||||
Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
|
||||
|
||||
ReconCandidate match = null;
|
||||
String topicID = request.getParameter("topicID");
|
||||
if (topicID != null) {
|
||||
String scoreString = request.getParameter("score");
|
||||
|
||||
match = new ReconCandidate(
|
||||
topicID,
|
||||
request.getParameter("topicGUID"),
|
||||
request.getParameter("topicName"),
|
||||
request.getParameter("types").split(","),
|
||||
scoreString != null ? Double.parseDouble(scoreString) : 100
|
||||
);
|
||||
}
|
||||
|
||||
String shareNewTopics = request.getParameter("shareNewTopics");
|
||||
|
||||
return new ReconJudgeSimilarCellsOperation(
|
||||
engineConfig,
|
||||
columnName,
|
||||
similarValue,
|
||||
judgment,
|
||||
match,
|
||||
"true".equals(shareNewTopics)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ import com.metaweb.gridworks.model.AbstractOperation;
|
||||
import com.metaweb.gridworks.operations.ReconMarkNewTopicsOperation;
|
||||
|
||||
public class ReconMarkNewTopicsCommand extends EngineDependentCommand {
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
return new ReconMarkNewTopicsOperation(
|
||||
engineConfig,
|
||||
request.getParameter("columnName"),
|
||||
"true".equals(request.getParameter("shareNewTopics"))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
return new ReconMarkNewTopicsOperation(
|
||||
engineConfig,
|
||||
request.getParameter("columnName"),
|
||||
"true".equals(request.getParameter("shareNewTopics"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ import com.metaweb.gridworks.model.AbstractOperation;
|
||||
import com.metaweb.gridworks.operations.ReconMatchBestCandidatesOperation;
|
||||
|
||||
public class ReconMatchBestCandidatesCommand extends EngineDependentCommand {
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
|
||||
return new ReconMatchBestCandidatesOperation(engineConfig, columnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
|
||||
return new ReconMatchBestCandidatesOperation(engineConfig, columnName);
|
||||
}
|
||||
}
|
||||
|
@ -10,20 +10,20 @@ import com.metaweb.gridworks.model.ReconCandidate;
|
||||
import com.metaweb.gridworks.operations.ReconMatchSpecificTopicOperation;
|
||||
|
||||
public class ReconMatchSpecificTopicCommand extends EngineDependentCommand {
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
ReconCandidate match = new ReconCandidate(
|
||||
request.getParameter("topicID"),
|
||||
request.getParameter("topicGUID"),
|
||||
request.getParameter("topicName"),
|
||||
request.getParameter("types").split(","),
|
||||
100
|
||||
);
|
||||
|
||||
return new ReconMatchSpecificTopicOperation(engineConfig, columnName, match);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
ReconCandidate match = new ReconCandidate(
|
||||
request.getParameter("topicID"),
|
||||
request.getParameter("topicGUID"),
|
||||
request.getParameter("topicName"),
|
||||
request.getParameter("types").split(","),
|
||||
100
|
||||
);
|
||||
|
||||
return new ReconMatchSpecificTopicOperation(engineConfig, columnName, match);
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,17 @@ import com.metaweb.gridworks.model.recon.ReconConfig;
|
||||
import com.metaweb.gridworks.operations.ReconOperation;
|
||||
|
||||
public class ReconcileCommand extends EngineDependentCommand {
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String configString = request.getParameter("config");
|
||||
|
||||
JSONTokener t = new JSONTokener(configString);
|
||||
JSONObject config = (JSONObject) t.nextValue();
|
||||
|
||||
return new ReconOperation(engineConfig, columnName, ReconConfig.reconstruct(config));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractOperation createOperation(HttpServletRequest request,
|
||||
JSONObject engineConfig) throws Exception {
|
||||
|
||||
String columnName = request.getParameter("columnName");
|
||||
String configString = request.getParameter("config");
|
||||
|
||||
JSONTokener t = new JSONTokener(configString);
|
||||
JSONObject config = (JSONObject) t.nextValue();
|
||||
|
||||
return new ReconOperation(engineConfig, columnName, ReconConfig.reconstruct(config));
|
||||
}
|
||||
}
|
||||
|
@ -10,20 +10,20 @@ import com.metaweb.gridworks.commands.Command;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class CancelProcessesCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
project.processManager.cancelAll();
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
response.getWriter().write("{ \"code\" : \"ok\" }");
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,43 +16,43 @@ import com.metaweb.gridworks.gel.ControlFunctionRegistry;
|
||||
import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class GetExpressionLanguageInfoCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
Properties options = new Properties();
|
||||
|
||||
writer.object();
|
||||
|
||||
writer.key("functions");
|
||||
writer.object();
|
||||
{
|
||||
for (Entry<String, Function> entry : ControlFunctionRegistry.getFunctionMapping()) {
|
||||
writer.key(entry.getKey());
|
||||
entry.getValue().write(writer, options);
|
||||
}
|
||||
}
|
||||
writer.endObject();
|
||||
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
Properties options = new Properties();
|
||||
|
||||
writer.object();
|
||||
|
||||
writer.key("functions");
|
||||
writer.object();
|
||||
{
|
||||
for (Entry<String, Function> entry : ControlFunctionRegistry.getFunctionMapping()) {
|
||||
writer.key(entry.getKey());
|
||||
entry.getValue().write(writer, options);
|
||||
}
|
||||
}
|
||||
writer.endObject();
|
||||
|
||||
writer.key("controls");
|
||||
writer.object();
|
||||
{
|
||||
for (Entry<String, Control> entry : ControlFunctionRegistry.getControlMapping()) {
|
||||
writer.key(entry.getKey());
|
||||
entry.getValue().write(writer, options);
|
||||
entry.getValue().write(writer, options);
|
||||
}
|
||||
}
|
||||
writer.endObject();
|
||||
|
||||
writer.endObject();
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
writer.endObject();
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,181 +30,181 @@ import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||
|
||||
public class GuessTypesOfColumnCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
String columnName = request.getParameter("columnName");
|
||||
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
String columnName = request.getParameter("columnName");
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
writer.object();
|
||||
|
||||
Column column = project.columnModel.getColumnByName(columnName);
|
||||
if (column == null) {
|
||||
writer.key("code"); writer.value("error");
|
||||
writer.key("message"); writer.value("No such column");
|
||||
} else {
|
||||
try {
|
||||
writer.key("code"); writer.value("ok");
|
||||
writer.key("types"); writer.array();
|
||||
|
||||
List<TypeGroup> typeGroups = guessTypes(project, column);
|
||||
for (TypeGroup tg : typeGroups) {
|
||||
writer.object();
|
||||
writer.key("id"); writer.value(tg.id);
|
||||
writer.key("name"); writer.value(tg.name);
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
writer.object();
|
||||
|
||||
Column column = project.columnModel.getColumnByName(columnName);
|
||||
if (column == null) {
|
||||
writer.key("code"); writer.value("error");
|
||||
writer.key("message"); writer.value("No such column");
|
||||
} else {
|
||||
try {
|
||||
writer.key("code"); writer.value("ok");
|
||||
writer.key("types"); writer.array();
|
||||
|
||||
List<TypeGroup> typeGroups = guessTypes(project, column);
|
||||
for (TypeGroup tg : typeGroups) {
|
||||
writer.object();
|
||||
writer.key("id"); writer.value(tg.id);
|
||||
writer.key("name"); writer.value(tg.name);
|
||||
writer.key("score"); writer.value(tg.score);
|
||||
writer.key("count"); writer.value(tg.count);
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
writer.endArray();
|
||||
} catch (Exception e) {
|
||||
writer.key("code"); writer.value("error");
|
||||
}
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
writer.endArray();
|
||||
} catch (Exception e) {
|
||||
writer.key("code"); writer.value("error");
|
||||
}
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
final static int s_sampleSize = 20;
|
||||
|
||||
protected List<TypeGroup> guessTypes(Project project, Column column) {
|
||||
Map<String, TypeGroup> map = new HashMap<String, TypeGroup>();
|
||||
|
||||
int cellIndex = column.getCellIndex();
|
||||
|
||||
List<String> samples = new ArrayList<String>(s_sampleSize);
|
||||
Set<String> sampleSet = new HashSet<String>();
|
||||
|
||||
for (Row row : project.rows) {
|
||||
Object value = row.getCellValue(cellIndex);
|
||||
if (ExpressionUtils.isNonBlankData(value)) {
|
||||
String s = value.toString().trim();
|
||||
if (!sampleSet.contains(s)) {
|
||||
samples.add(s);
|
||||
sampleSet.add(s);
|
||||
if (samples.size() >= s_sampleSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JSONWriter jsonWriter = new JSONWriter(stringWriter);
|
||||
|
||||
jsonWriter.object();
|
||||
for (int i = 0; i < samples.size(); i++) {
|
||||
jsonWriter.key("q" + i + ":search");
|
||||
jsonWriter.object();
|
||||
|
||||
jsonWriter.key("query"); jsonWriter.value(samples.get(i));
|
||||
jsonWriter.key("limit"); jsonWriter.value(3);
|
||||
|
||||
jsonWriter.endObject();
|
||||
}
|
||||
jsonWriter.endObject();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("http://api.freebase.com/api/service/search?indent=1&queries=");
|
||||
sb.append(ParsingUtilities.encode(stringWriter.toString()));
|
||||
|
||||
URL url = new URL(sb.toString());
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.connect();
|
||||
|
||||
InputStream is = connection.getInputStream();
|
||||
try {
|
||||
String s = ParsingUtilities.inputStreamToString(is);
|
||||
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
|
||||
|
||||
for (int i = 0; i < samples.size(); i++) {
|
||||
String key = "q" + i + ":search";
|
||||
if (!o.has(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONObject o2 = o.getJSONObject(key);
|
||||
if (!(o2.has("result"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONArray results = o2.getJSONArray("result");
|
||||
int count = results.length();
|
||||
|
||||
for (int j = 0; j < count; j++) {
|
||||
JSONObject result = results.getJSONObject(j);
|
||||
double score = 1.0 / (1 + j); //result.getDouble("relevance:score");
|
||||
|
||||
JSONArray types = result.getJSONArray("type");
|
||||
int typeCount = types.length();
|
||||
|
||||
for (int t = 0; t < typeCount; t++) {
|
||||
JSONObject type = types.getJSONObject(t);
|
||||
String id = type.getString("id");
|
||||
if (id.equals("/common/topic") ||
|
||||
id.equals("/base/ontologies/ontology_instance") ||
|
||||
(id.startsWith("/base/") && id.endsWith("/topic")) ||
|
||||
id.startsWith("/user/") ||
|
||||
id.startsWith("/freebase/")
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (map.containsKey(id)) {
|
||||
TypeGroup tg = map.get(id);
|
||||
tg.score += score;
|
||||
tg.count++;
|
||||
} else {
|
||||
map.put(id, new TypeGroup(id, type.getString("name"), score));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<TypeGroup> types = new ArrayList<TypeGroup>(map.values());
|
||||
Collections.sort(types, new Comparator<TypeGroup>() {
|
||||
public int compare(TypeGroup o1, TypeGroup o2) {
|
||||
int c = Math.min(s_sampleSize, o2.count) - Math.min(s_sampleSize, o1.count);
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
return (int) Math.signum(o2.score / o2.count - o1.score / o1.count);
|
||||
}
|
||||
});
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
static protected class TypeGroup {
|
||||
String id;
|
||||
String name;
|
||||
int count;
|
||||
double score;
|
||||
|
||||
TypeGroup(String id, String name, double score) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.score = score;
|
||||
this.count = 1;
|
||||
}
|
||||
}
|
||||
protected List<TypeGroup> guessTypes(Project project, Column column) {
|
||||
Map<String, TypeGroup> map = new HashMap<String, TypeGroup>();
|
||||
|
||||
int cellIndex = column.getCellIndex();
|
||||
|
||||
List<String> samples = new ArrayList<String>(s_sampleSize);
|
||||
Set<String> sampleSet = new HashSet<String>();
|
||||
|
||||
for (Row row : project.rows) {
|
||||
Object value = row.getCellValue(cellIndex);
|
||||
if (ExpressionUtils.isNonBlankData(value)) {
|
||||
String s = value.toString().trim();
|
||||
if (!sampleSet.contains(s)) {
|
||||
samples.add(s);
|
||||
sampleSet.add(s);
|
||||
if (samples.size() >= s_sampleSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JSONWriter jsonWriter = new JSONWriter(stringWriter);
|
||||
|
||||
jsonWriter.object();
|
||||
for (int i = 0; i < samples.size(); i++) {
|
||||
jsonWriter.key("q" + i + ":search");
|
||||
jsonWriter.object();
|
||||
|
||||
jsonWriter.key("query"); jsonWriter.value(samples.get(i));
|
||||
jsonWriter.key("limit"); jsonWriter.value(3);
|
||||
|
||||
jsonWriter.endObject();
|
||||
}
|
||||
jsonWriter.endObject();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("http://api.freebase.com/api/service/search?indent=1&queries=");
|
||||
sb.append(ParsingUtilities.encode(stringWriter.toString()));
|
||||
|
||||
URL url = new URL(sb.toString());
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.connect();
|
||||
|
||||
InputStream is = connection.getInputStream();
|
||||
try {
|
||||
String s = ParsingUtilities.inputStreamToString(is);
|
||||
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
|
||||
|
||||
for (int i = 0; i < samples.size(); i++) {
|
||||
String key = "q" + i + ":search";
|
||||
if (!o.has(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONObject o2 = o.getJSONObject(key);
|
||||
if (!(o2.has("result"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONArray results = o2.getJSONArray("result");
|
||||
int count = results.length();
|
||||
|
||||
for (int j = 0; j < count; j++) {
|
||||
JSONObject result = results.getJSONObject(j);
|
||||
double score = 1.0 / (1 + j); //result.getDouble("relevance:score");
|
||||
|
||||
JSONArray types = result.getJSONArray("type");
|
||||
int typeCount = types.length();
|
||||
|
||||
for (int t = 0; t < typeCount; t++) {
|
||||
JSONObject type = types.getJSONObject(t);
|
||||
String id = type.getString("id");
|
||||
if (id.equals("/common/topic") ||
|
||||
id.equals("/base/ontologies/ontology_instance") ||
|
||||
(id.startsWith("/base/") && id.endsWith("/topic")) ||
|
||||
id.startsWith("/user/") ||
|
||||
id.startsWith("/freebase/")
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (map.containsKey(id)) {
|
||||
TypeGroup tg = map.get(id);
|
||||
tg.score += score;
|
||||
tg.count++;
|
||||
} else {
|
||||
map.put(id, new TypeGroup(id, type.getString("name"), score));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<TypeGroup> types = new ArrayList<TypeGroup>(map.values());
|
||||
Collections.sort(types, new Comparator<TypeGroup>() {
|
||||
public int compare(TypeGroup o1, TypeGroup o2) {
|
||||
int c = Math.min(s_sampleSize, o2.count) - Math.min(s_sampleSize, o1.count);
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
return (int) Math.signum(o2.score / o2.count - o1.score / o1.count);
|
||||
}
|
||||
});
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
static protected class TypeGroup {
|
||||
String id;
|
||||
String name;
|
||||
int count;
|
||||
double score;
|
||||
|
||||
TypeGroup(String id, String name, double score) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.score = score;
|
||||
this.count = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,81 +22,81 @@ import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
public class PreviewExpressionCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
int cellIndex = Integer.parseInt(request.getParameter("cellIndex"));
|
||||
|
||||
String expression = request.getParameter("expression");
|
||||
String rowIndicesString = request.getParameter("rowIndices");
|
||||
if (rowIndicesString == null) {
|
||||
respond(response, "{ \"code\" : \"error\", \"message\" : \"No row indices specified\" }");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
int cellIndex = Integer.parseInt(request.getParameter("cellIndex"));
|
||||
|
||||
String expression = request.getParameter("expression");
|
||||
String rowIndicesString = request.getParameter("rowIndices");
|
||||
if (rowIndicesString == null) {
|
||||
respond(response, "{ \"code\" : \"error\", \"message\" : \"No row indices specified\" }");
|
||||
return;
|
||||
}
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
JSONArray rowIndices = jsonStringToArray(rowIndicesString);
|
||||
int length = rowIndices.length();
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
writer.object();
|
||||
|
||||
try {
|
||||
Evaluable eval = MetaParser.parse(expression);
|
||||
|
||||
writer.key("code"); writer.value("ok");
|
||||
writer.key("results"); writer.array();
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
for (int i = 0; i < length; i++) {
|
||||
Object result = null;
|
||||
|
||||
int rowIndex = rowIndices.getInt(i);
|
||||
if (rowIndex >= 0 && rowIndex < project.rows.size()) {
|
||||
Row row = project.rows.get(rowIndex);
|
||||
Cell cell = row.getCell(cellIndex);
|
||||
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
|
||||
try {
|
||||
result = eval.evaluate(bindings);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (ExpressionUtils.isError(result)) {
|
||||
writer.object();
|
||||
writer.key("message"); writer.value(((EvalError) result).message);
|
||||
writer.endObject();
|
||||
} else {
|
||||
if (result != null && result instanceof HasFields) {
|
||||
result = "[object " + result.getClass().getSimpleName() + "]";
|
||||
}
|
||||
writer.value(result);
|
||||
}
|
||||
}
|
||||
writer.endArray();
|
||||
} catch (ParsingException e) {
|
||||
|
||||
JSONArray rowIndices = jsonStringToArray(rowIndicesString);
|
||||
int length = rowIndices.length();
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
writer.object();
|
||||
|
||||
try {
|
||||
Evaluable eval = MetaParser.parse(expression);
|
||||
|
||||
writer.key("code"); writer.value("ok");
|
||||
writer.key("results"); writer.array();
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
for (int i = 0; i < length; i++) {
|
||||
Object result = null;
|
||||
|
||||
int rowIndex = rowIndices.getInt(i);
|
||||
if (rowIndex >= 0 && rowIndex < project.rows.size()) {
|
||||
Row row = project.rows.get(rowIndex);
|
||||
Cell cell = row.getCell(cellIndex);
|
||||
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
|
||||
try {
|
||||
result = eval.evaluate(bindings);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (ExpressionUtils.isError(result)) {
|
||||
writer.object();
|
||||
writer.key("message"); writer.value(((EvalError) result).message);
|
||||
writer.endObject();
|
||||
} else {
|
||||
if (result != null && result instanceof HasFields) {
|
||||
result = "[object " + result.getClass().getSimpleName() + "]";
|
||||
}
|
||||
writer.value(result);
|
||||
}
|
||||
}
|
||||
writer.endArray();
|
||||
} catch (ParsingException e) {
|
||||
writer.key("code"); writer.value("error");
|
||||
writer.key("type"); writer.value("parser");
|
||||
writer.key("message"); writer.value(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
writer.key("code"); writer.value("error");
|
||||
} catch (Exception e) {
|
||||
writer.key("code"); writer.value("error");
|
||||
writer.key("type"); writer.value("other");
|
||||
writer.key("message"); writer.value(e.getMessage());
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,48 +17,48 @@ import com.metaweb.gridworks.protograph.transpose.Transposer;
|
||||
import com.metaweb.gridworks.protograph.transpose.TripleLoaderTransposedNodeFactory;
|
||||
|
||||
public class PreviewProtographCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Project project = getProject(request);
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
String jsonString = request.getParameter("protograph");
|
||||
JSONObject json = jsonStringToObject(jsonString);
|
||||
Protograph protograph = Protograph.reconstruct(json);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("{ ");
|
||||
|
||||
{
|
||||
TripleLoaderTransposedNodeFactory nodeFactory = new TripleLoaderTransposedNodeFactory();
|
||||
|
||||
Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory);
|
||||
|
||||
sb.append("\"tripleloader\" : ");
|
||||
sb.append(JSONObject.quote(nodeFactory.getLoad()));
|
||||
}
|
||||
|
||||
{
|
||||
MqlreadLikeTransposedNodeFactory nodeFactory = new MqlreadLikeTransposedNodeFactory();
|
||||
|
||||
Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory);
|
||||
|
||||
JSONArray results = nodeFactory.getJSON();
|
||||
|
||||
sb.append(", \"mqllike\" : ");
|
||||
sb.append(results.toString());
|
||||
}
|
||||
|
||||
String jsonString = request.getParameter("protograph");
|
||||
JSONObject json = jsonStringToObject(jsonString);
|
||||
Protograph protograph = Protograph.reconstruct(json);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("{ ");
|
||||
|
||||
{
|
||||
TripleLoaderTransposedNodeFactory nodeFactory = new TripleLoaderTransposedNodeFactory();
|
||||
|
||||
Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory);
|
||||
|
||||
sb.append("\"tripleloader\" : ");
|
||||
sb.append(JSONObject.quote(nodeFactory.getLoad()));
|
||||
}
|
||||
|
||||
{
|
||||
MqlreadLikeTransposedNodeFactory nodeFactory = new MqlreadLikeTransposedNodeFactory();
|
||||
|
||||
Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory);
|
||||
|
||||
JSONArray results = nodeFactory.getJSON();
|
||||
|
||||
sb.append(", \"mqllike\" : ");
|
||||
sb.append(results.toString());
|
||||
}
|
||||
|
||||
sb.append(" }");
|
||||
|
||||
respond(response, sb.toString());
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
sb.append(" }");
|
||||
|
||||
respond(response, sb.toString());
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ package com.metaweb.gridworks.expr;
|
||||
import java.util.Properties;
|
||||
|
||||
public interface Evaluable {
|
||||
public Object evaluate(Properties bindings);
|
||||
public Object evaluate(Properties bindings);
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ package com.metaweb.gridworks.expr;
|
||||
import java.util.Properties;
|
||||
|
||||
public interface HasFields {
|
||||
public Object getField(String name, Properties bindings);
|
||||
public Object getField(String name, Properties bindings);
|
||||
}
|
||||
|
@ -10,85 +10,85 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Get implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length > 1 && args.length <= 3) {
|
||||
Object v = args[0];
|
||||
Object from = args[1];
|
||||
Object to = args.length == 3 ? args[2] : null;
|
||||
|
||||
if (v != null && from != null) {
|
||||
if (v instanceof HasFields) {
|
||||
if (from instanceof String) {
|
||||
return ((HasFields) v).getField((String) from, bindings);
|
||||
}
|
||||
} else {
|
||||
if (from instanceof Number && (to == null || to instanceof Number)) {
|
||||
if (v.getClass().isArray()) {
|
||||
Object[] a = (Object[]) v;
|
||||
int start = ((Number) from).intValue();
|
||||
if (start < 0) {
|
||||
start = a.length + start;
|
||||
}
|
||||
start = Math.min(a.length, Math.max(0, start));
|
||||
|
||||
if (to == null) {
|
||||
return start < a.length ? a[start] : null;
|
||||
} else {
|
||||
int end = to != null && to instanceof Number ?
|
||||
((Number) to).intValue() : a.length;
|
||||
|
||||
if (end < 0) {
|
||||
end = a.length + end;
|
||||
}
|
||||
end = Math.min(a.length, Math.max(start, end));
|
||||
|
||||
if (end > start) {
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length > 1 && args.length <= 3) {
|
||||
Object v = args[0];
|
||||
Object from = args[1];
|
||||
Object to = args.length == 3 ? args[2] : null;
|
||||
|
||||
if (v != null && from != null) {
|
||||
if (v instanceof HasFields) {
|
||||
if (from instanceof String) {
|
||||
return ((HasFields) v).getField((String) from, bindings);
|
||||
}
|
||||
} else {
|
||||
if (from instanceof Number && (to == null || to instanceof Number)) {
|
||||
if (v.getClass().isArray()) {
|
||||
Object[] a = (Object[]) v;
|
||||
int start = ((Number) from).intValue();
|
||||
if (start < 0) {
|
||||
start = a.length + start;
|
||||
}
|
||||
start = Math.min(a.length, Math.max(0, start));
|
||||
|
||||
if (to == null) {
|
||||
return start < a.length ? a[start] : null;
|
||||
} else {
|
||||
int end = to != null && to instanceof Number ?
|
||||
((Number) to).intValue() : a.length;
|
||||
|
||||
if (end < 0) {
|
||||
end = a.length + end;
|
||||
}
|
||||
end = Math.min(a.length, Math.max(start, end));
|
||||
|
||||
if (end > start) {
|
||||
Object[] a2 = new Object[end - start];
|
||||
|
||||
System.arraycopy(a, start, a2, 0, end - start);
|
||||
|
||||
System.arraycopy(a, start, a2, 0, end - start);
|
||||
|
||||
return a2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String s = (v instanceof String ? (String) v : v.toString());
|
||||
|
||||
int start = ((Number) from).intValue();
|
||||
if (start < 0) {
|
||||
start = s.length() + start;
|
||||
}
|
||||
start = Math.min(s.length(), Math.max(0, start));
|
||||
|
||||
if (to != null && to instanceof Number) {
|
||||
int end = ((Number) to).intValue();
|
||||
if (end < 0) {
|
||||
end = s.length() + end;
|
||||
}
|
||||
end = Math.min(s.length(), Math.max(start, end));
|
||||
|
||||
return s.substring(start, end);
|
||||
} else {
|
||||
return s.substring(start, start + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String s = (v instanceof String ? (String) v : v.toString());
|
||||
|
||||
int start = ((Number) from).intValue();
|
||||
if (start < 0) {
|
||||
start = s.length() + start;
|
||||
}
|
||||
start = Math.min(s.length(), Math.max(0, start));
|
||||
|
||||
if (to != null && to instanceof Number) {
|
||||
int end = ((Number) to).intValue();
|
||||
if (end < 0) {
|
||||
end = s.length() + end;
|
||||
}
|
||||
end = Math.min(s.length(), Math.max(start, end));
|
||||
|
||||
return s.substring(start, end);
|
||||
} else {
|
||||
return s.substring(start, start + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(
|
||||
"If o has fields, returns the field named 'from' of o. " +
|
||||
"If o is an array, returns o[from, to]. " +
|
||||
"if o is a string, returns o.substring(from, to)"
|
||||
);
|
||||
writer.key("params"); writer.value("o, number or string from, optional number to");
|
||||
writer.key("returns"); writer.value("Depends on actual arguments");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(
|
||||
"If o has fields, returns the field named 'from' of o. " +
|
||||
"If o is an array, returns o[from, to]. " +
|
||||
"if o is a string, returns o.substring(from, to)"
|
||||
);
|
||||
writer.key("params"); writer.value("o, number or string from, optional number to");
|
||||
writer.key("returns"); writer.value("Depends on actual arguments");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,30 +11,30 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Length implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
Object v = args[0];
|
||||
|
||||
if (v != null) {
|
||||
if (v.getClass().isArray()) {
|
||||
Object[] a = (Object[]) v;
|
||||
return a.length;
|
||||
} else {
|
||||
String s = (v instanceof String ? (String) v : v.toString());
|
||||
return s.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
Object v = args[0];
|
||||
|
||||
if (v != null) {
|
||||
if (v.getClass().isArray()) {
|
||||
Object[] a = (Object[]) v;
|
||||
return a.length;
|
||||
} else {
|
||||
String s = (v instanceof String ? (String) v : v.toString());
|
||||
return s.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array or a string");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the length of o");
|
||||
writer.key("params"); writer.value("array or string o");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the length of o");
|
||||
writer.key("params"); writer.value("array or string o");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -9,69 +9,69 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Slice implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length > 1 && args.length <= 3) {
|
||||
Object v = args[0];
|
||||
Object from = args[1];
|
||||
Object to = args.length == 3 ? args[2] : null;
|
||||
|
||||
if (v != null && from != null && from instanceof Number && (to == null || to instanceof Number)) {
|
||||
if (v.getClass().isArray()) {
|
||||
Object[] a = (Object[]) v;
|
||||
int start = ((Number) from).intValue();
|
||||
int end = to != null && to instanceof Number ?
|
||||
((Number) to).intValue() : a.length;
|
||||
|
||||
if (start < 0) {
|
||||
start = a.length + start;
|
||||
}
|
||||
start = Math.min(a.length, Math.max(0, start));
|
||||
|
||||
if (end < 0) {
|
||||
end = a.length + end;
|
||||
}
|
||||
end = Math.min(a.length, Math.max(start, end));
|
||||
|
||||
Object[] a2 = new Object[end - start];
|
||||
System.arraycopy(a, start, a2, 0, end - start);
|
||||
|
||||
return a2;
|
||||
} else {
|
||||
String s = (v instanceof String ? (String) v : v.toString());
|
||||
|
||||
int start = ((Number) from).intValue();
|
||||
if (start < 0) {
|
||||
start = s.length() + start;
|
||||
}
|
||||
start = Math.min(s.length(), Math.max(0, start));
|
||||
|
||||
if (to != null && to instanceof Number) {
|
||||
int end = ((Number) to).intValue();
|
||||
if (end < 0) {
|
||||
end = s.length() + end;
|
||||
}
|
||||
end = Math.min(s.length(), Math.max(start, end));
|
||||
|
||||
return s.substring(start, end);
|
||||
} else {
|
||||
return s.substring(start);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length > 1 && args.length <= 3) {
|
||||
Object v = args[0];
|
||||
Object from = args[1];
|
||||
Object to = args.length == 3 ? args[2] : null;
|
||||
|
||||
if (v != null && from != null && from instanceof Number && (to == null || to instanceof Number)) {
|
||||
if (v.getClass().isArray()) {
|
||||
Object[] a = (Object[]) v;
|
||||
int start = ((Number) from).intValue();
|
||||
int end = to != null && to instanceof Number ?
|
||||
((Number) to).intValue() : a.length;
|
||||
|
||||
if (start < 0) {
|
||||
start = a.length + start;
|
||||
}
|
||||
start = Math.min(a.length, Math.max(0, start));
|
||||
|
||||
if (end < 0) {
|
||||
end = a.length + end;
|
||||
}
|
||||
end = Math.min(a.length, Math.max(start, end));
|
||||
|
||||
Object[] a2 = new Object[end - start];
|
||||
System.arraycopy(a, start, a2, 0, end - start);
|
||||
|
||||
return a2;
|
||||
} else {
|
||||
String s = (v instanceof String ? (String) v : v.toString());
|
||||
|
||||
int start = ((Number) from).intValue();
|
||||
if (start < 0) {
|
||||
start = s.length() + start;
|
||||
}
|
||||
start = Math.min(s.length(), Math.max(0, start));
|
||||
|
||||
if (to != null && to instanceof Number) {
|
||||
int end = ((Number) to).intValue();
|
||||
if (end < 0) {
|
||||
end = s.length() + end;
|
||||
}
|
||||
end = Math.min(s.length(), Math.max(start, end));
|
||||
|
||||
return s.substring(start, end);
|
||||
} else {
|
||||
return s.substring(start);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(
|
||||
"If o is an array, returns o[from, to]. " +
|
||||
"if o is a string, returns o.substring(from, to)"
|
||||
);
|
||||
writer.key("params"); writer.value("o, number from, optional number to");
|
||||
writer.key("returns"); writer.value("Depends on actual arguments");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value(
|
||||
"If o is an array, returns o[from, to]. " +
|
||||
"if o is a string, returns o.substring(from, to)"
|
||||
);
|
||||
writer.key("params"); writer.value("o, number from, optional number to");
|
||||
writer.key("returns"); writer.value("Depends on actual arguments");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class ToDate implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 || args.length == 2) {
|
||||
Object o1 = args[0];
|
||||
if (o1 != null && o1 instanceof String) {
|
||||
@ -28,18 +28,18 @@ public class ToDate implements Function {
|
||||
// do something about
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns o converted to a date object");
|
||||
writer.key("params"); writer.value("o, boolean month_first (optional)");
|
||||
writer.key("returns"); writer.value("date");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns o converted to a date object");
|
||||
writer.key("params"); writer.value("o, boolean month_first (optional)");
|
||||
writer.key("returns"); writer.value("date");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -9,21 +9,21 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class ToNumber implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
return args[0] instanceof Number ? args[0] : Double.parseDouble(args[0].toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns o converted to a number");
|
||||
writer.key("params"); writer.value("o");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
return args[0] instanceof Number ? args[0] : Double.parseDouble(args[0].toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns o converted to a number");
|
||||
writer.key("params"); writer.value("o");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class ToString implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length >= 1) {
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length >= 1) {
|
||||
Object o1 = args[0];
|
||||
if (o1 != null) {
|
||||
if (o1 instanceof Calendar) {
|
||||
@ -27,18 +27,18 @@ public class ToString implements Function {
|
||||
return (o1 instanceof String) ? o1 : o1.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns o converted to a string");
|
||||
writer.key("params"); writer.value("o, string format (optional)");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns o converted to a string");
|
||||
writer.key("params"); writer.value("o, string format (optional)");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,40 +11,40 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Join implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object v = args[0];
|
||||
Object s = args[1];
|
||||
|
||||
if (v != null && v.getClass().isArray() &&
|
||||
s != null && s instanceof String) {
|
||||
|
||||
Object[] a = (Object[]) v;
|
||||
String separator = (String) s;
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (Object o : a) {
|
||||
if (o != null) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(separator);
|
||||
}
|
||||
sb.append(o.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object v = args[0];
|
||||
Object s = args[1];
|
||||
|
||||
if (v != null && v.getClass().isArray() &&
|
||||
s != null && s instanceof String) {
|
||||
|
||||
Object[] a = (Object[]) v;
|
||||
String separator = (String) s;
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (Object o : a) {
|
||||
if (o != null) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(separator);
|
||||
}
|
||||
sb.append(o.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array and a string");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the string obtained by joining the array a with the separator sep");
|
||||
writer.key("params"); writer.value("array a, string sep");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the string obtained by joining the array a with the separator sep");
|
||||
writer.key("params"); writer.value("array a, string sep");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,31 +11,31 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Reverse implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
Object v = args[0];
|
||||
|
||||
if (v != null && v.getClass().isArray()) {
|
||||
Object[] a = (Object[]) v;
|
||||
Object[] r = new Object[a.length];
|
||||
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
r[i] = a[r.length - i - 1];
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
Object v = args[0];
|
||||
|
||||
if (v != null && v.getClass().isArray()) {
|
||||
Object[] a = (Object[]) v;
|
||||
Object[] r = new Object[a.length];
|
||||
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
r[i] = a[r.length - i - 1];
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Reverses array a");
|
||||
writer.key("params"); writer.value("array a");
|
||||
writer.key("returns"); writer.value("array");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Reverses array a");
|
||||
writer.key("params"); writer.value("array a");
|
||||
writer.key("returns"); writer.value("array");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -12,30 +12,30 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Sort implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
Object v = args[0];
|
||||
|
||||
|
||||
if (v != null && v.getClass().isArray()) {
|
||||
Object[] a = (Object[]) v;
|
||||
Object[] r = a.clone();
|
||||
|
||||
Arrays.sort(r, 0, r.length);
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
Object v = args[0];
|
||||
|
||||
|
||||
if (v != null && v.getClass().isArray()) {
|
||||
Object[] a = (Object[]) v;
|
||||
Object[] r = a.clone();
|
||||
|
||||
Arrays.sort(r, 0, r.length);
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Sorts array a");
|
||||
writer.key("params"); writer.value("array a");
|
||||
writer.key("returns"); writer.value("array");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Sorts array a");
|
||||
writer.key("params"); writer.value("array a");
|
||||
writer.key("returns"); writer.value("array");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -9,22 +9,22 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class And implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
for (Object o : args) {
|
||||
if (!Not.objectToBoolean(o)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
for (Object o : args) {
|
||||
if (!Not.objectToBoolean(o)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("ANDs two boolean values");
|
||||
writer.key("params"); writer.value("boolean a, boolean b");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,25 +11,25 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Not implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
return !objectToBoolean(args[0]);
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
return !objectToBoolean(args[0]);
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a boolean");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean objectToBoolean(Object o) {
|
||||
return o == null ? false : (
|
||||
(o instanceof Boolean) ? ((Boolean) o).booleanValue() : Boolean.parseBoolean(o.toString()));
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the opposite of b");
|
||||
writer.key("params"); writer.value("boolean b");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
public static boolean objectToBoolean(Object o) {
|
||||
return o == null ? false : (
|
||||
(o instanceof Boolean) ? ((Boolean) o).booleanValue() : Boolean.parseBoolean(o.toString()));
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the opposite of b");
|
||||
writer.key("params"); writer.value("boolean b");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -9,22 +9,22 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Or implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
for (Object o : args) {
|
||||
if (Not.objectToBoolean(o)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns a OR b");
|
||||
writer.key("params"); writer.value("boolean a, boolean b");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
for (Object o : args) {
|
||||
if (Not.objectToBoolean(o)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns a OR b");
|
||||
writer.key("params"); writer.value("boolean a, boolean b");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,20 +11,20 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Ceil implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
||||
return (long) Math.ceil(((Number) args[0]).doubleValue());
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
||||
return (long) Math.ceil(((Number) args[0]).doubleValue());
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the ceiling of a number");
|
||||
writer.key("params"); writer.value("number d");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the ceiling of a number");
|
||||
writer.key("params"); writer.value("number d");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -9,20 +9,20 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Exp implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] instanceof Number) {
|
||||
return Math.exp(((Number) args[0]).doubleValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] instanceof Number) {
|
||||
return Math.exp(((Number) args[0]).doubleValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns e^n");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns e^n");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,21 +11,21 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Floor implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
||||
return (long) Math.floor(((Number) args[0]).doubleValue());
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
||||
return (long) Math.floor(((Number) args[0]).doubleValue());
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the floor of a number");
|
||||
writer.key("params"); writer.value("number d");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the floor of a number");
|
||||
writer.key("params"); writer.value("number d");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,20 +11,20 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Ln implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
||||
return Math.log(((Number) args[0]).doubleValue());
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
||||
return Math.log(((Number) args[0]).doubleValue());
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the natural log of n");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the natural log of n");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,20 +11,20 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Log implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
||||
return Math.log10(((Number) args[0]).doubleValue());
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
||||
return Math.log10(((Number) args[0]).doubleValue());
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the base 10 log of n");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the base 10 log of n");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,24 +11,24 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Max implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2 &&
|
||||
args[0] != null && args[0] instanceof Number &&
|
||||
args[1] != null && args[1] instanceof Number) {
|
||||
return Math.max(
|
||||
((Number) args[0]).doubleValue(),
|
||||
((Number) args[1]).doubleValue());
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2 &&
|
||||
args[0] != null && args[0] instanceof Number &&
|
||||
args[1] != null && args[1] instanceof Number) {
|
||||
return Math.max(
|
||||
((Number) args[0]).doubleValue(),
|
||||
((Number) args[1]).doubleValue());
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the greater of two numbers");
|
||||
writer.key("params"); writer.value("number a, number b");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the greater of two numbers");
|
||||
writer.key("params"); writer.value("number a, number b");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,24 +11,24 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Min implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2 &&
|
||||
args[0] != null && args[0] instanceof Number &&
|
||||
args[1] != null && args[1] instanceof Number) {
|
||||
return Math.min(
|
||||
((Number) args[0]).doubleValue(),
|
||||
((Number) args[1]).doubleValue());
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2 &&
|
||||
args[0] != null && args[0] instanceof Number &&
|
||||
args[1] != null && args[1] instanceof Number) {
|
||||
return Math.min(
|
||||
((Number) args[0]).doubleValue(),
|
||||
((Number) args[1]).doubleValue());
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the smaller of two numbers");
|
||||
writer.key("params"); writer.value("number a, number b");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the smaller of two numbers");
|
||||
writer.key("params"); writer.value("number a, number b");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,25 +11,25 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Mod implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2 &&
|
||||
args[0] != null && args[0] instanceof Number &&
|
||||
args[1] != null && args[1] instanceof Number) {
|
||||
int a = ((Number) args[0]).intValue();
|
||||
int b = ((Number) args[0]).intValue();
|
||||
|
||||
return a % b;
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2 &&
|
||||
args[0] != null && args[0] instanceof Number &&
|
||||
args[1] != null && args[1] instanceof Number) {
|
||||
int a = ((Number) args[0]).intValue();
|
||||
int b = ((Number) args[0]).intValue();
|
||||
|
||||
return a % b;
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns a modulus b");
|
||||
writer.key("params"); writer.value("number a, number b");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns a modulus b");
|
||||
writer.key("params"); writer.value("number a, number b");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,20 +11,20 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Round implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
||||
return ((Number) args[0]).longValue();
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
|
||||
return ((Number) args[0]).longValue();
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns n rounded");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns n rounded");
|
||||
writer.key("params"); writer.value("number n");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -9,23 +9,23 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Contains implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).indexOf((String) s2) > -1;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether s contains frag");
|
||||
writer.key("params"); writer.value("string s, string frag");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).indexOf((String) s2) > -1;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether s contains frag");
|
||||
writer.key("params"); writer.value("string s, string frag");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,24 +11,24 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class EndsWith implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).endsWith((String) s2);
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).endsWith((String) s2);
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether s ends with sub");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether s ends with sub");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -14,28 +14,28 @@ public class Fingerprint implements Function {
|
||||
|
||||
static final Pattern alphanum = Pattern.compile("\\p{Punct}|\\p{Cntrl}");
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
s = s.trim(); // first off, remove whitespace around the string
|
||||
s = s.toLowerCase(); // then lowercase it
|
||||
s = alphanum.matcher(s).replaceAll(""); // then remove all punctuation and control chars
|
||||
String[] frags = StringUtils.split(s); // split by whitespace
|
||||
Arrays.sort(frags); // sort the fragments
|
||||
return StringUtils.join(frags," "); // rejoin them with a single space between them
|
||||
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
s = s.trim(); // first off, remove whitespace around the string
|
||||
s = s.toLowerCase(); // then lowercase it
|
||||
s = alphanum.matcher(s).replaceAll(""); // then remove all punctuation and control chars
|
||||
String[] frags = StringUtils.split(s); // split by whitespace
|
||||
Arrays.sort(frags); // sort the fragments
|
||||
return StringUtils.join(frags," "); // rejoin them with a single space between them
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the fingerprint of s, a derived string that aims to be a more canonical form of it (this is mostly useful for finding clusters of strings related to the same information).");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the fingerprint of s, a derived string that aims to be a more canonical form of it (this is mostly useful for finding clusters of strings related to the same information).");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,24 +11,24 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class IndexOf implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).indexOf((String) s2);
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).indexOf((String) s2);
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the index of sub first ocurring in s");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the index of sub first ocurring in s");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,25 +11,25 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class LastIndexOf implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).lastIndexOf((String) s2);
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).lastIndexOf((String) s2);
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the index of sub last ocurring in s");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the index of sub last ocurring in s");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("number");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,22 +12,22 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class MD5 implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
return DigestUtils.md5Hex(s);
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
return DigestUtils.md5Hex(s);
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the MD5 hash of s");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the MD5 hash of s");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class Phonetic implements Function {
|
||||
private Metaphone metaphone = new Metaphone();
|
||||
private Soundex soundex = new Soundex();
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object o1 = args[0];
|
||||
Object o2 = args[1];
|
||||
@ -37,15 +37,15 @@ public class Phonetic implements Function {
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the a phonetic encoding of s (optionally indicating which encoding to use')");
|
||||
writer.key("params"); writer.value("string s, string encoding (optional, defaults to 'DoubleMetaphone')");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the a phonetic encoding of s (optionally indicating which encoding to use')");
|
||||
writer.key("params"); writer.value("string s, string encoding (optional, defaults to 'DoubleMetaphone')");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import com.metaweb.gridworks.model.Project;
|
||||
|
||||
public class Reinterpret implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object o1 = args[0];
|
||||
Object o2 = args[1];
|
||||
@ -37,15 +37,15 @@ public class Reinterpret implements Function {
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 arguments");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s reinterpreted thru the given encoder.");
|
||||
writer.key("params"); writer.value("string s, string encoder");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s reinterpreted thru the given encoder.");
|
||||
writer.key("params"); writer.value("string s, string encoder");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Replace implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 3) {
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 3) {
|
||||
Object o1 = args[0];
|
||||
Object o2 = args[1];
|
||||
Object o3 = args[2];
|
||||
@ -20,18 +20,18 @@ public class Replace implements Function {
|
||||
String str = (o1 instanceof String) ? (String) o1 : o1.toString();
|
||||
return str.replace((String) o2, (String) o3);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the string obtained by replacing f with r in s");
|
||||
writer.key("params"); writer.value("string s, string f, string r");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the string obtained by replacing f with r in s");
|
||||
writer.key("params"); writer.value("string s, string f, string r");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -12,27 +12,27 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class ReplaceChars implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 3) {
|
||||
Object o1 = args[0];
|
||||
Object o2 = args[1];
|
||||
Object o3 = args[2];
|
||||
if (o1 != null && o2 != null && o3 != null && o2 instanceof String && o3 instanceof String) {
|
||||
String str = (o1 instanceof String) ? (String) o1 : o1.toString();
|
||||
return StringUtils.replaceChars(str, (String) o2, (String) o3);
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 3) {
|
||||
Object o1 = args[0];
|
||||
Object o2 = args[1];
|
||||
Object o3 = args[2];
|
||||
if (o1 != null && o2 != null && o3 != null && o2 instanceof String && o3 instanceof String) {
|
||||
String str = (o1 instanceof String) ? (String) o1 : o1.toString();
|
||||
return StringUtils.replaceChars(str, (String) o2, (String) o3);
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the string obtained by replacing all chars in f with the char in s at that same position");
|
||||
writer.key("params"); writer.value("string s, string f, string r");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the string obtained by replacing all chars in f with the char in s at that same position");
|
||||
writer.key("params"); writer.value("string s, string f, string r");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class ReplaceRegexp implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 3) {
|
||||
Object o1 = args[0];
|
||||
Object o2 = args[1];
|
||||
@ -22,16 +22,16 @@ public class ReplaceRegexp implements Function {
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the string obtained by replacing f with r in s");
|
||||
writer.key("params"); writer.value("string s, string f, string r");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the string obtained by replacing f with r in s");
|
||||
writer.key("params"); writer.value("string s, string f, string r");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -12,22 +12,22 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class SHA1 implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
return DigestUtils.shaHex(s);
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
return DigestUtils.shaHex(s);
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the SHA-1 hash of s");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the SHA-1 hash of s");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,24 +11,24 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Split implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object v = args[0];
|
||||
Object split = args[1];
|
||||
if (v != null && split != null && split instanceof String) {
|
||||
return (v instanceof String ? (String) v : v.toString()).split((String) split);
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object v = args[0];
|
||||
Object split = args[1];
|
||||
if (v != null && split != null && split instanceof String) {
|
||||
return (v instanceof String ? (String) v : v.toString()).split((String) split);
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the array of strings obtained by splitting s with separator sep");
|
||||
writer.key("params"); writer.value("string s, string sep");
|
||||
writer.key("returns"); writer.value("array");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns the array of strings obtained by splitting s with separator sep");
|
||||
writer.key("params"); writer.value("string s, string sep");
|
||||
writer.key("returns"); writer.value("array");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -12,24 +12,24 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class SplitByCharType implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
Object o = args[0];
|
||||
if (o != null) {
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
return StringUtils.splitByCharacterType(s);
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
Object o = args[0];
|
||||
if (o != null) {
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
return StringUtils.splitByCharacterType(s);
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns an array of strings obtained by splitting s grouping consecutive chars by their unicode type");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("array");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns an array of strings obtained by splitting s grouping consecutive chars by their unicode type");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("array");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,23 +11,23 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class StartsWith implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).startsWith((String) s2);
|
||||
}
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).startsWith((String) s2);
|
||||
}
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether s starts with sub");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns whether s starts with sub");
|
||||
writer.key("params"); writer.value("string s, string sub");
|
||||
writer.key("returns"); writer.value("boolean");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,21 +11,21 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class ToLowercase implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
return (o instanceof String ? (String) o : o.toString()).toLowerCase();
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
return (o instanceof String ? (String) o : o.toString()).toLowerCase();
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s converted to lowercase");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s converted to lowercase");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -11,36 +11,36 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class ToTitlecase implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = o instanceof String ? (String) o : o.toString();
|
||||
String[] words = s.split("\\s+");
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < words.length; i++) {
|
||||
String word = words[i];
|
||||
if (word.length() > 0) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(' ');
|
||||
}
|
||||
sb.append(word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = o instanceof String ? (String) o : o.toString();
|
||||
String[] words = s.split("\\s+");
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < words.length; i++) {
|
||||
String word = words[i];
|
||||
if (word.length() > 0) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(' ');
|
||||
}
|
||||
sb.append(word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s converted to titlecase");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s converted to titlecase");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,21 +11,21 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class ToUppercase implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
return (o instanceof String ? (String) o : o.toString()).toUpperCase();
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
return (o instanceof String ? (String) o : o.toString()).toUpperCase();
|
||||
}
|
||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s converted to uppercase");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns s converted to uppercase");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -9,22 +9,22 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Trim implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
Object s1 = args[0];
|
||||
if (s1 != null && s1 instanceof String) {
|
||||
return ((String) s1).trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns copy of the string, with leading and trailing whitespace omitted.");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1) {
|
||||
Object s1 = args[0];
|
||||
if (s1 != null && s1 instanceof String) {
|
||||
return ((String) s1).trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns copy of the string, with leading and trailing whitespace omitted.");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -9,26 +9,26 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class Unicode implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
Integer[] output = new Integer[s.length()];
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
output[i] = s.codePointAt(i);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
Integer[] output = new Integer[s.length()];
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
output[i] = s.codePointAt(i);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns an array of strings describing each character of s in their full unicode notation");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns an array of strings describing each character of s in their full unicode notation");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -9,63 +9,63 @@ import com.metaweb.gridworks.gel.Function;
|
||||
|
||||
public class UnicodeType implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
String[] output = new String[s.length()];
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
output[i] = translateType(Character.getType(s.codePointAt(i)));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 1 && args[0] != null) {
|
||||
Object o = args[0];
|
||||
String s = (o instanceof String) ? (String) o : o.toString();
|
||||
String[] output = new String[s.length()];
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
output[i] = translateType(Character.getType(s.codePointAt(i)));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String translateType(int type) {
|
||||
switch(type) {
|
||||
case 0: return "unassigned";
|
||||
case 1: return "uppercase letter";
|
||||
case 2: return "lowercase letter";
|
||||
case 3: return "titlecase letter";
|
||||
case 4: return "modifier letter";
|
||||
case 5: return "other letter";
|
||||
case 6: return "non spacing mark";
|
||||
case 7: return "enclosing mark";
|
||||
case 8: return "combining spacing mark";
|
||||
case 9: return "decimal digit number";
|
||||
case 10: return "letter number";
|
||||
case 11: return "other number";
|
||||
case 12: return "space separator";
|
||||
case 13: return "line separator";
|
||||
case 14: return "paragraph separator";
|
||||
case 15: return "control";
|
||||
case 16: return "format";
|
||||
// 17 does not seem to be used
|
||||
case 18: return "private use";
|
||||
case 19: return "surrogate";
|
||||
case 20: return "dash punctuation";
|
||||
case 21: return "start punctuation";
|
||||
case 22: return "end punctuation";
|
||||
case 23: return "connector punctuation";
|
||||
case 24: return "other punctuation";
|
||||
case 25: return "math symbol";
|
||||
case 26: return "currency symbol";
|
||||
case 27: return "modifier symbol";
|
||||
case 28: return "other symbol";
|
||||
case 29: return "initial quote punctuation";
|
||||
case 30: return "final quote punctuation";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String translateType(int type) {
|
||||
switch(type) {
|
||||
case 0: return "unassigned";
|
||||
case 1: return "uppercase letter";
|
||||
case 2: return "lowercase letter";
|
||||
case 3: return "titlecase letter";
|
||||
case 4: return "modifier letter";
|
||||
case 5: return "other letter";
|
||||
case 6: return "non spacing mark";
|
||||
case 7: return "enclosing mark";
|
||||
case 8: return "combining spacing mark";
|
||||
case 9: return "decimal digit number";
|
||||
case 10: return "letter number";
|
||||
case 11: return "other number";
|
||||
case 12: return "space separator";
|
||||
case 13: return "line separator";
|
||||
case 14: return "paragraph separator";
|
||||
case 15: return "control";
|
||||
case 16: return "format";
|
||||
// 17 does not seem to be used
|
||||
case 18: return "private use";
|
||||
case 19: return "surrogate";
|
||||
case 20: return "dash punctuation";
|
||||
case 21: return "start punctuation";
|
||||
case 22: return "end punctuation";
|
||||
case 23: return "connector punctuation";
|
||||
case 24: return "other punctuation";
|
||||
case 25: return "math symbol";
|
||||
case 26: return "currency symbol";
|
||||
case 27: return "modifier symbol";
|
||||
case 28: return "other symbol";
|
||||
case 29: return "initial quote punctuation";
|
||||
case 30: return "final quote punctuation";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns an array of strings describing each character of s in their full unicode notation");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("description"); writer.value("Returns an array of strings describing each character of s in their full unicode notation");
|
||||
writer.key("params"); writer.value("string s");
|
||||
writer.key("returns"); writer.value("string");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user