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:
David Huynh 2010-03-03 04:19:58 +00:00
parent 2691ee50d7
commit b75f1faea8
185 changed files with 8803 additions and 8803 deletions

View File

@ -46,89 +46,89 @@ import com.metaweb.gridworks.commands.util.PreviewProtographCommand;
public class GridworksServlet extends HttpServlet { public class GridworksServlet extends HttpServlet {
private static final long serialVersionUID = 2386057901503517403L; private static final long serialVersionUID = 2386057901503517403L;
static protected Map<String, Command> _commands = new HashMap<String, Command>(); static protected Map<String, Command> _commands = new HashMap<String, Command>();
static { static {
_commands.put("create-project-from-upload", new CreateProjectCommand()); _commands.put("create-project-from-upload", new CreateProjectCommand());
_commands.put("export-rows", new ExportRowsCommand()); _commands.put("export-rows", new ExportRowsCommand());
_commands.put("get-project-metadata", new GetProjectMetadataCommand()); _commands.put("get-project-metadata", new GetProjectMetadataCommand());
_commands.put("get-all-project-metadata", new GetAllProjectMetadataCommand()); _commands.put("get-all-project-metadata", new GetAllProjectMetadataCommand());
_commands.put("get-models", new GetModelsCommand()); _commands.put("get-models", new GetModelsCommand());
_commands.put("get-rows", new GetRowsCommand()); _commands.put("get-rows", new GetRowsCommand());
_commands.put("get-processes", new GetProcessesCommand()); _commands.put("get-processes", new GetProcessesCommand());
_commands.put("get-history", new GetHistoryCommand()); _commands.put("get-history", new GetHistoryCommand());
_commands.put("get-operations", new GetOperationsCommand()); _commands.put("get-operations", new GetOperationsCommand());
_commands.put("undo-redo", new UndoRedoCommand()); _commands.put("undo-redo", new UndoRedoCommand());
_commands.put("apply-operations", new ApplyOperationsCommand()); _commands.put("apply-operations", new ApplyOperationsCommand());
_commands.put("cancel-processes", new CancelProcessesCommand()); _commands.put("cancel-processes", new CancelProcessesCommand());
_commands.put("compute-facets", new ComputeFacetsCommand()); _commands.put("compute-facets", new ComputeFacetsCommand());
_commands.put("do-text-transform", new DoTextTransformCommand()); _commands.put("do-text-transform", new DoTextTransformCommand());
_commands.put("facet-based-edit", new FacetBasedEditCommand()); _commands.put("facet-based-edit", new FacetBasedEditCommand());
_commands.put("add-column", new AddColumnCommand()); _commands.put("add-column", new AddColumnCommand());
_commands.put("remove-column", new RemoveColumnCommand()); _commands.put("remove-column", new RemoveColumnCommand());
_commands.put("join-multi-value-cells", new JoinMultiValueCellsCommand()); _commands.put("join-multi-value-cells", new JoinMultiValueCellsCommand());
_commands.put("split-multi-value-cells", new SplitMultiValueCellsCommand()); _commands.put("split-multi-value-cells", new SplitMultiValueCellsCommand());
_commands.put("reconcile", new ReconcileCommand()); _commands.put("reconcile", new ReconcileCommand());
_commands.put("recon-match-best-candidates", new ReconMatchBestCandidatesCommand()); _commands.put("recon-match-best-candidates", new ReconMatchBestCandidatesCommand());
_commands.put("recon-mark-new-topics", new ReconMarkNewTopicsCommand()); _commands.put("recon-mark-new-topics", new ReconMarkNewTopicsCommand());
_commands.put("recon-discard-judgments", new ReconDiscardJudgmentsCommand()); _commands.put("recon-discard-judgments", new ReconDiscardJudgmentsCommand());
_commands.put("recon-match-specific-topic-to-cells", new ReconMatchSpecificTopicCommand()); _commands.put("recon-match-specific-topic-to-cells", new ReconMatchSpecificTopicCommand());
_commands.put("recon-judge-one-cell", new ReconJudgeOneCellCommand()); _commands.put("recon-judge-one-cell", new ReconJudgeOneCellCommand());
_commands.put("recon-judge-similar-cells", new ReconJudgeSimilarCellsCommand()); _commands.put("recon-judge-similar-cells", new ReconJudgeSimilarCellsCommand());
_commands.put("annotate-one-row", new AnnotateOneRowCommand()); _commands.put("annotate-one-row", new AnnotateOneRowCommand());
_commands.put("annotate-rows", new AnnotateRowsCommand()); _commands.put("annotate-rows", new AnnotateRowsCommand());
_commands.put("save-protograph", new SaveProtographCommand()); _commands.put("save-protograph", new SaveProtographCommand());
_commands.put("preview-expression", new PreviewExpressionCommand()); _commands.put("preview-expression", new PreviewExpressionCommand());
_commands.put("get-expression-language-info", new GetExpressionLanguageInfoCommand()); _commands.put("get-expression-language-info", new GetExpressionLanguageInfoCommand());
_commands.put("preview-protograph", new PreviewProtographCommand()); _commands.put("preview-protograph", new PreviewProtographCommand());
_commands.put("guess-types-of-column", new GuessTypesOfColumnCommand()); _commands.put("guess-types-of-column", new GuessTypesOfColumnCommand());
} }
@Override @Override
public void init() throws ServletException { public void init() throws ServletException {
super.init(); super.init();
} }
@Override @Override
public void destroy() { public void destroy() {
if (ProjectManager.singleton != null) { if (ProjectManager.singleton != null) {
ProjectManager.singleton.saveAllProjects(); ProjectManager.singleton.saveAllProjects();
ProjectManager.singleton.save(); ProjectManager.singleton.save();
ProjectManager.singleton = null; ProjectManager.singleton = null;
} }
super.destroy(); super.destroy();
} }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ProjectManager.initialize(); ProjectManager.initialize();
String commandName = request.getPathInfo().substring(1); String commandName = request.getPathInfo().substring(1);
Command command = _commands.get(commandName); Command command = _commands.get(commandName);
if (command != null) { if (command != null) {
command.doPost(request, response); command.doPost(request, response);
} }
} }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ProjectManager.initialize(); ProjectManager.initialize();
String commandName = request.getPathInfo().substring(1); String commandName = request.getPathInfo().substring(1);
Command command = _commands.get(commandName); Command command = _commands.get(commandName);
if (command != null) { if (command != null) {
command.doGet(request, response); command.doGet(request, response);
} }
} }
} }

View File

@ -6,5 +6,5 @@ import org.json.JSONException;
import org.json.JSONWriter; import org.json.JSONWriter;
public interface Jsonizable { public interface Jsonizable {
public void write(JSONWriter writer, Properties options) throws JSONException; public void write(JSONWriter writer, Properties options) throws JSONException;
} }

View File

