|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object prefuse.data.expression.parser.ExpressionParser
public class ExpressionParser
Parser for statements written in the prefuse expression language. Text
expression are parsed into Expression
instances, and can be used as predicates or to create derived
table columns. This parser is implemented using the
JavaCC package. To parse
a text String to an Expression
, use
the parse(String)
method. If a parse error occurs, the method
will fail silently and return null. Any generated exception can be
later retrieved using the getError()
method. One can also
use the parse(String, boolean)
with a true
boolean argument to request that Exceptions be thrown when
errors occur.
The prefuse expression language provides a convenient way of creating manipulable statements
over data in a prefuse data structure. For example, the expression language can be used to
write Predicate
instances for querying and filtering a table
or graph, or to create arbitrary expressions over a data set to generate new, derived data
fields that can in turn be subject to additional processing or visualization. For example,
the TupleSet.tuples(prefuse.data.expression.Predicate)
method
uses a Predicate to filter the requested set of tuples, and the
Table.addColumn(java.lang.String,prefuse.data.expression.Expression)
method creates a new table column whose values are generated by the provided Expression.
The expression machinery is used
throughout the toolkit -- it underlies the filtering and query optimization features,
is a key component of dynamic query bindings
, and is used to
create the rule chains evaluated by the
DefaultRendererFactory
,
ColorAction
,
ShapeAction
,
FontAction
, and
SizeAction
classes.
The Expression
interface is quite simple: given a single
Tuple, compute and return a value. The returned value could be an Object, a boolean, an int,
or other primitive type. Individual methods for each type are available, and which ones are
legal to call for any given Expression depends on the type of Expression.
Expressions can be created directly in Java, by instantiating and chaining together the
desired Expression instances. This process, however, can be somewhat tedious, so prefuse
also provides a built-in parser/compiler for generating these chains of Expression
instances from a textual language. The language is based on a subset of SQL, the
standard language for database queries. If you have ever written a "WHERE" clause in
a SQL "SELECT" query, you probably know most of the language already. To parse an
expression, simply pass a text string containing an expression statement to the
parse(java.lang.String)
method. If the string parses successfully, the parsed Expression instance will be
returned.
Below is the reference for the language, including literal types, data field references,
basic operators, and included functions. If need be, you can also introduce a new
function by creating a new instance of the Function
interface
and registering it with the FunctionTable
class.
All keywords and functions in the prefuse expression language can be written in either uppercase or lowercase. Writing in mixed-case, however, will likely result in parse errors.
The fundamental building blocks of the expression language, representing data values or referencing the contents of a Tuple data field.
TRUE, FALSE
)boolean
1, -5, 12340
)int
1L, -5L, 12340L
)long
1.0, 3.1415, 1e-35, 2.3e6
)double
1.0f, 3.1415f, 1e-35f, 2.3e6f
)float
"some text", 'a label'
)String
literals
null
)null
is parsed as an ObjectLiteral of type null.
_strokeColor, [a data field]
)true
parses to a boolean literal while
[true]
parses to a reference to a data field named 'true'.
Basic operators and control flow structures for the expression language.
x + y
(addition)x
and y
x - y
(subtraction)y
from x
x * y
(multiplication)x
and y
x / y
(division)x
by y
x ^ y
(exponentiation, pow)x
to the exponent y
x % y
(modulo)x
divded by y
x = y, x == y
(equality)x
and y
are equal
x != y, x <> y
(inequality)x
and y
are not equal
x > y
(greater than)x
is greater than y
x >= y
(greater than or equal to)x
is greater than or equal to y
x < y
(less than)x
is less than y
x <= y
(less than or equal to)x
is less than or equal to y
x AND y, x && y
(and)x
and y
are true
x OR y, x || y
(or)x
or y
is true
NOT x, !x
(not)x
is true
x XOR y
(exclusive or)x
or y
is true
IF test THEN x ELSE y
(if-then-else)test
, and if true evaluates and returns the
expression x
, and if false evaluates and returns the expression
y
()
(parentheses)1+2*3
evaluates to 7
, while (1+2)*3
evaluates
to 9
.
General purpose functions.
ROW()
ISNODE()
ISEDGE()
DEGREE()
INDEGREE()
OUTDEGREE()
CHILDCOUNT()
Graph.getSpanningTree()
for more.
TREEDEPTH()
Graph.getSpanningTree()
for
more.
Functions for performing mathematical calculations.
ABS(x)
x
ACOS(x)
x
ASIN(x)
x
ATAN(x)
x
ATAN2(y, x)
x
, y
return the polar coordinate angle theta
CEIL(x), CEILING(x)
x
.
COS(x)
x
COT(x)
x
DEGREES(x)
x
from radians to degrees
EXP(x)
x
power
FLOOR(x)
x
.
LOG(x), LOG(b, x)
x
x
for the provided base b
LOG2(x)
x
LOG10(x)
x
MAX(a, b, c, ...)
MIN(a, b, c, ...)
MOD(x, y)
x
modulo y
(the remainder of x
divided by y
)
PI()
POW(x, y), POWER(x, y)
x
raised to the exponent y
RADIANS(x)
x
from degrees to radians
RAND()
ROUND(x)
x
rounded to the nearest integer
SIGN(x)
x
: 1 for positive, -1 for negative
SIN(x)
x
SQRT(x)
x
SUM(a, b, c, ...)
TAN(x)
x
SAFELOG10(x)
x
, equivalent to
SIGN(x) * LOG10(ABS(x))
SAFESQRT(x)
x
, equivalent to
SIGN(x) * SQRT(ABS(x))
Functions for processing text strings.
CAP(str)
str
. Individual words/names will be given
uppercase first letters, with all other letters in lowercase.
CONCAT(a, b, c, ...)
CONCAT_WS(sep, a, b, c, ...)
sep
between each of the other arguments
FORMAT(x, d)
x
as a string of the type "#,###.##", showing d
decimal places
INSERT(str, pos, len, newstr)
len
starting at position pos
in input
string str
with the string newstr
LEFT(str, len)
len
characters of string str
LENGTH(str)
str
LOWER(str), LCASE(str)
str
mapped to lowercase letters
LPAD(str, len, pad)
str
with copies of string pad
,
up to a total padding of len
characters
MID(str, pos, len)
str
of length len
, starting at
position pos
POSITION(substr, str)
substr
in the string str
. Returns -1 if the substring is not found.
REVERSE(str)
str
REPEAT(str, count)
str
repeated count
times
REPLACE(str, orig, replace)
str
in which all occurrences of orig
have been
replaced by replace
RIGHT(str, len)
len
rightmost characters of string str
RPAD(x)
str
with copies of string pad
,
up to a total padding of len
characters
SPACE(n)
n
whitespace characters
SUBSTRING(str,pos), SUBSTRING(str,pos,len)
str
starting at position
pos
and continuing to the end of the string.str
of length len
,
beginning at position pos
UPPER(str), UCASE(str
str
mapped to uppercase letters
Functions for generating, translating, and interpolating color values.
RGB(r, g, b)
RGBA(r, g, b, a)
GRAY(v)
v
HEX(hex)
hex
HSB(h, s, b)
hue
), saturation (s
), and brightness
(b
) color space values (as floating point numbers between 0 and 1) to
an integer representing an RGB color value
HSBA(h, s, b, a)
hue
), saturation (s
), brightness
(b
), and alpha (a
) color space values (as floating point
numbers between 0 and 1) to an integer representing an RGBA color value
COLORINTERP(c1, c2, f)
c1
and
c2
determined by the mixing proportion f
, a value
between 0 and 1
These functions can only be used when the Tuple being evaluated is
a VisualItem, and provide access to data group information of the VisualItem's
Visualization. Individual visual data fields can be accessed directly using
a data field reference. For example, _x
, _y
,
_hover
, _highlight
, _fillColor
would
evaluate to references for the x-coordinate, y-coordinate, mouse hover status,
highlight status, and fill color, respectively.
GROUPSIZE(group)
group
INGROUP(group)
group
MATCH(group, includeAll)
INGROUP(group)
, but also includes a possible special case when no
query has been issued and all items should be counted as "matches" (indicated
by includeAll
being true).
QUERY(group)
group
VISIBLE()
_visible
VALIDATED()
_validated
Field Summary | |
---|---|
static Token |
jj_nt
|
static Token |
token
|
static ExpressionParserTokenManager |
token_source
|
Fields inherited from interface prefuse.data.expression.parser.ExpressionParserConstants |
---|
ADD, AND, DECIMAL_LITERAL, DEFAULT, DIGIT, DIV, DOUBLE, ELSE, EOF, EQ, EXPONENT, FALSE, FLOAT, GE, GT, HEX_LITERAL, IDENTIFIER, IF, INT, LE, LETTER, LONG, LPAREN, LT, MOD, MUL, NE, NOT, NULL, OCTAL_LITERAL, OR, POW, QUOTED, RPAREN, STRING, SUB, THEN, tokenImage, TRUE, XOR |
Constructor Summary | |
---|---|
ExpressionParser(ExpressionParserTokenManager tm)
|
|
ExpressionParser(java.io.InputStream stream)
|
|
ExpressionParser(java.io.Reader stream)
|
Method Summary | |
---|---|
static Expression |
AdditiveExpression()
|
static Expression |
AndExpression()
|
static void |
disable_tracing()
|
static void |
enable_tracing()
|
static Expression |
EqualityExpression()
|
static Expression |
Expression()
|
static ParseException |
generateParseException()
|
static java.lang.Throwable |
getError()
Get the last error, if any, generated by a parse operation. |
static Token |
getNextToken()
|
static Token |
getToken(int index)
|
static Expression |
Identifier()
|
static Expression |
IfStatement()
|
static Expression |
Literal()
|
static Expression |
MultiplicativeExpression()
|
static java.lang.String |
Name()
|
static Expression |
OrExpression()
|
static Expression |
Parse()
|
static Expression |
parse(java.lang.String expr)
Parse an expression. |
static Expression |
parse(java.lang.String expr,
boolean throwsException)
Parse an expression. |
static Predicate |
predicate(java.lang.String expr)
Parse an expression as a predicate. |
static Expression |
PrimaryExpression()
|
static java.lang.String |
Quoted()
|
void |
ReInit(ExpressionParserTokenManager tm)
|
static void |
ReInit(java.io.InputStream stream)
|
static void |
ReInit(java.io.Reader stream)
|
static Expression |
RelationalExpression()
|
static Expression |
UnaryExpression()
|
static Expression |
UnaryExpressionNotPlusMinus()
|
static Expression |
XorExpression()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static ExpressionParserTokenManager token_source
public static Token token
public static Token jj_nt
Constructor Detail |
---|
public ExpressionParser(java.io.InputStream stream)
public ExpressionParser(java.io.Reader stream)
public ExpressionParser(ExpressionParserTokenManager tm)
Method Detail |
---|
public static Expression parse(java.lang.String expr, boolean throwsException)
expr
- the expression text to parsethrowsException
- true if this method should throw an
exception if an error occurs or should fail quietly
public static Expression parse(java.lang.String expr)
getError()
to access any
generated exceptions.
expr
- the expression text to parse
public static Predicate predicate(java.lang.String expr)
getError()
to access
any generated exceptions.
expr
- the expression text to parse
public static java.lang.Throwable getError()
public static final java.lang.String Name() throws ParseException
ParseException
public static final java.lang.String Quoted() throws ParseException
ParseException
public static final Expression Parse() throws ParseException
ParseException
public static final Expression Expression() throws ParseException
ParseException
public static final Expression OrExpression() throws ParseException
ParseException
public static final Expression XorExpression() throws ParseException
ParseException
public static final Expression AndExpression() throws ParseException
ParseException
public static final Expression EqualityExpression() throws ParseException
ParseException
public static final Expression RelationalExpression() throws ParseException
ParseException
public static final Expression AdditiveExpression() throws ParseException
ParseException
public static final Expression MultiplicativeExpression() throws ParseException
ParseException
public static final Expression UnaryExpression() throws ParseException
ParseException
public static final Expression UnaryExpressionNotPlusMinus() throws ParseException
ParseException
public static final Expression PrimaryExpression() throws ParseException
ParseException
public static final Expression Literal() throws ParseException
ParseException
public static final Expression Identifier() throws ParseException
ParseException
public static final Expression IfStatement() throws ParseException
ParseException
public static void ReInit(java.io.InputStream stream)
public static void ReInit(java.io.Reader stream)
public void ReInit(ExpressionParserTokenManager tm)
public static final Token getNextToken()
public static final Token getToken(int index)
public static ParseException generateParseException()
public static final void enable_tracing()
public static final void disable_tracing()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |