Documented expr.* packages.

Converted some tabs into spaces.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@332 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-03-22 00:54:56 +00:00
parent 60f60507f7
commit 60dd7eab82
14 changed files with 174 additions and 140 deletions

View File

@ -8,6 +8,12 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable;
/**
* An error that occurs during the evaluation of an Evaluable. Errors are values, too
* because they can be stored in cells just like strings, numbers, etc. Errors are not
* thrown because an error might occupy just one element in an array and doesn't need
* to make the whole array erroneous.
*/
public class EvalError implements Serializable, Jsonizable {
private static final long serialVersionUID = -102681220092874080L;

View File

@ -2,6 +2,15 @@ package com.metaweb.gridworks.expr;
import java.util.Properties;
/**
* Interface for evaluable expressions in any arbitrary language.
*/
public interface Evaluable {
/**
* Evaluate this expression in the given environment (bindings).
*
* @param bindings
* @return
*/
public Object evaluate(Properties bindings);
}

View File

@ -65,9 +65,11 @@ public class ExpressionUtils {
static public boolean sameValue(Object v1, Object v2) {
if (v1 == null) {
return (v2 == null) || (v2 instanceof String && ((String) v2).length() == 0);
return (v2 == null)
|| (v2 instanceof String && ((String) v2).length() == 0);
} else if (v2 == null) {
return (v1 == null) || (v1 instanceof String && ((String) v1).length() == 0);
return (v1 == null)
|| (v1 instanceof String && ((String) v1).length() == 0);
} else {
return v1.equals(v2);
}

View File

@ -2,6 +2,10 @@ package com.metaweb.gridworks.expr;
import java.util.Properties;
/**
* Interface for objects that have named fields, which can be retrieved using the
* dot notation or the bracket notation, e.g., cells.Country, cells["Type of Disaster"].
*/
public interface HasFields {
public Object getField(String name, Properties bindings);
}

View File

@ -5,11 +5,11 @@ import java.util.Properties;
import org.python.core.PyObject;
import org.python.core.PyString;
public class JythonHasFieldsWrapper extends PyObject {
private static final long serialVersionUID = -1275353513262385099L;
public HasFields _obj;
private Properties _bindings;
public JythonHasFieldsWrapper(HasFields obj, Properties bindings) {

View File

@ -8,6 +8,15 @@ import clojure.lang.IFn;
import com.metaweb.gridworks.gel.Parser;
abstract public class MetaParser {
/**
* Parse an expression that might have a language prefix into an Evaluable.
* Expressions without valid prefixes or without any prefix are assumed to be
* GEL expressions.
*
* @param s
* @return
* @throws ParsingException
*/
static public Evaluable parse(String s) throws ParsingException {
String language = "gel";

View File

@ -1,6 +1,7 @@
package com.metaweb.gridworks.expr.functions;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Properties;
@ -20,18 +21,21 @@ public class Type implements Function {
if (v != null) {
if (v instanceof String) {
return "string";
} else if (v instanceof Calendar) {
} else if (v instanceof Calendar || v instanceof Date) {
return "date";
} else if (v instanceof Number) {
return "number";
} else if (v.getClass().isArray() || v instanceof List<?>) {
return "array";
} else if (v instanceof EvalError) {
return "error";
} else {
return v.getClass().getName();
}
}
return "undefined";
}
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a parameter");
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects one argument");
}
public void write(JSONWriter writer, Properties options)