@ -15,55 +15,55 @@ import com.codeberry.jdatapath.JDataPathSystem;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class ProjectManager implements Serializable { public class ProjectManager implements Serializable {
private static final long serialVersionUID = -2967415873336723962L; private static final long serialVersionUID = -2967415873336723962L;
protected File _dir; protected File _dir;
protected Map<Long, ProjectMetadata> _projectsMetadata; protected Map<Long, ProjectMetadata> _projectsMetadata;
transient protected Map<Long, Project> _projects; transient protected Map<Long, Project> _projects;
static public ProjectManager singleton; static public ProjectManager singleton;
static public void initialize() { static public void initialize() {
if (singleton == null) { if (singleton == null) {
File dir = getProjectLocation(); File dir = getProjectLocation();
Gridworks.log("Using data directory: " + dir.getAbsolutePath()); Gridworks.log("Using data directory: " + dir.getAbsolutePath());
File file = new File(dir, "projects"); File file = new File(dir, "projects");
if (file.exists()) { if (file.exists()) {
singleton = load(file); singleton = load(file);
} else { } else {
singleton = new ProjectManager(dir); singleton = new ProjectManager(dir);
} }
} }
} }
static protected File getProjectLocation() { static protected File getProjectLocation() {
String data_dir = Configurations.get("gridworks.data_dir"); String data_dir = Configurations.get("gridworks.data_dir");
if (data_dir != null) { if (data_dir != null) {
return new File(data_dir); return new File(data_dir);
} }
String os = Configurations.get("os.name").toLowerCase(); String os = Configurations.get("os.name").toLowerCase();
if (os.contains("windows")) { if (os.contains("windows")) {
// NOTE(SM): finding the "local data app" in windows from java is actually a PITA // 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 // 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, // 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 // it's not elegant but it's the safest bet
DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Gridworks"); DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Gridworks");
File data = new File(localDataPath.getPath()); File data = new File(localDataPath.getPath());
data.mkdirs(); data.mkdirs();
return data; return data;
} else if (os.contains("mac os x")) { } else if (os.contains("mac os x")) {
// on macosx, use "~/Library/Application Support" // on macosx, use "~/Library/Application Support"
String home = System.getProperty("user.home"); String home = System.getProperty("user.home");
String data_home = (home != null) ? home + "/Library/Application Support/Gridworks" : ".gridworks"; String data_home = (home != null) ? home + "/Library/Application Support/Gridworks" : ".gridworks";
File data = new File(data_home); File data = new File(data_home);
data.mkdirs(); data.mkdirs();
return data; return data;
} else { // most likely a UNIX flavor } else { // most likely a UNIX flavor
// start with the XDG environment // start with the XDG environment
// see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html // see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
String data_home = System.getenv("XDG_DATA_HOME"); String data_home = System.getenv("XDG_DATA_HOME");
if (data_home == null) { // if not found, default back to ~/.local/share if (data_home == null) { // if not found, default back to ~/.local/share
String home = System.getProperty("user.home"); String home = System.getProperty("user.home");
@ -73,172 +73,172 @@ public class ProjectManager implements Serializable {
File data = new File(data_home + "/gridworks"); File data = new File(data_home + "/gridworks");
data.mkdirs(); data.mkdirs();
return data; return data;
} }
} }
static protected ProjectManager load(File file) { static protected ProjectManager load(File file) {
ProjectManager pm = null; ProjectManager pm = null;
FileInputStream fis = null; FileInputStream fis = null;
ObjectInputStream in = null; ObjectInputStream in = null;
try { try {
fis = new FileInputStream(file); fis = new FileInputStream(file);
in = new ObjectInputStream(fis); in = new ObjectInputStream(fis);
pm = (ProjectManager) in.readObject(); pm = (ProjectManager) in.readObject();
} catch(IOException e) { } catch(IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch(ClassNotFoundException e) { } catch(ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (fis != null) { if (fis != null) {
try { try {
fis.close(); fis.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
if (in != null) { if (in != null) {
try { try {
in.close(); in.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
} }
return pm; return pm;
} }
private ProjectManager(File dir) { private ProjectManager(File dir) {
_dir = dir; _dir = dir;
_dir.mkdirs(); _dir.mkdirs();
_projectsMetadata = new HashMap<Long, ProjectMetadata>(); _projectsMetadata = new HashMap<Long, ProjectMetadata>();
internalInitialize(); internalInitialize();
} }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject(); in.defaultReadObject();
internalInitialize(); internalInitialize();
} }
private void internalInitialize() { private void internalInitialize() {
_projects = new HashMap<Long, Project>(); _projects = new HashMap<Long, Project>();
} }
public File getDataDir() { public File getDataDir() {
return _dir; return _dir;
} }
public void registerProject(Project project, ProjectMetadata projectMetadata) { public void registerProject(Project project, ProjectMetadata projectMetadata) {
_projects.put(project.id, project); _projects.put(project.id, project);
_projectsMetadata.put(project.id, projectMetadata); _projectsMetadata.put(project.id, projectMetadata);
} }
public ProjectMetadata getProjectMetadata(long id) { public ProjectMetadata getProjectMetadata(long id) {
return _projectsMetadata.get(id); return _projectsMetadata.get(id);
} }
public Map<Long, ProjectMetadata> getAllProjectMetadata() { public Map<Long, ProjectMetadata> getAllProjectMetadata() {
return _projectsMetadata; return _projectsMetadata;
} }
public Project getProject(long id) { public Project getProject(long id) {
if (_projects.containsKey(id)) { if (_projects.containsKey(id)) {
return _projects.get(id); return _projects.get(id);
} else { } else {
File file = new File(_dir, id + ".project"); File file = new File(_dir, id + ".project");
Project project = null; Project project = null;
FileInputStream fis = null; FileInputStream fis = null;
ObjectInputStream in = null; ObjectInputStream in = null;
try { try {
fis = new FileInputStream(file); fis = new FileInputStream(file);
in = new ObjectInputStream(fis); in = new ObjectInputStream(fis);
project = (Project) in.readObject(); project = (Project) in.readObject();
} catch(IOException e) { } catch(IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch(ClassNotFoundException e) { } catch(ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (fis != null) { if (fis != null) {
try { try {
fis.close(); fis.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
if (in != null) { if (in != null) {
try { try {
in.close(); in.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
} }
_projects.put(id, project); _projects.put(id, project);
return project; return project;
} }
} }
public void save() { public void save() {
File file = new File(_dir, "projects"); File file = new File(_dir, "projects");
FileOutputStream fos = null; FileOutputStream fos = null;
ObjectOutputStream out = null; ObjectOutputStream out = null;
try { try {
fos = new FileOutputStream(file); fos = new FileOutputStream(file);
out = new ObjectOutputStream(fos); out = new ObjectOutputStream(fos);
out.writeObject(this); out.writeObject(this);
out.flush(); out.flush();
} catch(IOException e) { } catch(IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (fos != null) { if (fos != null) {
try { try {
fos.close(); fos.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
if (out != null) { if (out != null) {
try { try {
out.close(); out.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
} }
} }
public void saveAllProjects() { public void saveAllProjects() {
for (Project project : _projects.values()) { for (Project project : _projects.values()) {
saveProject(project); saveProject(project);
} }
} }
protected void saveProject(Project project) { protected void saveProject(Project project) {
File file = new File(_dir, project.id + ".project"); File file = new File(_dir, project.id + ".project");
FileOutputStream fos = null; FileOutputStream fos = null;
ObjectOutputStream out = null; ObjectOutputStream out = null;
try { try {
fos = new FileOutputStream(file); fos = new FileOutputStream(file);
out = new ObjectOutputStream(fos); out = new ObjectOutputStream(fos);
out.writeObject(project); out.writeObject(project);
out.flush(); out.flush();
} catch(IOException e) { } catch(IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (fos != null) { if (fos != null) {
try { try {
fos.close(); fos.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
if (out != null) { if (out != null) {
try { try {
out.close(); out.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
} }
} }
} }

View File

@ -9,26 +9,26 @@ import org.json.JSONException;
import org.json.JSONWriter; import org.json.JSONWriter;
public class ProjectMetadata implements Serializable, Jsonizable { public class ProjectMetadata implements Serializable, Jsonizable {
private static final long serialVersionUID = 7959027046468240844L; private static final long serialVersionUID = 7959027046468240844L;
private final Date _created = new Date(); private final Date _created = new Date();
private String _name; private String _name;
private String _password; private String _password;
private String _encoding; private String _encoding;
private int _encodingConfidence; private int _encodingConfidence;
private Date _modified = new Date(); private Date _modified = new Date();
public Date getCreated() { public Date getCreated() {
return _created; return _created;
} }
public void setName(String name) { public void setName(String name) {
this._name = name; this._name = name;
} }
public String getName() { public String getName() {
return _name; return _name;
} }
public void setEncoding(String encoding) { public void setEncoding(String encoding) {
this._encoding = encoding; this._encoding = encoding;
@ -50,31 +50,31 @@ public class ProjectMetadata implements Serializable, Jsonizable {
return _encodingConfidence; return _encodingConfidence;
} }
public void setPassword(String password) { public void setPassword(String password) {
this._password = password; this._password = password;
} }
public String getPassword() { public String getPassword() {
return _password; return _password;
} }
public Date getModified() { public Date getModified() {
return _modified; return _modified;
} }
public void updateModified() { public void updateModified() {
_modified = new Date(); _modified = new Date();
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance(); SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance();
writer.object(); writer.object();
writer.key("name"); writer.value(getName()); writer.key("name"); writer.value(getName());
writer.key("created"); writer.value(sdf.format(getCreated())); writer.key("created"); writer.value(sdf.format(getCreated()));
writer.key("modified"); writer.value(sdf.format(_modified)); writer.key("modified"); writer.value(sdf.format(_modified));
writer.endObject(); writer.endObject();
} }
} }

View File

@ -8,75 +8,75 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
public class ConjunctiveFilteredRows implements FilteredRows { public class ConjunctiveFilteredRows implements FilteredRows {
final protected List<RowFilter> _rowFilters = new LinkedList<RowFilter>(); final protected List<RowFilter> _rowFilters = new LinkedList<RowFilter>();
final protected boolean _contextual; final protected boolean _contextual;
public ConjunctiveFilteredRows(boolean contextual) { public ConjunctiveFilteredRows(boolean contextual) {
_contextual = contextual; _contextual = contextual;
} }
public void add(RowFilter rowFilter) { public void add(RowFilter rowFilter) {
_rowFilters.add(rowFilter); _rowFilters.add(rowFilter);
} }
public void accept(Project project, RowVisitor visitor) { public void accept(Project project, RowVisitor visitor) {
if (_contextual) { if (_contextual) {
contextualAccept(project, visitor); contextualAccept(project, visitor);
} else { } else {
simpleAccept(project, visitor); simpleAccept(project, visitor);
} }
} }
protected void simpleAccept(Project project, RowVisitor visitor) { protected void simpleAccept(Project project, RowVisitor visitor) {
for (int i = 0; i < project.rows.size(); i++) { for (int i = 0; i < project.rows.size(); i++) {
Row row = project.rows.get(i); Row row = project.rows.get(i);
boolean ok = true; boolean ok = true;
for (RowFilter rowFilter : _rowFilters) { for (RowFilter rowFilter : _rowFilters) {
if (!rowFilter.filterRow(project, i, row)) { if (!rowFilter.filterRow(project, i, row)) {
ok = false; ok = false;
break; break;
} }
} }
if (ok) { if (ok) {
visitor.visit(project, i, row, false); visitor.visit(project, i, row, false);
} }
} }
} }
protected void contextualAccept(Project project, RowVisitor visitor) { protected void contextualAccept(Project project, RowVisitor visitor) {
int lastVisitedRow = -1; int lastVisitedRow = -1;
for (int i = 0; i < project.rows.size(); i++) { for (int i = 0; i < project.rows.size(); i++) {
Row row = project.rows.get(i); Row row = project.rows.get(i);
boolean ok = true; boolean ok = true;
for (RowFilter rowFilter : _rowFilters) { for (RowFilter rowFilter : _rowFilters) {
if (!rowFilter.filterRow(project, i, row)) { if (!rowFilter.filterRow(project, i, row)) {
ok = false; ok = false;
break; break;
} }
} }
if (ok) { if (ok) {
if (row.contextRows != null && lastVisitedRow < i - 1) { if (row.contextRows != null && lastVisitedRow < i - 1) {
for (int contextRowIndex : row.contextRows) { for (int contextRowIndex : row.contextRows) {
if (contextRowIndex > lastVisitedRow) { if (contextRowIndex > lastVisitedRow) {
visitor.visit( visitor.visit(
project, project,
contextRowIndex, contextRowIndex,
project.rows.get(contextRowIndex), project.rows.get(contextRowIndex),
true true
); );
lastVisitedRow = contextRowIndex; lastVisitedRow = contextRowIndex;
} }
} }
} }
visitor.visit(project, i, row, false); visitor.visit(project, i, row, false);
lastVisitedRow = i; lastVisitedRow = i;
} }
} }
} }
} }

View File

@ -8,19 +8,19 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable; import com.metaweb.gridworks.Jsonizable;
public class DecoratedValue implements Jsonizable { public class DecoratedValue implements Jsonizable {
final public Object value; final public Object value;
final public String label; final public String label;
public DecoratedValue(Object value, String label) { public DecoratedValue(Object value, String label) {
this.value = value; this.value = value;
this.label = label; this.label = label;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("v"); writer.value(value); writer.key("v"); writer.value(value);
writer.key("l"); writer.value(label); writer.key("l"); writer.value(label);
writer.endObject(); writer.endObject();
} }
} }

View File

@ -18,71 +18,71 @@ import com.metaweb.gridworks.browsing.filters.RowFilter;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class Engine implements Jsonizable { public class Engine implements Jsonizable {
protected Project _project; protected Project _project;
protected List<Facet> _facets = new LinkedList<Facet>(); protected List<Facet> _facets = new LinkedList<Facet>();
public Engine(Project project) { public Engine(Project project) {
_project = project; _project = project;
} }
public FilteredRows getAllFilteredRows(boolean contextual) { public FilteredRows getAllFilteredRows(boolean contextual) {
return getFilteredRows(null, contextual); return getFilteredRows(null, contextual);
} }
public FilteredRows getFilteredRows(Facet except, boolean contextual) { public FilteredRows getFilteredRows(Facet except, boolean contextual) {
ConjunctiveFilteredRows cfr = new ConjunctiveFilteredRows(contextual); ConjunctiveFilteredRows cfr = new ConjunctiveFilteredRows(contextual);
for (Facet facet : _facets) { for (Facet facet : _facets) {
if (facet != except) { if (facet != except) {
RowFilter rowFilter = facet.getRowFilter(); RowFilter rowFilter = facet.getRowFilter();
if (rowFilter != null) { if (rowFilter != null) {
cfr.add(rowFilter); cfr.add(rowFilter);
} }
} }
} }
return cfr; return cfr;
} }
public void initializeFromJSON(JSONObject o) throws Exception { public void initializeFromJSON(JSONObject o) throws Exception {
JSONArray a = o.getJSONArray("facets"); JSONArray a = o.getJSONArray("facets");
int length = a.length(); int length = a.length();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
JSONObject fo = a.getJSONObject(i); JSONObject fo = a.getJSONObject(i);
String type = fo.has("type") ? fo.getString("type") : "list"; String type = fo.has("type") ? fo.getString("type") : "list";
Facet facet = null; Facet facet = null;
if ("list".equals(type)) { if ("list".equals(type)) {
facet = new ListFacet(); facet = new ListFacet();
} else if ("range".equals(type)) { } else if ("range".equals(type)) {
facet = new RangeFacet(); facet = new RangeFacet();
} else if ("text".equals(type)) { } else if ("text".equals(type)) {
facet = new TextSearchFacet(); facet = new TextSearchFacet();
} }
if (facet != null) { if (facet != null) {
facet.initializeFromJSON(_project, fo); facet.initializeFromJSON(_project, fo);
_facets.add(facet); _facets.add(facet);
} }
} }
} }
public void computeFacets() throws JSONException { public void computeFacets() throws JSONException {
for (Facet facet : _facets) { for (Facet facet : _facets) {
FilteredRows filteredRows = getFilteredRows(facet, false); FilteredRows filteredRows = getFilteredRows(facet, false);
facet.computeChoices(_project, filteredRows); facet.computeChoices(_project, filteredRows);
} }
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("facets"); writer.array(); writer.key("facets"); writer.array();
for (Facet facet : _facets) { for (Facet facet : _facets) {
facet.write(writer, options); facet.write(writer, options);
} }
writer.endArray(); writer.endArray();
writer.endObject(); writer.endObject();
} }
} }

View File

@ -3,5 +3,5 @@ package com.metaweb.gridworks.browsing;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public interface FilteredRows { public interface FilteredRows {
public void accept(Project project, RowVisitor visitor); public void accept(Project project, RowVisitor visitor);
} }

View File

@ -4,6 +4,6 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
public interface RowVisitor { 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);
} }

View File

@ -13,55 +13,55 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
public class ExpressionNominalRowGrouper implements RowVisitor { public class ExpressionNominalRowGrouper implements RowVisitor {
final protected Evaluable _evaluable; final protected Evaluable _evaluable;
final protected int _cellIndex; final protected int _cellIndex;
final public Map<Object, NominalFacetChoice> choices = new HashMap<Object, NominalFacetChoice>(); final public Map<Object, NominalFacetChoice> choices = new HashMap<Object, NominalFacetChoice>();
public int blankCount = 0; public int blankCount = 0;
public int errorCount = 0; public int errorCount = 0;
public ExpressionNominalRowGrouper(Evaluable evaluable, int cellIndex) { public ExpressionNominalRowGrouper(Evaluable evaluable, int cellIndex) {
_evaluable = evaluable; _evaluable = evaluable;
_cellIndex = cellIndex; _cellIndex = cellIndex;
} }
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) { public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
Cell cell = row.getCell(_cellIndex); Cell cell = row.getCell(_cellIndex);
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
ExpressionUtils.bind(bindings, row, rowIndex, cell); ExpressionUtils.bind(bindings, row, rowIndex, cell);
Object value = _evaluable.evaluate(bindings); Object value = _evaluable.evaluate(bindings);
if (value != null && value.getClass().isArray()) { if (value != null && value.getClass().isArray()) {
Object[] a = (Object[]) value; Object[] a = (Object[]) value;
for (Object v : a) { for (Object v : a) {
processValue(v); processValue(v);
} }
} else { } else {
processValue(value); processValue(value);
} }
return false; return false;
} }
protected void processValue(Object value) { protected void processValue(Object value) {
if (ExpressionUtils.isError(value)) { if (ExpressionUtils.isError(value)) {
errorCount++; errorCount++;
} else if (ExpressionUtils.isNonBlankData(value)) { } else if (ExpressionUtils.isNonBlankData(value)) {
String valueString = value.toString(); String valueString = value.toString();
String label = value.toString(); String label = value.toString();
DecoratedValue dValue = new DecoratedValue(value, label); DecoratedValue dValue = new DecoratedValue(value, label);
if (choices.containsKey(valueString)) { if (choices.containsKey(valueString)) {
choices.get(valueString).count++; choices.get(valueString).count++;
} else { } else {
NominalFacetChoice choice = new NominalFacetChoice(dValue); NominalFacetChoice choice = new NominalFacetChoice(dValue);
choice.count = 1; choice.count = 1;
choices.put(valueString, choice); choices.put(valueString, choice);
} }
} else { } else {
blankCount++; blankCount++;
} }
} }
} }

View File

@ -10,46 +10,46 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
public class ExpressionNumericRowBinner implements RowVisitor { public class ExpressionNumericRowBinner implements RowVisitor {
final protected Evaluable _evaluable; final protected Evaluable _evaluable;
final protected int _cellIndex; final protected int _cellIndex;
final protected NumericBinIndex _index; final protected NumericBinIndex _index;
final public int[] bins; final public int[] bins;
public ExpressionNumericRowBinner(Evaluable evaluable, int cellIndex, NumericBinIndex index) { public ExpressionNumericRowBinner(Evaluable evaluable, int cellIndex, NumericBinIndex index) {
_evaluable = evaluable; _evaluable = evaluable;
_cellIndex = cellIndex; _cellIndex = cellIndex;
_index = index; _index = index;
bins = new int[_index.getBins().length]; bins = new int[_index.getBins().length];
} }
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) { public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
Cell cell = row.getCell(_cellIndex); Cell cell = row.getCell(_cellIndex);
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
ExpressionUtils.bind(bindings, row, rowIndex, cell); ExpressionUtils.bind(bindings, row, rowIndex, cell);
Object value = _evaluable.evaluate(bindings); Object value = _evaluable.evaluate(bindings);
if (value != null) { if (value != null) {
if (value.getClass().isArray()) { if (value.getClass().isArray()) {
Object[] a = (Object[]) value; Object[] a = (Object[]) value;
for (Object v : a) { for (Object v : a) {
processValue(v); processValue(v);
} }
} else { } else {
processValue(value); processValue(value);
} }
} }
return false; return false;
} }
protected void processValue(Object value) { protected void processValue(Object value) {
if (value instanceof Number) { if (value instanceof Number) {
double d = ((Number) value).doubleValue(); double d = ((Number) value).doubleValue();
int bin = (int) Math.round((d - _index.getMin()) / _index.getStep()); int bin = (int) Math.round((d - _index.getMin()) / _index.getStep());
bins[bin]++; bins[bin]++;
} }
} }
} }

View File

@ -8,9 +8,9 @@ import com.metaweb.gridworks.browsing.filters.RowFilter;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public interface Facet extends Jsonizable { public interface Facet extends Jsonizable {
public RowFilter getRowFilter(); public RowFilter getRowFilter();
public void computeChoices(Project project, FilteredRows filteredRows); public void computeChoices(Project project, FilteredRows filteredRows);
public void initializeFromJSON(Project project, JSONObject o) throws Exception; public void initializeFromJSON(Project project, JSONObject o) throws Exception;
} }

View File

@ -18,45 +18,45 @@ import com.metaweb.gridworks.expr.MetaParser;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class ListFacet implements Facet { public class ListFacet implements Facet {
protected List<NominalFacetChoice> _selection = new LinkedList<NominalFacetChoice>(); protected List<NominalFacetChoice> _selection = new LinkedList<NominalFacetChoice>();
protected boolean _selectBlank; protected boolean _selectBlank;
protected boolean _selectError; protected boolean _selectError;
protected String _name; protected String _name;
protected String _expression; protected String _expression;
protected String _columnName; protected String _columnName;
protected int _cellIndex; protected int _cellIndex;
protected Evaluable _eval; protected Evaluable _eval;
// computed // computed
protected List<NominalFacetChoice> _choices = new LinkedList<NominalFacetChoice>(); protected List<NominalFacetChoice> _choices = new LinkedList<NominalFacetChoice>();
protected int _blankCount; protected int _blankCount;
protected int _errorCount; protected int _errorCount;
public ListFacet() { public ListFacet() {
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("name"); writer.value(_name); writer.key("name"); writer.value(_name);
writer.key("expression"); writer.value(_expression); writer.key("expression"); writer.value(_expression);
writer.key("columnName"); writer.value(_columnName); writer.key("columnName"); writer.value(_columnName);
writer.key("choices"); writer.array(); writer.key("choices"); writer.array();
for (NominalFacetChoice choice : _choices) { for (NominalFacetChoice choice : _choices) {
choice.write(writer, options); choice.write(writer, options);
} }
writer.endArray(); writer.endArray();
if (_selectBlank || _blankCount > 0) { if (_selectBlank || _blankCount > 0) {
writer.key("blankChoice"); writer.key("blankChoice");
writer.object(); writer.object();
writer.key("s"); writer.value(_selectBlank); writer.key("s"); writer.value(_selectBlank);
writer.key("c"); writer.value(_blankCount); writer.key("c"); writer.value(_blankCount);
writer.endObject(); writer.endObject();
} }
if (_selectError || _errorCount > 0) { if (_selectError || _errorCount > 0) {
writer.key("errorChoice"); writer.key("errorChoice");
writer.object(); writer.object();
@ -64,76 +64,76 @@ public class ListFacet implements Facet {
writer.key("c"); writer.value(_errorCount); writer.key("c"); writer.value(_errorCount);
writer.endObject(); writer.endObject();
} }
writer.endObject(); writer.endObject();
} }
public void initializeFromJSON(Project project, JSONObject o) throws Exception { public void initializeFromJSON(Project project, JSONObject o) throws Exception {
_name = o.getString("name"); _name = o.getString("name");
_expression = o.getString("expression"); _expression = o.getString("expression");
_columnName = o.getString("columnName"); _columnName = o.getString("columnName");
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex(); _cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
_eval = MetaParser.parse(_expression); _eval = MetaParser.parse(_expression);
_selection.clear(); _selection.clear();
JSONArray a = o.getJSONArray("selection"); JSONArray a = o.getJSONArray("selection");
int length = a.length(); int length = a.length();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
JSONObject oc = a.getJSONObject(i); JSONObject oc = a.getJSONObject(i);
JSONObject ocv = oc.getJSONObject("v"); JSONObject ocv = oc.getJSONObject("v");
DecoratedValue decoratedValue = new DecoratedValue( DecoratedValue decoratedValue = new DecoratedValue(
ocv.get("v"), ocv.getString("l")); ocv.get("v"), ocv.getString("l"));
NominalFacetChoice nominalFacetChoice = new NominalFacetChoice(decoratedValue); NominalFacetChoice nominalFacetChoice = new NominalFacetChoice(decoratedValue);
nominalFacetChoice.selected = true; nominalFacetChoice.selected = true;
_selection.add(nominalFacetChoice); _selection.add(nominalFacetChoice);
} }
if (o.has("selectBlank")) { if (o.has("selectBlank")) {
_selectBlank = o.getBoolean("selectBlank"); _selectBlank = o.getBoolean("selectBlank");
} }
if (o.has("selectError")) { if (o.has("selectError")) {
_selectError = o.getBoolean("selectError"); _selectError = o.getBoolean("selectError");
} }
} }
public RowFilter getRowFilter() { public RowFilter getRowFilter() {
return _selection.size() == 0 && !_selectBlank && !_selectError ? null : return _selection.size() == 0 && !_selectBlank && !_selectError ? null :
new ExpressionEqualRowFilter(_eval, _cellIndex, createMatches(), _selectBlank, _selectError); new ExpressionEqualRowFilter(_eval, _cellIndex, createMatches(), _selectBlank, _selectError);
} }
public void computeChoices(Project project, FilteredRows filteredRows) { public void computeChoices(Project project, FilteredRows filteredRows) {
ExpressionNominalRowGrouper grouper = ExpressionNominalRowGrouper grouper =
new ExpressionNominalRowGrouper(_eval, _cellIndex); new ExpressionNominalRowGrouper(_eval, _cellIndex);
filteredRows.accept(project, grouper); filteredRows.accept(project, grouper);
_choices.clear(); _choices.clear();
_choices.addAll(grouper.choices.values()); _choices.addAll(grouper.choices.values());
for (NominalFacetChoice choice : _selection) { for (NominalFacetChoice choice : _selection) {
String valueString = choice.decoratedValue.value.toString(); String valueString = choice.decoratedValue.value.toString();
if (grouper.choices.containsKey(valueString)) { if (grouper.choices.containsKey(valueString)) {
grouper.choices.get(valueString).selected = true; grouper.choices.get(valueString).selected = true;
} else { } else {
choice.count = 0; choice.count = 0;
_choices.add(choice); _choices.add(choice);
} }
} }
_blankCount = grouper.blankCount; _blankCount = grouper.blankCount;
_errorCount = grouper.errorCount; _errorCount = grouper.errorCount;
} }
protected Object[] createMatches() { protected Object[] createMatches() {
Object[] a = new Object[_selection.size()]; Object[] a = new Object[_selection.size()];
for (int i = 0; i < a.length; i++) { for (int i = 0; i < a.length; i++) {
a[i] = _selection.get(i).decoratedValue.value; a[i] = _selection.get(i).decoratedValue.value;
} }
return a; return a;
} }
} }

View File

@ -9,20 +9,20 @@ import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.browsing.DecoratedValue; import com.metaweb.gridworks.browsing.DecoratedValue;
public class NominalFacetChoice implements Jsonizable { public class NominalFacetChoice implements Jsonizable {
final public DecoratedValue decoratedValue; final public DecoratedValue decoratedValue;
public int count; public int count;
public boolean selected; public boolean selected;
public NominalFacetChoice(DecoratedValue decoratedValue) { public NominalFacetChoice(DecoratedValue decoratedValue) {
this.decoratedValue = decoratedValue; this.decoratedValue = decoratedValue;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("v"); decoratedValue.write(writer, options); writer.key("v"); decoratedValue.write(writer, options);
writer.key("c"); writer.value(count); writer.key("c"); writer.value(count);
writer.key("s"); writer.value(selected); writer.key("s"); writer.value(selected);
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,92 +11,92 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
public class NumericBinIndex { public class NumericBinIndex {
private double _min; private double _min;
private double _max; private double _max;
private double _step; private double _step;
private int[] _bins; private int[] _bins;
public NumericBinIndex(Project project, int cellIndex, Evaluable eval) { public NumericBinIndex(Project project, int cellIndex, Evaluable eval) {
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
_min = Double.POSITIVE_INFINITY; _min = Double.POSITIVE_INFINITY;
_max = Double.NEGATIVE_INFINITY; _max = Double.NEGATIVE_INFINITY;
List<Double> allValues = new ArrayList<Double>(); List<Double> allValues = new ArrayList<Double>();
for (int i = 0; i < project.rows.size(); i++) { for (int i = 0; i < project.rows.size(); i++) {
Row row = project.rows.get(i); Row row = project.rows.get(i);
Cell cell = row.getCell(cellIndex); Cell cell = row.getCell(cellIndex);
ExpressionUtils.bind(bindings, row, i, cell); ExpressionUtils.bind(bindings, row, i, cell);
Object value = eval.evaluate(bindings); Object value = eval.evaluate(bindings);
if (value != null) { if (value != null) {
if (value.getClass().isArray()) { if (value.getClass().isArray()) {
Object[] a = (Object[]) value; Object[] a = (Object[]) value;
for (Object v : a) { for (Object v : a) {
if (v instanceof Number) { if (v instanceof Number) {
processValue(((Number) v).doubleValue(), allValues); processValue(((Number) v).doubleValue(), allValues);
} }
} }
} else if (value instanceof Number) { } else if (value instanceof Number) {
processValue(((Number) value).doubleValue(), allValues); processValue(((Number) value).doubleValue(), allValues);
} }
} }
} }
if (_min >= _max) { if (_min >= _max) {
_step = 0; _step = 0;
_bins = new int[1]; _bins = new int[1];
return; return;
} }
double diff = getMax() - getMin(); double diff = getMax() - getMin();
_step = 1; _step = 1;
if (diff > 10) { if (diff > 10) {
while (getStep() * 100 < diff) { while (getStep() * 100 < diff) {
_step *= 10; _step *= 10;
} }
} else { } else {
while (getStep() * 100 > diff) { while (getStep() * 100 > diff) {
_step /= 10; _step /= 10;
} }
} }
_min = (Math.floor(_min / _step) * _step); _min = (Math.floor(_min / _step) * _step);
_max = (Math.ceil(_max / _step) * _step); _max = (Math.ceil(_max / _step) * _step);
int binCount = 1 + (int) Math.ceil((getMax() - getMin()) / getStep()); int binCount = 1 + (int) Math.ceil((getMax() - getMin()) / getStep());
if (binCount > 100) { if (binCount > 100) {
_step *= 2; _step *= 2;
binCount = Math.round((1 + binCount) / 2); binCount = Math.round((1 + binCount) / 2);
} }
_bins = new int[binCount]; _bins = new int[binCount];
for (double d : allValues) { for (double d : allValues) {
int bin = (int) Math.round((d - _min) / _step); int bin = (int) Math.round((d - _min) / _step);
_bins[bin]++; _bins[bin]++;
} }
} }
public double getMin() { public double getMin() {
return _min; return _min;
} }
public double getMax() { public double getMax() {
return _max; return _max;
} }
public double getStep() { public double getStep() {
return _step; return _step;
} }
public int[] getBins() { public int[] getBins() {
return _bins; return _bins;
} }
protected void processValue(double v, List<Double> allValues) { protected void processValue(double v, List<Double> allValues) {
_min = Math.min(getMin(), v); _min = Math.min(getMin(), v);
_max = Math.max(getMax(), v); _max = Math.max(getMax(), v);
allValues.add(v); allValues.add(v);
} }
} }

View File

@ -15,147 +15,147 @@ import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class RangeFacet implements Facet { public class RangeFacet implements Facet {
protected String _name; protected String _name;
protected String _expression; protected String _expression;
protected String _columnName; protected String _columnName;
protected int _cellIndex; protected int _cellIndex;
protected Evaluable _eval; protected Evaluable _eval;
protected String _mode; protected String _mode;
protected double _min; protected double _min;
protected double _max; protected double _max;
protected double _step; protected double _step;
protected int[] _baseBins; protected int[] _baseBins;
protected int[] _bins; protected int[] _bins;
protected double _from; protected double _from;
protected double _to; protected double _to;
protected boolean _selected; protected boolean _selected;
public RangeFacet() { public RangeFacet() {
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("name"); writer.value(_name); writer.key("name"); writer.value(_name);
writer.key("expression"); writer.value(_expression); writer.key("expression"); writer.value(_expression);
writer.key("columnName"); writer.value(_columnName); writer.key("columnName"); writer.value(_columnName);
writer.key("mode"); writer.value(_mode); writer.key("mode"); writer.value(_mode);
if (!Double.isInfinite(_min) && !Double.isInfinite(_max)) { if (!Double.isInfinite(_min) && !Double.isInfinite(_max)) {
writer.key("min"); writer.value(_min); writer.key("min"); writer.value(_min);
writer.key("max"); writer.value(_max); writer.key("max"); writer.value(_max);
writer.key("step"); writer.value(_step); writer.key("step"); writer.value(_step);
writer.key("bins"); writer.array(); writer.key("bins"); writer.array();
for (int b : _bins) { for (int b : _bins) {
writer.value(b); writer.value(b);
} }
writer.endArray(); writer.endArray();
writer.key("baseBins"); writer.array(); writer.key("baseBins"); writer.array();
for (int b : _baseBins) { for (int b : _baseBins) {
writer.value(b); writer.value(b);
} }
writer.endArray(); writer.endArray();
if ("min".equals(_mode)) { if ("min".equals(_mode)) {
writer.key("from"); writer.value(_from); writer.key("from"); writer.value(_from);
} else if ("max".equals(_mode)) { } else if ("max".equals(_mode)) {
writer.key("to"); writer.value(_to); writer.key("to"); writer.value(_to);
} else { } else {
writer.key("from"); writer.value(_from); writer.key("from"); writer.value(_from);
writer.key("to"); writer.value(_to); writer.key("to"); writer.value(_to);
} }
} }
writer.endObject(); writer.endObject();
} }
public void initializeFromJSON(Project project, JSONObject o) throws Exception { public void initializeFromJSON(Project project, JSONObject o) throws Exception {
_name = o.getString("name"); _name = o.getString("name");
_expression = o.getString("expression"); _expression = o.getString("expression");
_columnName = o.getString("columnName"); _columnName = o.getString("columnName");
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex(); _cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
_eval = MetaParser.parse(_expression); _eval = MetaParser.parse(_expression);
_mode = o.getString("mode"); _mode = o.getString("mode");
if ("min".equals(_mode)) { if ("min".equals(_mode)) {
if (o.has("from")) { if (o.has("from")) {
_from = o.getDouble("from"); _from = o.getDouble("from");
_selected = true; _selected = true;
} }
} else if ("max".equals(_mode)) { } else if ("max".equals(_mode)) {
if (o.has("to")) { if (o.has("to")) {
_to = o.getDouble("to"); _to = o.getDouble("to");
_selected = true; _selected = true;
} }
} else { } else {
if (o.has("from") && o.has("to")) { if (o.has("from") && o.has("to")) {
_from = o.getDouble("from"); _from = o.getDouble("from");
_to = o.getDouble("to"); _to = o.getDouble("to");
_selected = true; _selected = true;
} }
} }
} }
public RowFilter getRowFilter() { public RowFilter getRowFilter() {
if (_selected) { if (_selected) {
if ("min".equals(_mode)) { if ("min".equals(_mode)) {
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) { return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
protected boolean checkValue(double d) { protected boolean checkValue(double d) {
return d >= _from; return d >= _from;
}; };
}; };
} else if ("max".equals(_mode)) { } else if ("max".equals(_mode)) {
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) { return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
protected boolean checkValue(double d) { protected boolean checkValue(double d) {
return d <= _to; return d <= _to;
}; };
}; };
} else { } else {
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) { return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
protected boolean checkValue(double d) { protected boolean checkValue(double d) {
return d >= _from && d <= _to; return d >= _from && d <= _to;
}; };
}; };
} }
} else { } else {
return null; return null;
} }
} }
public void computeChoices(Project project, FilteredRows filteredRows) { public void computeChoices(Project project, FilteredRows filteredRows) {
Column column = project.columnModel.getColumnByCellIndex(_cellIndex); Column column = project.columnModel.getColumnByCellIndex(_cellIndex);
String key = "numeric-bin:" + _expression; String key = "numeric-bin:" + _expression;
NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key); NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key);
if (index == null) { if (index == null) {
index = new NumericBinIndex(project, _cellIndex, _eval); index = new NumericBinIndex(project, _cellIndex, _eval);
column.setPrecompute(key, index); column.setPrecompute(key, index);
} }
_min = index.getMin(); _min = index.getMin();
_max = index.getMax(); _max = index.getMax();
_step = index.getStep(); _step = index.getStep();
_baseBins = index.getBins(); _baseBins = index.getBins();
if (_selected) { if (_selected) {
_from = Math.max(_from, _min); _from = Math.max(_from, _min);
_to = Math.min(_to, _max); _to = Math.min(_to, _max);
} else { } else {
_from = _min; _from = _min;
_to = _max; _to = _max;
} }
ExpressionNumericRowBinner binner = ExpressionNumericRowBinner binner =
new ExpressionNumericRowBinner(_eval, _cellIndex, index); new ExpressionNumericRowBinner(_eval, _cellIndex, index);
filteredRows.accept(project, binner); filteredRows.accept(project, binner);
_bins = binner.bins; _bins = binner.bins;
} }
} }

View File

@ -14,71 +14,71 @@ import com.metaweb.gridworks.gel.ast.VariableExpr;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class TextSearchFacet implements Facet { public class TextSearchFacet implements Facet {
protected String _name; protected String _name;
protected String _columnName; protected String _columnName;
protected int _cellIndex; protected int _cellIndex;
protected String _query; protected String _query;
protected String _mode; protected String _mode;
protected boolean _caseSensitive; protected boolean _caseSensitive;
public TextSearchFacet() { public TextSearchFacet() {
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("name"); writer.value(_name); writer.key("name"); writer.value(_name);
writer.key("columnName"); writer.value(_columnName); writer.key("columnName"); writer.value(_columnName);
writer.key("query"); writer.value(_query); writer.key("query"); writer.value(_query);
writer.key("mode"); writer.value(_mode); writer.key("mode"); writer.value(_mode);
writer.key("caseSensitive"); writer.value(_caseSensitive); writer.key("caseSensitive"); writer.value(_caseSensitive);
writer.endObject(); writer.endObject();
} }
public void initializeFromJSON(Project project, JSONObject o) throws Exception { public void initializeFromJSON(Project project, JSONObject o) throws Exception {
_name = o.getString("name"); _name = o.getString("name");
_columnName = o.getString("columnName"); _columnName = o.getString("columnName");
_cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex(); _cellIndex = project.columnModel.getColumnByName(_columnName).getCellIndex();
if (!o.isNull("query")) { if (!o.isNull("query")) {
_query = o.getString("query"); _query = o.getString("query");
} }
_mode = o.getString("mode"); _mode = o.getString("mode");
_caseSensitive = o.getBoolean("caseSensitive"); _caseSensitive = o.getBoolean("caseSensitive");
if (_query != null) { if (_query != null) {
_query = _query.trim(); _query = _query.trim();
if (!_caseSensitive) { if (!_caseSensitive) {
_query = _query.toLowerCase(); _query = _query.toLowerCase();
} }
} }
} }
public RowFilter getRowFilter() { public RowFilter getRowFilter() {
if (_query == null || _query.length() == 0) { if (_query == null || _query.length() == 0) {
return null; return null;
} }
Evaluable eval = new VariableExpr("value"); Evaluable eval = new VariableExpr("value");
if ("regex".equals(_mode)) { if ("regex".equals(_mode)) {
return new ExpressionStringComparisonRowFilter(eval, _cellIndex) { return new ExpressionStringComparisonRowFilter(eval, _cellIndex) {
protected boolean checkValue(String s) { protected boolean checkValue(String s) {
return s.matches(_query); return s.matches(_query);
}; };
}; };
} else { } else {
return new ExpressionStringComparisonRowFilter(eval, _cellIndex) { return new ExpressionStringComparisonRowFilter(eval, _cellIndex) {
protected boolean checkValue(String s) { protected boolean checkValue(String s) {
return (_caseSensitive ? s : s.toLowerCase()).contains(_query); return (_caseSensitive ? s : s.toLowerCase()).contains(_query);
}; };
}; };
} }
} }
public void computeChoices(Project project, FilteredRows filteredRows) { public void computeChoices(Project project, FilteredRows filteredRows) {
// nothing to do // nothing to do
} }
} }

View File

@ -9,57 +9,57 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
public class ExpressionEqualRowFilter implements RowFilter { public class ExpressionEqualRowFilter implements RowFilter {
final protected Evaluable _evaluable; final protected Evaluable _evaluable;
final protected int _cellIndex; final protected int _cellIndex;
final protected Object[] _matches; final protected Object[] _matches;
final protected boolean _selectBlank; final protected boolean _selectBlank;
final protected boolean _selectError; final protected boolean _selectError;
public ExpressionEqualRowFilter(Evaluable evaluable, int cellIndex, Object[] matches, boolean selectBlank, boolean selectError) { public ExpressionEqualRowFilter(Evaluable evaluable, int cellIndex, Object[] matches, boolean selectBlank, boolean selectError) {
_evaluable = evaluable; _evaluable = evaluable;
_cellIndex = cellIndex; _cellIndex = cellIndex;
_matches = matches; _matches = matches;
_selectBlank = selectBlank; _selectBlank = selectBlank;
_selectError = selectError; _selectError = selectError;
} }
public boolean filterRow(Project project, int rowIndex, Row row) { public boolean filterRow(Project project, int rowIndex, Row row) {
Cell cell = row.getCell(_cellIndex); Cell cell = row.getCell(_cellIndex);
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
ExpressionUtils.bind(bindings, row, rowIndex, cell); ExpressionUtils.bind(bindings, row, rowIndex, cell);
Object value = _evaluable.evaluate(bindings); Object value = _evaluable.evaluate(bindings);
if (value != null && value.getClass().isArray()) { if (value != null && value.getClass().isArray()) {
Object[] a = (Object[]) value; Object[] a = (Object[]) value;
for (Object v : a) { for (Object v : a) {
if (testValue(v)) { if (testValue(v)) {
return true; return true;
} }
} }
} else { } else {
return testValue(value); return testValue(value);
} }
return false; return false;
} }
protected boolean testValue(Object v) { protected boolean testValue(Object v) {
if (ExpressionUtils.isError(v)) { if (ExpressionUtils.isError(v)) {
return _selectError; return _selectError;
} else if (ExpressionUtils.isNonBlankData(v)) { } else if (ExpressionUtils.isNonBlankData(v)) {
for (Object match : _matches) { for (Object match : _matches) {
if (testValue(v, match)) { if (testValue(v, match)) {
return true; return true;
} }
} }
return false; return false;
} else { } else {
return _selectBlank; return _selectBlank;
} }
} }
protected boolean testValue(Object v, Object match) { protected boolean testValue(Object v, Object match) {
return (v instanceof Number && match instanceof Number) ? return (v instanceof Number && match instanceof Number) ?
((Number) match).doubleValue() == ((Number) v).doubleValue() : ((Number) match).doubleValue() == ((Number) v).doubleValue() :
match.equals(v); match.equals(v);
} }
} }

View File

@ -9,37 +9,37 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
abstract public class ExpressionNumberComparisonRowFilter implements RowFilter { abstract public class ExpressionNumberComparisonRowFilter implements RowFilter {
final protected Evaluable _evaluable; final protected Evaluable _evaluable;
final protected int _cellIndex; final protected int _cellIndex;
public ExpressionNumberComparisonRowFilter(Evaluable evaluable, int cellIndex) { public ExpressionNumberComparisonRowFilter(Evaluable evaluable, int cellIndex) {
_evaluable = evaluable; _evaluable = evaluable;
_cellIndex = cellIndex; _cellIndex = cellIndex;
} }
public boolean filterRow(Project project, int rowIndex, Row row) { public boolean filterRow(Project project, int rowIndex, Row row) {
Cell cell = row.getCell(_cellIndex); Cell cell = row.getCell(_cellIndex);
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
ExpressionUtils.bind(bindings, row, rowIndex, cell); ExpressionUtils.bind(bindings, row, rowIndex, cell);
Object value = _evaluable.evaluate(bindings); Object value = _evaluable.evaluate(bindings);
if (value != null) { if (value != null) {
if (value.getClass().isArray()) { if (value.getClass().isArray()) {
Object[] a = (Object[]) value; Object[] a = (Object[]) value;
for (Object v : a) { for (Object v : a) {
if (v instanceof Number && checkValue(((Number) v).doubleValue())) { if (v instanceof Number && checkValue(((Number) v).doubleValue())) {
return true; return true;
} }
} }
} else { } else {
if (value instanceof Number && checkValue(((Number) value).doubleValue())) { if (value instanceof Number && checkValue(((Number) value).doubleValue())) {
return true; return true;
} }
} }
} }
return false; return false;
} }
abstract protected boolean checkValue(double d); abstract protected boolean checkValue(double d);
} }

View File

@ -9,36 +9,36 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
abstract public class ExpressionStringComparisonRowFilter implements RowFilter { abstract public class ExpressionStringComparisonRowFilter implements RowFilter {
final protected Evaluable _evaluable; final protected Evaluable _evaluable;
final protected int _cellIndex; final protected int _cellIndex;
public ExpressionStringComparisonRowFilter(Evaluable evaluable, int cellIndex) { public ExpressionStringComparisonRowFilter(Evaluable evaluable, int cellIndex) {
_evaluable = evaluable; _evaluable = evaluable;
_cellIndex = cellIndex; _cellIndex = cellIndex;
} }
public boolean filterRow(Project project, int rowIndex, Row row) { public boolean filterRow(Project project, int rowIndex, Row row) {
Cell cell = row.getCell(_cellIndex); Cell cell = row.getCell(_cellIndex);
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
ExpressionUtils.bind(bindings, row, rowIndex, cell); ExpressionUtils.bind(bindings, row, rowIndex, cell);
Object value = _evaluable.evaluate(bindings); Object value = _evaluable.evaluate(bindings);
if (value != null) { if (value != null) {
if (value.getClass().isArray()) { if (value.getClass().isArray()) {
Object[] a = (Object[]) value; Object[] a = (Object[]) value;
for (Object v : a) { for (Object v : a) {
if (checkValue(v instanceof String ? ((String) v) : v.toString())) { if (checkValue(v instanceof String ? ((String) v) : v.toString())) {
return true; return true;
} }
} }
} else { } else {
if (checkValue(value instanceof String ? ((String) value) : value.toString())) { if (checkValue(value instanceof String ? ((String) value) : value.toString())) {
return true; return true;
} }
} }
} }
return false; return false;
} }
abstract protected boolean checkValue(String s); abstract protected boolean checkValue(String s);
} }

View File

@ -4,5 +4,5 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
public interface RowFilter { public interface RowFilter {
public boolean filterRow(Project project, int rowIndex, Row row); public boolean filterRow(Project project, int rowIndex, Row row);
} }

View File

@ -32,160 +32,160 @@ import com.oreilly.servlet.multipart.Part;
public abstract class Command { public abstract class Command {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 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 { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
throw new NotImplementedException(); throw new NotImplementedException();
}; };
protected Project getProject(HttpServletRequest request) throws ServletException { protected Project getProject(HttpServletRequest request) throws ServletException {
try { try {
Project p = ProjectManager.singleton.getProject(Long.parseLong(request.getParameter("project"))); Project p = ProjectManager.singleton.getProject(Long.parseLong(request.getParameter("project")));
if (p != null) { if (p != null) {
return p; return p;
} }
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }
throw new ServletException("Missing or bad project URL parameter"); throw new ServletException("Missing or bad project URL parameter");
} }
protected int getIntegerParameter(HttpServletRequest request, String name, int def) throws ServletException { protected int getIntegerParameter(HttpServletRequest request, String name, int def) throws ServletException {
try { try {
return Integer.parseInt(request.getParameter(name)); return Integer.parseInt(request.getParameter(name));
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }
return def; return def;
} }
protected void respond(HttpServletResponse response, String content) throws IOException { protected void respond(HttpServletResponse response, String content) throws IOException {
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
OutputStream os = response.getOutputStream(); OutputStream os = response.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os); OutputStreamWriter osw = new OutputStreamWriter(os);
try { try {
osw.write(content); osw.write(content);
} finally { } finally {
osw.flush(); osw.flush();
osw.close(); osw.close();
} }
} }
protected void respondJSON(HttpServletResponse response, Jsonizable o) throws IOException, JSONException { 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 { protected void respondJSON(HttpServletResponse response, Jsonizable o, Properties options) throws IOException, JSONException {
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
o.write(writer, options); o.write(writer, options);
} }
protected void respondException(HttpServletResponse response, Exception e) throws IOException { protected void respondException(HttpServletResponse response, Exception e) throws IOException {
e.printStackTrace(); e.printStackTrace();
try { try {
JSONObject o = new JSONObject(); JSONObject o = new JSONObject();
o.put("code", "error"); o.put("code", "error");
o.put("message", e.getMessage()); o.put("message", e.getMessage());
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw); e.printStackTrace(pw);
pw.flush(); pw.flush();
sw.flush(); sw.flush();
o.put("stack", sw.toString()); o.put("stack", sw.toString());
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
respond(response, o.toString()); respond(response, o.toString());
} catch (JSONException e1) { } catch (JSONException e1) {
e.printStackTrace(response.getWriter()); e.printStackTrace(response.getWriter());
} }
} }
protected void redirect(HttpServletResponse response, String url) throws IOException { protected void redirect(HttpServletResponse response, String url) throws IOException {
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
String content = "<html><head><meta http-equiv=\"refresh\" content=\"1;url=" + url + "\"></head><body></body></html>"; String content = "<html><head><meta http-equiv=\"refresh\" content=\"1;url=" + url + "\"></head><body></body></html>";
response.getWriter().print(content); response.getWriter().print(content);
} }
protected String readFileUpload(HttpServletRequest request, Properties properties) throws IOException { protected String readFileUpload(HttpServletRequest request, Properties properties) throws IOException {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
try { try {
MultipartParser parser = new MultipartParser(request, 20 * 1024 * 1024); MultipartParser parser = new MultipartParser(request, 20 * 1024 * 1024);
Part part = null; Part part = null;
while ((part = parser.readNextPart()) != null) { while ((part = parser.readNextPart()) != null) {
if (part.isFile()) { if (part.isFile()) {
Reader reader = new InputStreamReader(((FilePart) part).getInputStream()); Reader reader = new InputStreamReader(((FilePart) part).getInputStream());
LineNumberReader lnr = new LineNumberReader(reader); LineNumberReader lnr = new LineNumberReader(reader);
try { try {
String line = null; String line = null;
while ((line = lnr.readLine()) != null) { while ((line = lnr.readLine()) != null) {
sb.append(line); sb.append(line);
sb.append('\n'); sb.append('\n');
} }
} finally { } finally {
lnr.close(); lnr.close();
} }
} else if (part.isParam()) { } else if (part.isParam()) {
ParamPart paramPart = (ParamPart) part; ParamPart paramPart = (ParamPart) part;
properties.put(part.getName(), paramPart.getStringValue()); properties.put(part.getName(), paramPart.getStringValue());
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return sb.toString(); return sb.toString();
} }
protected JSONObject getJsonParameter(HttpServletRequest request, String name) { protected JSONObject getJsonParameter(HttpServletRequest request, String name) {
String value = request.getParameter(name); String value = request.getParameter(name);
if (value != null) { if (value != null) {
try { try {
JSONObject o = jsonStringToObject(value); JSONObject o = jsonStringToObject(value);
return o; return o;
} catch (JSONException e) { } catch (JSONException e) {
} }
} }
return null; return null;
} }
protected JSONObject jsonStringToObject(String s) throws JSONException { protected JSONObject jsonStringToObject(String s) throws JSONException {
JSONTokener t = new JSONTokener(s); JSONTokener t = new JSONTokener(s);
JSONObject o = (JSONObject) t.nextValue(); JSONObject o = (JSONObject) t.nextValue();
return o; return o;
} }
protected JSONArray jsonStringToArray(String s) throws JSONException { protected JSONArray jsonStringToArray(String s) throws JSONException {
JSONTokener t = new JSONTokener(s); JSONTokener t = new JSONTokener(s);
JSONArray a = (JSONArray) t.nextValue(); JSONArray a = (JSONArray) t.nextValue();
return a; return a;
} }
protected JSONObject getEngineConfig(HttpServletRequest request) throws Exception { protected JSONObject getEngineConfig(HttpServletRequest request) throws Exception {
String json = request.getParameter("engine"); String json = request.getParameter("engine");
if (json != null) { if (json != null) {
return jsonStringToObject(json); return jsonStringToObject(json);
} }
return null; return null;
} }
protected Engine getEngine(HttpServletRequest request, Project project) throws Exception { protected Engine getEngine(HttpServletRequest request, Project project) throws Exception {
Engine engine = new Engine(project); Engine engine = new Engine(project);
String json = request.getParameter("engine"); String json = request.getParameter("engine");
if (json != null) { if (json != null) {
JSONObject o = jsonStringToObject(json); JSONObject o = jsonStringToObject(json);
engine.initializeFromJSON(o); engine.initializeFromJSON(o);
} }
return engine; return engine;
} }
} }

View File

@ -14,25 +14,25 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.process.Process; import com.metaweb.gridworks.process.Process;
abstract public class EngineDependentCommand extends Command { abstract public class EngineDependentCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
AbstractOperation op = createOperation(request, getEngineConfig(request)); AbstractOperation op = createOperation(request, getEngineConfig(request));
Process process = op.createProcess(project, new Properties()); Process process = op.createProcess(project, new Properties());
boolean done = project.processManager.queueProcess(process); boolean done = project.processManager.queueProcess(process);
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }"); respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
abstract protected AbstractOperation createOperation( abstract protected AbstractOperation createOperation(
HttpServletRequest request, JSONObject engineConfig) throws Exception; HttpServletRequest request, JSONObject engineConfig) throws Exception;
} }

View File

@ -9,22 +9,22 @@ import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.operations.ColumnAdditionOperation; import com.metaweb.gridworks.operations.ColumnAdditionOperation;
public class AddColumnCommand extends EngineDependentCommand { public class AddColumnCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(HttpServletRequest request, protected AbstractOperation createOperation(HttpServletRequest request,
JSONObject engineConfig) throws Exception { JSONObject engineConfig) throws Exception {
String baseColumnName = request.getParameter("baseColumnName"); String baseColumnName = request.getParameter("baseColumnName");
String expression = request.getParameter("expression"); String expression = request.getParameter("expression");
String headerLabel = request.getParameter("headerLabel"); String headerLabel = request.getParameter("headerLabel");
int columnInsertIndex = Integer.parseInt(request.getParameter("columnInsertIndex")); int columnInsertIndex = Integer.parseInt(request.getParameter("columnInsertIndex"));
return new ColumnAdditionOperation( return new ColumnAdditionOperation(
engineConfig, engineConfig,
baseColumnName, baseColumnName,
expression, expression,
headerLabel, headerLabel,
columnInsertIndex columnInsertIndex
); );
} }
} }

View File

@ -15,71 +15,71 @@ import com.metaweb.gridworks.model.changes.RowStarChange;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess; import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class AnnotateOneRowCommand extends Command { public class AnnotateOneRowCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
try { try {
Project project = getProject(request); Project project = getProject(request);
int rowIndex = Integer.parseInt(request.getParameter("row")); int rowIndex = Integer.parseInt(request.getParameter("row"));
String starredString = request.getParameter("starred"); String starredString = request.getParameter("starred");
if (starredString != null) { if (starredString != null) {
boolean starred = "true".endsWith(starredString); boolean starred = "true".endsWith(starredString);
String description = starred ? "Star row " + rowIndex : "Unstar row " + rowIndex; String description = starred ? "Star row " + rowIndex : "Unstar row " + rowIndex;
StarOneRowProcess process = new StarOneRowProcess( StarOneRowProcess process = new StarOneRowProcess(
project, project,
description, description,
rowIndex, rowIndex,
starred starred
); );
boolean done = project.processManager.queueProcess(process); boolean done = project.processManager.queueProcess(process);
if (done) { if (done) {
JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
writer.object(); writer.object();
writer.key("code"); writer.value("ok"); writer.key("code"); writer.value("ok");
writer.endObject(); writer.endObject();
} else { } else {
respond(response, "{ \"code\" : \"pending\" }"); respond(response, "{ \"code\" : \"pending\" }");
} }
} else { } else {
respond(response, "{ \"code\" : \"error\", \"message\" : \"invalid command parameters\" }"); respond(response, "{ \"code\" : \"error\", \"message\" : \"invalid command parameters\" }");
} }
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
protected class StarOneRowProcess extends QuickHistoryEntryProcess { protected class StarOneRowProcess extends QuickHistoryEntryProcess {
final int rowIndex; final int rowIndex;
final boolean starred; final boolean starred;
StarOneRowProcess( StarOneRowProcess(
Project project, Project project,
String briefDescription, String briefDescription,
int rowIndex, int rowIndex,
boolean starred boolean starred
) { ) {
super(project, briefDescription); super(project, briefDescription);
this.rowIndex = rowIndex; this.rowIndex = rowIndex;
this.starred = starred; this.starred = starred;
} }
protected HistoryEntry createHistoryEntry() throws Exception { protected HistoryEntry createHistoryEntry() throws Exception {
return new HistoryEntry( return new HistoryEntry(
_project, _project,
starred ? "Star row " + rowIndex : "Unstar row " + rowIndex, starred ? "Star row " + rowIndex : "Unstar row " + rowIndex,
null, null,
new RowStarChange(rowIndex, starred) new RowStarChange(rowIndex, starred)
); );
} }
} }
} }

View File

@ -9,11 +9,11 @@ import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.operations.RowStarOperation; import com.metaweb.gridworks.operations.RowStarOperation;
public class AnnotateRowsCommand extends EngineDependentCommand { public class AnnotateRowsCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(HttpServletRequest request, protected AbstractOperation createOperation(HttpServletRequest request,
JSONObject engineConfig) throws Exception { JSONObject engineConfig) throws Exception {
String starredString = request.getParameter("starred"); String starredString = request.getParameter("starred");
if (starredString != null) { if (starredString != null) {
boolean starred = "true".endsWith(starredString); boolean starred = "true".endsWith(starredString);
@ -21,5 +21,5 @@ public class AnnotateRowsCommand extends EngineDependentCommand {
return new RowStarOperation(engineConfig, starred); return new RowStarOperation(engineConfig, starred);
} }
return null; return null;
} }
} }

View File

@ -19,55 +19,55 @@ import com.metaweb.gridworks.operations.OperationRegistry;
import com.metaweb.gridworks.process.Process; import com.metaweb.gridworks.process.Process;
public class ApplyOperationsCommand extends Command { public class ApplyOperationsCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
Project project = getProject(request); Project project = getProject(request);
String jsonString = request.getParameter("operations"); String jsonString = request.getParameter("operations");
try { try {
JSONArray a = jsonStringToArray(jsonString); JSONArray a = jsonStringToArray(jsonString);
int count = a.length(); int count = a.length();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
JSONObject obj = a.getJSONObject(i); JSONObject obj = a.getJSONObject(i);
reconstructOperation(project, obj); reconstructOperation(project, obj);
} }
if (project.processManager.hasPending()) { if (project.processManager.hasPending()) {
respond(response, "{ \"code\" : \"pending\" }"); respond(response, "{ \"code\" : \"pending\" }");
} else { } else {
respond(response, "{ \"code\" : \"ok\" }"); respond(response, "{ \"code\" : \"ok\" }");
} }
} catch (JSONException e) { } catch (JSONException e) {
respondException(response, e); respondException(response, e);
} }
} }
protected void reconstructOperation(Project project, JSONObject obj) { protected void reconstructOperation(Project project, JSONObject obj) {
try { try {
String op = obj.getString("op"); String op = obj.getString("op");
Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op); Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op);
if (klass == null) { if (klass == null) {
return; return;
} }
Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class); Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class);
if (reconstruct == null) { if (reconstruct == null) {
return; return;
} }
AbstractOperation operation = (AbstractOperation) reconstruct.invoke(null, project, obj); AbstractOperation operation = (AbstractOperation) reconstruct.invoke(null, project, obj);
if (operation != null) { if (operation != null) {
Process process = operation.createProcess(project, new Properties()); Process process = operation.createProcess(project, new Properties());
project.processManager.queueProcess(process); project.processManager.queueProcess(process);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

@ -34,79 +34,79 @@ import com.oreilly.servlet.multipart.Part;
public class CreateProjectCommand extends Command { public class CreateProjectCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Properties options = parseUrlParameters(request); Properties options = parseUrlParameters(request);
Project project = new Project(); Project project = new Project();
internalImport(request, project, options); internalImport(request, project, options);
ProjectMetadata pm = new ProjectMetadata(); ProjectMetadata pm = new ProjectMetadata();
pm.setName(options.getProperty("project-name")); pm.setName(options.getProperty("project-name"));
pm.setPassword(options.getProperty("project-password")); pm.setPassword(options.getProperty("project-password"));
pm.setEncoding(options.getProperty("encoding")); pm.setEncoding(options.getProperty("encoding"));
pm.setEncodingConfidence(options.getProperty("encoding_confidence")); pm.setEncodingConfidence(options.getProperty("encoding_confidence"));
ProjectManager.singleton.registerProject(project, pm); ProjectManager.singleton.registerProject(project, pm);
project.columnModel.update(); project.columnModel.update();
project.recomputeRowContextDependencies(); project.recomputeRowContextDependencies();
redirect(response, "/project.html?project=" + project.id); redirect(response, "/project.html?project=" + project.id);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
protected Properties parseUrlParameters(HttpServletRequest request) { protected Properties parseUrlParameters(HttpServletRequest request) {
Properties options = new Properties(); Properties options = new Properties();
String query = request.getQueryString(); String query = request.getQueryString();
if (query != null) { if (query != null) {
if (query.startsWith("?")) { if (query.startsWith("?")) {
query = query.substring(1); query = query.substring(1);
} }
String[] pairs = query.split("&"); String[] pairs = query.split("&");
for (String pairString : pairs) { for (String pairString : pairs) {
int equal = pairString.indexOf('='); int equal = pairString.indexOf('=');
String name = equal >= 0 ? pairString.substring(0, equal) : ""; String name = equal >= 0 ? pairString.substring(0, equal) : "";
String value = equal >= 0 ? ParsingUtilities.decode(pairString.substring(equal + 1)) : ""; String value = equal >= 0 ? ParsingUtilities.decode(pairString.substring(equal + 1)) : "";
options.put(name, value); options.put(name, value);
} }
} }
return options; return options;
} }
protected void internalImport( protected void internalImport(
HttpServletRequest request, HttpServletRequest request,
Project project, Project project,
Properties options Properties options
) throws Exception { ) throws Exception {
MultipartParser parser = null; MultipartParser parser = null;
try { try {
parser = new MultipartParser(request, 20 * 1024 * 1024); parser = new MultipartParser(request, 20 * 1024 * 1024);
} catch (Exception e) { } catch (Exception e) {
// silent // silent
} }
if (parser != null) { if (parser != null) {
Part part = null; Part part = null;
String url = null; String url = null;
int limit = -1; int limit = -1;
int skip = 0; int skip = 0;
if (options.containsKey("limit")) { if (options.containsKey("limit")) {
String s = options.getProperty("limit"); String s = options.getProperty("limit");
try { try {
limit = Integer.parseInt(s); limit = Integer.parseInt(s);
} catch (Exception e) { } catch (Exception e) {
} }
} }
if (options.containsKey("skip")) { if (options.containsKey("skip")) {
String s = options.getProperty("skip"); String s = options.getProperty("skip");
try { try {
@ -114,15 +114,15 @@ public class CreateProjectCommand extends Command {
} catch (Exception e) { } catch (Exception e) {
} }
} }
while ((part = parser.readNextPart()) != null) { while ((part = parser.readNextPart()) != null) {
if (part.isFile()) { if (part.isFile()) {
FilePart filePart = (FilePart) part; FilePart filePart = (FilePart) part;
Importer importer = guessImporter(options, null, filePart.getFileName()); Importer importer = guessImporter(options, null, filePart.getFileName());
if (importer.takesReader()) { if (importer.takesReader()) {
CharsetDetector detector = new CharsetDetector(); CharsetDetector detector = new CharsetDetector();
detector.setDeclaredEncoding("utf8"); // the content on the web is encoded in UTF-8 so assume that detector.setDeclaredEncoding("utf8"); // the content on the web is encoded in UTF-8 so assume that
CharsetMatch charsetMatch = detector.setText(enforceMarking(filePart.getInputStream())).detect(); CharsetMatch charsetMatch = detector.setText(enforceMarking(filePart.getInputStream())).detect();
@ -135,120 +135,120 @@ public class CreateProjectCommand extends Command {
} finally { } finally {
reader.close(); reader.close();
} }
} else { } else {
InputStream inputStream = filePart.getInputStream(); InputStream inputStream = filePart.getInputStream();
try { try {
importer.read(inputStream, project, options, skip, limit); importer.read(inputStream, project, options, skip, limit);
} finally { } finally {
inputStream.close(); inputStream.close();
} }
} }
} else if (part.isParam()) { } else if (part.isParam()) {
ParamPart paramPart = (ParamPart) part; ParamPart paramPart = (ParamPart) part;
String paramName = paramPart.getName(); String paramName = paramPart.getName();
if (paramName.equals("raw-text")) { if (paramName.equals("raw-text")) {
StringReader reader = new StringReader(paramPart.getStringValue()); StringReader reader = new StringReader(paramPart.getStringValue());
try { try {
new TsvCsvImporter().read(reader, project, options, skip, limit); new TsvCsvImporter().read(reader, project, options, skip, limit);
} finally { } finally {
reader.close(); reader.close();
} }
} else if (paramName.equals("url")) { } else if (paramName.equals("url")) {
url = paramPart.getStringValue(); url = paramPart.getStringValue();
} else { } else {
options.put(paramName, paramPart.getStringValue()); options.put(paramName, paramPart.getStringValue());
} }
} }
} }
if (url != null && url.length() > 0) { if (url != null && url.length() > 0) {
internalImportURL(request, project, options, url, skip, limit); internalImportURL(request, project, options, url, skip, limit);
} }
} }
} }
protected void internalImportURL( protected void internalImportURL(
HttpServletRequest request, HttpServletRequest request,
Project project, Project project,
Properties options, Properties options,
String urlString, String urlString,
int skip, int skip,
int limit int limit
) throws Exception { ) throws Exception {
URL url = new URL(urlString); URL url = new URL(urlString);
URLConnection connection = null; URLConnection connection = null;
try { try {
connection = url.openConnection(); connection = url.openConnection();
connection.setConnectTimeout(5000); connection.setConnectTimeout(5000);
connection.connect(); connection.connect();
} catch (Exception e) { } catch (Exception e) {
throw new Exception("Cannot connect to " + urlString, e); throw new Exception("Cannot connect to " + urlString, e);
} }
InputStream inputStream = null; InputStream inputStream = null;
try { try {
inputStream = connection.getInputStream(); inputStream = connection.getInputStream();
} catch (Exception e) { } catch (Exception e) {
throw new Exception("Cannot retrieve content from " + url, e); throw new Exception("Cannot retrieve content from " + url, e);
} }
try { try {
Importer importer = guessImporter( Importer importer = guessImporter(
options, options,
connection.getContentType(), connection.getContentType(),
url.getPath() url.getPath()
); );
if (importer.takesReader()) { if (importer.takesReader()) {
String encoding = connection.getContentEncoding(); String encoding = connection.getContentEncoding();
Reader reader = new InputStreamReader( Reader reader = new InputStreamReader(
inputStream, (encoding == null) ? "ISO-8859-1" : encoding); inputStream, (encoding == null) ? "ISO-8859-1" : encoding);
importer.read(reader, project, options, skip, limit); importer.read(reader, project, options, skip, limit);
} else { } else {
importer.read(inputStream, project, options, skip, limit); importer.read(inputStream, project, options, skip, limit);
} }
} finally { } finally {
inputStream.close(); inputStream.close();
} }
} }
protected Importer guessImporter( protected Importer guessImporter(
Properties options, String contentType, String fileName) { Properties options, String contentType, String fileName) {
if (contentType != null) { if (contentType != null) {
contentType = contentType.toLowerCase().trim(); contentType = contentType.toLowerCase().trim();
if ("application/msexcel".equals(contentType) || if ("application/msexcel".equals(contentType) ||
"application/x-msexcel".equals(contentType) || "application/x-msexcel".equals(contentType) ||
"application/x-ms-excel".equals(contentType) || "application/x-ms-excel".equals(contentType) ||
"application/vnd.ms-excel".equals(contentType) || "application/vnd.ms-excel".equals(contentType) ||
"application/x-excel".equals(contentType) || "application/x-excel".equals(contentType) ||
"application/xls".equals(contentType)) { "application/xls".equals(contentType)) {
return new ExcelImporter(false); return new ExcelImporter(false);
} else if("application/x-xls".equals(contentType)) { } else if("application/x-xls".equals(contentType)) {
return new ExcelImporter(true); return new ExcelImporter(true);
} }
} else if (fileName != null) { } else if (fileName != null) {
fileName = fileName.toLowerCase(); fileName = fileName.toLowerCase();
if (fileName.endsWith(".xls")) { if (fileName.endsWith(".xls")) {
return new ExcelImporter(false); return new ExcelImporter(false);
} else if (fileName.endsWith(".xlsx")) { } else if (fileName.endsWith(".xlsx")) {
return new ExcelImporter(true); return new ExcelImporter(true);
} }
} }
return new TsvCsvImporter(); return new TsvCsvImporter();
} }
/* /*
* NOTE(SM): The ICU4J char detection code requires the input stream to support mark/reset. Unfortunately, not * 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 * 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. * it work. It's far from ideal but I don't have a more efficient solution.
*/ */
private static InputStream enforceMarking(InputStream input) throws IOException { private static InputStream enforceMarking(InputStream input) throws IOException {
if (input.markSupported()) { if (input.markSupported()) {
return input; return input;
@ -267,5 +267,5 @@ public class CreateProjectCommand extends Command {
return new ByteArrayInputStream(output.toByteArray()); return new ByteArrayInputStream(output.toByteArray());
} }
} }
} }

View File

@ -9,13 +9,13 @@ import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.operations.TextTransformOperation; import com.metaweb.gridworks.operations.TextTransformOperation;
public class DoTextTransformCommand extends EngineDependentCommand { public class DoTextTransformCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(HttpServletRequest request, protected AbstractOperation createOperation(HttpServletRequest request,
JSONObject engineConfig) throws Exception { JSONObject engineConfig) throws Exception {
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
String expression = request.getParameter("expression"); String expression = request.getParameter("expression");
return new TextTransformOperation(engineConfig, columnName, expression); return new TextTransformOperation(engineConfig, columnName, expression);
} }
} }

View File

@ -10,19 +10,19 @@ import com.metaweb.gridworks.operations.FacetBasedEditOperation;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class FacetBasedEditCommand extends EngineDependentCommand { public class FacetBasedEditCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(HttpServletRequest request, protected AbstractOperation createOperation(HttpServletRequest request,
JSONObject engineConfig) throws Exception { JSONObject engineConfig) throws Exception {
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
String expression = request.getParameter("expression"); String expression = request.getParameter("expression");
String editsString = request.getParameter("edits"); String editsString = request.getParameter("edits");
return new FacetBasedEditOperation( return new FacetBasedEditOperation(
engineConfig, engineConfig,
columnName, columnName,
expression, expression,
FacetBasedEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString)) FacetBasedEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString))
); );
} }
} }

View File

@ -14,26 +14,26 @@ import com.metaweb.gridworks.operations.MultiValuedCellJoinOperation;
import com.metaweb.gridworks.process.Process; import com.metaweb.gridworks.process.Process;
public class JoinMultiValueCellsCommand extends Command { public class JoinMultiValueCellsCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
String keyColumnName = request.getParameter("keyColumnName"); String keyColumnName = request.getParameter("keyColumnName");
String separator = request.getParameter("separator"); String separator = request.getParameter("separator");
AbstractOperation op = new MultiValuedCellJoinOperation(columnName, keyColumnName, separator); AbstractOperation op = new MultiValuedCellJoinOperation(columnName, keyColumnName, separator);
Process process = op.createProcess(project, new Properties()); Process process = op.createProcess(project, new Properties());
boolean done = project.processManager.queueProcess(process); boolean done = project.processManager.queueProcess(process);
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }"); respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -14,24 +14,24 @@ import com.metaweb.gridworks.operations.ColumnRemovalOperation;
import com.metaweb.gridworks.process.Process; import com.metaweb.gridworks.process.Process;
public class RemoveColumnCommand extends Command { public class RemoveColumnCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
AbstractOperation op = new ColumnRemovalOperation(columnName); AbstractOperation op = new ColumnRemovalOperation(columnName);
Process process = op.createProcess(project, new Properties()); Process process = op.createProcess(project, new Properties());
boolean done = project.processManager.queueProcess(process); boolean done = project.processManager.queueProcess(process);
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }"); respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -17,26 +17,26 @@ import com.metaweb.gridworks.process.Process;
import com.metaweb.gridworks.protograph.Protograph; import com.metaweb.gridworks.protograph.Protograph;
public class SaveProtographCommand extends Command { public class SaveProtographCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
String jsonString = request.getParameter("protograph"); String jsonString = request.getParameter("protograph");
JSONObject json = jsonStringToObject(jsonString); JSONObject json = jsonStringToObject(jsonString);
Protograph protograph = Protograph.reconstruct(json); Protograph protograph = Protograph.reconstruct(json);
AbstractOperation op = new SaveProtographOperation(protograph); AbstractOperation op = new SaveProtographOperation(protograph);
Process process = op.createProcess(project, new Properties()); Process process = op.createProcess(project, new Properties());
boolean done = project.processManager.queueProcess(process); boolean done = project.processManager.queueProcess(process);
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }"); respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -14,27 +14,27 @@ import com.metaweb.gridworks.operations.MultiValuedCellSplitOperation;
import com.metaweb.gridworks.process.Process; import com.metaweb.gridworks.process.Process;
public class SplitMultiValueCellsCommand extends Command { public class SplitMultiValueCellsCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
String keyColumnName = request.getParameter("keyColumnName"); String keyColumnName = request.getParameter("keyColumnName");
String separator = request.getParameter("separator"); String separator = request.getParameter("separator");
String mode = request.getParameter("mode"); String mode = request.getParameter("mode");
AbstractOperation op = new MultiValuedCellSplitOperation(columnName, keyColumnName, separator, mode); AbstractOperation op = new MultiValuedCellSplitOperation(columnName, keyColumnName, separator, mode);
Process process = op.createProcess(project, new Properties()); Process process = op.createProcess(project, new Properties());
boolean done = project.processManager.queueProcess(process); boolean done = project.processManager.queueProcess(process);
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }"); respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -11,17 +11,17 @@ import com.metaweb.gridworks.history.HistoryProcess;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class UndoRedoCommand extends Command { public class UndoRedoCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
Project project = getProject(request); Project project = getProject(request);
long lastDoneID = Long.parseLong(request.getParameter("lastDoneID")); long lastDoneID = Long.parseLong(request.getParameter("lastDoneID"));
boolean done = project.processManager.queueProcess( boolean done = project.processManager.queueProcess(
new HistoryProcess(project, lastDoneID)); new HistoryProcess(project, lastDoneID));
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }"); respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
} }
} }

View File

@ -11,19 +11,19 @@ import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class ComputeFacetsCommand extends Command { public class ComputeFacetsCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
Engine engine = getEngine(request, project); Engine engine = getEngine(request, project);
engine.computeFacets(); engine.computeFacets();
respondJSON(response, engine); respondJSON(response, engine);
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -19,91 +19,91 @@ import com.metaweb.gridworks.model.Row;
public class ExportRowsCommand extends Command { public class ExportRowsCommand extends Command {
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
Engine engine = getEngine(request, project); Engine engine = getEngine(request, project);
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "text/plain"); response.setHeader("Content-Type", "text/plain");
PrintWriter writer = response.getWriter(); PrintWriter writer = response.getWriter();
boolean first = true; boolean first = true;
for (Column column : project.columnModel.columns) { for (Column column : project.columnModel.columns) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
writer.print("\t"); writer.print("\t");
} }
writer.print(column.getHeaderLabel()); writer.print(column.getHeaderLabel());
} }
writer.print("\n"); writer.print("\n");
{ {
RowVisitor visitor = new RowVisitor() { RowVisitor visitor = new RowVisitor() {
PrintWriter writer; PrintWriter writer;
public RowVisitor init(PrintWriter writer) { public RowVisitor init(PrintWriter writer) {
this.writer = writer; this.writer = writer;
return this; return this;
} }
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) { public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
boolean first = true; boolean first = true;
for (Column column : project.columnModel.columns) { for (Column column : project.columnModel.columns) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
writer.print("\t"); writer.print("\t");
} }
int cellIndex = column.getCellIndex(); int cellIndex = column.getCellIndex();
if (cellIndex < row.cells.size()) { if (cellIndex < row.cells.size()) {
Cell cell = row.cells.get(cellIndex); Cell cell = row.cells.get(cellIndex);
if (cell != null && cell.value != null) { if (cell != null && cell.value != null) {
writer.print(cell.value); writer.print(cell.value);
} }
} }
} }
writer.print("\n"); writer.print("\n");
return false; return false;
} }
}.init(writer); }.init(writer);
FilteredRows filteredRows = engine.getAllFilteredRows(true); FilteredRows filteredRows = engine.getAllFilteredRows(true);
filteredRows.accept(project, visitor); filteredRows.accept(project, visitor);
} }
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
static protected class RowAccumulator implements RowVisitor { static protected class RowAccumulator implements RowVisitor {
final public int start; final public int start;
final public int limit; final public int limit;
public int total; public int total;
public RowAccumulator(int start, int limit) { public RowAccumulator(int start, int limit) {
this.start = start; this.start = start;
this.limit = limit; this.limit = limit;
} }
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) { public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
boolean r = false; boolean r = false;
if (total >= start && total < start + limit) { if (total >= start && total < start + limit) {
r = internalVisit(rowIndex, row); r = internalVisit(rowIndex, row);
} }
total++; total++;
return r; return r;
} }
protected boolean internalVisit(int rowIndex, Row row) { protected boolean internalVisit(int rowIndex, Row row) {
return false; return false;
} }
} }
} }

View File

@ -16,30 +16,30 @@ import com.metaweb.gridworks.ProjectMetadata;
import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.commands.Command;
public class GetAllProjectMetadataCommand extends Command { public class GetAllProjectMetadataCommand extends Command {
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
Properties options = new Properties(); Properties options = new Properties();
writer.object(); writer.object();
writer.key("projects"); writer.object(); writer.key("projects"); writer.object();
Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata(); Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
for (Long id : m.keySet()) { for (Long id : m.keySet()) {
writer.key(id.toString()); writer.key(id.toString());
m.get(id).write(writer, options); m.get(id).write(writer, options);
} }
writer.endObject(); writer.endObject();
writer.endObject(); writer.endObject();
} catch (JSONException e) { } catch (JSONException e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -12,16 +12,16 @@ import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class GetHistoryCommand extends Command { public class GetHistoryCommand extends Command {
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
Project project = getProject(request); Project project = getProject(request);
try { try {
respondJSON(response, project.history); respondJSON(response, project.history);
} catch (JSONException e) { } catch (JSONException e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -14,31 +14,31 @@ import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class GetModelsCommand extends Command { public class GetModelsCommand extends Command {
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
Project project = getProject(request); Project project = getProject(request);
try { try {
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
Properties options = new Properties(); Properties options = new Properties();
JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
writer.object(); writer.object();
writer.key("columnModel"); project.columnModel.write(writer, options); writer.key("columnModel"); project.columnModel.write(writer, options);
writer.key("protograph"); writer.key("protograph");
if (project.protograph == null) { if (project.protograph == null) {
writer.value(null); writer.value(null);
} else { } else {
project.protograph.write(writer, options); project.protograph.write(writer, options);
} }
writer.endObject(); writer.endObject();
} catch (JSONException e) { } catch (JSONException e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -15,36 +15,36 @@ import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class GetOperationsCommand extends Command { public class GetOperationsCommand extends Command {
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
Project project = getProject(request); Project project = getProject(request);
try { try {
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
Properties options = new Properties(); Properties options = new Properties();
JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
writer.object(); writer.object();
writer.key("entries"); writer.array(); writer.key("entries"); writer.array();
for (HistoryEntry entry : project.history.getLastPastEntries(-1)) { for (HistoryEntry entry : project.history.getLastPastEntries(-1)) {
writer.object(); writer.object();
writer.key("description"); writer.value(entry.description); writer.key("description"); writer.value(entry.description);
if (entry.operation != null) { if (entry.operation != null) {
writer.key("operation"); writer.key("operation");
entry.operation.write(writer, options); entry.operation.write(writer, options);
} }
writer.endObject(); writer.endObject();
} }
writer.endArray(); writer.endArray();
writer.endObject(); writer.endObject();
} catch (JSONException e) { } catch (JSONException e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -12,16 +12,16 @@ import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class GetProcessesCommand extends Command { public class GetProcessesCommand extends Command {
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
Project project = getProject(request); Project project = getProject(request);
try { try {
respondJSON(response, project.processManager); respondJSON(response, project.processManager);
} catch (JSONException e) { } catch (JSONException e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -13,16 +13,16 @@ import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class GetProjectMetadataCommand extends Command { public class GetProjectMetadataCommand extends Command {
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
Project project = getProject(request); Project project = getProject(request);
try { try {
respondJSON(response, ProjectManager.singleton.getProjectMetadata(project.id)); respondJSON(response, ProjectManager.singleton.getProjectMetadata(project.id));
} catch (JSONException e) { } catch (JSONException e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -20,99 +20,99 @@ import com.metaweb.gridworks.model.Row;
public class GetRowsCommand extends Command { public class GetRowsCommand extends Command {
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
Engine engine = getEngine(request, project); Engine engine = getEngine(request, project);
int start = Math.min(project.rows.size(), Math.max(0, getIntegerParameter(request, "start", 0))); 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))); int limit = Math.min(project.rows.size() - start, Math.max(0, getIntegerParameter(request, "limit", 20)));
Properties options = new Properties(); Properties options = new Properties();
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
writer.object(); writer.object();
{ {
RowAccumulator acc = new RowAccumulator(start, limit) { RowAccumulator acc = new RowAccumulator(start, limit) {
JSONWriter writer; JSONWriter writer;
Properties options; Properties options;
Properties extra; Properties extra;
public RowAccumulator init(JSONWriter writer, Properties options) { public RowAccumulator init(JSONWriter writer, Properties options) {
this.writer = writer; this.writer = writer;
this.options = options; this.options = options;
this.extra = new Properties(); this.extra = new Properties();
this.extra.put("contextual", true); this.extra.put("contextual", true);
return this; return this;
} }
@Override @Override
public boolean internalVisit(int rowIndex, Row row, boolean contextual) { public boolean internalVisit(int rowIndex, Row row, boolean contextual) {
try { try {
if (contextual) { if (contextual) {
options.put("extra", extra); options.put("extra", extra);
} else { } else {
options.remove("extra"); options.remove("extra");
} }
options.put("rowIndex", rowIndex); options.put("rowIndex", rowIndex);
row.write(writer, options); row.write(writer, options);
} catch (JSONException e) { } catch (JSONException e) {
} }
return false; return false;
} }
}.init(writer, options); }.init(writer, options);
FilteredRows filteredRows = engine.getAllFilteredRows(true); FilteredRows filteredRows = engine.getAllFilteredRows(true);
writer.key("rows"); writer.array(); writer.key("rows"); writer.array();
filteredRows.accept(project, acc); filteredRows.accept(project, acc);
writer.endArray(); writer.endArray();
writer.key("filtered"); writer.value(acc.total); writer.key("filtered"); writer.value(acc.total);
} }
writer.key("start"); writer.value(start); writer.key("start"); writer.value(start);
writer.key("limit"); writer.value(limit); writer.key("limit"); writer.value(limit);
writer.key("total"); writer.value(project.rows.size()); writer.key("total"); writer.value(project.rows.size());
writer.endObject(); writer.endObject();
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
static protected class RowAccumulator implements RowVisitor { static protected class RowAccumulator implements RowVisitor {
final public int start; final public int start;
final public int limit; final public int limit;
public int total; public int total;
public RowAccumulator(int start, int limit) { public RowAccumulator(int start, int limit) {
this.start = start; this.start = start;
this.limit = limit; this.limit = limit;
} }
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) { public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
boolean r = false; boolean r = false;
if (total >= start && total < start + limit) { if (total >= start && total < start + limit) {
r = internalVisit(rowIndex, row, contextual); r = internalVisit(rowIndex, row, contextual);
} }
if (!contextual) { if (!contextual) {
total++; total++;
} }
return r; return r;
} }
protected boolean internalVisit(int rowIndex, Row row, boolean contextual) { protected boolean internalVisit(int rowIndex, Row row, boolean contextual) {
return false; return false;
} }
} }
} }

View File

@ -9,12 +9,12 @@ import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.operations.ReconDiscardJudgmentsOperation; import com.metaweb.gridworks.operations.ReconDiscardJudgmentsOperation;
public class ReconDiscardJudgmentsCommand extends EngineDependentCommand { public class ReconDiscardJudgmentsCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(HttpServletRequest request, protected AbstractOperation createOperation(HttpServletRequest request,
JSONObject engineConfig) throws Exception { JSONObject engineConfig) throws Exception {
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
return new ReconDiscardJudgmentsOperation(engineConfig, columnName); return new ReconDiscardJudgmentsOperation(engineConfig, columnName);
} }
} }

View File

@ -25,154 +25,154 @@ import com.metaweb.gridworks.model.changes.ReconChange;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess; import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class ReconJudgeOneCellCommand extends Command { public class ReconJudgeOneCellCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
int rowIndex = Integer.parseInt(request.getParameter("row")); int rowIndex = Integer.parseInt(request.getParameter("row"));
int cellIndex = Integer.parseInt(request.getParameter("cell")); int cellIndex = Integer.parseInt(request.getParameter("cell"));
Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment")); Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
ReconCandidate match = null; ReconCandidate match = null;
String topicID = request.getParameter("topicID"); String topicID = request.getParameter("topicID");
if (topicID != null) { if (topicID != null) {
String scoreString = request.getParameter("score"); String scoreString = request.getParameter("score");
match = new ReconCandidate( match = new ReconCandidate(
topicID, topicID,
request.getParameter("topicGUID"), request.getParameter("topicGUID"),
request.getParameter("topicName"), request.getParameter("topicName"),
request.getParameter("types").split(","), request.getParameter("types").split(","),
scoreString != null ? Double.parseDouble(scoreString) : 100 scoreString != null ? Double.parseDouble(scoreString) : 100
); );
} }
JudgeOneCellProcess process = new JudgeOneCellProcess( JudgeOneCellProcess process = new JudgeOneCellProcess(
project, project,
"Judge one cell's recon result", "Judge one cell's recon result",
judgment, judgment,
rowIndex, rowIndex,
cellIndex, cellIndex,
match match
); );
boolean done = project.processManager.queueProcess(process); boolean done = project.processManager.queueProcess(process);
if (done) { if (done) {
JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
writer.object(); writer.object();
writer.key("code"); writer.value("ok"); writer.key("code"); writer.value("ok");
writer.key("cell"); process.newCell.write(writer, new Properties()); writer.key("cell"); process.newCell.write(writer, new Properties());
writer.endObject(); writer.endObject();
} else { } else {
respond(response, "{ \"code\" : \"pending\" }"); respond(response, "{ \"code\" : \"pending\" }");
} }
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
protected class JudgeOneCellProcess extends QuickHistoryEntryProcess { protected class JudgeOneCellProcess extends QuickHistoryEntryProcess {
final int rowIndex; final int rowIndex;
final int cellIndex; final int cellIndex;
final Judgment judgment; final Judgment judgment;
final ReconCandidate match; final ReconCandidate match;
Cell newCell; Cell newCell;
JudgeOneCellProcess( JudgeOneCellProcess(
Project project, Project project,
String briefDescription, String briefDescription,
Judgment judgment, Judgment judgment,
int rowIndex, int rowIndex,
int cellIndex, int cellIndex,
ReconCandidate match ReconCandidate match
) { ) {
super(project, briefDescription); super(project, briefDescription);
this.judgment = judgment; this.judgment = judgment;
this.rowIndex = rowIndex; this.rowIndex = rowIndex;
this.cellIndex = cellIndex; this.cellIndex = cellIndex;
this.match = match; this.match = match;
} }
protected HistoryEntry createHistoryEntry() throws Exception { protected HistoryEntry createHistoryEntry() throws Exception {
Cell cell = _project.rows.get(rowIndex).getCell(cellIndex); Cell cell = _project.rows.get(rowIndex).getCell(cellIndex);
if (cell == null || !ExpressionUtils.isNonBlankData(cell.value)) { if (cell == null || !ExpressionUtils.isNonBlankData(cell.value)) {
throw new Exception("Cell is blank or error"); throw new Exception("Cell is blank or error");
} }
Column column = _project.columnModel.getColumnByCellIndex(cellIndex); Column column = _project.columnModel.getColumnByCellIndex(cellIndex);
if (column == null) { if (column == null) {
throw new Exception("No such column"); throw new Exception("No such column");
} }
Judgment oldJudgment = cell.recon == null ? Judgment.None : cell.recon.judgment; Judgment oldJudgment = cell.recon == null ? Judgment.None : cell.recon.judgment;
newCell = new Cell( newCell = new Cell(
cell.value, cell.value,
cell.recon == null ? new Recon() : cell.recon.dup() cell.recon == null ? new Recon() : cell.recon.dup()
); );
String cellDescription = String cellDescription =
"single cell on row " + (rowIndex + 1) + "single cell on row " + (rowIndex + 1) +
", column " + column.getHeaderLabel() + ", column " + column.getHeaderLabel() +
", containing \"" + cell.value + "\""; ", containing \"" + cell.value + "\"";
String description = null; String description = null;
if (judgment == Judgment.None) { if (judgment == Judgment.None) {
newCell.recon.judgment = Recon.Judgment.None; newCell.recon.judgment = Recon.Judgment.None;
newCell.recon.match = null; newCell.recon.match = null;
description = "Discard recon judgment for " + cellDescription; description = "Discard recon judgment for " + cellDescription;
} else if (judgment == Judgment.New) { } else if (judgment == Judgment.New) {
newCell.recon.judgment = Recon.Judgment.New; newCell.recon.judgment = Recon.Judgment.New;
description = "Mark to create new topic for " + cellDescription; description = "Mark to create new topic for " + cellDescription;
} else { } else {
newCell.recon.judgment = Recon.Judgment.Matched; newCell.recon.judgment = Recon.Judgment.Matched;
newCell.recon.match = this.match; newCell.recon.match = this.match;
description = "Match " + this.match.topicName + description = "Match " + this.match.topicName +
" (" + match.topicID + ") to " + " (" + match.topicID + ") to " +
cellDescription; cellDescription;
} }
ReconStats stats = column.getReconStats(); ReconStats stats = column.getReconStats();
if (stats == null) { if (stats == null) {
stats = ReconStats.create(_project, cellIndex); stats = ReconStats.create(_project, cellIndex);
} else { } else {
int newChange = 0; int newChange = 0;
int matchChange = 0; int matchChange = 0;
if (oldJudgment == Judgment.New) { if (oldJudgment == Judgment.New) {
newChange--; newChange--;
} }
if (oldJudgment == Judgment.Matched) { if (oldJudgment == Judgment.Matched) {
matchChange--; matchChange--;
} }
if (newCell.recon.judgment == Judgment.New) { if (newCell.recon.judgment == Judgment.New) {
newChange++; newChange++;
} }
if (newCell.recon.judgment == Judgment.Matched) { if (newCell.recon.judgment == Judgment.Matched) {
matchChange++; matchChange++;
} }
stats = new ReconStats( stats = new ReconStats(
stats.nonBlanks, stats.nonBlanks,
stats.newTopics + newChange, stats.newTopics + newChange,
stats.matchedTopics + matchChange); stats.matchedTopics + matchChange);
} }
Change change = new ReconChange( Change change = new ReconChange(
new CellChange(rowIndex, cellIndex, cell, newCell), new CellChange(rowIndex, cellIndex, cell, newCell),
column.getHeaderLabel(), column.getHeaderLabel(),
column.getReconConfig(), column.getReconConfig(),
stats stats
); );
return new HistoryEntry( return new HistoryEntry(
_project, description, null, change); _project, description, null, change);
} }
} }
} }

View File

@ -13,37 +13,37 @@ import com.metaweb.gridworks.operations.ReconJudgeSimilarCellsOperation;
public class ReconJudgeSimilarCellsCommand extends EngineDependentCommand { public class ReconJudgeSimilarCellsCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation( protected AbstractOperation createOperation(
HttpServletRequest request, JSONObject engineConfig) throws Exception { HttpServletRequest request, JSONObject engineConfig) throws Exception {
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
String similarValue = request.getParameter("similarValue"); String similarValue = request.getParameter("similarValue");
Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment")); Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
ReconCandidate match = null; ReconCandidate match = null;
String topicID = request.getParameter("topicID"); String topicID = request.getParameter("topicID");
if (topicID != null) { if (topicID != null) {
String scoreString = request.getParameter("score"); String scoreString = request.getParameter("score");
match = new ReconCandidate( match = new ReconCandidate(
topicID, topicID,
request.getParameter("topicGUID"), request.getParameter("topicGUID"),
request.getParameter("topicName"), request.getParameter("topicName"),
request.getParameter("types").split(","), request.getParameter("types").split(","),
scoreString != null ? Double.parseDouble(scoreString) : 100 scoreString != null ? Double.parseDouble(scoreString) : 100
); );
} }
String shareNewTopics = request.getParameter("shareNewTopics"); String shareNewTopics = request.getParameter("shareNewTopics");
return new ReconJudgeSimilarCellsOperation( return new ReconJudgeSimilarCellsOperation(
engineConfig, engineConfig,
columnName, columnName,
similarValue, similarValue,
judgment, judgment,
match, match,
"true".equals(shareNewTopics) "true".equals(shareNewTopics)
); );
} }
} }

View File

@ -9,15 +9,15 @@ import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.operations.ReconMarkNewTopicsOperation; import com.metaweb.gridworks.operations.ReconMarkNewTopicsOperation;
public class ReconMarkNewTopicsCommand extends EngineDependentCommand { public class ReconMarkNewTopicsCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(HttpServletRequest request, protected AbstractOperation createOperation(HttpServletRequest request,
JSONObject engineConfig) throws Exception { JSONObject engineConfig) throws Exception {
return new ReconMarkNewTopicsOperation( return new ReconMarkNewTopicsOperation(
engineConfig, engineConfig,
request.getParameter("columnName"), request.getParameter("columnName"),
"true".equals(request.getParameter("shareNewTopics")) "true".equals(request.getParameter("shareNewTopics"))
); );
} }
} }

View File

@ -9,13 +9,13 @@ import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.operations.ReconMatchBestCandidatesOperation; import com.metaweb.gridworks.operations.ReconMatchBestCandidatesOperation;
public class ReconMatchBestCandidatesCommand extends EngineDependentCommand { public class ReconMatchBestCandidatesCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(HttpServletRequest request, protected AbstractOperation createOperation(HttpServletRequest request,
JSONObject engineConfig) throws Exception { JSONObject engineConfig) throws Exception {
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
return new ReconMatchBestCandidatesOperation(engineConfig, columnName); return new ReconMatchBestCandidatesOperation(engineConfig, columnName);
} }
} }

View File

@ -10,20 +10,20 @@ import com.metaweb.gridworks.model.ReconCandidate;
import com.metaweb.gridworks.operations.ReconMatchSpecificTopicOperation; import com.metaweb.gridworks.operations.ReconMatchSpecificTopicOperation;
public class ReconMatchSpecificTopicCommand extends EngineDependentCommand { public class ReconMatchSpecificTopicCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(HttpServletRequest request, protected AbstractOperation createOperation(HttpServletRequest request,
JSONObject engineConfig) throws Exception { JSONObject engineConfig) throws Exception {
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
ReconCandidate match = new ReconCandidate( ReconCandidate match = new ReconCandidate(
request.getParameter("topicID"), request.getParameter("topicID"),
request.getParameter("topicGUID"), request.getParameter("topicGUID"),
request.getParameter("topicName"), request.getParameter("topicName"),
request.getParameter("types").split(","), request.getParameter("types").split(","),
100 100
); );
return new ReconMatchSpecificTopicOperation(engineConfig, columnName, match); return new ReconMatchSpecificTopicOperation(engineConfig, columnName, match);
} }
} }

View File

@ -11,17 +11,17 @@ import com.metaweb.gridworks.model.recon.ReconConfig;
import com.metaweb.gridworks.operations.ReconOperation; import com.metaweb.gridworks.operations.ReconOperation;
public class ReconcileCommand extends EngineDependentCommand { public class ReconcileCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(HttpServletRequest request, protected AbstractOperation createOperation(HttpServletRequest request,
JSONObject engineConfig) throws Exception { JSONObject engineConfig) throws Exception {
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
String configString = request.getParameter("config"); String configString = request.getParameter("config");
JSONTokener t = new JSONTokener(configString); JSONTokener t = new JSONTokener(configString);
JSONObject config = (JSONObject) t.nextValue(); JSONObject config = (JSONObject) t.nextValue();
return new ReconOperation(engineConfig, columnName, ReconConfig.reconstruct(config)); return new ReconOperation(engineConfig, columnName, ReconConfig.reconstruct(config));
} }
} }

View File

@ -10,20 +10,20 @@ import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class CancelProcessesCommand extends Command { public class CancelProcessesCommand extends Command {
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
project.processManager.cancelAll(); project.processManager.cancelAll();
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
response.getWriter().write("{ \"code\" : \"ok\" }"); response.getWriter().write("{ \"code\" : \"ok\" }");
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -16,43 +16,43 @@ import com.metaweb.gridworks.gel.ControlFunctionRegistry;
import com.metaweb.gridworks.gel.Function; import com.metaweb.gridworks.gel.Function;
public class GetExpressionLanguageInfoCommand extends Command { public class GetExpressionLanguageInfoCommand extends Command {
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
Properties options = new Properties(); Properties options = new Properties();
writer.object(); writer.object();
writer.key("functions"); writer.key("functions");
writer.object(); writer.object();
{ {
for (Entry<String, Function> entry : ControlFunctionRegistry.getFunctionMapping()) { for (Entry<String, Function> entry : ControlFunctionRegistry.getFunctionMapping()) {
writer.key(entry.getKey()); writer.key(entry.getKey());
entry.getValue().write(writer, options); entry.getValue().write(writer, options);
} }
} }
writer.endObject(); writer.endObject();
writer.key("controls"); writer.key("controls");
writer.object(); writer.object();
{ {
for (Entry<String, Control> entry : ControlFunctionRegistry.getControlMapping()) { for (Entry<String, Control> entry : ControlFunctionRegistry.getControlMapping()) {
writer.key(entry.getKey()); writer.key(entry.getKey());
entry.getValue().write(writer, options); entry.getValue().write(writer, options);
} }
} }
writer.endObject(); writer.endObject();
writer.endObject(); writer.endObject();
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -30,181 +30,181 @@ import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class GuessTypesOfColumnCommand extends Command { public class GuessTypesOfColumnCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
String columnName = request.getParameter("columnName"); String columnName = request.getParameter("columnName");
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
writer.object(); writer.object();
Column column = project.columnModel.getColumnByName(columnName); Column column = project.columnModel.getColumnByName(columnName);
if (column == null) { if (column == null) {
writer.key("code"); writer.value("error"); writer.key("code"); writer.value("error");
writer.key("message"); writer.value("No such column"); writer.key("message"); writer.value("No such column");
} else { } else {
try { try {
writer.key("code"); writer.value("ok"); writer.key("code"); writer.value("ok");
writer.key("types"); writer.array(); writer.key("types"); writer.array();
List<TypeGroup> typeGroups = guessTypes(project, column); List<TypeGroup> typeGroups = guessTypes(project, column);
for (TypeGroup tg : typeGroups) { for (TypeGroup tg : typeGroups) {
writer.object(); writer.object();
writer.key("id"); writer.value(tg.id); writer.key("id"); writer.value(tg.id);
writer.key("name"); writer.value(tg.name); writer.key("name"); writer.value(tg.name);
writer.key("score"); writer.value(tg.score); writer.key("score"); writer.value(tg.score);
writer.key("count"); writer.value(tg.count); writer.key("count"); writer.value(tg.count);
writer.endObject(); writer.endObject();
} }
writer.endArray(); writer.endArray();
} catch (Exception e) { } catch (Exception e) {
writer.key("code"); writer.value("error"); writer.key("code"); writer.value("error");
} }
} }
writer.endObject(); writer.endObject();
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
final static int s_sampleSize = 20; final static int s_sampleSize = 20;
protected List<TypeGroup> guessTypes(Project project, Column column) { protected List<TypeGroup> guessTypes(Project project, Column column) {
Map<String, TypeGroup> map = new HashMap<String, TypeGroup>(); Map<String, TypeGroup> map = new HashMap<String, TypeGroup>();
int cellIndex = column.getCellIndex(); int cellIndex = column.getCellIndex();
List<String> samples = new ArrayList<String>(s_sampleSize); List<String> samples = new ArrayList<String>(s_sampleSize);
Set<String> sampleSet = new HashSet<String>(); Set<String> sampleSet = new HashSet<String>();
for (Row row : project.rows) { for (Row row : project.rows) {
Object value = row.getCellValue(cellIndex); Object value = row.getCellValue(cellIndex);
if (ExpressionUtils.isNonBlankData(value)) { if (ExpressionUtils.isNonBlankData(value)) {
String s = value.toString().trim(); String s = value.toString().trim();
if (!sampleSet.contains(s)) { if (!sampleSet.contains(s)) {
samples.add(s); samples.add(s);
sampleSet.add(s); sampleSet.add(s);
if (samples.size() >= s_sampleSize) { if (samples.size() >= s_sampleSize) {
break; break;
} }
} }
} }
} }
try { try {
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter); JSONWriter jsonWriter = new JSONWriter(stringWriter);
jsonWriter.object(); jsonWriter.object();
for (int i = 0; i < samples.size(); i++) { for (int i = 0; i < samples.size(); i++) {
jsonWriter.key("q" + i + ":search"); jsonWriter.key("q" + i + ":search");
jsonWriter.object(); jsonWriter.object();
jsonWriter.key("query"); jsonWriter.value(samples.get(i)); jsonWriter.key("query"); jsonWriter.value(samples.get(i));
jsonWriter.key("limit"); jsonWriter.value(3); jsonWriter.key("limit"); jsonWriter.value(3);
jsonWriter.endObject(); jsonWriter.endObject();
} }
jsonWriter.endObject(); jsonWriter.endObject();
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("http://api.freebase.com/api/service/search?indent=1&queries="); sb.append("http://api.freebase.com/api/service/search?indent=1&queries=");
sb.append(ParsingUtilities.encode(stringWriter.toString())); sb.append(ParsingUtilities.encode(stringWriter.toString()));
URL url = new URL(sb.toString()); URL url = new URL(sb.toString());
URLConnection connection = url.openConnection(); URLConnection connection = url.openConnection();
connection.setConnectTimeout(5000); connection.setConnectTimeout(5000);
connection.connect(); connection.connect();
InputStream is = connection.getInputStream(); InputStream is = connection.getInputStream();
try { try {
String s = ParsingUtilities.inputStreamToString(is); String s = ParsingUtilities.inputStreamToString(is);
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
for (int i = 0; i < samples.size(); i++) { for (int i = 0; i < samples.size(); i++) {
String key = "q" + i + ":search"; String key = "q" + i + ":search";
if (!o.has(key)) { if (!o.has(key)) {
continue; continue;
} }
JSONObject o2 = o.getJSONObject(key); JSONObject o2 = o.getJSONObject(key);
if (!(o2.has("result"))) { if (!(o2.has("result"))) {
continue; continue;
} }
JSONArray results = o2.getJSONArray("result"); JSONArray results = o2.getJSONArray("result");
int count = results.length(); int count = results.length();
for (int j = 0; j < count; j++) { for (int j = 0; j < count; j++) {
JSONObject result = results.getJSONObject(j); JSONObject result = results.getJSONObject(j);
double score = 1.0 / (1 + j); //result.getDouble("relevance:score"); double score = 1.0 / (1 + j); //result.getDouble("relevance:score");
JSONArray types = result.getJSONArray("type"); JSONArray types = result.getJSONArray("type");
int typeCount = types.length(); int typeCount = types.length();
for (int t = 0; t < typeCount; t++) { for (int t = 0; t < typeCount; t++) {
JSONObject type = types.getJSONObject(t); JSONObject type = types.getJSONObject(t);
String id = type.getString("id"); String id = type.getString("id");
if (id.equals("/common/topic") || if (id.equals("/common/topic") ||
id.equals("/base/ontologies/ontology_instance") || id.equals("/base/ontologies/ontology_instance") ||
(id.startsWith("/base/") && id.endsWith("/topic")) || (id.startsWith("/base/") && id.endsWith("/topic")) ||
id.startsWith("/user/") || id.startsWith("/user/") ||
id.startsWith("/freebase/") id.startsWith("/freebase/")
) { ) {
continue; continue;
} }
if (map.containsKey(id)) { if (map.containsKey(id)) {
TypeGroup tg = map.get(id); TypeGroup tg = map.get(id);
tg.score += score; tg.score += score;
tg.count++; tg.count++;
} else { } else {
map.put(id, new TypeGroup(id, type.getString("name"), score)); map.put(id, new TypeGroup(id, type.getString("name"), score));
} }
} }
} }
} }
} finally { } finally {
is.close(); is.close();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
List<TypeGroup> types = new ArrayList<TypeGroup>(map.values()); List<TypeGroup> types = new ArrayList<TypeGroup>(map.values());
Collections.sort(types, new Comparator<TypeGroup>() { Collections.sort(types, new Comparator<TypeGroup>() {
public int compare(TypeGroup o1, TypeGroup o2) { public int compare(TypeGroup o1, TypeGroup o2) {
int c = Math.min(s_sampleSize, o2.count) - Math.min(s_sampleSize, o1.count); int c = Math.min(s_sampleSize, o2.count) - Math.min(s_sampleSize, o1.count);
if (c != 0) { if (c != 0) {
return c; return c;
} }
return (int) Math.signum(o2.score / o2.count - o1.score / o1.count); return (int) Math.signum(o2.score / o2.count - o1.score / o1.count);
} }
}); });
return types; return types;
} }
static protected class TypeGroup { static protected class TypeGroup {
String id; String id;
String name; String name;
int count; int count;
double score; double score;
TypeGroup(String id, String name, double score) { TypeGroup(String id, String name, double score) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.score = score; this.score = score;
this.count = 1; this.count = 1;
} }
} }
} }

View File

@ -22,81 +22,81 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
public class PreviewExpressionCommand extends Command { public class PreviewExpressionCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
int cellIndex = Integer.parseInt(request.getParameter("cellIndex")); int cellIndex = Integer.parseInt(request.getParameter("cellIndex"));
String expression = request.getParameter("expression"); String expression = request.getParameter("expression");
String rowIndicesString = request.getParameter("rowIndices"); String rowIndicesString = request.getParameter("rowIndices");
if (rowIndicesString == null) { if (rowIndicesString == null) {
respond(response, "{ \"code\" : \"error\", \"message\" : \"No row indices specified\" }"); respond(response, "{ \"code\" : \"error\", \"message\" : \"No row indices specified\" }");
return; return;
} }
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
JSONArray rowIndices = jsonStringToArray(rowIndicesString); JSONArray rowIndices = jsonStringToArray(rowIndicesString);
int length = rowIndices.length(); int length = rowIndices.length();
JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
writer.object(); writer.object();
try { try {
Evaluable eval = MetaParser.parse(expression); Evaluable eval = MetaParser.parse(expression);
writer.key("code"); writer.value("ok"); writer.key("code"); writer.value("ok");
writer.key("results"); writer.array(); writer.key("results"); writer.array();
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
Object result = null; Object result = null;
int rowIndex = rowIndices.getInt(i); int rowIndex = rowIndices.getInt(i);
if (rowIndex >= 0 && rowIndex < project.rows.size()) { if (rowIndex >= 0 && rowIndex < project.rows.size()) {
Row row = project.rows.get(rowIndex); Row row = project.rows.get(rowIndex);
Cell cell = row.getCell(cellIndex); Cell cell = row.getCell(cellIndex);
ExpressionUtils.bind(bindings, row, rowIndex, cell); ExpressionUtils.bind(bindings, row, rowIndex, cell);
try { try {
result = eval.evaluate(bindings); result = eval.evaluate(bindings);
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }
} }
if (ExpressionUtils.isError(result)) { if (ExpressionUtils.isError(result)) {
writer.object(); writer.object();
writer.key("message"); writer.value(((EvalError) result).message); writer.key("message"); writer.value(((EvalError) result).message);
writer.endObject(); writer.endObject();
} else { } else {
if (result != null && result instanceof HasFields) { if (result != null && result instanceof HasFields) {
result = "[object " + result.getClass().getSimpleName() + "]"; result = "[object " + result.getClass().getSimpleName() + "]";
} }
writer.value(result); writer.value(result);
} }
} }
writer.endArray(); writer.endArray();
} catch (ParsingException e) { } catch (ParsingException e) {
writer.key("code"); writer.value("error"); writer.key("code"); writer.value("error");
writer.key("type"); writer.value("parser"); writer.key("type"); writer.value("parser");
writer.key("message"); writer.value(e.getMessage()); writer.key("message"); writer.value(e.getMessage());
} catch (Exception e) { } catch (Exception e) {
writer.key("code"); writer.value("error"); writer.key("code"); writer.value("error");
writer.key("type"); writer.value("other"); writer.key("type"); writer.value("other");
writer.key("message"); writer.value(e.getMessage()); writer.key("message"); writer.value(e.getMessage());
} }
writer.endObject(); writer.endObject();
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -17,48 +17,48 @@ import com.metaweb.gridworks.protograph.transpose.Transposer;
import com.metaweb.gridworks.protograph.transpose.TripleLoaderTransposedNodeFactory; import com.metaweb.gridworks.protograph.transpose.TripleLoaderTransposedNodeFactory;
public class PreviewProtographCommand extends Command { public class PreviewProtographCommand extends Command {
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
try { try {
Project project = getProject(request); Project project = getProject(request);
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
String jsonString = request.getParameter("protograph"); String jsonString = request.getParameter("protograph");
JSONObject json = jsonStringToObject(jsonString); JSONObject json = jsonStringToObject(jsonString);
Protograph protograph = Protograph.reconstruct(json); Protograph protograph = Protograph.reconstruct(json);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("{ "); sb.append("{ ");
{ {
TripleLoaderTransposedNodeFactory nodeFactory = new TripleLoaderTransposedNodeFactory(); TripleLoaderTransposedNodeFactory nodeFactory = new TripleLoaderTransposedNodeFactory();
Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory); Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory);
sb.append("\"tripleloader\" : "); sb.append("\"tripleloader\" : ");
sb.append(JSONObject.quote(nodeFactory.getLoad())); sb.append(JSONObject.quote(nodeFactory.getLoad()));
} }
{ {
MqlreadLikeTransposedNodeFactory nodeFactory = new MqlreadLikeTransposedNodeFactory(); MqlreadLikeTransposedNodeFactory nodeFactory = new MqlreadLikeTransposedNodeFactory();
Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory); Transposer.transpose(project, protograph, protograph.getRootNode(0), nodeFactory);
JSONArray results = nodeFactory.getJSON(); JSONArray results = nodeFactory.getJSON();
sb.append(", \"mqllike\" : "); sb.append(", \"mqllike\" : ");
sb.append(results.toString()); sb.append(results.toString());
} }
sb.append(" }"); sb.append(" }");
respond(response, sb.toString()); respond(response, sb.toString());
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }
} }
} }

View File

@ -3,5 +3,5 @@ package com.metaweb.gridworks.expr;
import java.util.Properties; import java.util.Properties;
public interface Evaluable { public interface Evaluable {
public Object evaluate(Properties bindings); public Object evaluate(Properties bindings);
} }

View File

@ -3,5 +3,5 @@ package com.metaweb.gridworks.expr;
import java.util.Properties; import java.util.Properties;
public interface HasFields { public interface HasFields {
public Object getField(String name, Properties bindings); public Object getField(String name, Properties bindings);
} }

View File

@ -10,85 +10,85 @@ import com.metaweb.gridworks.gel.Function;
public class Get implements Function { public class Get implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length > 1 && args.length <= 3) { if (args.length > 1 && args.length <= 3) {
Object v = args[0]; Object v = args[0];
Object from = args[1]; Object from = args[1];
Object to = args.length == 3 ? args[2] : null; Object to = args.length == 3 ? args[2] : null;
if (v != null && from != null) { if (v != null && from != null) {
if (v instanceof HasFields) { if (v instanceof HasFields) {
if (from instanceof String) { if (from instanceof String) {
return ((HasFields) v).getField((String) from, bindings); return ((HasFields) v).getField((String) from, bindings);
} }
} else { } else {
if (from instanceof Number && (to == null || to instanceof Number)) { if (from instanceof Number && (to == null || to instanceof Number)) {
if (v.getClass().isArray()) { if (v.getClass().isArray()) {
Object[] a = (Object[]) v; Object[] a = (Object[]) v;
int start = ((Number) from).intValue(); int start = ((Number) from).intValue();
if (start < 0) { if (start < 0) {
start = a.length + start; start = a.length + start;
} }
start = Math.min(a.length, Math.max(0, start)); start = Math.min(a.length, Math.max(0, start));
if (to == null) { if (to == null) {
return start < a.length ? a[start] : null; return start < a.length ? a[start] : null;
} else { } else {
int end = to != null && to instanceof Number ? int end = to != null && to instanceof Number ?
((Number) to).intValue() : a.length; ((Number) to).intValue() : a.length;
if (end < 0) { if (end < 0) {
end = a.length + end; end = a.length + end;
} }
end = Math.min(a.length, Math.max(start, end)); end = Math.min(a.length, Math.max(start, end));
if (end > start) { if (end > start) {
Object[] a2 = new Object[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; return a2;
} }
} }
} else { } else {
String s = (v instanceof String ? (String) v : v.toString()); String s = (v instanceof String ? (String) v : v.toString());
int start = ((Number) from).intValue(); int start = ((Number) from).intValue();
if (start < 0) { if (start < 0) {
start = s.length() + start; start = s.length() + start;
} }
start = Math.min(s.length(), Math.max(0, start)); start = Math.min(s.length(), Math.max(0, start));
if (to != null && to instanceof Number) { if (to != null && to instanceof Number) {
int end = ((Number) to).intValue(); int end = ((Number) to).intValue();
if (end < 0) { if (end < 0) {
end = s.length() + end; end = s.length() + end;
} }
end = Math.min(s.length(), Math.max(start, end)); end = Math.min(s.length(), Math.max(start, end));
return s.substring(start, end); return s.substring(start, end);
} else { } else {
return s.substring(start, start + 1); return s.substring(start, start + 1);
} }
} }
} }
} }
} }
} }
return null; return null;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value( writer.key("description"); writer.value(
"If o has fields, returns the field named 'from' of o. " + "If o has fields, returns the field named 'from' of o. " +
"If o is an array, returns o[from, to]. " + "If o is an array, returns o[from, to]. " +
"if o is a string, returns o.substring(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("params"); writer.value("o, number or string from, optional number to");
writer.key("returns"); writer.value("Depends on actual arguments"); writer.key("returns"); writer.value("Depends on actual arguments");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,30 +11,30 @@ import com.metaweb.gridworks.gel.Function;
public class Length implements Function { public class Length implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1) { if (args.length == 1) {
Object v = args[0]; Object v = args[0];
if (v != null) { if (v != null) {
if (v.getClass().isArray()) { if (v.getClass().isArray()) {
Object[] a = (Object[]) v; Object[] a = (Object[]) v;
return a.length; return a.length;
} else { } else {
String s = (v instanceof String ? (String) v : v.toString()); String s = (v instanceof String ? (String) v : v.toString());
return s.length(); return s.length();
} }
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array or a string"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array or a string");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the length of o"); writer.key("description"); writer.value("Returns the length of o");
writer.key("params"); writer.value("array or string o"); writer.key("params"); writer.value("array or string o");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -9,69 +9,69 @@ import com.metaweb.gridworks.gel.Function;
public class Slice implements Function { public class Slice implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length > 1 && args.length <= 3) { if (args.length > 1 && args.length <= 3) {
Object v = args[0]; Object v = args[0];
Object from = args[1]; Object from = args[1];
Object to = args.length == 3 ? args[2] : null; Object to = args.length == 3 ? args[2] : null;
if (v != null && from != null && from instanceof Number && (to == null || to instanceof Number)) { if (v != null && from != null && from instanceof Number && (to == null || to instanceof Number)) {
if (v.getClass().isArray()) { if (v.getClass().isArray()) {
Object[] a = (Object[]) v; Object[] a = (Object[]) v;
int start = ((Number) from).intValue(); int start = ((Number) from).intValue();
int end = to != null && to instanceof Number ? int end = to != null && to instanceof Number ?
((Number) to).intValue() : a.length; ((Number) to).intValue() : a.length;
if (start < 0) { if (start < 0) {
start = a.length + start; start = a.length + start;
} }
start = Math.min(a.length, Math.max(0, start)); start = Math.min(a.length, Math.max(0, start));
if (end < 0) { if (end < 0) {
end = a.length + end; end = a.length + end;
} }
end = Math.min(a.length, Math.max(start, end)); end = Math.min(a.length, Math.max(start, end));
Object[] a2 = new Object[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; return a2;
} else { } else {
String s = (v instanceof String ? (String) v : v.toString()); String s = (v instanceof String ? (String) v : v.toString());
int start = ((Number) from).intValue(); int start = ((Number) from).intValue();
if (start < 0) { if (start < 0) {
start = s.length() + start; start = s.length() + start;
} }
start = Math.min(s.length(), Math.max(0, start)); start = Math.min(s.length(), Math.max(0, start));
if (to != null && to instanceof Number) { if (to != null && to instanceof Number) {
int end = ((Number) to).intValue(); int end = ((Number) to).intValue();
if (end < 0) { if (end < 0) {
end = s.length() + end; end = s.length() + end;
} }
end = Math.min(s.length(), Math.max(start, end)); end = Math.min(s.length(), Math.max(start, end));
return s.substring(start, end); return s.substring(start, end);
} else { } else {
return s.substring(start); return s.substring(start);
} }
} }
} }
} }
return null; return null;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value( writer.key("description"); writer.value(
"If o is an array, returns o[from, to]. " + "If o is an array, returns o[from, to]. " +
"if o is a string, returns o.substring(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("params"); writer.value("o, number from, optional number to");
writer.key("returns"); writer.value("Depends on actual arguments"); writer.key("returns"); writer.value("Depends on actual arguments");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,7 +11,7 @@ import com.metaweb.gridworks.gel.Function;
public class ToDate implements 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) { if (args.length == 1 || args.length == 2) {
Object o1 = args[0]; Object o1 = args[0];
if (o1 != null && o1 instanceof String) { if (o1 != null && o1 instanceof String) {
@ -28,18 +28,18 @@ public class ToDate implements Function {
// do something about // do something about
} }
} }
} }
return null; return null;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns o converted to a date 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("params"); writer.value("o, boolean month_first (optional)");
writer.key("returns"); writer.value("date"); writer.key("returns"); writer.value("date");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -9,21 +9,21 @@ import com.metaweb.gridworks.gel.Function;
public class ToNumber implements Function { public class ToNumber implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null) { if (args.length == 1 && args[0] != null) {
return args[0] instanceof Number ? args[0] : Double.parseDouble(args[0].toString()); return args[0] instanceof Number ? args[0] : Double.parseDouble(args[0].toString());
} }
return null; return null;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns o converted to a number"); writer.key("description"); writer.value("Returns o converted to a number");
writer.key("params"); writer.value("o"); writer.key("params"); writer.value("o");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,8 +11,8 @@ import com.metaweb.gridworks.gel.Function;
public class ToString implements Function { public class ToString implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length >= 1) { if (args.length >= 1) {
Object o1 = args[0]; Object o1 = args[0];
if (o1 != null) { if (o1 != null) {
if (o1 instanceof Calendar) { if (o1 instanceof Calendar) {
@ -27,18 +27,18 @@ public class ToString implements Function {
return (o1 instanceof String) ? o1 : o1.toString(); return (o1 instanceof String) ? o1 : o1.toString();
} }
} }
} }
return null; return null;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns o converted to a string"); writer.key("description"); writer.value("Returns o converted to a string");
writer.key("params"); writer.value("o, string format (optional)"); writer.key("params"); writer.value("o, string format (optional)");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,40 +11,40 @@ import com.metaweb.gridworks.gel.Function;
public class Join implements Function { public class Join implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2) { if (args.length == 2) {
Object v = args[0]; Object v = args[0];
Object s = args[1]; Object s = args[1];
if (v != null && v.getClass().isArray() && if (v != null && v.getClass().isArray() &&
s != null && s instanceof String) { s != null && s instanceof String) {
Object[] a = (Object[]) v; Object[] a = (Object[]) v;
String separator = (String) s; String separator = (String) s;
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (Object o : a) { for (Object o : a) {
if (o != null) { if (o != null) {
if (sb.length() > 0) { if (sb.length() > 0) {
sb.append(separator); sb.append(separator);
} }
sb.append(o.toString()); sb.append(o.toString());
} }
} }
return sb.toString(); return sb.toString();
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array and a string"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array and a string");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the string obtained by joining the array a with the separator sep"); 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("params"); writer.value("array a, string sep");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,31 +11,31 @@ import com.metaweb.gridworks.gel.Function;
public class Reverse implements Function { public class Reverse implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1) { if (args.length == 1) {
Object v = args[0]; Object v = args[0];
if (v != null && v.getClass().isArray()) { if (v != null && v.getClass().isArray()) {
Object[] a = (Object[]) v; Object[] a = (Object[]) v;
Object[] r = new Object[a.length]; Object[] r = new Object[a.length];
for (int i = 0; i < a.length; i++) { for (int i = 0; i < a.length; i++) {
r[i] = a[r.length - i - 1]; r[i] = a[r.length - i - 1];
} }
return r; return r;
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Reverses array a"); writer.key("description"); writer.value("Reverses array a");
writer.key("params"); writer.value("array a"); writer.key("params"); writer.value("array a");
writer.key("returns"); writer.value("array"); writer.key("returns"); writer.value("array");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -12,30 +12,30 @@ import com.metaweb.gridworks.gel.Function;
public class Sort implements Function { public class Sort implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1) { if (args.length == 1) {
Object v = args[0]; Object v = args[0];
if (v != null && v.getClass().isArray()) { if (v != null && v.getClass().isArray()) {
Object[] a = (Object[]) v; Object[] a = (Object[]) v;
Object[] r = a.clone(); Object[] r = a.clone();
Arrays.sort(r, 0, r.length); Arrays.sort(r, 0, r.length);
return r; return r;
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Sorts array a"); writer.key("description"); writer.value("Sorts array a");
writer.key("params"); writer.value("array a"); writer.key("params"); writer.value("array a");
writer.key("returns"); writer.value("array"); writer.key("returns"); writer.value("array");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -9,22 +9,22 @@ import com.metaweb.gridworks.gel.Function;
public class And implements Function { public class And implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
for (Object o : args) { for (Object o : args) {
if (!Not.objectToBoolean(o)) { if (!Not.objectToBoolean(o)) {
return false; return false;
} }
} }
return true; return true;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("ANDs two boolean values"); writer.key("description"); writer.value("ANDs two boolean values");
writer.key("params"); writer.value("boolean a, boolean b"); writer.key("params"); writer.value("boolean a, boolean b");
writer.key("returns"); writer.value("boolean"); writer.key("returns"); writer.value("boolean");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,25 +11,25 @@ import com.metaweb.gridworks.gel.Function;
public class Not implements Function { public class Not implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1) { if (args.length == 1) {
return !objectToBoolean(args[0]); return !objectToBoolean(args[0]);
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a boolean"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a boolean");
} }
public static boolean objectToBoolean(Object o) { public static boolean objectToBoolean(Object o) {
return o == null ? false : ( return o == null ? false : (
(o instanceof Boolean) ? ((Boolean) o).booleanValue() : Boolean.parseBoolean(o.toString())); (o instanceof Boolean) ? ((Boolean) o).booleanValue() : Boolean.parseBoolean(o.toString()));
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the opposite of b"); writer.key("description"); writer.value("Returns the opposite of b");
writer.key("params"); writer.value("boolean b"); writer.key("params"); writer.value("boolean b");
writer.key("returns"); writer.value("boolean"); writer.key("returns"); writer.value("boolean");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -9,22 +9,22 @@ import com.metaweb.gridworks.gel.Function;
public class Or implements Function { public class Or implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
for (Object o : args) { for (Object o : args) {
if (Not.objectToBoolean(o)) { if (Not.objectToBoolean(o)) {
return true; return true;
} }
} }
return false; return false;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns a OR b"); writer.key("description"); writer.value("Returns a OR b");
writer.key("params"); writer.value("boolean a, boolean b"); writer.key("params"); writer.value("boolean a, boolean b");
writer.key("returns"); writer.value("boolean"); writer.key("returns"); writer.value("boolean");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,20 +11,20 @@ import com.metaweb.gridworks.gel.Function;
public class Ceil implements Function { public class Ceil implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null && args[0] instanceof Number) { if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
return (long) Math.ceil(((Number) args[0]).doubleValue()); return (long) Math.ceil(((Number) args[0]).doubleValue());
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the ceiling of a number"); writer.key("description"); writer.value("Returns the ceiling of a number");
writer.key("params"); writer.value("number d"); writer.key("params"); writer.value("number d");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -9,20 +9,20 @@ import com.metaweb.gridworks.gel.Function;
public class Exp implements Function { public class Exp implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] instanceof Number) { if (args.length == 1 && args[0] instanceof Number) {
return Math.exp(((Number) args[0]).doubleValue()); return Math.exp(((Number) args[0]).doubleValue());
} }
return null; return null;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns e^n"); writer.key("description"); writer.value("Returns e^n");
writer.key("params"); writer.value("number n"); writer.key("params"); writer.value("number n");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,21 +11,21 @@ import com.metaweb.gridworks.gel.Function;
public class Floor implements Function { public class Floor implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null && args[0] instanceof Number) { if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
return (long) Math.floor(((Number) args[0]).doubleValue()); return (long) Math.floor(((Number) args[0]).doubleValue());
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the floor of a number"); writer.key("description"); writer.value("Returns the floor of a number");
writer.key("params"); writer.value("number d"); writer.key("params"); writer.value("number d");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,20 +11,20 @@ import com.metaweb.gridworks.gel.Function;
public class Ln implements Function { public class Ln implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null && args[0] instanceof Number) { if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
return Math.log(((Number) args[0]).doubleValue()); return Math.log(((Number) args[0]).doubleValue());
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the natural log of n"); writer.key("description"); writer.value("Returns the natural log of n");
writer.key("params"); writer.value("number n"); writer.key("params"); writer.value("number n");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,20 +11,20 @@ import com.metaweb.gridworks.gel.Function;
public class Log implements Function { public class Log implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null && args[0] instanceof Number) { if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
return Math.log10(((Number) args[0]).doubleValue()); return Math.log10(((Number) args[0]).doubleValue());
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the base 10 log of n"); writer.key("description"); writer.value("Returns the base 10 log of n");
writer.key("params"); writer.value("number n"); writer.key("params"); writer.value("number n");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,24 +11,24 @@ import com.metaweb.gridworks.gel.Function;
public class Max implements Function { public class Max implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2 && if (args.length == 2 &&
args[0] != null && args[0] instanceof Number && args[0] != null && args[0] instanceof Number &&
args[1] != null && args[1] instanceof Number) { args[1] != null && args[1] instanceof Number) {
return Math.max( return Math.max(
((Number) args[0]).doubleValue(), ((Number) args[0]).doubleValue(),
((Number) args[1]).doubleValue()); ((Number) args[1]).doubleValue());
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the greater of two numbers"); writer.key("description"); writer.value("Returns the greater of two numbers");
writer.key("params"); writer.value("number a, number b"); writer.key("params"); writer.value("number a, number b");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,24 +11,24 @@ import com.metaweb.gridworks.gel.Function;
public class Min implements Function { public class Min implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2 && if (args.length == 2 &&
args[0] != null && args[0] instanceof Number && args[0] != null && args[0] instanceof Number &&
args[1] != null && args[1] instanceof Number) { args[1] != null && args[1] instanceof Number) {
return Math.min( return Math.min(
((Number) args[0]).doubleValue(), ((Number) args[0]).doubleValue(),
((Number) args[1]).doubleValue()); ((Number) args[1]).doubleValue());
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the smaller of two numbers"); writer.key("description"); writer.value("Returns the smaller of two numbers");
writer.key("params"); writer.value("number a, number b"); writer.key("params"); writer.value("number a, number b");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,25 +11,25 @@ import com.metaweb.gridworks.gel.Function;
public class Mod implements Function { public class Mod implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2 && if (args.length == 2 &&
args[0] != null && args[0] instanceof Number && args[0] != null && args[0] instanceof Number &&
args[1] != null && args[1] instanceof Number) { args[1] != null && args[1] instanceof Number) {
int a = ((Number) args[0]).intValue(); int a = ((Number) args[0]).intValue();
int b = ((Number) args[0]).intValue(); int b = ((Number) args[0]).intValue();
return a % b; return a % b;
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns a modulus b"); writer.key("description"); writer.value("Returns a modulus b");
writer.key("params"); writer.value("number a, number b"); writer.key("params"); writer.value("number a, number b");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,20 +11,20 @@ import com.metaweb.gridworks.gel.Function;
public class Round implements Function { public class Round implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null && args[0] instanceof Number) { if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
return ((Number) args[0]).longValue(); return ((Number) args[0]).longValue();
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns n rounded"); writer.key("description"); writer.value("Returns n rounded");
writer.key("params"); writer.value("number n"); writer.key("params"); writer.value("number n");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -9,23 +9,23 @@ import com.metaweb.gridworks.gel.Function;
public class Contains implements Function { public class Contains implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2) { if (args.length == 2) {
Object s1 = args[0]; Object s1 = args[0];
Object s2 = args[1]; Object s2 = args[1];
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) { if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
return ((String) s1).indexOf((String) s2) > -1; return ((String) s1).indexOf((String) s2) > -1;
} }
} }
return null; return null;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns whether s contains frag"); writer.key("description"); writer.value("Returns whether s contains frag");
writer.key("params"); writer.value("string s, string frag"); writer.key("params"); writer.value("string s, string frag");
writer.key("returns"); writer.value("boolean"); writer.key("returns"); writer.value("boolean");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,24 +11,24 @@ import com.metaweb.gridworks.gel.Function;
public class EndsWith implements Function { public class EndsWith implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2) { if (args.length == 2) {
Object s1 = args[0]; Object s1 = args[0];
Object s2 = args[1]; Object s2 = args[1];
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) { if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
return ((String) s1).endsWith((String) s2); return ((String) s1).endsWith((String) s2);
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns whether s ends with sub"); writer.key("description"); writer.value("Returns whether s ends with sub");
writer.key("params"); writer.value("string s, string sub"); writer.key("params"); writer.value("string s, string sub");
writer.key("returns"); writer.value("boolean"); writer.key("returns"); writer.value("boolean");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -14,28 +14,28 @@ public class Fingerprint implements Function {
static final Pattern alphanum = Pattern.compile("\\p{Punct}|\\p{Cntrl}"); static final Pattern alphanum = Pattern.compile("\\p{Punct}|\\p{Cntrl}");
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null) { if (args.length == 1 && args[0] != null) {
Object o = args[0]; Object o = args[0];
String s = (o instanceof String) ? (String) o : o.toString(); String s = (o instanceof String) ? (String) o : o.toString();
s = s.trim(); // first off, remove whitespace around the string s = s.trim(); // first off, remove whitespace around the string
s = s.toLowerCase(); // then lowercase it s = s.toLowerCase(); // then lowercase it
s = alphanum.matcher(s).replaceAll(""); // then remove all punctuation and control chars s = alphanum.matcher(s).replaceAll(""); // then remove all punctuation and control chars
String[] frags = StringUtils.split(s); // split by whitespace String[] frags = StringUtils.split(s); // split by whitespace
Arrays.sort(frags); // sort the fragments Arrays.sort(frags); // sort the fragments
return StringUtils.join(frags," "); // rejoin them with a single space between them return StringUtils.join(frags," "); // rejoin them with a single space between them
} }
return null; return null;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); 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("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("params"); writer.value("string s");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,24 +11,24 @@ import com.metaweb.gridworks.gel.Function;
public class IndexOf implements Function { public class IndexOf implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2) { if (args.length == 2) {
Object s1 = args[0]; Object s1 = args[0];
Object s2 = args[1]; Object s2 = args[1];
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) { if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
return ((String) s1).indexOf((String) s2); return ((String) s1).indexOf((String) s2);
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the index of sub first ocurring in s"); 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("params"); writer.value("string s, string sub");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,25 +11,25 @@ import com.metaweb.gridworks.gel.Function;
public class LastIndexOf implements Function { public class LastIndexOf implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2) { if (args.length == 2) {
Object s1 = args[0]; Object s1 = args[0];
Object s2 = args[1]; Object s2 = args[1];
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) { if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
return ((String) s1).lastIndexOf((String) s2); return ((String) s1).lastIndexOf((String) s2);
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the index of sub last ocurring in s"); 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("params"); writer.value("string s, string sub");
writer.key("returns"); writer.value("number"); writer.key("returns"); writer.value("number");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -12,22 +12,22 @@ import com.metaweb.gridworks.gel.Function;
public class MD5 implements Function { public class MD5 implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null) { if (args.length == 1 && args[0] != null) {
Object o = args[0]; Object o = args[0];
String s = (o instanceof String) ? (String) o : o.toString(); String s = (o instanceof String) ? (String) o : o.toString();
return DigestUtils.md5Hex(s); return DigestUtils.md5Hex(s);
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the MD5 hash of s"); writer.key("description"); writer.value("Returns the MD5 hash of s");
writer.key("params"); writer.value("string s"); writer.key("params"); writer.value("string s");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -18,7 +18,7 @@ public class Phonetic implements Function {
private Metaphone metaphone = new Metaphone(); private Metaphone metaphone = new Metaphone();
private Soundex soundex = new Soundex(); private Soundex soundex = new Soundex();
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2) { if (args.length == 2) {
Object o1 = args[0]; Object o1 = args[0];
Object o2 = args[1]; Object o2 = args[1];
@ -37,15 +37,15 @@ public class Phonetic implements Function {
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the a phonetic encoding of s (optionally indicating which encoding to use')"); 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("params"); writer.value("string s, string encoding (optional, defaults to 'DoubleMetaphone')");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -15,7 +15,7 @@ import com.metaweb.gridworks.model.Project;
public class Reinterpret implements Function { public class Reinterpret implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2) { if (args.length == 2) {
Object o1 = args[0]; Object o1 = args[0];
Object o2 = args[1]; Object o2 = args[1];
@ -37,15 +37,15 @@ public class Reinterpret implements Function {
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 arguments"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 arguments");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns s reinterpreted thru the given encoder."); writer.key("description"); writer.value("Returns s reinterpreted thru the given encoder.");
writer.key("params"); writer.value("string s, string encoder"); writer.key("params"); writer.value("string s, string encoder");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,8 +11,8 @@ import com.metaweb.gridworks.gel.Function;
public class Replace implements Function { public class Replace implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 3) { if (args.length == 3) {
Object o1 = args[0]; Object o1 = args[0];
Object o2 = args[1]; Object o2 = args[1];
Object o3 = args[2]; Object o3 = args[2];
@ -20,18 +20,18 @@ public class Replace implements Function {
String str = (o1 instanceof String) ? (String) o1 : o1.toString(); String str = (o1 instanceof String) ? (String) o1 : o1.toString();
return str.replace((String) o2, (String) o3); return str.replace((String) o2, (String) o3);
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the string obtained by replacing f with r in s"); 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("params"); writer.value("string s, string f, string r");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -12,27 +12,27 @@ import com.metaweb.gridworks.gel.Function;
public class ReplaceChars implements Function { public class ReplaceChars implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 3) { if (args.length == 3) {
Object o1 = args[0]; Object o1 = args[0];
Object o2 = args[1]; Object o2 = args[1];
Object o3 = args[2]; Object o3 = args[2];
if (o1 != null && o2 != null && o3 != null && o2 instanceof String && o3 instanceof String) { if (o1 != null && o2 != null && o3 != null && o2 instanceof String && o3 instanceof String) {
String str = (o1 instanceof String) ? (String) o1 : o1.toString(); String str = (o1 instanceof String) ? (String) o1 : o1.toString();
return StringUtils.replaceChars(str, (String) o2, (String) o3); return StringUtils.replaceChars(str, (String) o2, (String) o3);
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); 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("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("params"); writer.value("string s, string f, string r");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,7 +11,7 @@ import com.metaweb.gridworks.gel.Function;
public class ReplaceRegexp implements Function { public class ReplaceRegexp implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 3) { if (args.length == 3) {
Object o1 = args[0]; Object o1 = args[0];
Object o2 = args[1]; Object o2 = args[1];
@ -22,16 +22,16 @@ public class ReplaceRegexp implements Function {
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the string obtained by replacing f with r in s"); 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("params"); writer.value("string s, string f, string r");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -12,22 +12,22 @@ import com.metaweb.gridworks.gel.Function;
public class SHA1 implements Function { public class SHA1 implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null) { if (args.length == 1 && args[0] != null) {
Object o = args[0]; Object o = args[0];
String s = (o instanceof String) ? (String) o : o.toString(); String s = (o instanceof String) ? (String) o : o.toString();
return DigestUtils.shaHex(s); return DigestUtils.shaHex(s);
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the SHA-1 hash of s"); writer.key("description"); writer.value("Returns the SHA-1 hash of s");
writer.key("params"); writer.value("string s"); writer.key("params"); writer.value("string s");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,24 +11,24 @@ import com.metaweb.gridworks.gel.Function;
public class Split implements Function { public class Split implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2) { if (args.length == 2) {
Object v = args[0]; Object v = args[0];
Object split = args[1]; Object split = args[1];
if (v != null && split != null && split instanceof String) { if (v != null && split != null && split instanceof String) {
return (v instanceof String ? (String) v : v.toString()).split((String) split); return (v instanceof String ? (String) v : v.toString()).split((String) split);
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns the array of strings obtained by splitting s with separator sep"); 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("params"); writer.value("string s, string sep");
writer.key("returns"); writer.value("array"); writer.key("returns"); writer.value("array");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -12,24 +12,24 @@ import com.metaweb.gridworks.gel.Function;
public class SplitByCharType implements Function { public class SplitByCharType implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1) { if (args.length == 1) {
Object o = args[0]; Object o = args[0];
if (o != null) { if (o != null) {
String s = (o instanceof String) ? (String) o : o.toString(); String s = (o instanceof String) ? (String) o : o.toString();
return StringUtils.splitByCharacterType(s); return StringUtils.splitByCharacterType(s);
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); 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("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("params"); writer.value("string s");
writer.key("returns"); writer.value("array"); writer.key("returns"); writer.value("array");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,23 +11,23 @@ import com.metaweb.gridworks.gel.Function;
public class StartsWith implements Function { public class StartsWith implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 2) { if (args.length == 2) {
Object s1 = args[0]; Object s1 = args[0];
Object s2 = args[1]; Object s2 = args[1];
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) { if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
return ((String) s1).startsWith((String) s2); return ((String) s1).startsWith((String) s2);
} }
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns whether s starts with sub"); writer.key("description"); writer.value("Returns whether s starts with sub");
writer.key("params"); writer.value("string s, string sub"); writer.key("params"); writer.value("string s, string sub");
writer.key("returns"); writer.value("boolean"); writer.key("returns"); writer.value("boolean");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,21 +11,21 @@ import com.metaweb.gridworks.gel.Function;
public class ToLowercase implements Function { public class ToLowercase implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null) { if (args.length == 1 && args[0] != null) {
Object o = args[0]; Object o = args[0];
return (o instanceof String ? (String) o : o.toString()).toLowerCase(); return (o instanceof String ? (String) o : o.toString()).toLowerCase();
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns s converted to lowercase"); writer.key("description"); writer.value("Returns s converted to lowercase");
writer.key("params"); writer.value("string s"); writer.key("params"); writer.value("string s");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,36 +11,36 @@ import com.metaweb.gridworks.gel.Function;
public class ToTitlecase implements Function { public class ToTitlecase implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null) { if (args.length == 1 && args[0] != null) {
Object o = args[0]; Object o = args[0];
String s = o instanceof String ? (String) o : o.toString(); String s = o instanceof String ? (String) o : o.toString();
String[] words = s.split("\\s+"); String[] words = s.split("\\s+");
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (int i = 0; i < words.length; i++) { for (int i = 0; i < words.length; i++) {
String word = words[i]; String word = words[i];
if (word.length() > 0) { if (word.length() > 0) {
if (sb.length() > 0) { if (sb.length() > 0) {
sb.append(' '); sb.append(' ');
} }
sb.append(word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase()); sb.append(word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase());
} }
} }
return sb.toString(); return sb.toString();
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns s converted to titlecase"); writer.key("description"); writer.value("Returns s converted to titlecase");
writer.key("params"); writer.value("string s"); writer.key("params"); writer.value("string s");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -11,21 +11,21 @@ import com.metaweb.gridworks.gel.Function;
public class ToUppercase implements Function { public class ToUppercase implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null) { if (args.length == 1 && args[0] != null) {
Object o = args[0]; Object o = args[0];
return (o instanceof String ? (String) o : o.toString()).toUpperCase(); return (o instanceof String ? (String) o : o.toString()).toUpperCase();
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns s converted to uppercase"); writer.key("description"); writer.value("Returns s converted to uppercase");
writer.key("params"); writer.value("string s"); writer.key("params"); writer.value("string s");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -9,22 +9,22 @@ import com.metaweb.gridworks.gel.Function;
public class Trim implements Function { public class Trim implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1) { if (args.length == 1) {
Object s1 = args[0]; Object s1 = args[0];
if (s1 != null && s1 instanceof String) { if (s1 != null && s1 instanceof String) {
return ((String) s1).trim(); return ((String) s1).trim();
} }
} }
return null; return null;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns copy of the string, with leading and trailing whitespace omitted."); 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("params"); writer.value("string s");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -9,26 +9,26 @@ import com.metaweb.gridworks.gel.Function;
public class Unicode implements Function { public class Unicode implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null) { if (args.length == 1 && args[0] != null) {
Object o = args[0]; Object o = args[0];
String s = (o instanceof String) ? (String) o : o.toString(); String s = (o instanceof String) ? (String) o : o.toString();
Integer[] output = new Integer[s.length()]; Integer[] output = new Integer[s.length()];
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < s.length(); i++) {
output[i] = s.codePointAt(i); output[i] = s.codePointAt(i);
} }
return output; return output;
} }
return null; return null;
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns an array of strings describing each character of s in their full unicode notation"); 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("params"); writer.value("string s");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

View File

@ -9,63 +9,63 @@ import com.metaweb.gridworks.gel.Function;
public class UnicodeType implements Function { public class UnicodeType implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 1 && args[0] != null) { if (args.length == 1 && args[0] != null) {
Object o = args[0]; Object o = args[0];
String s = (o instanceof String) ? (String) o : o.toString(); String s = (o instanceof String) ? (String) o : o.toString();
String[] output = new String[s.length()]; String[] output = new String[s.length()];
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < s.length(); i++) {
output[i] = translateType(Character.getType(s.codePointAt(i))); output[i] = translateType(Character.getType(s.codePointAt(i)));
} }
return output; return output;
} }
return null; return null;
} }
private String translateType(int type) { private String translateType(int type) {
switch(type) { switch(type) {
case 0: return "unassigned"; case 0: return "unassigned";
case 1: return "uppercase letter"; case 1: return "uppercase letter";
case 2: return "lowercase letter"; case 2: return "lowercase letter";
case 3: return "titlecase letter"; case 3: return "titlecase letter";
case 4: return "modifier letter"; case 4: return "modifier letter";
case 5: return "other letter"; case 5: return "other letter";
case 6: return "non spacing mark"; case 6: return "non spacing mark";
case 7: return "enclosing mark"; case 7: return "enclosing mark";
case 8: return "combining spacing mark"; case 8: return "combining spacing mark";
case 9: return "decimal digit number"; case 9: return "decimal digit number";
case 10: return "letter number"; case 10: return "letter number";
case 11: return "other number"; case 11: return "other number";
case 12: return "space separator"; case 12: return "space separator";
case 13: return "line separator"; case 13: return "line separator";
case 14: return "paragraph separator"; case 14: return "paragraph separator";
case 15: return "control"; case 15: return "control";
case 16: return "format"; case 16: return "format";
// 17 does not seem to be used // 17 does not seem to be used
case 18: return "private use"; case 18: return "private use";
case 19: return "surrogate"; case 19: return "surrogate";
case 20: return "dash punctuation"; case 20: return "dash punctuation";
case 21: return "start punctuation"; case 21: return "start punctuation";
case 22: return "end punctuation"; case 22: return "end punctuation";
case 23: return "connector punctuation"; case 23: return "connector punctuation";
case 24: return "other punctuation"; case 24: return "other punctuation";
case 25: return "math symbol"; case 25: return "math symbol";
case 26: return "currency symbol"; case 26: return "currency symbol";
case 27: return "modifier symbol"; case 27: return "modifier symbol";
case 28: return "other symbol"; case 28: return "other symbol";
case 29: return "initial quote punctuation"; case 29: return "initial quote punctuation";
case 30: return "final quote punctuation"; case 30: return "final quote punctuation";
default: return "unknown"; default: return "unknown";
} }
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("description"); writer.value("Returns an array of strings describing each character of s in their full unicode notation"); 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("params"); writer.value("string s");
writer.key("returns"); writer.value("string"); writer.key("returns"); writer.value("string");
writer.endObject(); writer.endObject();
} }
} }

Some files were not shown because too many files have changed in this diff Show More